react-native-ble-nitro 1.0.0-alpha.1 → 1.0.0-beta.0
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.
- package/lib/BleManagerCompatFactory.d.ts +7 -6
- package/lib/BleManagerCompatFactory.js +3 -3
- package/lib/BleManagerFactory.d.ts +2 -2
- package/lib/compatibility/constants.d.ts +1 -1
- package/lib/compatibility/constants.js +1 -1
- package/lib/compatibility/deviceWrapper.d.ts +2 -2
- package/lib/compatibility/deviceWrapper.js +2 -2
- package/lib/compatibility/enums.d.ts +34 -39
- package/lib/compatibility/enums.js +126 -91
- package/lib/compatibility/index.d.ts +5 -4
- package/lib/compatibility/index.js +5 -5
- package/lib/compatibility/serviceData.d.ts +1 -1
- package/lib/errors/BleError.d.ts +2 -2
- package/lib/errors/BleError.js +1 -1
- package/lib/index.d.ts +9 -7
- package/lib/index.js +8 -6
- package/lib/specs/BleManager.nitro.d.ts +1 -1
- package/lib/specs/Characteristic.nitro.d.ts +1 -1
- package/lib/specs/Descriptor.nitro.d.ts +1 -1
- package/lib/specs/Device.nitro.d.ts +1 -1
- package/lib/specs/Service.nitro.d.ts +1 -1
- package/package.json +3 -2
- package/src/BleManagerCompatFactory.ts +12 -14
- package/src/BleManagerFactory.ts +2 -2
- package/src/__tests__/BleManager.test.ts +7 -7
- package/src/__tests__/compatibility/enums.test.ts +105 -94
- package/src/compatibility/constants.ts +1 -1
- package/src/compatibility/deviceWrapper.ts +4 -4
- package/src/compatibility/enums.ts +146 -116
- package/src/compatibility/index.ts +13 -5
- package/src/compatibility/serviceData.ts +1 -1
- package/src/errors/BleError.ts +2 -2
- package/src/index.ts +19 -7
- package/src/specs/BleManager.nitro.ts +1 -1
- package/src/specs/Characteristic.nitro.ts +1 -1
- package/src/specs/Descriptor.nitro.ts +1 -1
- package/src/specs/Device.nitro.ts +1 -1
- package/src/specs/Service.nitro.ts +1 -1
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* by wrapping the Nitro implementation with compatibility shims
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import { createBleManager } from './BleManagerFactory';
|
|
9
|
-
import type { BleManager as BleManagerInterface } from './specs/BleManager.nitro';
|
|
8
|
+
import { createBleManager } from './BleManagerFactory.js';
|
|
9
|
+
import type { BleManager as BleManagerInterface } from './specs/BleManager.nitro.js';
|
|
10
10
|
import type {
|
|
11
11
|
BleManagerOptions,
|
|
12
12
|
UUID,
|
|
@@ -20,20 +20,18 @@ import type {
|
|
|
20
20
|
NativeCharacteristic,
|
|
21
21
|
NativeDescriptor,
|
|
22
22
|
LogLevel,
|
|
23
|
-
State,
|
|
24
23
|
Subscription
|
|
25
|
-
} from './specs/types';
|
|
26
|
-
import { DeviceWrapper } from './compatibility/deviceWrapper';
|
|
24
|
+
} from './specs/types.js';
|
|
25
|
+
import { DeviceWrapper } from './compatibility/deviceWrapper.js';
|
|
27
26
|
import {
|
|
28
27
|
stateToString,
|
|
29
|
-
stringToState,
|
|
30
28
|
logLevelToString,
|
|
31
|
-
stringToLogLevel,
|
|
32
29
|
normalizeLogLevel,
|
|
33
30
|
normalizeCharacteristicSubscriptionType,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
State as PlxState,
|
|
32
|
+
LogLevel as PlxLogLevel
|
|
33
|
+
} from './compatibility/enums.js';
|
|
34
|
+
|
|
37
35
|
|
|
38
36
|
/**
|
|
39
37
|
* BleManager wrapper that provides react-native-ble-plx compatibility
|
|
@@ -51,13 +49,13 @@ export class BleManagerCompat {
|
|
|
51
49
|
}
|
|
52
50
|
|
|
53
51
|
// Common operations with compatibility
|
|
54
|
-
async setLogLevel(logLevel: LogLevel | string): Promise<
|
|
52
|
+
async setLogLevel(logLevel: LogLevel | string): Promise<PlxLogLevel> {
|
|
55
53
|
const normalizedLogLevel = normalizeLogLevel(logLevel);
|
|
56
54
|
const result = await this.bleManager.setLogLevel(normalizedLogLevel);
|
|
57
55
|
return logLevelToString(result);
|
|
58
56
|
}
|
|
59
57
|
|
|
60
|
-
async logLevel(): Promise<
|
|
58
|
+
async logLevel(): Promise<PlxLogLevel> {
|
|
61
59
|
const result = await this.bleManager.logLevel();
|
|
62
60
|
return logLevelToString(result);
|
|
63
61
|
}
|
|
@@ -77,13 +75,13 @@ export class BleManagerCompat {
|
|
|
77
75
|
return this;
|
|
78
76
|
}
|
|
79
77
|
|
|
80
|
-
async state(): Promise<
|
|
78
|
+
async state(): Promise<PlxState> {
|
|
81
79
|
const result = await this.bleManager.state();
|
|
82
80
|
return stateToString(result);
|
|
83
81
|
}
|
|
84
82
|
|
|
85
83
|
onStateChange(
|
|
86
|
-
listener: (newState:
|
|
84
|
+
listener: (newState: PlxState) => void,
|
|
87
85
|
emitCurrentState?: boolean
|
|
88
86
|
): Subscription {
|
|
89
87
|
return this.bleManager.onStateChange((state) => {
|
package/src/BleManagerFactory.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NitroModules } from 'react-native-nitro-modules';
|
|
2
|
-
import type { BleManager as BleManagerInterface } from './specs/BleManager.nitro';
|
|
3
|
-
import type { BleManagerOptions } from './specs/types';
|
|
2
|
+
import type { BleManager as BleManagerInterface } from './specs/BleManager.nitro.js';
|
|
3
|
+
import type { BleManagerOptions } from './specs/types.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Creates a BleManager instance using Nitro Modules
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* Copyright © 2025 Zyke (https://zyke.co)
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import { BleManager } from '../index';
|
|
8
|
-
import { State, LogLevel } from '../specs/types';
|
|
7
|
+
import { BleManager } from '../index.js';
|
|
8
|
+
import { State, LogLevel } from '../specs/types.js';
|
|
9
9
|
|
|
10
10
|
// Create a mock Nitro manager
|
|
11
11
|
const mockNitroManager = {
|
|
@@ -102,20 +102,20 @@ describe('BleManager', () => {
|
|
|
102
102
|
|
|
103
103
|
it('should set log level', async () => {
|
|
104
104
|
const result = await manager.setLogLevel(LogLevel.Info);
|
|
105
|
-
expect(result).toBe('Info'); // BleManagerCompat returns
|
|
105
|
+
expect(result).toBe('Info'); // BleManagerCompat returns PlxLogLevel for compatibility
|
|
106
106
|
});
|
|
107
107
|
|
|
108
108
|
it('should get current log level', async () => {
|
|
109
109
|
await manager.setLogLevel(LogLevel.Debug);
|
|
110
110
|
const level = await manager.logLevel();
|
|
111
|
-
expect(level).toBe('Info'); // BleManagerCompat returns
|
|
111
|
+
expect(level).toBe('Info'); // BleManagerCompat returns PlxLogLevel for compatibility
|
|
112
112
|
});
|
|
113
113
|
});
|
|
114
114
|
|
|
115
115
|
describe('State Management', () => {
|
|
116
116
|
it('should get current state', async () => {
|
|
117
117
|
const state = await manager.state();
|
|
118
|
-
expect(state).toBe('PoweredOn'); // BleManagerCompat converts State.PoweredOn -> 'PoweredOn'
|
|
118
|
+
expect(state).toBe('PoweredOn'); // BleManagerCompat converts State.PoweredOn -> PlxState 'PoweredOn'
|
|
119
119
|
});
|
|
120
120
|
|
|
121
121
|
it('should listen to state changes', async () => {
|
|
@@ -314,10 +314,10 @@ describe('Device Wrapper Compatibility', () => {
|
|
|
314
314
|
expect(typeof device.discoverAllServicesAndCharacteristics).toBe('function');
|
|
315
315
|
});
|
|
316
316
|
|
|
317
|
-
it('should convert enum values to
|
|
317
|
+
it('should convert enum values to PlxState for compatibility', async () => {
|
|
318
318
|
const state = await manager.state();
|
|
319
319
|
|
|
320
|
-
// State should be
|
|
320
|
+
// State should be PlxState string literal type (mocked return value is 'PoweredOn')
|
|
321
321
|
expect(typeof state).toBe('string');
|
|
322
322
|
expect(state).toBe('PoweredOn');
|
|
323
323
|
|
|
@@ -13,59 +13,66 @@ import {
|
|
|
13
13
|
stringToCharacteristicSubscriptionType,
|
|
14
14
|
normalizeState,
|
|
15
15
|
normalizeLogLevel,
|
|
16
|
-
normalizeCharacteristicSubscriptionType
|
|
16
|
+
normalizeCharacteristicSubscriptionType,
|
|
17
|
+
State,
|
|
18
|
+
LogLevel,
|
|
19
|
+
type CharacteristicSubscriptionType
|
|
17
20
|
} from '../../compatibility/enums';
|
|
18
|
-
import {
|
|
21
|
+
import {
|
|
22
|
+
State as NitroState,
|
|
23
|
+
LogLevel as NitroLogLevel,
|
|
24
|
+
CharacteristicSubscriptionType as NitroCharacteristicSubscriptionType
|
|
25
|
+
} from '../../specs/types';
|
|
19
26
|
|
|
20
27
|
describe('State Enum Conversions', () => {
|
|
21
28
|
describe('stateToString', () => {
|
|
22
29
|
it('should convert numeric state values to strings', () => {
|
|
23
|
-
expect(stateToString(
|
|
24
|
-
expect(stateToString(
|
|
25
|
-
expect(stateToString(
|
|
26
|
-
expect(stateToString(
|
|
27
|
-
expect(stateToString(
|
|
28
|
-
expect(stateToString(
|
|
30
|
+
expect(stateToString(NitroState.Unknown)).toBe(State.Unknown);
|
|
31
|
+
expect(stateToString(NitroState.Resetting)).toBe(State.Resetting);
|
|
32
|
+
expect(stateToString(NitroState.Unsupported)).toBe(State.Unsupported);
|
|
33
|
+
expect(stateToString(NitroState.Unauthorized)).toBe(State.Unauthorized);
|
|
34
|
+
expect(stateToString(NitroState.PoweredOff)).toBe(State.PoweredOff);
|
|
35
|
+
expect(stateToString(NitroState.PoweredOn)).toBe(State.PoweredOn);
|
|
29
36
|
});
|
|
30
37
|
|
|
31
38
|
it('should handle invalid state values', () => {
|
|
32
|
-
expect(stateToString(999 as
|
|
33
|
-
expect(stateToString(-1 as
|
|
39
|
+
expect(stateToString(999 as NitroState)).toBe(State.Unknown);
|
|
40
|
+
expect(stateToString(-1 as NitroState)).toBe(State.Unknown);
|
|
34
41
|
});
|
|
35
42
|
});
|
|
36
43
|
|
|
37
44
|
describe('stringToState', () => {
|
|
38
45
|
it('should convert string state values to numeric enums', () => {
|
|
39
|
-
expect(stringToState('Unknown')).toBe(
|
|
40
|
-
expect(stringToState('Resetting')).toBe(
|
|
41
|
-
expect(stringToState('Unsupported')).toBe(
|
|
42
|
-
expect(stringToState('Unauthorized')).toBe(
|
|
43
|
-
expect(stringToState('PoweredOff')).toBe(
|
|
44
|
-
expect(stringToState('PoweredOn')).toBe(
|
|
46
|
+
expect(stringToState('Unknown')).toBe(NitroState.Unknown);
|
|
47
|
+
expect(stringToState('Resetting')).toBe(NitroState.Resetting);
|
|
48
|
+
expect(stringToState('Unsupported')).toBe(NitroState.Unsupported);
|
|
49
|
+
expect(stringToState('Unauthorized')).toBe(NitroState.Unauthorized);
|
|
50
|
+
expect(stringToState('PoweredOff')).toBe(NitroState.PoweredOff);
|
|
51
|
+
expect(stringToState('PoweredOn')).toBe(NitroState.PoweredOn);
|
|
45
52
|
});
|
|
46
53
|
|
|
47
54
|
it('should handle case insensitive conversion', () => {
|
|
48
|
-
expect(stringToState('
|
|
49
|
-
expect(stringToState('
|
|
50
|
-
expect(stringToState('
|
|
55
|
+
expect(stringToState('PoweredOn')).toBe(NitroState.PoweredOn);
|
|
56
|
+
expect(stringToState('PoweredOff')).toBe(NitroState.PoweredOff);
|
|
57
|
+
expect(stringToState('Unknown')).toBe(NitroState.Unknown);
|
|
51
58
|
});
|
|
52
59
|
|
|
53
60
|
it('should handle invalid string values', () => {
|
|
54
|
-
expect(stringToState('InvalidState')).toBe(
|
|
55
|
-
expect(stringToState('')).toBe(
|
|
56
|
-
expect(stringToState('null')).toBe(
|
|
61
|
+
expect(stringToState('InvalidState')).toBe(NitroState.Unknown);
|
|
62
|
+
expect(stringToState('')).toBe(NitroState.Unknown);
|
|
63
|
+
expect(stringToState('null')).toBe(NitroState.Unknown);
|
|
57
64
|
});
|
|
58
65
|
});
|
|
59
66
|
|
|
60
67
|
describe('normalizeState', () => {
|
|
61
68
|
it('should pass through numeric state values', () => {
|
|
62
|
-
expect(normalizeState(
|
|
63
|
-
expect(normalizeState(
|
|
69
|
+
expect(normalizeState(NitroState.PoweredOn)).toBe(NitroState.PoweredOn);
|
|
70
|
+
expect(normalizeState(NitroState.PoweredOff)).toBe(NitroState.PoweredOff);
|
|
64
71
|
});
|
|
65
72
|
|
|
66
73
|
it('should convert string state values to numeric', () => {
|
|
67
|
-
expect(normalizeState('PoweredOn' as any)).toBe(
|
|
68
|
-
expect(normalizeState('PoweredOff' as any)).toBe(
|
|
74
|
+
expect(normalizeState('PoweredOn' as any)).toBe(NitroState.PoweredOn);
|
|
75
|
+
expect(normalizeState('PoweredOff' as any)).toBe(NitroState.PoweredOff);
|
|
69
76
|
});
|
|
70
77
|
});
|
|
71
78
|
});
|
|
@@ -73,52 +80,52 @@ describe('State Enum Conversions', () => {
|
|
|
73
80
|
describe('LogLevel Enum Conversions', () => {
|
|
74
81
|
describe('logLevelToString', () => {
|
|
75
82
|
it('should convert numeric log level values to strings', () => {
|
|
76
|
-
expect(logLevelToString(
|
|
77
|
-
expect(logLevelToString(
|
|
78
|
-
expect(logLevelToString(
|
|
79
|
-
expect(logLevelToString(
|
|
80
|
-
expect(logLevelToString(
|
|
81
|
-
expect(logLevelToString(
|
|
83
|
+
expect(logLevelToString(NitroLogLevel.None)).toBe(LogLevel.None);
|
|
84
|
+
expect(logLevelToString(NitroLogLevel.Error)).toBe(LogLevel.Error);
|
|
85
|
+
expect(logLevelToString(NitroLogLevel.Warning)).toBe(LogLevel.Warning);
|
|
86
|
+
expect(logLevelToString(NitroLogLevel.Info)).toBe(LogLevel.Info);
|
|
87
|
+
expect(logLevelToString(NitroLogLevel.Debug)).toBe(LogLevel.Debug);
|
|
88
|
+
expect(logLevelToString(NitroLogLevel.Verbose)).toBe(LogLevel.Verbose);
|
|
82
89
|
});
|
|
83
90
|
|
|
84
91
|
it('should handle invalid log level values', () => {
|
|
85
|
-
expect(logLevelToString(999 as
|
|
86
|
-
expect(logLevelToString(-1 as
|
|
92
|
+
expect(logLevelToString(999 as NitroLogLevel)).toBe(LogLevel.None);
|
|
93
|
+
expect(logLevelToString(-1 as NitroLogLevel)).toBe(LogLevel.None);
|
|
87
94
|
});
|
|
88
95
|
});
|
|
89
96
|
|
|
90
97
|
describe('stringToLogLevel', () => {
|
|
91
98
|
it('should convert string log level values to numeric enums', () => {
|
|
92
|
-
expect(stringToLogLevel('None')).toBe(
|
|
93
|
-
expect(stringToLogLevel('Error')).toBe(
|
|
94
|
-
expect(stringToLogLevel('Warning')).toBe(
|
|
95
|
-
expect(stringToLogLevel('Info')).toBe(
|
|
96
|
-
expect(stringToLogLevel('Debug')).toBe(
|
|
97
|
-
expect(stringToLogLevel('Verbose')).toBe(
|
|
99
|
+
expect(stringToLogLevel('None')).toBe(NitroLogLevel.None);
|
|
100
|
+
expect(stringToLogLevel('Error')).toBe(NitroLogLevel.Error);
|
|
101
|
+
expect(stringToLogLevel('Warning')).toBe(NitroLogLevel.Warning);
|
|
102
|
+
expect(stringToLogLevel('Info')).toBe(NitroLogLevel.Info);
|
|
103
|
+
expect(stringToLogLevel('Debug')).toBe(NitroLogLevel.Debug);
|
|
104
|
+
expect(stringToLogLevel('Verbose')).toBe(NitroLogLevel.Verbose);
|
|
98
105
|
});
|
|
99
106
|
|
|
100
107
|
it('should handle case insensitive conversion', () => {
|
|
101
|
-
expect(stringToLogLevel('
|
|
102
|
-
expect(stringToLogLevel('
|
|
103
|
-
expect(stringToLogLevel('
|
|
108
|
+
expect(stringToLogLevel('Error')).toBe(NitroLogLevel.Error);
|
|
109
|
+
expect(stringToLogLevel('Warning')).toBe(NitroLogLevel.Warning);
|
|
110
|
+
expect(stringToLogLevel('Info')).toBe(NitroLogLevel.Info);
|
|
104
111
|
});
|
|
105
112
|
|
|
106
113
|
it('should handle invalid string values', () => {
|
|
107
|
-
expect(stringToLogLevel('InvalidLevel')).toBe(
|
|
108
|
-
expect(stringToLogLevel('')).toBe(
|
|
109
|
-
expect(stringToLogLevel('trace')).toBe(
|
|
114
|
+
expect(stringToLogLevel('InvalidLevel')).toBe(NitroLogLevel.None);
|
|
115
|
+
expect(stringToLogLevel('')).toBe(NitroLogLevel.None);
|
|
116
|
+
expect(stringToLogLevel('trace')).toBe(NitroLogLevel.None);
|
|
110
117
|
});
|
|
111
118
|
});
|
|
112
119
|
|
|
113
120
|
describe('normalizeLogLevel', () => {
|
|
114
121
|
it('should pass through numeric log level values', () => {
|
|
115
|
-
expect(normalizeLogLevel(
|
|
116
|
-
expect(normalizeLogLevel(
|
|
122
|
+
expect(normalizeLogLevel(NitroLogLevel.Debug)).toBe(NitroLogLevel.Debug);
|
|
123
|
+
expect(normalizeLogLevel(NitroLogLevel.Error)).toBe(NitroLogLevel.Error);
|
|
117
124
|
});
|
|
118
125
|
|
|
119
126
|
it('should convert string log level values to numeric', () => {
|
|
120
|
-
expect(normalizeLogLevel('Debug' as any)).toBe(
|
|
121
|
-
expect(normalizeLogLevel('Error' as any)).toBe(
|
|
127
|
+
expect(normalizeLogLevel('Debug' as any)).toBe(NitroLogLevel.Debug);
|
|
128
|
+
expect(normalizeLogLevel('Error' as any)).toBe(NitroLogLevel.Error);
|
|
122
129
|
});
|
|
123
130
|
});
|
|
124
131
|
});
|
|
@@ -126,48 +133,48 @@ describe('LogLevel Enum Conversions', () => {
|
|
|
126
133
|
describe('CharacteristicSubscriptionType Enum Conversions', () => {
|
|
127
134
|
describe('characteristicSubscriptionTypeToString', () => {
|
|
128
135
|
it('should convert numeric subscription type values to strings', () => {
|
|
129
|
-
expect(characteristicSubscriptionTypeToString(
|
|
130
|
-
expect(characteristicSubscriptionTypeToString(
|
|
136
|
+
expect(characteristicSubscriptionTypeToString(NitroCharacteristicSubscriptionType.Notification)).toBe('notification');
|
|
137
|
+
expect(characteristicSubscriptionTypeToString(NitroCharacteristicSubscriptionType.Indication)).toBe('indication');
|
|
131
138
|
});
|
|
132
139
|
|
|
133
140
|
it('should handle invalid subscription type values', () => {
|
|
134
|
-
expect(characteristicSubscriptionTypeToString(999 as
|
|
135
|
-
expect(characteristicSubscriptionTypeToString(-1 as
|
|
141
|
+
expect(characteristicSubscriptionTypeToString(999 as NitroCharacteristicSubscriptionType)).toBe('notification');
|
|
142
|
+
expect(characteristicSubscriptionTypeToString(-1 as NitroCharacteristicSubscriptionType)).toBe('notification');
|
|
136
143
|
});
|
|
137
144
|
});
|
|
138
145
|
|
|
139
146
|
describe('stringToCharacteristicSubscriptionType', () => {
|
|
140
147
|
it('should convert string subscription type values to numeric enums', () => {
|
|
141
|
-
expect(stringToCharacteristicSubscriptionType('
|
|
142
|
-
expect(stringToCharacteristicSubscriptionType('
|
|
148
|
+
expect(stringToCharacteristicSubscriptionType('notification')).toBe(NitroCharacteristicSubscriptionType.Notification);
|
|
149
|
+
expect(stringToCharacteristicSubscriptionType('indication')).toBe(NitroCharacteristicSubscriptionType.Indication);
|
|
143
150
|
});
|
|
144
151
|
|
|
145
152
|
it('should handle case insensitive conversion', () => {
|
|
146
|
-
expect(stringToCharacteristicSubscriptionType('notification')).toBe(
|
|
147
|
-
expect(stringToCharacteristicSubscriptionType('
|
|
153
|
+
expect(stringToCharacteristicSubscriptionType('notification')).toBe(NitroCharacteristicSubscriptionType.Notification);
|
|
154
|
+
expect(stringToCharacteristicSubscriptionType('indication')).toBe(NitroCharacteristicSubscriptionType.Indication);
|
|
148
155
|
});
|
|
149
156
|
|
|
150
157
|
it('should handle invalid string values', () => {
|
|
151
|
-
expect(stringToCharacteristicSubscriptionType('InvalidType')).toBe(
|
|
152
|
-
expect(stringToCharacteristicSubscriptionType('')).toBe(
|
|
153
|
-
expect(stringToCharacteristicSubscriptionType('subscribe')).toBe(
|
|
158
|
+
expect(stringToCharacteristicSubscriptionType('InvalidType')).toBe(NitroCharacteristicSubscriptionType.Notification);
|
|
159
|
+
expect(stringToCharacteristicSubscriptionType('')).toBe(NitroCharacteristicSubscriptionType.Notification);
|
|
160
|
+
expect(stringToCharacteristicSubscriptionType('subscribe')).toBe(NitroCharacteristicSubscriptionType.Notification);
|
|
154
161
|
});
|
|
155
162
|
});
|
|
156
163
|
|
|
157
164
|
describe('normalizeCharacteristicSubscriptionType', () => {
|
|
158
165
|
it('should pass through numeric subscription type values', () => {
|
|
159
|
-
expect(normalizeCharacteristicSubscriptionType(
|
|
160
|
-
expect(normalizeCharacteristicSubscriptionType(
|
|
166
|
+
expect(normalizeCharacteristicSubscriptionType(NitroCharacteristicSubscriptionType.Indication)).toBe(NitroCharacteristicSubscriptionType.Indication);
|
|
167
|
+
expect(normalizeCharacteristicSubscriptionType(NitroCharacteristicSubscriptionType.Notification)).toBe(NitroCharacteristicSubscriptionType.Notification);
|
|
161
168
|
});
|
|
162
169
|
|
|
163
170
|
it('should convert string subscription type values to numeric', () => {
|
|
164
|
-
expect(normalizeCharacteristicSubscriptionType('
|
|
165
|
-
expect(normalizeCharacteristicSubscriptionType('
|
|
171
|
+
expect(normalizeCharacteristicSubscriptionType('indication' as any)).toBe(NitroCharacteristicSubscriptionType.Indication);
|
|
172
|
+
expect(normalizeCharacteristicSubscriptionType('notification' as any)).toBe(NitroCharacteristicSubscriptionType.Notification);
|
|
166
173
|
});
|
|
167
174
|
|
|
168
175
|
it('should handle legacy string values from react-native-ble-plx', () => {
|
|
169
|
-
expect(normalizeCharacteristicSubscriptionType('notification')).toBe(
|
|
170
|
-
expect(normalizeCharacteristicSubscriptionType('indication')).toBe(
|
|
176
|
+
expect(normalizeCharacteristicSubscriptionType('notification')).toBe(NitroCharacteristicSubscriptionType.Notification);
|
|
177
|
+
expect(normalizeCharacteristicSubscriptionType('indication')).toBe(NitroCharacteristicSubscriptionType.Indication);
|
|
171
178
|
});
|
|
172
179
|
});
|
|
173
180
|
});
|
|
@@ -176,28 +183,28 @@ describe('Backward Compatibility', () => {
|
|
|
176
183
|
it('should maintain compatibility with react-native-ble-plx string values', () => {
|
|
177
184
|
// Test that the old string-based API still works through normalization
|
|
178
185
|
const state1 = normalizeState('PoweredOn' as any);
|
|
179
|
-
const state2 = normalizeState(
|
|
186
|
+
const state2 = normalizeState(NitroState.PoweredOn);
|
|
180
187
|
expect(state1).toBe(state2);
|
|
181
188
|
|
|
182
189
|
const logLevel1 = normalizeLogLevel('Debug' as any);
|
|
183
|
-
const logLevel2 = normalizeLogLevel(
|
|
190
|
+
const logLevel2 = normalizeLogLevel(NitroLogLevel.Debug);
|
|
184
191
|
expect(logLevel1).toBe(logLevel2);
|
|
185
192
|
|
|
186
193
|
const subscriptionType1 = normalizeCharacteristicSubscriptionType('notification');
|
|
187
|
-
const subscriptionType2 = normalizeCharacteristicSubscriptionType(
|
|
194
|
+
const subscriptionType2 = normalizeCharacteristicSubscriptionType(NitroCharacteristicSubscriptionType.Notification);
|
|
188
195
|
expect(subscriptionType1).toBe(subscriptionType2);
|
|
189
196
|
});
|
|
190
197
|
|
|
191
198
|
it('should provide string representations for user-facing display', () => {
|
|
192
199
|
// Test that numeric enums can be converted back to user-friendly strings
|
|
193
|
-
expect(stateToString(
|
|
194
|
-
expect(logLevelToString(
|
|
195
|
-
expect(characteristicSubscriptionTypeToString(
|
|
200
|
+
expect(stateToString(NitroState.PoweredOn)).toBe(State.PoweredOn);
|
|
201
|
+
expect(logLevelToString(NitroLogLevel.Debug)).toBe(LogLevel.Debug);
|
|
202
|
+
expect(characteristicSubscriptionTypeToString(NitroCharacteristicSubscriptionType.Notification)).toBe('notification');
|
|
196
203
|
});
|
|
197
204
|
|
|
198
205
|
it('should handle edge cases gracefully', () => {
|
|
199
206
|
// Test that invalid values don't crash and default to reasonable fallbacks
|
|
200
|
-
expect(() => stateToString(999 as
|
|
207
|
+
expect(() => stateToString(999 as NitroState)).not.toThrow();
|
|
201
208
|
expect(() => stringToState('invalid')).not.toThrow();
|
|
202
209
|
expect(() => normalizeState(null as any)).not.toThrow();
|
|
203
210
|
expect(() => normalizeLogLevel(undefined as any)).not.toThrow();
|
|
@@ -206,28 +213,32 @@ describe('Backward Compatibility', () => {
|
|
|
206
213
|
|
|
207
214
|
describe('Enum Value Validation', () => {
|
|
208
215
|
it('should have correct numeric enum values', () => {
|
|
209
|
-
// Verify that our numeric enums match the expected values
|
|
210
|
-
expect(
|
|
211
|
-
expect(
|
|
212
|
-
expect(
|
|
213
|
-
expect(
|
|
214
|
-
expect(
|
|
215
|
-
expect(
|
|
216
|
-
|
|
217
|
-
expect(
|
|
218
|
-
expect(
|
|
219
|
-
expect(
|
|
220
|
-
expect(
|
|
221
|
-
expect(
|
|
222
|
-
expect(
|
|
223
|
-
|
|
224
|
-
expect(
|
|
225
|
-
expect(
|
|
216
|
+
// Verify that our numeric enums match the expected values
|
|
217
|
+
expect(NitroState.Unknown).toBe(0);
|
|
218
|
+
expect(NitroState.Resetting).toBe(1);
|
|
219
|
+
expect(NitroState.Unsupported).toBe(2);
|
|
220
|
+
expect(NitroState.Unauthorized).toBe(3);
|
|
221
|
+
expect(NitroState.PoweredOff).toBe(4);
|
|
222
|
+
expect(NitroState.PoweredOn).toBe(5);
|
|
223
|
+
|
|
224
|
+
expect(NitroLogLevel.None).toBe(0);
|
|
225
|
+
expect(NitroLogLevel.Verbose).toBe(1);
|
|
226
|
+
expect(NitroLogLevel.Debug).toBe(2);
|
|
227
|
+
expect(NitroLogLevel.Info).toBe(3);
|
|
228
|
+
expect(NitroLogLevel.Warning).toBe(4);
|
|
229
|
+
expect(NitroLogLevel.Error).toBe(5);
|
|
230
|
+
|
|
231
|
+
expect(NitroCharacteristicSubscriptionType.Notification).toBe(0);
|
|
232
|
+
expect(NitroCharacteristicSubscriptionType.Indication).toBe(1);
|
|
233
|
+
|
|
234
|
+
// Verify that our string enums match the expected values
|
|
235
|
+
expect(State.Unknown).toBe('Unknown');
|
|
236
|
+
expect(LogLevel.Debug).toBe('Debug');
|
|
226
237
|
});
|
|
227
238
|
|
|
228
239
|
it('should provide complete bidirectional conversion coverage', () => {
|
|
229
240
|
// Test that every enum value can be converted to string and back
|
|
230
|
-
const states = [
|
|
241
|
+
const states = [NitroState.Unknown, NitroState.Resetting, NitroState.Unsupported, NitroState.Unauthorized, NitroState.PoweredOff, NitroState.PoweredOn];
|
|
231
242
|
|
|
232
243
|
states.forEach(state => {
|
|
233
244
|
const stringValue = stateToString(state);
|
|
@@ -235,7 +246,7 @@ describe('Enum Value Validation', () => {
|
|
|
235
246
|
expect(backToNumber).toBe(state);
|
|
236
247
|
});
|
|
237
248
|
|
|
238
|
-
const logLevels = [
|
|
249
|
+
const logLevels = [NitroLogLevel.None, NitroLogLevel.Error, NitroLogLevel.Warning, NitroLogLevel.Info, NitroLogLevel.Debug, NitroLogLevel.Verbose];
|
|
239
250
|
|
|
240
251
|
logLevels.forEach(level => {
|
|
241
252
|
const stringValue = logLevelToString(level);
|
|
@@ -243,7 +254,7 @@ describe('Enum Value Validation', () => {
|
|
|
243
254
|
expect(backToNumber).toBe(level);
|
|
244
255
|
});
|
|
245
256
|
|
|
246
|
-
const subscriptionTypes = [
|
|
257
|
+
const subscriptionTypes = [NitroCharacteristicSubscriptionType.Notification, NitroCharacteristicSubscriptionType.Indication];
|
|
247
258
|
|
|
248
259
|
subscriptionTypes.forEach(type => {
|
|
249
260
|
const stringValue = characteristicSubscriptionTypeToString(type);
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Wraps Nitro Device objects to provide the original react-native-ble-plx API
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import type { Device as NitroDevice } from '../specs/Device.nitro';
|
|
7
|
+
import type { Device as NitroDevice } from '../specs/Device.nitro.js';
|
|
8
8
|
import type {
|
|
9
9
|
NativeDevice,
|
|
10
10
|
UUID,
|
|
@@ -19,13 +19,13 @@ import type {
|
|
|
19
19
|
NativeDescriptor,
|
|
20
20
|
CharacteristicSubscriptionType,
|
|
21
21
|
Subscription
|
|
22
|
-
} from '../specs/types';
|
|
23
|
-
import { serviceDataArrayToMap } from './serviceData';
|
|
22
|
+
} from '../specs/types.js';
|
|
23
|
+
import { serviceDataArrayToMap } from './serviceData.js';
|
|
24
24
|
import {
|
|
25
25
|
normalizeCharacteristicSubscriptionType,
|
|
26
26
|
stateToString,
|
|
27
27
|
characteristicSubscriptionTypeToString
|
|
28
|
-
} from './enums';
|
|
28
|
+
} from './enums.js';
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
31
|
* Device wrapper that provides react-native-ble-plx compatibility
|