@neurodevs/ndx-native 0.0.1
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/.nvmrc +1 -0
- package/.vscode/launch.json +58 -0
- package/.vscode/settings.json +67 -0
- package/.vscode/tasks.json +130 -0
- package/LICENSE +21 -0
- package/README.md +2 -0
- package/build/.spruce/settings.json +11 -0
- package/build/__tests__/AbstractPackageTest.d.ts +7 -0
- package/build/__tests__/AbstractPackageTest.js +14 -0
- package/build/__tests__/AbstractPackageTest.js.map +1 -0
- package/build/__tests__/impl/LabrecorderAdapter.test.d.ts +30 -0
- package/build/__tests__/impl/LabrecorderAdapter.test.js +164 -0
- package/build/__tests__/impl/LabrecorderAdapter.test.js.map +1 -0
- package/build/__tests__/impl/LiblslAdapter.test.d.ts +84 -0
- package/build/__tests__/impl/LiblslAdapter.test.js +750 -0
- package/build/__tests__/impl/LiblslAdapter.test.js.map +1 -0
- package/build/__tests__/impl/LibxdfAdapter.test.d.ts +45 -0
- package/build/__tests__/impl/LibxdfAdapter.test.js +243 -0
- package/build/__tests__/impl/LibxdfAdapter.test.js.map +1 -0
- package/build/consts.d.ts +11 -0
- package/build/consts.js +21 -0
- package/build/consts.js.map +1 -0
- package/build/impl/LabrecorderAdapter.d.ts +30 -0
- package/build/impl/LabrecorderAdapter.js +69 -0
- package/build/impl/LabrecorderAdapter.js.map +1 -0
- package/build/impl/LiblslAdapter.d.ts +172 -0
- package/build/impl/LiblslAdapter.js +360 -0
- package/build/impl/LiblslAdapter.js.map +1 -0
- package/build/impl/LibxdfAdapter.d.ts +92 -0
- package/build/impl/LibxdfAdapter.js +130 -0
- package/build/impl/LibxdfAdapter.js.map +1 -0
- package/build/index.d.ts +14 -0
- package/build/index.js +18 -0
- package/build/index.js.map +1 -0
- package/build/lib/handleError.d.ts +8 -0
- package/build/lib/handleError.js +25 -0
- package/build/lib/handleError.js.map +1 -0
- package/build/testDoubles/Labrecorder/FakeLabrecorder.d.ts +15 -0
- package/build/testDoubles/Labrecorder/FakeLabrecorder.js +26 -0
- package/build/testDoubles/Labrecorder/FakeLabrecorder.js.map +1 -0
- package/build/testDoubles/Liblsl/FakeLiblsl.d.ts +57 -0
- package/build/testDoubles/Liblsl/FakeLiblsl.js +140 -0
- package/build/testDoubles/Liblsl/FakeLiblsl.js.map +1 -0
- package/build/testDoubles/Libxdf/FakeLibxdf.d.ts +13 -0
- package/build/testDoubles/Libxdf/FakeLibxdf.js +25 -0
- package/build/testDoubles/Libxdf/FakeLibxdf.js.map +1 -0
- package/build/testDoubles/Libxdf/SpyLibxdf.d.ts +6 -0
- package/build/testDoubles/Libxdf/SpyLibxdf.js +10 -0
- package/build/testDoubles/Libxdf/SpyLibxdf.js.map +1 -0
- package/eslint.config.mjs +3 -0
- package/package.json +84 -0
- package/src/.spruce/settings.json +11 -0
- package/src/__tests__/AbstractPackageTest.ts +16 -0
- package/src/__tests__/impl/LabrecorderAdapter.test.ts +197 -0
- package/src/__tests__/impl/LiblslAdapter.test.ts +907 -0
- package/src/__tests__/impl/LibxdfAdapter.test.ts +290 -0
- package/src/consts.ts +21 -0
- package/src/impl/LabrecorderAdapter.ts +100 -0
- package/src/impl/LiblslAdapter.ts +616 -0
- package/src/impl/LibxdfAdapter.ts +227 -0
- package/src/index.ts +26 -0
- package/src/lib/handleError.ts +24 -0
- package/src/testDoubles/Labrecorder/FakeLabrecorder.ts +37 -0
- package/src/testDoubles/Liblsl/FakeLiblsl.ts +204 -0
- package/src/testDoubles/Libxdf/FakeLibxdf.ts +33 -0
- package/src/testDoubles/Libxdf/SpyLibxdf.ts +13 -0
- package/tsconfig.json +28 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import AbstractModuleTest from '@neurodevs/node-tdd'
|
|
2
|
+
|
|
3
|
+
export default abstract class AbstractPackageTest extends AbstractModuleTest {
|
|
4
|
+
protected static readonly channelNames = [
|
|
5
|
+
this.generateId(),
|
|
6
|
+
this.generateId(),
|
|
7
|
+
this.generateId(),
|
|
8
|
+
]
|
|
9
|
+
|
|
10
|
+
protected static readonly channelCount = this.channelNames.length
|
|
11
|
+
protected static readonly chunkSize = 2
|
|
12
|
+
|
|
13
|
+
protected static async beforeEach() {
|
|
14
|
+
await super.beforeEach()
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import generateId from '@neurodevs/generate-id'
|
|
2
|
+
import { test, assert } from '@neurodevs/node-tdd'
|
|
3
|
+
import { DataType, OpenParams } from 'ffi-rs'
|
|
4
|
+
|
|
5
|
+
import LabrecorderAdapter, {
|
|
6
|
+
RecordingHandle,
|
|
7
|
+
Labrecorder,
|
|
8
|
+
LabrecorderBindings,
|
|
9
|
+
} from '../../impl/LabrecorderAdapter.js'
|
|
10
|
+
import AbstractPackageTest from '../AbstractPackageTest.js'
|
|
11
|
+
|
|
12
|
+
export default class LabrecorderAdapterTest extends AbstractPackageTest {
|
|
13
|
+
private static instance: Labrecorder
|
|
14
|
+
private static fakeBindings: LabrecorderBindings
|
|
15
|
+
private static ffiRsOpenOptions?: OpenParams
|
|
16
|
+
private static ffiRsDefineOptions?: Record<string, unknown>
|
|
17
|
+
|
|
18
|
+
private static callsToRecordingCreate: {
|
|
19
|
+
filename: string
|
|
20
|
+
watchFor: string[]
|
|
21
|
+
watchForCount: number
|
|
22
|
+
}[] = []
|
|
23
|
+
|
|
24
|
+
private static callsToRecordingStop: RecordingHandle[] = []
|
|
25
|
+
private static callsToRecordingDelete: RecordingHandle[] = []
|
|
26
|
+
|
|
27
|
+
private static readonly filename = generateId()
|
|
28
|
+
private static readonly watchFor = [generateId(), generateId()]
|
|
29
|
+
|
|
30
|
+
protected static async beforeEach() {
|
|
31
|
+
await super.beforeEach()
|
|
32
|
+
|
|
33
|
+
this.setupFakeBindings()
|
|
34
|
+
this.fakeFfiRsOpen()
|
|
35
|
+
this.fakeFfiRsDefine()
|
|
36
|
+
|
|
37
|
+
this.instance = this.LabrecorderAdapter()
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@test()
|
|
41
|
+
protected static async canCreateLabrecorderAdapter() {
|
|
42
|
+
assert.isTruthy(this.instance, 'Should create an instance!')
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@test()
|
|
46
|
+
protected static async callsFfiRsOpenWithRequiredOptions() {
|
|
47
|
+
assert.isEqualDeep(this.ffiRsOpenOptions, {
|
|
48
|
+
library: 'labrecorder',
|
|
49
|
+
path: this.labrecorderPath,
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@test()
|
|
54
|
+
protected static async callsFfiRsDefineWithRequiredOptions() {
|
|
55
|
+
this.LabrecorderAdapter()
|
|
56
|
+
|
|
57
|
+
assert.isEqualDeep(
|
|
58
|
+
this.ffiRsDefineOptions,
|
|
59
|
+
{
|
|
60
|
+
recording_create: {
|
|
61
|
+
library: 'labrecorder',
|
|
62
|
+
retType: DataType.External, // Pointer to the recording object
|
|
63
|
+
paramsType: [
|
|
64
|
+
DataType.String, // filename
|
|
65
|
+
DataType.StringArray, // watchfor
|
|
66
|
+
DataType.U64, // watchfor_count
|
|
67
|
+
],
|
|
68
|
+
},
|
|
69
|
+
recording_stop: {
|
|
70
|
+
library: 'labrecorder',
|
|
71
|
+
retType: DataType.Void,
|
|
72
|
+
paramsType: [
|
|
73
|
+
DataType.External, // Pointer to the recording object
|
|
74
|
+
],
|
|
75
|
+
},
|
|
76
|
+
recording_delete: {
|
|
77
|
+
library: 'labrecorder',
|
|
78
|
+
retType: DataType.Void,
|
|
79
|
+
paramsType: [
|
|
80
|
+
DataType.External, // Pointer to the recording object
|
|
81
|
+
],
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
'Please pass valid options to ffiRsDefine!'
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
@test()
|
|
89
|
+
protected static async createRecordingCallsBindings() {
|
|
90
|
+
this.createRecording()
|
|
91
|
+
|
|
92
|
+
assert.isEqualDeep(
|
|
93
|
+
this.callsToRecordingCreate[0],
|
|
94
|
+
{
|
|
95
|
+
filename: this.filename,
|
|
96
|
+
watchFor: this.watchFor,
|
|
97
|
+
watchForCount: this.watchFor.length,
|
|
98
|
+
},
|
|
99
|
+
'Should create a recording!'
|
|
100
|
+
)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
@test()
|
|
104
|
+
protected static async defaultsToMacOsPath() {
|
|
105
|
+
const defaultLabrecorderPath = '/opt/local/lib/liblabrecorder.dylib'
|
|
106
|
+
LabrecorderAdapter.Create()
|
|
107
|
+
|
|
108
|
+
const { path } = this.ffiRsOpenOptions ?? {}
|
|
109
|
+
|
|
110
|
+
assert.isEqual(path, defaultLabrecorderPath)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
@test()
|
|
114
|
+
protected static async stopRecordingCallsBindings() {
|
|
115
|
+
const recording = this.createRecording()
|
|
116
|
+
this.stopRecording(recording)
|
|
117
|
+
|
|
118
|
+
assert.isEqualDeep(this.callsToRecordingStop[0], recording)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
@test()
|
|
122
|
+
protected static async deleteRecordingCallsBindings() {
|
|
123
|
+
const recording = this.createAndDeleteRecording()
|
|
124
|
+
|
|
125
|
+
assert.isEqualDeep(this.callsToRecordingDelete[0], recording)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
private static createAndDeleteRecording() {
|
|
129
|
+
const recording = this.createRecording()
|
|
130
|
+
this.deleteRecording(recording)
|
|
131
|
+
return recording
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
private static createRecording() {
|
|
135
|
+
return this.instance.createRecording(this.filename, this.watchFor)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
private static stopRecording(recording: RecordingHandle) {
|
|
139
|
+
this.instance.stopRecording(recording)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
private static deleteRecording(recording: RecordingHandle) {
|
|
143
|
+
this.instance.deleteRecording(recording)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
private static setupFakeBindings() {
|
|
147
|
+
this.fakeBindings = this.FakeBindings()
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
private static fakeFfiRsOpen() {
|
|
151
|
+
LabrecorderAdapter.ffiRsOpen = (options) => {
|
|
152
|
+
this.ffiRsOpenOptions = options
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
private static fakeFfiRsDefine() {
|
|
157
|
+
LabrecorderAdapter.ffiRsDefine = (options) => {
|
|
158
|
+
this.ffiRsDefineOptions = options
|
|
159
|
+
return this.fakeBindings as any
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
private static readonly labrecorderPath = generateId()
|
|
164
|
+
|
|
165
|
+
private static FakeBindings() {
|
|
166
|
+
this.callsToRecordingCreate = []
|
|
167
|
+
this.callsToRecordingStop = []
|
|
168
|
+
this.callsToRecordingDelete = []
|
|
169
|
+
|
|
170
|
+
return {
|
|
171
|
+
recording_create: ([filename, watchFor, watchForCount]: [
|
|
172
|
+
string,
|
|
173
|
+
string[],
|
|
174
|
+
number,
|
|
175
|
+
]) => {
|
|
176
|
+
this.callsToRecordingCreate.push({
|
|
177
|
+
filename,
|
|
178
|
+
watchFor,
|
|
179
|
+
watchForCount,
|
|
180
|
+
})
|
|
181
|
+
return {} as RecordingHandle
|
|
182
|
+
},
|
|
183
|
+
recording_stop: ([recording]: [RecordingHandle]) => {
|
|
184
|
+
this.callsToRecordingStop.push(recording)
|
|
185
|
+
},
|
|
186
|
+
recording_delete: ([recording]: [RecordingHandle]) => {
|
|
187
|
+
this.callsToRecordingDelete.push(recording)
|
|
188
|
+
},
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
private static LabrecorderAdapter(labrecorderPath?: string) {
|
|
193
|
+
return LabrecorderAdapter.Create(
|
|
194
|
+
labrecorderPath ?? this.labrecorderPath
|
|
195
|
+
)
|
|
196
|
+
}
|
|
197
|
+
}
|