nemar-cli 0.1.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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +353 -0
  3. package/dist/index.js +256 -0
  4. package/package.json +66 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 NEMAR Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,353 @@
1
+ # NEMAR CLI
2
+
3
+ [![Documentation](https://img.shields.io/badge/docs-nemar--cli.pages.dev-blue)](https://nemar-cli.pages.dev)
4
+ [![Tests](https://github.com/nemarDatasets/nemar-cli/actions/workflows/test.yml/badge.svg)](https://github.com/nemarDatasets/nemar-cli/actions/workflows/test.yml)
5
+
6
+ Command-line interface for [NEMAR](https://nemar.org) (Neuroelectromagnetic Data Archive and Tools Resource) dataset management.
7
+
8
+ **[Documentation](https://nemar-cli.pages.dev)** | [Quick Start](https://nemar-cli.pages.dev/getting-started/quickstart/) | [Commands](https://nemar-cli.pages.dev/commands/)
9
+
10
+ ## Features
11
+
12
+ - **Dataset Management**: Upload, download, validate, and version BIDS datasets
13
+ - **PR-Based Versioning**: All changes require pull requests (main branch protected)
14
+ - **Collaborative**: Any NEMAR user can contribute to any dataset
15
+ - **BIDS Validation**: Automatic validation before upload and on PRs
16
+ - **DOI Integration**: Zenodo DOI creation for dataset versioning
17
+ - **DataLad Backend**: Git-annex for large file management with S3 storage
18
+
19
+ ## Installation
20
+
21
+ Requires [Bun](https://bun.sh) runtime.
22
+
23
+ ```bash
24
+ # Install Bun (if not already installed)
25
+ curl -fsSL https://bun.sh/install | bash
26
+
27
+ # Install NEMAR CLI
28
+ bun install -g nemar-cli
29
+
30
+ # Or run directly without installing
31
+ bunx nemar-cli
32
+ ```
33
+
34
+ ### Prerequisites
35
+
36
+ For dataset operations:
37
+
38
+ - [DataLad](https://www.datalad.org/) and git-annex
39
+ - [Deno](https://deno.land/) (for BIDS validation)
40
+ - GitHub account (for PR collaboration)
41
+
42
+ ```bash
43
+ # macOS
44
+ brew install datalad git-annex deno
45
+
46
+ # Ubuntu/Debian
47
+ sudo apt-get install git-annex
48
+ pip install datalad
49
+ curl -fsSL https://deno.land/install.sh | sh
50
+ ```
51
+
52
+ ## Quick Start
53
+
54
+ ```bash
55
+ # 1. Sign up for NEMAR
56
+ nemar auth signup
57
+
58
+ # 2. After admin approval, login
59
+ nemar auth login
60
+
61
+ # 3. Validate your BIDS dataset
62
+ nemar dataset validate /path/to/dataset
63
+
64
+ # 4. Upload to NEMAR
65
+ nemar dataset upload /path/to/dataset --name "My Dataset"
66
+ ```
67
+
68
+ ## Architecture Overview
69
+
70
+ ```mermaid
71
+ graph TB
72
+ subgraph "User's Machine"
73
+ CLI[NEMAR CLI]
74
+ DL[DataLad]
75
+ end
76
+
77
+ subgraph "NEMAR Backend"
78
+ API[Cloudflare Workers API]
79
+ DB[(D1 Database)]
80
+ end
81
+
82
+ subgraph "Storage"
83
+ GH[GitHub nemarDatasets]
84
+ S3[(AWS S3)]
85
+ ZEN[Zenodo DOI]
86
+ end
87
+
88
+ CLI --> API
89
+ CLI --> DL
90
+ DL --> GH
91
+ DL --> S3
92
+ API --> DB
93
+ API --> GH
94
+ API --> S3
95
+ API --> ZEN
96
+ ```
97
+
98
+ ## Workflows
99
+
100
+ ### User Registration & Authentication
101
+
102
+ ```mermaid
103
+ sequenceDiagram
104
+ participant U as User
105
+ participant CLI as NEMAR CLI
106
+ participant API as Backend
107
+ participant Admin as Admin
108
+
109
+ U->>CLI: nemar auth signup
110
+ CLI->>API: POST /auth/signup
111
+ API-->>U: Verification email
112
+ U->>API: Click verification link
113
+ API->>Admin: Notification: new user pending
114
+ Admin->>CLI: nemar admin approve <user>
115
+ CLI->>API: POST /admin/approve
116
+ API-->>U: Approval email with instructions
117
+ U->>CLI: nemar auth login
118
+ CLI->>API: Validate API key
119
+ API-->>CLI: Success + user info
120
+ ```
121
+
122
+ ### Dataset Upload (New Dataset)
123
+
124
+ ```mermaid
125
+ sequenceDiagram
126
+ participant U as User
127
+ participant CLI as NEMAR CLI
128
+ participant API as Backend
129
+ participant GH as GitHub
130
+ participant S3 as AWS S3
131
+
132
+ U->>CLI: nemar dataset upload /path
133
+ CLI->>CLI: Validate BIDS locally
134
+ CLI->>API: POST /datasets/create
135
+ API->>API: Assign dataset ID (nm000XXX)
136
+ API->>GH: Create repo (Admin PAT)
137
+ API->>GH: Add user as collaborator
138
+ API->>GH: Set branch protection
139
+ API-->>CLI: Dataset ID + presigned URLs
140
+ CLI->>S3: Upload data files
141
+ CLI->>GH: Push via DataLad
142
+ CLI-->>U: Success! URLs provided
143
+ ```
144
+
145
+ ### Pull Request Workflow (Contributing to Dataset)
146
+
147
+ ```mermaid
148
+ sequenceDiagram
149
+ participant C as Contributor
150
+ participant CLI as NEMAR CLI
151
+ participant API as Backend
152
+ participant S3 as AWS S3
153
+ participant GH as GitHub
154
+ participant GA as GitHub Actions
155
+ participant O as Dataset Owner
156
+
157
+ C->>CLI: nemar dataset clone nm000104
158
+ CLI->>GH: datalad clone
159
+ CLI->>S3: datalad get (fetch data)
160
+
161
+ Note over C: Make local changes
162
+
163
+ C->>CLI: nemar dataset pr create
164
+ CLI->>API: POST /pr/create
165
+ API->>S3: Create staging area
166
+ API-->>CLI: Presigned URLs
167
+ CLI->>S3: Upload to staging/pr-XXX/
168
+ CLI->>GH: Push branch + create PR
169
+
170
+ GH->>GA: Trigger: PR opened
171
+ GA->>S3: Fetch staged data
172
+ GA->>GA: Run BIDS validation
173
+ GA->>GH: Report status
174
+
175
+ O->>GH: Review PR
176
+ O->>GH: Approve & Merge
177
+
178
+ GH->>GA: Trigger: PR merged
179
+ GA->>S3: Copy staging → final
180
+ GA->>S3: Delete staging
181
+ GA->>GH: Post success comment
182
+ ```
183
+
184
+ ### PR Data Flow (S3 Staging)
185
+
186
+ ```mermaid
187
+ graph LR
188
+ subgraph "Before Merge"
189
+ A[Local Files] -->|Upload| B[S3 staging/pr-XXX/]
190
+ B -->|git-annex points to| C[PR Branch]
191
+ end
192
+
193
+ subgraph "After Merge"
194
+ B -->|Copy| D[S3 nm000XXX/]
195
+ D -->|git-annex points to| E[Main Branch]
196
+ B -->|Delete| F[Cleaned Up]
197
+ end
198
+ ```
199
+
200
+ ### Dataset Versioning & DOI
201
+
202
+ ```mermaid
203
+ sequenceDiagram
204
+ participant A as Admin
205
+ participant CLI as NEMAR CLI
206
+ participant API as Backend
207
+ participant ZEN as Zenodo
208
+ participant GH as GitHub
209
+
210
+ Note over A: First release: Admin creates concept DOI
211
+ A->>CLI: nemar admin doi create nm000104
212
+ CLI->>API: POST /admin/doi/create
213
+ API->>ZEN: Pre-reserve DOI
214
+ API->>GH: Update dataset_description.json
215
+ API->>GH: Create release tag
216
+ API->>ZEN: Upload & publish
217
+ API-->>A: Concept DOI: 10.5281/zenodo.XXX
218
+
219
+ Note over A: Later: User creates version DOI
220
+ participant U as User
221
+ U->>CLI: nemar dataset version nm000104 v1.1.0
222
+ CLI->>API: POST /datasets/version
223
+ API->>ZEN: Create new version DOI
224
+ API->>GH: Create release tag
225
+ API-->>U: Version DOI created
226
+ ```
227
+
228
+ ## Commands
229
+
230
+ ### Authentication
231
+
232
+ ```bash
233
+ nemar auth signup # Register new account
234
+ nemar auth login # Login with API key
235
+ nemar auth status # Check authentication status
236
+ nemar auth logout # Clear credentials
237
+ ```
238
+
239
+ ### Dataset Management
240
+
241
+ ```bash
242
+ nemar dataset validate <path> # Validate BIDS dataset
243
+ nemar dataset upload <path> # Upload new dataset
244
+ nemar dataset download <id> [output] # Download dataset
245
+ nemar dataset clone <id> [output] # Clone for contribution
246
+ nemar dataset list # List your datasets
247
+ nemar dataset list --all # List all NEMAR datasets
248
+ nemar dataset status <id> # Check dataset status
249
+ nemar dataset version <id> <version> # Create new version with DOI
250
+ ```
251
+
252
+ ### Pull Requests
253
+
254
+ ```bash
255
+ nemar dataset pr create # Create PR from local changes
256
+ nemar dataset pr list # List PRs on your datasets
257
+ nemar dataset pr list --mine # List PRs you created
258
+ nemar dataset pr show <pr-id> # View PR details
259
+ nemar dataset pr update <pr-id> # Push updates to PR
260
+ nemar dataset pr close <pr-id> # Close PR without merging
261
+ ```
262
+
263
+ ### Admin Commands
264
+
265
+ ```bash
266
+ nemar admin users # List all users
267
+ nemar admin users --pending # List pending approvals
268
+ nemar admin approve <username> # Approve user
269
+ nemar admin revoke <username> # Revoke user access
270
+ nemar admin doi create <dataset-id> # Create concept DOI
271
+ ```
272
+
273
+ ## Access Control
274
+
275
+ | Role | Push Branches | Merge PRs | Delete Repos | Create DOI |
276
+ |------|--------------|-----------|--------------|------------|
277
+ | NEMAR User | All repos | Own datasets | No | Version DOI |
278
+ | Dataset Owner | All repos | Own datasets | No | Version DOI |
279
+ | Admin | All repos | All datasets | Yes | Concept DOI |
280
+
281
+ ### Key Principles
282
+
283
+ 1. **PR-Mandatory**: Main branch is protected; all changes require PRs
284
+ 2. **Collaborative**: Any NEMAR user can create PRs on any dataset
285
+ 3. **Owner Approval**: Only dataset owner (or admin) can merge PRs
286
+ 4. **No Deletion**: Users cannot delete repositories or S3 data
287
+ 5. **Audit Trail**: All changes tracked via PR history
288
+
289
+ ## Storage Architecture
290
+
291
+ ```mermaid
292
+ graph TB
293
+ subgraph "GitHub (nemarDatasets org)"
294
+ META[Metadata + git history]
295
+ REL[Releases + tags]
296
+ end
297
+
298
+ subgraph "AWS S3 (nemar bucket)"
299
+ FINAL[nm000XXX/ - Published data]
300
+ STAGE[staging/pr-XXX/ - PR data]
301
+ end
302
+
303
+ subgraph "Zenodo"
304
+ DOI[DOIs + archived releases]
305
+ end
306
+
307
+ META ---|git-annex pointers| FINAL
308
+ STAGE -->|On merge| FINAL
309
+ REL -->|Archive| DOI
310
+ ```
311
+
312
+ ## Environment Variables
313
+
314
+ ```bash
315
+ NEMAR_API_KEY # API key (alternative to login)
316
+ NEMAR_API_URL # Custom API endpoint (default: https://api.nemar.org)
317
+ NEMAR_NO_COLOR # Disable colored output
318
+ ```
319
+
320
+ ## Development
321
+
322
+ ```bash
323
+ # Clone repository
324
+ git clone https://github.com/nemarDatasets/nemar-cli.git
325
+ cd nemar-cli
326
+
327
+ # Install dependencies
328
+ bun install
329
+
330
+ # Run in development
331
+ bun run dev
332
+
333
+ # Run tests
334
+ bun test
335
+
336
+ # Lint
337
+ bun run lint
338
+
339
+ # Build
340
+ bun run build
341
+ ```
342
+
343
+ ## Related Projects
344
+
345
+ - [NEMAR](https://nemar.org) - Neuroelectromagnetic Data Archive
346
+ - [OpenNeuro](https://openneuro.org) - Open platform for neuroimaging data
347
+ - [BIDS](https://bids.neuroimaging.io) - Brain Imaging Data Structure
348
+ - [DataLad](https://www.datalad.org) - Distributed data management
349
+ - [BIDS Validator](https://github.com/bids-standard/bids-validator) - BIDS validation tool
350
+
351
+ ## License
352
+
353
+ MIT