@neurodevs/node-lsl 8.0.1 → 8.0.3

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 (51) hide show
  1. package/.vscode/settings.json +17 -20
  2. package/build/.spruce/errors/errors.types.js +0 -2
  3. package/build/.spruce/errors/errors.types.js.map +1 -1
  4. package/build/__tests__/behavioral/LslOutlet.test.js +9 -14
  5. package/build/__tests__/behavioral/LslOutlet.test.js.map +1 -1
  6. package/build/__tests__/behavioral/TimeMarkerOutlet.test.js.map +1 -1
  7. package/build/__tests__/implementation/Liblsl.test.js +17 -4
  8. package/build/__tests__/implementation/Liblsl.test.js.map +1 -1
  9. package/build/__tests__/support/consts.js.map +1 -1
  10. package/build/__tests__/support/generateRandomOutletOptions.js.map +1 -1
  11. package/build/assertions.js.map +1 -1
  12. package/build/consts.js.map +1 -1
  13. package/build/errors/SpruceError.d.ts +1 -1
  14. package/build/errors/SpruceError.js.map +1 -1
  15. package/build/errors/failedToLoadLiblsl.builder.js.map +1 -1
  16. package/build/implementations/Liblsl.js +22 -6
  17. package/build/implementations/Liblsl.js.map +1 -1
  18. package/build/implementations/LslOutlet.js +6 -14
  19. package/build/implementations/LslOutlet.js.map +1 -1
  20. package/build/implementations/TimeMarkerOutlet.js +4 -1
  21. package/build/implementations/TimeMarkerOutlet.js.map +1 -1
  22. package/build/nodeLsl.types.d.ts +2 -2
  23. package/build/testDoubles/FakeLiblsl.js.map +1 -1
  24. package/build/testDoubles/MockTimeMarkerOutlet.js.map +1 -1
  25. package/build/testDoubles/SpyExtendsTimeMarkerOutlet.js.map +1 -1
  26. package/build/testDoubles/SpyImplementsTimeMarkerOutlet.js.map +1 -1
  27. package/build/validations.js.map +1 -1
  28. package/eslint.config.mjs +3 -0
  29. package/package.json +26 -26
  30. package/src/.spruce/errors/errors.types.ts +0 -3
  31. package/src/__tests__/behavioral/LslOutlet.test.ts +272 -267
  32. package/src/__tests__/behavioral/TimeMarkerOutlet.test.ts +144 -141
  33. package/src/__tests__/implementation/Liblsl.test.ts +461 -438
  34. package/src/__tests__/support/consts.ts +22 -22
  35. package/src/__tests__/support/generateRandomOutletOptions.ts +13 -13
  36. package/src/assertions.ts +39 -39
  37. package/src/consts.ts +16 -16
  38. package/src/errors/SpruceError.ts +16 -16
  39. package/src/errors/failedToLoadLiblsl.builder.ts +8 -8
  40. package/src/implementations/Liblsl.ts +205 -181
  41. package/src/implementations/LslOutlet.ts +114 -114
  42. package/src/implementations/TimeMarkerOutlet.ts +50 -50
  43. package/src/nodeLsl.types.ts +60 -63
  44. package/src/testDoubles/FakeLiblsl.ts +58 -56
  45. package/src/testDoubles/MockTimeMarkerOutlet.ts +56 -56
  46. package/src/testDoubles/SpyExtendsTimeMarkerOutlet.ts +11 -11
  47. package/src/testDoubles/SpyImplementsTimeMarkerOutlet.ts +28 -28
  48. package/src/validations.ts +6 -6
  49. package/tsconfig.json +3 -4
  50. package/.eslintignore +0 -3
  51. package/.eslintrc.js +0 -3
@@ -1,34 +1,34 @@
1
1
  export const TEST_SUPPORTED_CHANNEL_FORMATS = ['float32', 'string'] as const
2
2
 
3
3
  export const TEST_UNSUPPORTED_CHANNEL_FORMATS = [
4
- 'undefined',
5
- 'double64',
6
- 'int32',
7
- 'int16',
8
- 'int8',
9
- 'int64',
4
+ 'undefined',
5
+ 'double64',
6
+ 'int32',
7
+ 'int16',
8
+ 'int8',
9
+ 'int64',
10
10
  ] as const
11
11
 
12
12
  export const TEST_CHANNEL_FORMATS = [
13
- 'undefined',
14
- 'float32',
15
- 'double64',
16
- 'string',
17
- 'int32',
18
- 'int16',
19
- 'int8',
20
- 'int64',
13
+ 'undefined',
14
+ 'float32',
15
+ 'double64',
16
+ 'string',
17
+ 'int32',
18
+ 'int16',
19
+ 'int8',
20
+ 'int64',
21
21
  ] as const
22
22
 
23
23
  export const TEST_CHANNEL_FORMATS_MAP = {
24
- undefined: 0,
25
- float32: 1,
26
- double64: 2,
27
- string: 3,
28
- int32: 4,
29
- int16: 5,
30
- int8: 6,
31
- int64: 7,
24
+ undefined: 0,
25
+ float32: 1,
26
+ double64: 2,
27
+ string: 3,
28
+ int32: 4,
29
+ int16: 5,
30
+ int8: 6,
31
+ int64: 7,
32
32
  }
33
33
 
34
34
  export type TestChannelFormat = (typeof TEST_CHANNEL_FORMATS)[number]
@@ -4,18 +4,18 @@ import { LslOutletOptions } from '../../nodeLsl.types'
4
4
  import { TEST_SUPPORTED_CHANNEL_FORMATS } from './consts'
5
5
 
6
6
  export default function generateRandomOutletOptions() {
7
- const randomChannelIdx = randomInt(TEST_SUPPORTED_CHANNEL_FORMATS.length)
7
+ const randomChannelIdx = randomInt(TEST_SUPPORTED_CHANNEL_FORMATS.length)
8
8
 
9
- return {
10
- name: generateId(),
11
- type: generateId(),
12
- channelNames: new Array(randomInt(1, 10)).fill(generateId()),
13
- sampleRate: Math.random() * 10,
14
- channelFormat: TEST_SUPPORTED_CHANNEL_FORMATS[randomChannelIdx],
15
- sourceId: generateId(),
16
- manufacturer: generateId(),
17
- unit: generateId(),
18
- chunkSize: randomInt(0, 10),
19
- maxBuffered: randomInt(0, 10),
20
- } as LslOutletOptions
9
+ return {
10
+ name: generateId(),
11
+ type: generateId(),
12
+ channelNames: new Array(randomInt(1, 10)).fill(generateId()),
13
+ sampleRate: Math.random() * 10,
14
+ channelFormat: TEST_SUPPORTED_CHANNEL_FORMATS[randomChannelIdx],
15
+ sourceId: generateId(),
16
+ manufacturer: generateId(),
17
+ unit: generateId(),
18
+ chunkSize: randomInt(0, 10),
19
+ maxBuffered: randomInt(0, 10),
20
+ } as LslOutletOptions
21
21
  }
package/src/assertions.ts CHANGED
@@ -2,58 +2,58 @@ import { SchemaError } from '@sprucelabs/schema'
2
2
  import { CHANNEL_FORMATS } from './consts'
3
3
  import { ChannelFormat } from './nodeLsl.types'
4
4
  import {
5
- isGreaterThanOrEqualToZero,
6
- isPositiveInteger,
7
- isPositiveIntegerOrZero,
8
- isStringInArray,
5
+ isGreaterThanOrEqualToZero,
6
+ isPositiveInteger,
7
+ isPositiveIntegerOrZero,
8
+ isStringInArray,
9
9
  } from './validations'
10
10
 
11
11
  export function assertValidMaxBuffered(maxBuffered: number) {
12
- if (!isPositiveIntegerOrZero(maxBuffered)) {
13
- throw new SchemaError({
14
- code: 'INVALID_PARAMETERS',
15
- parameters: ['maxBuffered'],
16
- friendlyMessage: 'Max buffered must be a positive integer or zero.',
17
- })
18
- }
12
+ if (!isPositiveIntegerOrZero(maxBuffered)) {
13
+ throw new SchemaError({
14
+ code: 'INVALID_PARAMETERS',
15
+ parameters: ['maxBuffered'],
16
+ friendlyMessage: 'Max buffered must be a positive integer or zero.',
17
+ })
18
+ }
19
19
  }
20
20
 
21
21
  export function assertValidChunkSize(chunkSize: number) {
22
- if (!isPositiveIntegerOrZero(chunkSize)) {
23
- throw new SchemaError({
24
- code: 'INVALID_PARAMETERS',
25
- parameters: ['chunkSize'],
26
- friendlyMessage: 'Chunk size must be a positive integer or zero.',
27
- })
28
- }
22
+ if (!isPositiveIntegerOrZero(chunkSize)) {
23
+ throw new SchemaError({
24
+ code: 'INVALID_PARAMETERS',
25
+ parameters: ['chunkSize'],
26
+ friendlyMessage: 'Chunk size must be a positive integer or zero.',
27
+ })
28
+ }
29
29
  }
30
30
 
31
31
  export function assertValidChannelFormat(channelFormat: ChannelFormat) {
32
- if (!isStringInArray(channelFormat, CHANNEL_FORMATS)) {
33
- throw new SchemaError({
34
- code: 'INVALID_PARAMETERS',
35
- parameters: ['channelFormat'],
36
- friendlyMessage: `Invalid `,
37
- })
38
- }
32
+ if (!isStringInArray(channelFormat, CHANNEL_FORMATS)) {
33
+ throw new SchemaError({
34
+ code: 'INVALID_PARAMETERS',
35
+ parameters: ['channelFormat'],
36
+ friendlyMessage: `Invalid `,
37
+ })
38
+ }
39
39
  }
40
40
 
41
41
  export function assertValidSampleRate(sampleRate: number) {
42
- if (!isGreaterThanOrEqualToZero(sampleRate)) {
43
- throw new SchemaError({
44
- code: 'INVALID_PARAMETERS',
45
- parameters: ['sampleRate'],
46
- friendlyMessage: 'Sample rate must be a positive number or zero.',
47
- })
48
- }
42
+ if (!isGreaterThanOrEqualToZero(sampleRate)) {
43
+ throw new SchemaError({
44
+ code: 'INVALID_PARAMETERS',
45
+ parameters: ['sampleRate'],
46
+ friendlyMessage: 'Sample rate must be a positive number or zero.',
47
+ })
48
+ }
49
49
  }
50
50
 
51
51
  export function assertValidChannelCount(channelCount: number) {
52
- if (!isPositiveInteger(channelCount)) {
53
- throw new SchemaError({
54
- code: 'INVALID_PARAMETERS',
55
- parameters: ['channelNames'],
56
- friendlyMessage: 'channelNames must have 1 or more labels.',
57
- })
58
- }
52
+ if (!isPositiveInteger(channelCount)) {
53
+ throw new SchemaError({
54
+ code: 'INVALID_PARAMETERS',
55
+ parameters: ['channelNames'],
56
+ friendlyMessage: 'channelNames must have 1 or more labels.',
57
+ })
58
+ }
59
59
  }
package/src/consts.ts CHANGED
@@ -1,21 +1,21 @@
1
1
  export const CHANNEL_FORMATS = [
2
- 'undefined',
3
- 'float32',
4
- 'double64',
5
- 'string',
6
- 'int32',
7
- 'int16',
8
- 'int8',
9
- 'int64',
2
+ 'undefined',
3
+ 'float32',
4
+ 'double64',
5
+ 'string',
6
+ 'int32',
7
+ 'int16',
8
+ 'int8',
9
+ 'int64',
10
10
  ] as const
11
11
 
12
12
  export const CHANNEL_FORMATS_MAP = {
13
- undefined: 0,
14
- float32: 1,
15
- double64: 2,
16
- string: 3,
17
- int32: 4,
18
- int16: 5,
19
- int8: 6,
20
- int64: 7,
13
+ undefined: 0,
14
+ float32: 1,
15
+ double64: 2,
16
+ string: 3,
17
+ int32: 4,
18
+ int16: 5,
19
+ int8: 6,
20
+ int64: 7,
21
21
  }
@@ -2,22 +2,22 @@ import BaseSpruceError from '@sprucelabs/error'
2
2
  import ErrorOptions from '#spruce/errors/options.types'
3
3
 
4
4
  export default class SpruceError extends BaseSpruceError<ErrorOptions> {
5
- /** an easy to understand version of the errors */
6
- public friendlyMessage(): string {
7
- const { options } = this
8
- let message
9
- switch (options?.code) {
10
- case 'FAILED_TO_LOAD_LIBLSL':
11
- message = `Well shoot! Loading the liblsl dylib failed. I tried to load it from ${options.liblslPath}.`
12
- break
13
- default:
14
- message = super.friendlyMessage()
15
- }
5
+ /** an easy to understand version of the errors */
6
+ public friendlyMessage(): string {
7
+ const { options } = this
8
+ let message
9
+ switch (options?.code) {
10
+ case 'FAILED_TO_LOAD_LIBLSL':
11
+ message = `Well shoot! Loading the liblsl dylib failed. I tried to load it from ${options.liblslPath}.`
12
+ break
13
+ default:
14
+ message = super.friendlyMessage()
15
+ }
16
16
 
17
- const fullMessage = options.friendlyMessage
18
- ? options.friendlyMessage
19
- : message
17
+ const fullMessage = options.friendlyMessage
18
+ ? options.friendlyMessage
19
+ : message
20
20
 
21
- return fullMessage
22
- }
21
+ return fullMessage
22
+ }
23
23
  }
@@ -1,12 +1,12 @@
1
1
  import { buildErrorSchema } from '@sprucelabs/schema'
2
2
 
3
3
  export default buildErrorSchema({
4
- id: 'failedToLoadLiblsl',
5
- name: 'FAILED_TO_LOAD_LIBLSL',
6
- fields: {
7
- liblslPath: {
8
- type: 'text',
9
- isRequired: true,
10
- },
11
- },
4
+ id: 'failedToLoadLiblsl',
5
+ name: 'FAILED_TO_LOAD_LIBLSL',
6
+ fields: {
7
+ liblslPath: {
8
+ type: 'text',
9
+ isRequired: true,
10
+ },
11
+ },
12
12
  })