nemar-cli 0.9.7-dev.1925 → 0.9.7-dev.1927

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 (2) hide show
  1. package/dist/index.js +3 -3
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -102,7 +102,7 @@ ${W.dim(`eta: ${D.eta}`)}`:"";process.stderr.write(`${F}
102
102
  ${$} ${D.message}
103
103
  ${Q}${J}
104
104
  ${F}
105
- `)}var xp=!1;var Sz=k(()=>{e0()});var fp;var _p=k(()=>{fp={name:"nemar-cli",version:"0.9.7-dev.1925",description:"CLI for NEMAR (Neuroelectromagnetic Data Archive and Tools Resource) dataset management",type:"module",main:"dist/index.js",bin:{nemar:"dist/index.js"},scripts:{dev:"bun run src/index.ts",build:"bun build src/index.ts --outdir dist --target bun --minify && sed '1s|#!/usr/bin/env node|#!/usr/bin/env bun|' dist/index.js > dist/index.js.tmp && mv dist/index.js.tmp dist/index.js",test:"bun test",lint:"biome check src/","lint:fix":"biome check --fix src/",format:"biome format --write src/",typecheck:"tsc --noEmit",prepublishOnly:"bun run build",prepare:"husky",postinstall:"bun scripts/postinstall-check.mjs",deploy:"wrangler deploy",preview:"wrangler dev"},keywords:["nemar","bids","neuroimaging","eeg","emg","datalad","cli"],author:"NEMAR Team",license:"CC-BY-NC-ND-4.0",repository:{type:"git",url:"git+https://github.com/nemarOrg/nemar-cli.git"},bugs:{url:"https://github.com/nemarOrg/nemar-cli/issues"},homepage:"https://docs.nemar.org",engines:{bun:">=1.0.0"},files:["dist","scripts/postinstall-check.mjs","README.md","LICENSE"],dependencies:{chalk:"^5.3.0",commander:"^12.1.0",conf:"^13.0.1","fuse.js":"^7.1.0",inquirer:"^9.2.15",ora:"^8.0.1",zod:"^3.23.8"},"lint-staged":{"src/**/*.{ts,tsx}":["biome check --fix"],"backend/src/**/*.{ts,tsx}":["biome check --fix"]},devDependencies:{"@biomejs/biome":"1.9.4","@types/bcryptjs":"^3.0.0","@types/bun":"latest","@types/inquirer":"^9.0.7",ajv:"^8.20.0","ajv-formats":"^3.0.1",bcryptjs:"^3.0.3",husky:"^9.1.7","lint-staged":"^16.3.2",typescript:"^5.5.4",wrangler:"^4.70.0",yaml:"^2.8.4"}}});var T3;var ZX=k(()=>{_p();T3=fp.version});function d(D){if(D instanceof Error)return D.message;return String(D)}var g,w3;var Z1=k(()=>{g=class g extends Error{statusCode;details;step;constructor(D,F,$,Q){super(F);this.statusCode=D;this.details=$;this.step=Q;this.name="ApiError"}};w3=class w3 extends g{mode;eta;constructor(D,F,$,Q){super(503,F,Q);this.mode=D;this.eta=$;this.name="MaintenanceError"}}});function bp(){if(process.env.TEST_API_URL)return process.env.TEST_API_URL;if(vz)return kz;return ZD().apiUrl||kz}async function y(D,F={},$=!1,Q){let J=`${bp()}${D}`,Y={"Content-Type":"application/json","X-CLI-Version":T3,...F.headers};if($){let B=ZD();if(!B.apiKey&&$===!0)throw new g(401,"Not authenticated. Run 'nemar auth login' first.");if(B.apiKey)Y.Authorization=`Bearer ${B.apiKey}`}let X;try{X=await fetch(J,{...F,headers:Y})}catch(B){throw new g(0,`Network error: Could not connect to ${bp()}`,{originalError:B instanceof Error?B.message:String(B)})}let G;try{G=await X.json()}catch{throw new g(X.status,`Invalid response from server (status ${X.status})`)}if(!X.ok){if(X.status===503&&(G.mode==="read-only"||G.mode==="full")){let B=typeof G.message==="string"?G.message:"NEMAR is in maintenance mode. Please retry shortly.",H=typeof G.eta==="string"?G.eta:null,q=new w3(G.mode,B,H,G.details);throw zX(q),q}throw new g(X.status,G.error||G.message||"Request failed",G.details,typeof G.step==="string"?G.step:void 0)}if(Q){let B=Q.safeParse(G);if(!B.success)throw new g(X.status,`Response for ${D} did not match the expected NEMAR contract`,{issues:B.error.issues});return B.data}return G}var kz="https://nemar-api-dev.sccn-org.workers.dev",vz;var S4=k(()=>{I4();Sz();ZX();Z1();vz=kz.includes("workers.dev")});async function gp(D,F){let $=new URLSearchParams;if(D)$.set("status",D);if(F)$.set("role",F);let Q=$.toString()?`?${$.toString()}`:"";return y(`/admin/users${Q}`,{},!0)}async function hp(D){return y(`/admin/approve/${D}`,{method:"POST"},!0)}async function up(D){return y(`/admin/revoke/${D}`,{method:"POST"},!0)}async function mp(D,F){return y(`/admin/users/${D}/role`,{method:"POST",body:JSON.stringify({role:F})},!0)}async function yz(D,F){return y(`/admin/datasets/${D}/visibility`,{method:"PATCH",body:JSON.stringify({visibility:F})},!0)}async function lp(D){return y(`/datasets/${D}/publish`,{method:"POST"},!0)}async function pp(D){return y(`/admin/datasets/${D}/ci`,{},!0)}async function T6(D){return y(`/admin/datasets/${D}/ci`,{method:"POST"},!0)}async function xz(D){return y(`/admin/datasets/${D}/ci/validate`,{method:"POST"},!0)}async function _z(D){return y(`/admin/datasets/${D}/ci/sync`,{method:"POST"},!0)}async function dp(D,F){return y(`/admin/datasets/${D}/doi/concept`,{method:"POST",body:JSON.stringify(F)},!0)}async function B$(D){return y(`/admin/datasets/${D}/doi`,{},!0)}async function fz(D,F){return y(`/admin/datasets/${D}/doi/update`,{method:"POST",body:JSON.stringify(F)},!0)}async function cp(D,F){return y(`/admin/datasets/${D}/withdraw`,{method:"POST",body:JSON.stringify({reason:F.reason,dry_run:F.dryRun})},!0)}async function np(D,F){return y(`/admin/datasets/${D}/restore`,{method:"POST",body:JSON.stringify({dry_run:F.dryRun})},!0)}async function ip(D){return y(`/admin/datasets/${D}/reset`,{method:"POST"},!0)}async function ap(D,F=!1){return y(`/admin/datasets/${D}`,{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({force:F})},!0)}async function op(D){return y("/admin/datasets/bulk-delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({dataset_ids:D})},!0)}async function sp(D){return y("/admin/datasets/import",{method:"POST",body:JSON.stringify(D)},!0)}async function rp(D){return y("/admin/datasets/exemplar",{method:"POST",body:JSON.stringify(D)},!0)}async function tp(D){return y(`/admin/datasets/${D}/exemplar/remint-dois`,{method:"POST"},!0)}async function bz(D,F){let $=new URLSearchParams;if(D)$.set("status",D);if(F!==void 0)$.set("blocklisted",F?"1":"0");let Q=$.toString();return y(`/admin/imports${Q?`?${Q}`:""}`,{},!0)}async function ep(D){return y(`/admin/imports/${D}/rollback`,{method:"POST"},!0)}async function Dd(D){return y(`/admin/imports/${D}/retry`,{method:"POST"},!0)}async function gz(D){return y(`/admin/imports/${D}/verify`,{method:"POST"},!0)}async function Fd(D){return y("/admin/imports/dispatch-cooldown",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({dataset_ids:D})},!0)}async function w5(D,F){return y(`/admin/datasets/${D}/reindex`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(F??{})},!0)}async function $d(D,F){return y("/admin/datasets/reindex/bulk",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filter:D,...F??{}})},!0)}async function Qd(D){let F=D?.limit??15;return y(`/admin/datasets/hed-sweep?limit=${encodeURIComponent(String(F))}`,{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function Jd(){return y("/admin/datasets/hed-sweep?reset=1",{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function Yd(D){let F=D?.limit??15,$=new URLSearchParams({limit:String(F)});if(D?.olderThan!=null)$.set("older-than",String(D.olderThan));if(D?.before!=null)$.set("before",D.before);return y(`/admin/datasets/data-integrity-sweep?${$.toString()}`,{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function Xd(){return y("/admin/datasets/data-integrity-sweep?reset=1",{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function Gd(D,F){let $=F?.write?"":"?dry_run=1";return y(`/admin/datasets/${D}/availability-report${$}`,{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function Bd(D){let F=D?.limit??30,$=new URLSearchParams({limit:String(F)});if(D?.missingOnly)$.set("missing-only","1");return y(`/admin/datasets/availability-report-sweep?${$.toString()}`,{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function Wd(){return y("/admin/datasets/availability-report-sweep?reset=1",{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function Hd(D){let F=new URLSearchParams;if(D?.prefix)F.set("prefix",D.prefix);if(D?.visibility)F.set("visibility",D.visibility);if(D?.limit)F.set("limit",String(D.limit));let $=F.toString()?`?${F.toString()}`:"";return y(`/admin/fleet/drift${$}`,{},!0)}async function P5(D,F){return y(`/admin/datasets/${D}/enforce`,{method:"POST",body:JSON.stringify({dry_run:F})},!0)}async function qd(D){return y("/admin/datasets/enforce/bulk",{method:"POST",body:JSON.stringify({prefix:D.prefix,visibility:D.visibility,limit:D.limit,dry_run:D.dryRun})},!0)}async function Kd(D,F=!1){return y(`/admin/datasets/${D}/revalidate${F?"?force=true":""}`,{method:"POST"},!0)}async function zd(D){let F=D?`?user=${encodeURIComponent(D)}`:"";return y(`/admin/email-preferences${F}`,{},!0)}async function Zd(D,F){let $=F?`?user=${encodeURIComponent(F)}`:"";return y(`/admin/email-preferences${$}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(D)},!0)}async function hz(D){return y("/admin/notify",{method:"POST",body:JSON.stringify(D)},!0)}async function Vd(){return y("/admin/summary/coverage",{},!0)}async function Ed(D,F,$){return y("/admin/manifest/dispatch",{method:"POST",body:JSON.stringify({dataset_id:D,version:F,skip_canary:$?.skipCanary??!1})},!0)}var I5=k(()=>{S4()});async function s8(D,F){return y(`/datasets/${D}/upload-credentials`,{method:"POST",body:JSON.stringify({duration_seconds:F})},!0)}async function uz(D,F){return y(`/datasets/${D}/download-credentials`,{method:"POST",body:JSON.stringify({duration_seconds:F})},!0)}async function Ud(D){return y(`/admin/datasets/${D}/files`,{},!0)}async function Ld(D){let F,$=0,Q=[],J=!0;while(J){let Y=await y(`/admin/datasets/${D}/s3-lock`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({continuation_token:F})},!0);if($+=Y.locked,Y.failed?.length)Q.push(...Y.failed);if(J=Y.hasMore,F=Y.continuation_token,J&&!F)throw new g(500,"S3 lock paginated response missing continuation_token; aborting to avoid infinite loop")}return{locked:$,failed:Q}}var S5=k(()=>{S4();Z1()});async function EX(D){return y(`/datasets/${D}/ci/status`,{},!0)}async function Md(D){return y(`/datasets/${D}/manifest`,{},!0)}async function UX(D,F){return y(`/datasets/${D}/manifest/${F}`,{},!0)}function Ad(D){let F=D;if(!F.status)F.status="active";else if(!["active","archived","deleted"].includes(F.status))throw Error(`Invalid dataset status: ${F.status}`);if(!F.visibility)F.visibility="private";else if(!["public","private"].includes(F.visibility))throw Error(`Invalid dataset visibility: ${F.visibility}`);return F}async function k5(D={}){let F=new URLSearchParams;if(D.mine)F.set("mine","true");if(D.search)F.set("search",D.search);if(D.modality)F.set("modality",D.modality);if(D.author)F.set("author",D.author);if(D.task)F.set("task",D.task);if(D.license)F.set("license",D.license);if(D.hasDoi)F.set("has_doi","true");if(D.hasHed)F.set("has_hed","1");if(D.dataComplete)F.set("data_complete","1");if(D.recent)F.set("recent",String(D.recent));if(D.sort)F.set("sort",D.sort);if(D.limit!=null)F.set("limit",String(D.limit));if(D.offset!=null)F.set("offset",String(D.offset));if(D.owner)F.set("owner",D.owner);let $=F.toString()?`?${F.toString()}`:"",Q=await y(`/datasets${$}`,{},D.mine?!0:"optional");return Q.datasets=Q.datasets.map(Ad),Q}async function Nd(D){return y(`/datasets/resolve/${D}`,{},"optional")}async function Cd(D,F={}){let $=new URLSearchParams({q:D});if(F.modality)$.set("modality",F.modality);if(F.limit)$.set("limit",String(F.limit));if(F.hasHed)$.set("has_hed","1");return y(`/datasets/search?${$.toString()}`,{},"optional")}async function VD(D){let F=await y(`/datasets/${D}`,{},"optional");return Ad(F.dataset)}async function Od(D){return y(`/datasets/${D}/versions`,{},!0)}async function LX(D){return y("/datasets",{method:"POST",body:JSON.stringify(D)},!0)}async function MX(D){return y(`/datasets/${D}/finalize`,{method:"POST"},!0)}async function mz(D){return y(`/datasets/${D}/request-access`,{method:"POST"},!0)}async function jd(D,F){let $=F?`?status=${F}`:"";return y(`/datasets/${D}/access-requests${$}`,{},!0)}async function Rd(D,F){return y(`/datasets/${D}/access-requests/${F}/approve`,{method:"POST"},!0)}async function Td(D,F){return y(`/datasets/${D}/access-requests/${F}/deny`,{method:"POST"},!0)}async function wd(D,F){return y(`/datasets/${D}/invite`,{method:"POST",body:JSON.stringify({username:F})},!0)}async function Pd(D){return y(`/datasets/${D}/collaborators`,{},!0)}async function Id(D,F){return y(`/admin/datasets/${D}/enrichment`,{method:"POST",body:JSON.stringify(F)},!0)}var VX;var P3=k(()=>{S4();VX=/^\d{4}-\d{4}-\d{4}-\d{3}[\dX]$/});var v5;var xd=k(()=>{v5=["ci_check","enrichment_check","s3_public_read","repo_public","tag_protect","doi_create","update_metadata","update_readme","create_tag","create_release","upload_to_zenodo","publish_doi","version_doi","s3_lock","sync_nemar","notify_user"]});async function y5(D){return y(`/datasets/${D}/publish/request`,{method:"POST"},!0)}async function fd(D){return y(`/datasets/${D}/publish/status`,{},!0)}async function bd(D){return y(`/datasets/${D}/publish/resend`,{method:"POST"},!0)}async function gd(D){let F=D?`?status=${D}`:"";return y(`/admin/publish/requests${F}`,{},!0)}async function hd(D,F){return y(`/admin/publish/${D}/deny`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({reason:F})},!0)}function ES0(D,F=[]){if(D){let $=v5.indexOf(D);if($>=0)return $+1}return Math.min(F.length+1,v5.length)}function US0(D){if(!(D instanceof g))return!1;if(D.statusCode===0)return!0;if(D.statusCode===429)return!0;if(D.statusCode>=500&&D.statusCode<600)return!0;if(D.statusCode===403&&/repository has been locked/i.test(D.message))return!0;return!1}async function x5(D,F=!1,$=!1,Q=!1,J,Y){let B,H,q=0,K=!1,Z,z=F,E=[],U;function L(A,N,j,T){if(!Y)return;Y({step:A,stepIndex:ES0(A,N),stepTotal:v5.length,s3LockLocked:j,s3LockTotal:T,s3LockResumed:A==="s3_lock"&&K?!0:void 0})}for(let A=1;A<=5;A++)try{let N,j=!0;do{if(N=await y(`/admin/publish/${D}/approve`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({resume:j?z:!0,sandbox:$,s3_lock_continuation_token:B,s3_lock_total:H,skip_ci_check:Q})},!0),j=!1,N.step_results)E.push(...N.step_results);if(N.s3_lock_total!==void 0)H=N.s3_lock_total;if(N.s3_lock_batch_count!==void 0)q+=N.s3_lock_batch_count;let T=N.step??N.step_results?.[N.step_results.length-1]?.step;if(T&&(T!==Z||T==="s3_lock"))L(T,N.steps_completed??[],T==="s3_lock"?q:void 0,T==="s3_lock"?H:void 0),Z=T;if(N.hasMore&&N.s3_lock_continuation_token!==void 0)B=N.s3_lock_continuation_token;else break}while(N.hasMore);if(E.length>0)N.step_results=_d(E);return N}catch(N){if(U=N,A===5||!US0(N)){if(N instanceof g&&E.length>0)N.stepResults=_d(E);throw N}let T=N;if(J?.({attempt:A,maxAttempts:5,delayMs:1e4,step:T.step,error:T.message}),await new Promise((C)=>setTimeout(C,1e4)),z=!0,B!==void 0)K=!0}throw U}function _d(D){let F=new Map;for(let $ of D)F.set($.step,$);return Array.from(F.values())}var W$=k(()=>{xd();S4();Z1()});function ld(D){dz=D}function cz(){return dz}function H$(D){if(dz)process.stderr.write(`${D}
105
+ `)}var xp=!1;var Sz=k(()=>{e0()});var fp;var _p=k(()=>{fp={name:"nemar-cli",version:"0.9.7-dev.1927",description:"CLI for NEMAR (Neuroelectromagnetic Data Archive and Tools Resource) dataset management",type:"module",main:"dist/index.js",bin:{nemar:"dist/index.js"},scripts:{dev:"bun run src/index.ts",build:"bun build src/index.ts --outdir dist --target bun --minify && sed '1s|#!/usr/bin/env node|#!/usr/bin/env bun|' dist/index.js > dist/index.js.tmp && mv dist/index.js.tmp dist/index.js",test:"bun test",lint:"biome check src/","lint:fix":"biome check --fix src/",format:"biome format --write src/",typecheck:"tsc --noEmit",prepublishOnly:"bun run build",prepare:"husky",postinstall:"bun scripts/postinstall-check.mjs",deploy:"wrangler deploy",preview:"wrangler dev"},keywords:["nemar","bids","neuroimaging","eeg","emg","datalad","cli"],author:"NEMAR Team",license:"CC-BY-NC-ND-4.0",repository:{type:"git",url:"git+https://github.com/nemarOrg/nemar-cli.git"},bugs:{url:"https://github.com/nemarOrg/nemar-cli/issues"},homepage:"https://docs.nemar.org",engines:{bun:">=1.0.0"},files:["dist","scripts/postinstall-check.mjs","README.md","LICENSE"],dependencies:{chalk:"^5.3.0",commander:"^12.1.0",conf:"^13.0.1","fuse.js":"^7.1.0",inquirer:"^9.2.15",ora:"^8.0.1",zod:"^3.23.8"},"lint-staged":{"src/**/*.{ts,tsx}":["biome check --fix"],"backend/src/**/*.{ts,tsx}":["biome check --fix"]},devDependencies:{"@biomejs/biome":"1.9.4","@types/bcryptjs":"^3.0.0","@types/bun":"latest","@types/inquirer":"^9.0.7",ajv:"^8.20.0","ajv-formats":"^3.0.1",bcryptjs:"^3.0.3",husky:"^9.1.7","lint-staged":"^16.3.2",typescript:"^5.5.4",wrangler:"^4.70.0",yaml:"^2.8.4"}}});var T3;var ZX=k(()=>{_p();T3=fp.version});function d(D){if(D instanceof Error)return D.message;return String(D)}var g,w3;var Z1=k(()=>{g=class g extends Error{statusCode;details;step;constructor(D,F,$,Q){super(F);this.statusCode=D;this.details=$;this.step=Q;this.name="ApiError"}};w3=class w3 extends g{mode;eta;constructor(D,F,$,Q){super(503,F,Q);this.mode=D;this.eta=$;this.name="MaintenanceError"}}});function bp(){if(process.env.TEST_API_URL)return process.env.TEST_API_URL;if(vz)return kz;return ZD().apiUrl||kz}async function y(D,F={},$=!1,Q){let J=`${bp()}${D}`,Y={"Content-Type":"application/json","X-CLI-Version":T3,...F.headers};if($){let B=ZD();if(!B.apiKey&&$===!0)throw new g(401,"Not authenticated. Run 'nemar auth login' first.");if(B.apiKey)Y.Authorization=`Bearer ${B.apiKey}`}let X;try{X=await fetch(J,{...F,headers:Y})}catch(B){throw new g(0,`Network error: Could not connect to ${bp()}`,{originalError:B instanceof Error?B.message:String(B)})}let G;try{G=await X.json()}catch{throw new g(X.status,`Invalid response from server (status ${X.status})`)}if(!X.ok){if(X.status===503&&(G.mode==="read-only"||G.mode==="full")){let B=typeof G.message==="string"?G.message:"NEMAR is in maintenance mode. Please retry shortly.",H=typeof G.eta==="string"?G.eta:null,q=new w3(G.mode,B,H,G.details);throw zX(q),q}throw new g(X.status,G.error||G.message||"Request failed",G.details,typeof G.step==="string"?G.step:void 0)}if(Q){let B=Q.safeParse(G);if(!B.success)throw new g(X.status,`Response for ${D} did not match the expected NEMAR contract`,{issues:B.error.issues});return B.data}return G}var kz="https://nemar-api-dev.sccn-org.workers.dev",vz;var S4=k(()=>{I4();Sz();ZX();Z1();vz=kz.includes("workers.dev")});async function gp(D,F){let $=new URLSearchParams;if(D)$.set("status",D);if(F)$.set("role",F);let Q=$.toString()?`?${$.toString()}`:"";return y(`/admin/users${Q}`,{},!0)}async function hp(D){return y(`/admin/approve/${D}`,{method:"POST"},!0)}async function up(D){return y(`/admin/revoke/${D}`,{method:"POST"},!0)}async function mp(D,F){return y(`/admin/users/${D}/role`,{method:"POST",body:JSON.stringify({role:F})},!0)}async function yz(D,F){return y(`/admin/datasets/${D}/visibility`,{method:"PATCH",body:JSON.stringify({visibility:F})},!0)}async function lp(D){return y(`/datasets/${D}/publish`,{method:"POST"},!0)}async function pp(D){return y(`/admin/datasets/${D}/ci`,{},!0)}async function T6(D){return y(`/admin/datasets/${D}/ci`,{method:"POST"},!0)}async function xz(D){return y(`/admin/datasets/${D}/ci/validate`,{method:"POST"},!0)}async function _z(D){return y(`/admin/datasets/${D}/ci/sync`,{method:"POST"},!0)}async function dp(D,F){return y(`/admin/datasets/${D}/doi/concept`,{method:"POST",body:JSON.stringify(F)},!0)}async function B$(D){return y(`/admin/datasets/${D}/doi`,{},!0)}async function fz(D,F){return y(`/admin/datasets/${D}/doi/update`,{method:"POST",body:JSON.stringify(F)},!0)}async function cp(D,F){return y(`/admin/datasets/${D}/withdraw`,{method:"POST",body:JSON.stringify({reason:F.reason,dry_run:F.dryRun})},!0)}async function np(D,F){return y(`/admin/datasets/${D}/restore`,{method:"POST",body:JSON.stringify({dry_run:F.dryRun})},!0)}async function ip(D){return y(`/admin/datasets/${D}/reset`,{method:"POST"},!0)}async function ap(D,F=!1){return y(`/admin/datasets/${D}`,{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({force:F})},!0)}async function op(D){return y("/admin/datasets/bulk-delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({dataset_ids:D})},!0)}async function sp(D){return y("/admin/datasets/import",{method:"POST",body:JSON.stringify(D)},!0)}async function rp(D){return y("/admin/datasets/exemplar",{method:"POST",body:JSON.stringify(D)},!0)}async function tp(D){return y(`/admin/datasets/${D}/exemplar/remint-dois`,{method:"POST"},!0)}async function bz(D,F){let $=new URLSearchParams;if(D)$.set("status",D);if(F!==void 0)$.set("blocklisted",F?"1":"0");let Q=$.toString();return y(`/admin/imports${Q?`?${Q}`:""}`,{},!0)}async function ep(D){return y(`/admin/imports/${D}/rollback`,{method:"POST"},!0)}async function Dd(D){return y(`/admin/imports/${D}/retry`,{method:"POST"},!0)}async function gz(D){return y(`/admin/imports/${D}/verify`,{method:"POST"},!0)}async function Fd(D){return y("/admin/imports/dispatch-cooldown",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({dataset_ids:D})},!0)}async function w5(D,F){return y(`/admin/datasets/${D}/reindex`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(F??{})},!0)}async function $d(D,F){return y("/admin/datasets/reindex/bulk",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filter:D,...F??{}})},!0)}async function Qd(D){let F=D?.limit??15;return y(`/admin/datasets/hed-sweep?limit=${encodeURIComponent(String(F))}`,{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function Jd(){return y("/admin/datasets/hed-sweep?reset=1",{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function Yd(D){let F=D?.limit??15,$=new URLSearchParams({limit:String(F)});if(D?.olderThan!=null)$.set("older-than",String(D.olderThan));if(D?.before!=null)$.set("before",D.before);return y(`/admin/datasets/data-integrity-sweep?${$.toString()}`,{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function Xd(){return y("/admin/datasets/data-integrity-sweep?reset=1",{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function Gd(D,F){let $=F?.write?"":"?dry_run=1";return y(`/admin/datasets/${D}/availability-report${$}`,{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function Bd(D){let F=D?.limit??30,$=new URLSearchParams({limit:String(F)});if(D?.missingOnly)$.set("missing-only","1");return y(`/admin/datasets/availability-report-sweep?${$.toString()}`,{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function Wd(){return y("/admin/datasets/availability-report-sweep?reset=1",{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function Hd(D){let F=new URLSearchParams;if(D?.prefix)F.set("prefix",D.prefix);if(D?.visibility)F.set("visibility",D.visibility);if(D?.limit)F.set("limit",String(D.limit));let $=F.toString()?`?${F.toString()}`:"";return y(`/admin/fleet/drift${$}`,{},!0)}async function P5(D,F){return y(`/admin/datasets/${D}/enforce`,{method:"POST",body:JSON.stringify({dry_run:F})},!0)}async function qd(D){return y("/admin/datasets/enforce/bulk",{method:"POST",body:JSON.stringify({prefix:D.prefix,visibility:D.visibility,limit:D.limit,dry_run:D.dryRun})},!0)}async function Kd(D,F=!1){return y(`/admin/datasets/${D}/revalidate${F?"?force=true":""}`,{method:"POST"},!0)}async function zd(D){let F=D?`?user=${encodeURIComponent(D)}`:"";return y(`/admin/email-preferences${F}`,{},!0)}async function Zd(D,F){let $=F?`?user=${encodeURIComponent(F)}`:"";return y(`/admin/email-preferences${$}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(D)},!0)}async function hz(D){return y("/admin/notify",{method:"POST",body:JSON.stringify(D)},!0)}async function Vd(){return y("/admin/summary/coverage",{},!0)}async function Ed(D,F,$){return y("/admin/manifest/dispatch",{method:"POST",body:JSON.stringify({dataset_id:D,version:F,skip_canary:$?.skipCanary??!1})},!0)}var I5=k(()=>{S4()});async function s8(D,F){return y(`/datasets/${D}/upload-credentials`,{method:"POST",body:JSON.stringify({duration_seconds:F})},!0)}async function uz(D,F){return y(`/datasets/${D}/download-credentials`,{method:"POST",body:JSON.stringify({duration_seconds:F})},!0)}async function Ud(D){return y(`/admin/datasets/${D}/files`,{},!0)}async function Ld(D){let F,$=0,Q=[],J=!0;while(J){let Y=await y(`/admin/datasets/${D}/s3-lock`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({continuation_token:F})},!0);if($+=Y.locked,Y.failed?.length)Q.push(...Y.failed);if(J=Y.hasMore,F=Y.continuation_token,J&&!F)throw new g(500,"S3 lock paginated response missing continuation_token; aborting to avoid infinite loop")}return{locked:$,failed:Q}}var S5=k(()=>{S4();Z1()});async function EX(D){return y(`/datasets/${D}/ci/status`,{},!0)}async function Md(D){return y(`/datasets/${D}/manifest`,{},!0)}async function UX(D,F){return y(`/datasets/${D}/manifest/${F}`,{},!0)}function Ad(D){let F=D;if(!F.status)F.status="active";else if(!["active","archived","deleted"].includes(F.status))throw Error(`Invalid dataset status: ${F.status}`);if(!F.visibility)F.visibility="private";else if(!["public","private"].includes(F.visibility))throw Error(`Invalid dataset visibility: ${F.visibility}`);return F}async function k5(D={}){let F=new URLSearchParams;if(D.mine)F.set("mine","true");if(D.search)F.set("search",D.search);if(D.modality)F.set("modality",D.modality);if(D.author)F.set("author",D.author);if(D.task)F.set("task",D.task);if(D.license)F.set("license",D.license);if(D.hasDoi)F.set("has_doi","true");if(D.hasHed)F.set("has_hed","1");if(D.dataComplete)F.set("data_complete","1");if(D.recent)F.set("recent",String(D.recent));if(D.sort)F.set("sort",D.sort);if(D.limit!=null)F.set("limit",String(D.limit));if(D.offset!=null)F.set("offset",String(D.offset));if(D.owner)F.set("owner",D.owner);let $=F.toString()?`?${F.toString()}`:"",Q=await y(`/datasets${$}`,{},D.mine?!0:"optional");return Q.datasets=Q.datasets.map(Ad),Q}async function Nd(D){return y(`/datasets/resolve/${D}`,{},"optional")}async function Cd(D,F={}){let $=new URLSearchParams({q:D});if(F.modality)$.set("modality",F.modality);if(F.limit)$.set("limit",String(F.limit));if(F.hasHed)$.set("has_hed","1");return y(`/datasets/search?${$.toString()}`,{},"optional")}async function VD(D){let F=await y(`/datasets/${D}`,{},"optional");return Ad(F.dataset)}async function Od(D){return y(`/datasets/${D}/versions`,{},!0)}async function LX(D){return y("/datasets",{method:"POST",body:JSON.stringify(D)},!0)}async function MX(D){return y(`/datasets/${D}/finalize`,{method:"POST"},!0)}async function mz(D){return y(`/datasets/${D}/request-access`,{method:"POST"},!0)}async function jd(D,F){let $=F?`?status=${F}`:"";return y(`/datasets/${D}/access-requests${$}`,{},!0)}async function Rd(D,F){return y(`/datasets/${D}/access-requests/${F}/approve`,{method:"POST"},!0)}async function Td(D,F){return y(`/datasets/${D}/access-requests/${F}/deny`,{method:"POST"},!0)}async function wd(D,F){return y(`/datasets/${D}/invite`,{method:"POST",body:JSON.stringify({username:F})},!0)}async function Pd(D){return y(`/datasets/${D}/collaborators`,{},!0)}async function Id(D,F){return y(`/admin/datasets/${D}/enrichment`,{method:"POST",body:JSON.stringify(F)},!0)}var VX;var P3=k(()=>{S4();VX=/^\d{4}-\d{4}-\d{4}-\d{3}[\dX]$/});var v5;var xd=k(()=>{v5=["ci_check","enrichment_check","s3_public_read","repo_public","tag_protect","doi_create","update_metadata","update_readme","create_tag","create_release","upload_to_zenodo","publish_doi","version_doi","s3_lock","sync_nemar","notify_user"]});async function y5(D){return y(`/datasets/${D}/publish/request`,{method:"POST"},!0)}async function fd(D){return y(`/datasets/${D}/publish/status`,{},!0)}async function bd(D){return y(`/datasets/${D}/publish/resend`,{method:"POST"},!0)}async function gd(D){let F=D?`?status=${D}`:"";return y(`/admin/publish/requests${F}`,{},!0)}async function hd(D,F){return y(`/admin/publish/${D}/deny`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({reason:F})},!0)}function ES0(D,F=[]){if(D){let $=v5.indexOf(D);if($>=0)return $+1}return Math.min(F.length+1,v5.length)}function US0(D){if(!(D instanceof g))return!1;if(D.statusCode===0)return!0;if(D.statusCode===429)return!0;if(D.statusCode>=500&&D.statusCode<600)return!0;if(D.statusCode===403&&/repository has been locked/i.test(D.message))return!0;return!1}async function x5(D,F=!1,$=!1,Q=!1,J,Y){let B,H,q=0,K=!1,Z,z=F,E=[],U;function L(A,N,j,T){if(!Y)return;Y({step:A,stepIndex:ES0(A,N),stepTotal:v5.length,s3LockLocked:j,s3LockTotal:T,s3LockResumed:A==="s3_lock"&&K?!0:void 0})}for(let A=1;A<=5;A++)try{let N,j=!0;do{if(N=await y(`/admin/publish/${D}/approve`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({resume:j?z:!0,sandbox:$,s3_lock_continuation_token:B,s3_lock_total:H,skip_ci_check:Q})},!0),j=!1,N.step_results)E.push(...N.step_results);if(N.s3_lock_total!==void 0)H=N.s3_lock_total;if(N.s3_lock_batch_count!==void 0)q+=N.s3_lock_batch_count;let T=N.step??N.step_results?.[N.step_results.length-1]?.step;if(T&&(T!==Z||T==="s3_lock"))L(T,N.steps_completed??[],T==="s3_lock"?q:void 0,T==="s3_lock"?H:void 0),Z=T;if(N.hasMore&&N.s3_lock_continuation_token!==void 0)B=N.s3_lock_continuation_token;else break}while(N.hasMore);if(E.length>0)N.step_results=_d(E);return N}catch(N){if(U=N,A===5||!US0(N)){if(N instanceof g&&E.length>0)N.stepResults=_d(E);throw N}let T=N;if(J?.({attempt:A,maxAttempts:5,delayMs:1e4,step:T.step,error:T.message}),await new Promise((C)=>setTimeout(C,1e4)),z=!0,B!==void 0)K=!0}throw U}function _d(D){let F=new Map;for(let $ of D)F.set($.step,$);return Array.from(F.values())}var W$=k(()=>{xd();S4();Z1()});function ld(D){dz=D}function cz(){return dz}function H$(D){if(dz)process.stderr.write(`${D}
106
106
  `)}var dz=!1;var pd={};v6(pd,{runCommand:()=>w});var{spawn:LS0}=globalThis.Bun;async function w(D,F={}){let $={...process.env,GIT_TERMINAL_PROMPT:"0",...F.env};for(let H of F.unsetEnv??[])delete $[H];let Q=LS0({cmd:D,cwd:F.cwd,stdout:"pipe",stderr:"pipe",env:$}),J=!1,Y;if(F.timeout)Y=setTimeout(()=>{J=!0,Q.kill()},F.timeout);if(cz()){let H=F.cwd?` (cwd=${F.cwd})`:"";H$(W.dim(`$ ${D.join(" ")}${H}`))}let X=await new Response(Q.stdout).text(),G=await new Response(Q.stderr).text(),B=await Q.exited;if(Y)clearTimeout(Y);if(cz()){if(X.trim())H$(W.dim(X.trimEnd()));if(G.trim())H$(W.yellow(G.trimEnd()));H$(W.dim(`(exit ${B})`))}if(J)return{stdout:X,stderr:G||`Command timed out after ${Math.round(F.timeout/1000)}s`,exitCode:B??1};return{stdout:X,stderr:G,exitCode:B}}var V1=k(()=>{e0()});async function MS0(){try{let{exitCode:D,stderr:F}=await w(["ssh","-T","-o","BatchMode=yes","-o","ConnectTimeout=5","git@github.com"]),$=F.includes("successfully authenticated");if(!$)console.warn("SSH test to github.com failed:",{exitCode:D,stderr:F.trim().slice(0,500)});return{works:$,error:$?void 0:F.trim().slice(0,500)}}catch(D){let F=D instanceof Error?D.message:String(D);return console.warn("SSH test exception:",F),{works:!1,error:F}}}async function q$(){try{let{stdout:D,exitCode:F,stderr:$}=await w(["gh","auth","token"]);if(F!==0)return console.warn("gh CLI returned non-zero exit code:",F),console.warn("stderr:",$),{token:null,error:`gh auth token failed: ${$.trim()||"unknown error"}`};if(!D.trim())return console.warn("gh auth token returned empty output"),{token:null,error:"gh CLI returned empty token"};return{token:D.trim()}}catch(D){let F=D instanceof Error?D.message:String(D);if(console.error("Failed to get GitHub token from gh CLI:",F),F.includes("ENOENT")||F.includes("not found"))return{token:null,error:"gh CLI not installed (command not found)"};return{token:null,error:`gh CLI error: ${F}`}}}async function AX(D){try{let{stdout:F,exitCode:$,stderr:Q}=await w(["gh","api","user","--jq",".login"]);if($!==0){if(Q.includes("not logged in")||Q.includes("auth login"))return{authenticated:!1,error:"gh CLI not authenticated. Run 'gh auth login' to authenticate."};return{authenticated:!1,error:`gh CLI error: ${Q.trim()||"unknown error"}`}}let J=F.trim();if(!J)return{authenticated:!1,error:"gh CLI returned empty username"};if(D){let Y=J.toLowerCase()===D.toLowerCase();return{authenticated:!0,username:J,matches:Y,error:Y?void 0:`gh CLI authenticated as '${J}', expected '${D}'`}}return{authenticated:!0,username:J}}catch(F){let $=F instanceof Error?F.message:String(F);if($.includes("ENOENT")||$.includes("not found"))return{authenticated:!1,error:"gh CLI not installed. Install from https://cli.github.com/"};return{authenticated:!1,error:`Failed to verify gh CLI: ${$}`}}}async function NX(D){if(!/^[a-zA-Z0-9_.-]+\/[a-zA-Z0-9_.-]+$/.test(D))return{accepted:!1,error:`Invalid repository format: ${D}`};let{stdout:F,exitCode:$,stderr:Q}=await w(["gh","api","/user/repository_invitations"]);if($!==0){if(Q.includes("not logged in")||Q.includes("auth login"))return{accepted:!1,error:"gh CLI not authenticated. Run 'gh auth login' to authenticate."};if(Q.includes("API rate limit")||Q.includes("403"))return{accepted:!1,error:"GitHub API rate limit exceeded. Please try again in a few minutes."};if(Q.includes("ENOENT")||Q.includes("not found"))return{accepted:!1,error:"gh CLI not installed. Install from https://cli.github.com/"};return{accepted:!1,error:`Failed to list invitations: ${Q.trim()||"unknown error"}`}}let J=null;try{J=JSON.parse(F||"[]").find((H)=>H.repository.full_name===D)?.id??null}catch(G){let B=G instanceof Error?G.message:String(G);return console.error("Failed to parse GitHub invitations response:",B),console.error(" Raw response (first 500 chars):",(F||"").slice(0,500)),{accepted:!1,error:`Failed to parse GitHub API response: ${B}`}}if(!J){let{exitCode:G}=await w(["gh","api",`/repos/${D}`,"--silent"]);if(G===0)return{accepted:!0,alreadyCollaborator:!0};return{accepted:!1,error:`No pending invitation found for ${D}. You may need to accept it manually via GitHub.`}}let{exitCode:Y,stderr:X}=await w(["gh","api","--method","PATCH",`/user/repository_invitations/${J}`]);if(Y!==0)return{accepted:!1,error:`Failed to accept invitation: ${X.trim()||"unknown error"}`};return{accepted:!0}}async function r8(D,F,$="origin"){let Q=F;if(process.env.GH_TOKEN&&F.startsWith("git@github.com:")){let J=process.env.GH_TOKEN.trim();if(!J||/\s/.test(J))return{success:!1,error:"GH_TOKEN environment variable is set but appears malformed (empty or contains whitespace)"};Q=`https://github.com/${F.replace("git@github.com:","")}`,await w(["git","config","credential.https://github.com.helper",`!printf 'username=x-access-token\\npassword=${J}'`],{cwd:D})}else if(F.startsWith("git@github.com:")){let J=F.replace("git@github.com:",""),Y=await q$();if(Y.token)Q=`https://github.com/${J}`,await w(["git","config","credential.https://github.com.helper",`!printf 'username=x-access-token\\npassword=${Y.token}'`],{cwd:D});else{let X=await MS0();if(X.works)Q=F;else return{success:!1,error:`GitHub authentication not configured.
107
107
 
108
108
  gh CLI failed: ${Y.error||"could not get token"}
@@ -681,7 +681,7 @@ Examples:
681
681
  $ nemar dataset download nm000104 --tasks rest --datatypes eeg # Subset
682
682
  $ nemar dataset download nm000104 --stimuli # Also download stimuli/
683
683
  $ nemar dataset download nm000104 --stimuli --derivatives # Download everything
684
- $ nemar dataset download ds000248 # Download from OpenNeuro`).action(async(D,F)=>{let $=await jy0(D);if(!$){await Oy0(D,F);return}if(F.resume&&F.update)console.log(W.red("Error: --resume and --update are mutually exclusive.")),process.exit(1);if(F.prune&&!F.update)console.log(W.red("Error: --prune requires --update.")),process.exit(1);let Q=aX({subjects:F.subjects,sessions:F.sessions,tasks:F.tasks,runs:F.runs,datatypes:F.datatypes,include:F.include,exclude:F.exclude,excludeStimuli:F.stimuli!==!0,excludeDerivatives:F.derivatives!==!0});if(Q.active&&F.data===!1)console.log(W.red("Error: --no-data cannot be combined with BIDS filters (--subjects, --tasks, etc.). Filters imply data download.")),process.exit(1);await v3("download");let J=O("Checking git-annex...").start(),Y=await z$();if(!Y.allPassed){J.fail("Prerequisites check failed"),console.log();for(let A of Y.errors)console.log(W.red(` - ${A}`));process.exit(1)}J.succeed(`git-annex ${Y.gitAnnex.version}`),J=O(`Fetching dataset info for ${$}...`).start();let X;try{X=await VD($),J.succeed(`Found dataset: ${X.name}`)}catch(A){if(J.fail("Dataset not found"),A instanceof g)console.log(W.red(` ${A.message}`));else console.log(W.red(` ${A.message}`));process.exit(1)}if(!X.github_repo)console.log(W.red("Error: Dataset repository not available")),process.exit(1);let G=F.output||$,B=k6(G),H,q=F.resume?"resume":F.update?"update":null;if(q){if(!w1(B))console.log(W.red(`Error: --${q} target does not exist: ${B}`)),console.log(W.dim(`Drop --${q} to perform a fresh clone.`)),process.exit(1);if(J=O(`Validating ${q} target...`).start(),!await C8(B))J.fail("Not a git-annex dataset"),console.log(W.red(` ${B} is not a git-annex repository.`)),console.log(W.dim(`--${q} requires a previous clone of the same dataset.`)),process.exit(1);let A=await k4(B);if(A!==$)J.fail("Dataset ID mismatch"),console.log(W.red(` Expected ${$}, but ${B} is a clone of ${A??"an unknown repo"}.`)),process.exit(1);let N=await td(B);if(N.error)J.fail("Could not check working tree status"),console.log(W.red(` ${N.error}`)),process.exit(1);if(N.dirty)J.fail("Working tree is dirty"),console.log(W.red(` Refusing to ${q} with uncommitted local changes.`)),console.log(W.dim(" Commit, stash, or discard them first.")),process.exit(1);let j=await ed(B);if(!j.success)J.fail("Failed to fetch remote refs"),console.log(W.red(` ${j.error}`)),process.exit(1);let T=od(B);if(T.error)console.log(W.yellow(` Warning: ${T.error}`));let C=await sd(B);for(let b of C.warnings)console.log(W.yellow(` Warning: ${b}`));let P=T.version,R=C.version;if(F.resume){if(P&&R&&P!==R)J.fail("Local clone is behind upstream"),console.log(W.red(` Local version: ${P} | Remote HEAD: ${R}`)),console.log(W.dim(" Run `nemar dataset download <id> --update` to pull the version diff.")),process.exit(1);J.succeed(`Resume target verified: ${$}`)}else{if(P&&R&&P===R)J.succeed(`Already up to date (${P})`),process.exit(0);if(J.succeed(`Update plan: ${P??"unknown"} \u2192 ${R??"HEAD"}`),P&&R){J=O("Computing version diff from manifests...").start();try{let[r,M0]=await Promise.all([UX($,P),UX($,R)]),_0=Gi(r,M0);if(J.succeed(`Diff: +${_0.added.length} added, ~${_0.changed.length} changed, -${_0.removed.length} removed`),H=[..._0.added,..._0.changed],H.length===0)console.log(W.dim(" No annex content changes between versions; metadata-only update."))}catch(r){let M0=r.message;if(J.warn(`Manifest diff unavailable: ${M0}`),/401|403|unauthor/i.test(M0))console.log(W.yellow(" Looks like an auth issue. Run `nemar auth status` to verify."));else if(!/404|not found/i.test(M0))console.log(W.yellow(" Unexpected manifest error. Please report if this recurs."));console.log(W.dim(" Falling back to full git annex get (skips already-present files).")),H=void 0}}let b=await t8(B);if(b?.startsWith("adjusted/"))console.log(W.red(` --update is not supported on git-annex adjusted branches (${b}).`)),console.log(W.dim(" Run `git -C <clone> annex sync` to bring the clone onto a normal branch first.")),process.exit(1);J=O("Resolving remote tracking branch...").start();let I=await rd(B);if(!I.ref)J.fail("Cannot resolve remote tracking branch"),console.log(W.red(` ${I.error??"no upstream ref found"}`)),process.exit(1);J.text=`Fast-forwarding to ${I.ref}...`;let f=await Dc(B,I.ref);if(!f.success)J.fail("Cannot fast-forward (local has diverging commits)"),console.log(W.red(` ${f.error}`)),console.log(W.dim(" Use `nemar dataset update` (PR workflow) to push local changes first.")),process.exit(1);J.succeed(`Merged ${I.ref}`)}}else if(w1(B))console.log(W.red(`Error: Output path already exists: ${B}`)),console.log("Remove or rename the existing directory, or pass --resume / --update to reuse it."),process.exit(1);console.log();let K=F.update?"Update Plan:":F.resume?"Resume Plan:":"Download Plan:";if(console.log(W.bold(K)),console.log(` Dataset: ${X.name} (${$})`),console.log(` Output: ${B}`),console.log(` Data files: ${F.data===!1?"metadata only":"included"}`),F.data!==!1)console.log(` Parallel jobs: ${F.jobs}`);if(F.update&&H&&H.length>0)console.log(` Files to fetch: ${H.length}`);if(Q.active)for(let A of Q.summary)console.log(` Filter ${A}`);if(console.log(),!q){let A=`https://github.com/${X.github_repo}.git`;J=O("Cloning metadata from GitHub...").start();let N=await E1(A,B);if(!N.success)J.fail("Failed to clone dataset"),console.log(W.red(` ${N.error}`)),process.exit(1);J.succeed("Metadata cloned")}if(!F.skipPortCheck&&X.source==="openneuro"&&F.data!==!1){if(await nz(B)==="absent")console.log(),console.log(W.yellow("Porting still in progress.")),console.log(W.dim(" This dataset is being imported from OpenNeuro. Data files are not yet available.")),console.log(W.dim(" The metadata-only clone is already at the path above.")),console.log(W.dim(" Wait 5\u201330 minutes (depending on dataset size), then run:")),console.log(W.dim(` cd ${B} && nemar dataset get`)),console.log(W.dim(" Run 'nemar dataset status <id>' to track porting progress.")),console.log(W.dim(" Pass --skip-port-check to bypass this check if you are certain porting is complete.")),process.exit(1)}let Z=await Oa($,X.visibility),z=await f5(B,"nemar-s3",Z);if(z.enabled)console.log(W.dim(" S3 remote enabled for data downloads"));else if(!z.success)console.log(W.yellow(` Warning: Could not enable S3 remote: ${z.error}`));if(F.data===!1||F.update&&H&&H.length===0){if(F.data===!1)console.log(W.dim("Skipping data files (--no-data flag)"))}else{for(let C of Q.summary)console.log(W.dim(` ${C}`));console.log(W.bold(`Downloading data files (${F.jobs} parallel streams)...`));let A=Q.args.length>0?Q.args:void 0,N=await tz(B,void 0,A),j=new RX(N?.fileCount??0,N?.totalBytes??0),T=await ez(B,{jobs:Number.parseInt(F.jobs,10),credentials:Z,paths:H,extraArgs:A,requireComplete:Boolean(F.requireComplete),onProgress:(C)=>j.processLine(C)});if(!T.success){if(j.finish(0),console.log(W.red(`Failed to download data files: ${T.error}`)),console.log(W.dim("The dataset was cloned but data files are not available locally.")),console.log(W.dim(`You can try again with: cd ${B} && nemar dataset get`)),Z)await uD(B);process.exit(1)}if(j.finish(T.filesDownloaded),T.outcome==="partial")xZ(T);else console.log(W.green(`Data downloaded (${T.filesDownloaded} files)`))}if(F.update&&F.prune){J=O("Pruning orphan annex objects...").start();let A=await Lc(B);if(A.success)J.succeed(`Pruned ${A.dropped??0} unused annex objects`);else J.warn(`Prune skipped: ${A.error}`)}if(Z)await uD(B);let U=await nd(B);console.log();let L=F.update?"Update complete!":F.resume?"Resume complete!":"Download complete!";if(console.log(W.green.bold(L)),console.log(),console.log(` Location: ${W.cyan(B)}`),U){if(console.log(` Files: ${U.files}`),U.size!=="unknown")console.log(` Size: ${U.size}`);if(U.missingFiles>0)console.log(W.dim(` Missing files: ${U.missingFiles} (use 'git annex get' to download)`))}if(console.log(),F.update)console.log(W.dim("Note: --update fetches only the version diff. If a prior version was")),console.log(W.dim("partially downloaded, run with --resume to fill any pre-existing gaps.")),console.log();console.log(W.dim("To get additional data:")),console.log(W.dim(` cd ${B} && git annex get <path>`))});BD.command("status").description("Check status of a dataset").argument("<dataset-id>","Dataset ID (e.g., nm000104)").option("--json","Output as JSON for scripting").addHelpText("after",`
684
+ $ nemar dataset download ds000248 # Download from OpenNeuro`).action(async(D,F)=>{let $=await jy0(D);if(!$){await Oy0(D,F);return}if(F.resume&&F.update)console.log(W.red("Error: --resume and --update are mutually exclusive.")),process.exit(1);if(F.prune&&!F.update)console.log(W.red("Error: --prune requires --update.")),process.exit(1);let Q=aX({subjects:F.subjects,sessions:F.sessions,tasks:F.tasks,runs:F.runs,datatypes:F.datatypes,include:F.include,exclude:F.exclude,excludeStimuli:F.stimuli!==!0,excludeDerivatives:F.derivatives!==!0});if(Q.active&&F.data===!1)console.log(W.red("Error: --no-data cannot be combined with BIDS filters (--subjects, --tasks, etc.). Filters imply data download.")),process.exit(1);await v3("download");let J=O("Checking git-annex...").start(),Y=await z$();if(!Y.allPassed){J.fail("Prerequisites check failed"),console.log();for(let A of Y.errors)console.log(W.red(` - ${A}`));process.exit(1)}J.succeed(`git-annex ${Y.gitAnnex.version}`),J=O(`Fetching dataset info for ${$}...`).start();let X;try{X=await VD($),J.succeed(`Found dataset: ${X.name}`)}catch(A){if(J.fail("Dataset not found"),A instanceof g)console.log(W.red(` ${A.message}`));else console.log(W.red(` ${A.message}`));process.exit(1)}if(!X.github_repo)console.log(W.red("Error: Dataset repository not available")),process.exit(1);let G=F.output||$,B=k6(G),H,q=F.resume?"resume":F.update?"update":null;if(q){if(!w1(B))console.log(W.red(`Error: --${q} target does not exist: ${B}`)),console.log(W.dim(`Drop --${q} to perform a fresh clone.`)),process.exit(1);if(J=O(`Validating ${q} target...`).start(),!await C8(B))J.fail("Not a git-annex dataset"),console.log(W.red(` ${B} is not a git-annex repository.`)),console.log(W.dim(`--${q} requires a previous clone of the same dataset.`)),process.exit(1);let A=await k4(B);if(A!==$)J.fail("Dataset ID mismatch"),console.log(W.red(` Expected ${$}, but ${B} is a clone of ${A??"an unknown repo"}.`)),process.exit(1);let N=await td(B);if(N.error)J.fail("Could not check working tree status"),console.log(W.red(` ${N.error}`)),process.exit(1);if(N.dirty)J.fail("Working tree is dirty"),console.log(W.red(` Refusing to ${q} with uncommitted local changes.`)),console.log(W.dim(" Commit, stash, or discard them first.")),process.exit(1);let j=await ed(B);if(!j.success)J.fail("Failed to fetch remote refs"),console.log(W.red(` ${j.error}`)),process.exit(1);let T=od(B);if(T.error)console.log(W.yellow(` Warning: ${T.error}`));let C=await sd(B);for(let b of C.warnings)console.log(W.yellow(` Warning: ${b}`));let P=T.version,R=C.version;if(F.resume){if(P&&R&&P!==R)J.fail("Local clone is behind upstream"),console.log(W.red(` Local version: ${P} | Remote HEAD: ${R}`)),console.log(W.dim(" Run `nemar dataset download <id> --update` to pull the version diff.")),process.exit(1);J.succeed(`Resume target verified: ${$}`)}else{if(P&&R&&P===R)J.succeed(`Already up to date (${P})`),process.exit(0);if(J.succeed(`Update plan: ${P??"unknown"} \u2192 ${R??"HEAD"}`),P&&R){J=O("Computing version diff from manifests...").start();try{let[r,M0]=await Promise.all([UX($,P),UX($,R)]),_0=Gi(r,M0);if(J.succeed(`Diff: +${_0.added.length} added, ~${_0.changed.length} changed, -${_0.removed.length} removed`),H=[..._0.added,..._0.changed],H.length===0)console.log(W.dim(" No annex content changes between versions; metadata-only update."))}catch(r){let M0=r.message;if(J.warn(`Manifest diff unavailable: ${M0}`),/401|403|unauthor/i.test(M0))console.log(W.yellow(" Looks like an auth issue. Run `nemar auth status` to verify."));else if(!/404|not found/i.test(M0))console.log(W.yellow(" Unexpected manifest error. Please report if this recurs."));console.log(W.dim(" Falling back to full git annex get (skips already-present files).")),H=void 0}}let b=await t8(B);if(b?.startsWith("adjusted/"))console.log(W.red(` --update is not supported on git-annex adjusted branches (${b}).`)),console.log(W.dim(" Run `git -C <clone> annex sync` to bring the clone onto a normal branch first.")),process.exit(1);J=O("Resolving remote tracking branch...").start();let I=await rd(B);if(!I.ref)J.fail("Cannot resolve remote tracking branch"),console.log(W.red(` ${I.error??"no upstream ref found"}`)),process.exit(1);J.text=`Fast-forwarding to ${I.ref}...`;let f=await Dc(B,I.ref);if(!f.success)J.fail("Cannot fast-forward (local has diverging commits)"),console.log(W.red(` ${f.error}`)),console.log(W.dim(" Use `nemar dataset update` (PR workflow) to push local changes first.")),process.exit(1);J.succeed(`Merged ${I.ref}`)}}else if(w1(B))console.log(W.red(`Error: Output path already exists: ${B}`)),console.log("Remove or rename the existing directory, or pass --resume / --update to reuse it."),process.exit(1);console.log();let K=F.update?"Update Plan:":F.resume?"Resume Plan:":"Download Plan:";if(console.log(W.bold(K)),console.log(` Dataset: ${X.name} (${$})`),console.log(` Output: ${B}`),console.log(` Data files: ${F.data===!1?"metadata only":"included"}`),F.data!==!1)console.log(` Parallel jobs: ${F.jobs}`);if(F.update&&H&&H.length>0)console.log(` Files to fetch: ${H.length}`);if(Q.active)for(let A of Q.summary)console.log(` Filter ${A}`);if(console.log(),!q){let A=`https://github.com/${X.github_repo}.git`;J=O("Cloning metadata from GitHub...").start();let N=await E1(A,B);if(!N.success)J.fail("Failed to clone dataset"),console.log(W.red(` ${N.error}`)),process.exit(1);J.succeed("Metadata cloned")}if(!F.skipPortCheck&&X.source==="openneuro"&&F.data!==!1){if(await nz(B)==="absent")console.log(),console.log(W.yellow("Porting still in progress.")),console.log(W.dim(" This dataset is being imported from OpenNeuro. Data files are not yet available.")),console.log(W.dim(" The metadata-only clone is already at the path above.")),console.log(W.dim(" Wait 5\u201330 minutes (depending on dataset size), then run:")),console.log(W.dim(` cd ${B} && nemar dataset get`)),console.log(W.dim(" Run 'nemar dataset status <id>' to track porting progress.")),console.log(W.dim(" Pass --skip-port-check to bypass this check if you are certain porting is complete.")),process.exit(1)}let Z=await Oa($,X.visibility),z=await f5(B,"nemar-s3",Z);if(z.enabled)console.log(W.dim(" S3 remote enabled for data downloads"));else if(!z.success)console.log(W.yellow(` Warning: Could not enable S3 remote: ${z.error}`));if(F.data===!1||F.update&&H&&H.length===0){if(F.data===!1)console.log(W.dim("Skipping data files (--no-data flag)"))}else{for(let C of Q.summary)console.log(W.dim(` ${C}`));console.log(W.bold(`Downloading data files (${F.jobs} parallel streams)...`));let A=Q.args.length>0?Q.args:void 0,N=await tz(B,void 0,A),j=new RX(N?.fileCount??0,N?.totalBytes??0),T=await ez(B,{jobs:Number.parseInt(F.jobs,10),credentials:Z,paths:H,extraArgs:A,requireComplete:Boolean(F.requireComplete),onProgress:(C)=>j.processLine(C)});if(!T.success){if(j.finish(T.filesDownloaded),console.log(W.red(`Failed to download data files: ${T.error}`)),console.log(W.dim("The dataset was cloned but data files are not available locally.")),console.log(W.dim(`You can try again with: cd ${B} && nemar dataset get`)),Z)await uD(B);process.exit(1)}if(j.finish(T.filesDownloaded),T.outcome==="partial")xZ(T);else console.log(W.green(`Data downloaded (${T.filesDownloaded} files)`))}if(F.update&&F.prune){J=O("Pruning orphan annex objects...").start();let A=await Lc(B);if(A.success)J.succeed(`Pruned ${A.dropped??0} unused annex objects`);else J.warn(`Prune skipped: ${A.error}`)}if(Z)await uD(B);let U=await nd(B);console.log();let L=F.update?"Update complete!":F.resume?"Resume complete!":"Download complete!";if(console.log(W.green.bold(L)),console.log(),console.log(` Location: ${W.cyan(B)}`),U){if(console.log(` Files: ${U.files}`),U.size!=="unknown")console.log(` Size: ${U.size}`);if(U.missingFiles>0)console.log(W.dim(` Missing files: ${U.missingFiles} (use 'git annex get' to download)`))}if(console.log(),F.update)console.log(W.dim("Note: --update fetches only the version diff. If a prior version was")),console.log(W.dim("partially downloaded, run with --resume to fill any pre-existing gaps.")),console.log();console.log(W.dim("To get additional data:")),console.log(W.dim(` cd ${B} && git annex get <path>`))});BD.command("status").description("Check status of a dataset").argument("<dataset-id>","Dataset ID (e.g., nm000104)").option("--json","Output as JSON for scripting").addHelpText("after",`
685
685
  Description:
686
686
  Show detailed information about a NEMAR dataset including owner,
687
687
  creation date, GitHub repository, and DOI information.
@@ -928,7 +928,7 @@ Examples:
928
928
  $ nemar dataset get --stimuli --derivatives # Get everything
929
929
  $ nemar dataset get sub-01/eeg/ # Get specific directory
930
930
  $ nemar dataset get stimuli/ # Explicit path: fetches stimuli/
931
- $ nemar dataset get *.edf -j 8 # Get EDF files with 8 streams`).action(async(D,F)=>{let $=process.cwd();if(!await C8($))console.log(W.red("Error: Not inside a git-annex dataset directory")),console.log(W.dim("Use 'nemar dataset clone <id>' first, then cd into the dataset.")),process.exit(1);let Q=Number.parseInt(F.jobs,10);if(Number.isNaN(Q)||Q<1)console.log(W.red("Error: --jobs must be a positive integer")),process.exit(1);let J=null,Y=await k4($);if(Y){let U=null,L=!0;try{U=await VD(Y)}catch(A){if(A instanceof g&&A.statusCode!==0){if(A.statusCode===401||A.statusCode===403)console.log(W.red(`\u2716 ${A.message}`)),console.log(W.dim(" Run 'nemar auth login' or 'nemar auth regenerate-key'.")),process.exit(1);throw A}L=!1}if(!F.skipPortCheck){let A=U?.source==="openneuro";if(!L&&!A){let N=d5($,".nemar","metadata.json");if(w1(N))try{A=JSON.parse(rX(N,"utf-8")).source==="openneuro"}catch{}}if(A){if(await nz($)==="absent")console.log(W.yellow("Porting still in progress.")),console.log(W.dim(" This dataset is being imported from OpenNeuro. Data files are not yet available.")),console.log(W.dim(" Wait 5\u201330 minutes (depending on dataset size), then retry.")),console.log(W.dim(" Run 'nemar dataset status <id>' to track progress.")),console.log(W.dim(" Pass --skip-port-check to bypass this check if you are certain porting is complete.")),process.exit(1)}}if(U&&U.visibility!=="public"){if(!m0())console.log(W.red("Error: This is a private dataset. Authentication required.")),console.log(W.dim("Run 'nemar auth login' first.")),process.exit(1);let A=O("Requesting download credentials...").start();try{J=await uz(Y),A.succeed("Download credentials received (2h expiry)")}catch(N){A.fail("Failed to get download credentials"),console.log(W.red(` ${N.message}`)),console.log(W.dim("Private datasets require authentication. Run 'nemar auth login' first.")),process.exit(1)}}}let X=J?hD(J.credentials):void 0,G=await f5($,"nemar-s3",X);if(!G.success&&!G.enabled)console.log(W.yellow(` Warning: Could not enable S3 remote: ${G.error}`));let B=D.length>0?D:void 0,H=$i(B,{stimuli:F.stimuli,derivatives:F.derivatives}),q=H.args.length>0?H.args:void 0;for(let U of H.summary)console.log(W.dim(` ${U}`));let K=await tz($,B,q);if(K&&K.fileCount===0){if(console.log(W.green("All data files already present")),J)await uD($);return}let Z=B?`Getting ${B.length} path(s)${K?` (${K.fileCount} files, ${GD(K.totalBytes)})`:""}...`:`Getting all data files${K?` (${K.fileCount} files, ${GD(K.totalBytes)})`:""}...`;console.log(W.bold(Z));let z=new RX(K?.fileCount??0,K?.totalBytes??0),E=await ez($,{jobs:Q,paths:B,credentials:X,extraArgs:q,requireComplete:Boolean(F.requireComplete),onProgress:(U)=>z.processLine(U)});if(!E.success){if(z.finish(0),console.log(W.red(` ${E.error}`)),J)await uD($);process.exit(1)}if(z.finish(E.filesDownloaded),J)await uD($);if(E.outcome==="partial")xZ(E);else if(E.filesDownloaded===0)console.log(W.green("All data files already present"));else console.log(W.green(`Downloaded ${E.filesDownloaded} file(s)`))});async function ja(D){let F=process.cwd();if(!await C8(F))console.log(W.red("Error: Not inside a git-annex dataset directory")),process.exit(1);let $=O("Saving changes...").start(),Q=await P6(F,D.message);if(!Q.success)$.fail("Save failed"),console.log(W.red(` ${Q.error}`)),process.exit(1);$.succeed("Changes saved")}BD.command("commit").description("Stage and commit changes in the current dataset").option("-m, --message <msg>","Commit message","Save changes").addHelpText("after",`
931
+ $ nemar dataset get *.edf -j 8 # Get EDF files with 8 streams`).action(async(D,F)=>{let $=process.cwd();if(!await C8($))console.log(W.red("Error: Not inside a git-annex dataset directory")),console.log(W.dim("Use 'nemar dataset clone <id>' first, then cd into the dataset.")),process.exit(1);let Q=Number.parseInt(F.jobs,10);if(Number.isNaN(Q)||Q<1)console.log(W.red("Error: --jobs must be a positive integer")),process.exit(1);let J=null,Y=await k4($);if(Y){let U=null,L=!0;try{U=await VD(Y)}catch(A){if(A instanceof g&&A.statusCode!==0){if(A.statusCode===401||A.statusCode===403)console.log(W.red(`\u2716 ${A.message}`)),console.log(W.dim(" Run 'nemar auth login' or 'nemar auth regenerate-key'.")),process.exit(1);throw A}L=!1}if(!F.skipPortCheck){let A=U?.source==="openneuro";if(!L&&!A){let N=d5($,".nemar","metadata.json");if(w1(N))try{A=JSON.parse(rX(N,"utf-8")).source==="openneuro"}catch{}}if(A){if(await nz($)==="absent")console.log(W.yellow("Porting still in progress.")),console.log(W.dim(" This dataset is being imported from OpenNeuro. Data files are not yet available.")),console.log(W.dim(" Wait 5\u201330 minutes (depending on dataset size), then retry.")),console.log(W.dim(" Run 'nemar dataset status <id>' to track progress.")),console.log(W.dim(" Pass --skip-port-check to bypass this check if you are certain porting is complete.")),process.exit(1)}}if(U&&U.visibility!=="public"){if(!m0())console.log(W.red("Error: This is a private dataset. Authentication required.")),console.log(W.dim("Run 'nemar auth login' first.")),process.exit(1);let A=O("Requesting download credentials...").start();try{J=await uz(Y),A.succeed("Download credentials received (2h expiry)")}catch(N){A.fail("Failed to get download credentials"),console.log(W.red(` ${N.message}`)),console.log(W.dim("Private datasets require authentication. Run 'nemar auth login' first.")),process.exit(1)}}}let X=J?hD(J.credentials):void 0,G=await f5($,"nemar-s3",X);if(!G.success&&!G.enabled)console.log(W.yellow(` Warning: Could not enable S3 remote: ${G.error}`));let B=D.length>0?D:void 0,H=$i(B,{stimuli:F.stimuli,derivatives:F.derivatives}),q=H.args.length>0?H.args:void 0;for(let U of H.summary)console.log(W.dim(` ${U}`));let K=await tz($,B,q);if(K&&K.fileCount===0){if(console.log(W.green("All data files already present")),J)await uD($);return}let Z=B?`Getting ${B.length} path(s)${K?` (${K.fileCount} files, ${GD(K.totalBytes)})`:""}...`:`Getting all data files${K?` (${K.fileCount} files, ${GD(K.totalBytes)})`:""}...`;console.log(W.bold(Z));let z=new RX(K?.fileCount??0,K?.totalBytes??0),E=await ez($,{jobs:Q,paths:B,credentials:X,extraArgs:q,requireComplete:Boolean(F.requireComplete),onProgress:(U)=>z.processLine(U)});if(!E.success){if(z.finish(E.filesDownloaded),console.log(W.red(` ${E.error}`)),J)await uD($);process.exit(1)}if(z.finish(E.filesDownloaded),J)await uD($);if(E.outcome==="partial")xZ(E);else if(E.filesDownloaded===0)console.log(W.green("All data files already present"));else console.log(W.green(`Downloaded ${E.filesDownloaded} file(s)`))});async function ja(D){let F=process.cwd();if(!await C8(F))console.log(W.red("Error: Not inside a git-annex dataset directory")),process.exit(1);let $=O("Saving changes...").start(),Q=await P6(F,D.message);if(!Q.success)$.fail("Save failed"),console.log(W.red(` ${Q.error}`)),process.exit(1);$.succeed("Changes saved")}BD.command("commit").description("Stage and commit changes in the current dataset").option("-m, --message <msg>","Commit message","Save changes").addHelpText("after",`
932
932
  Description:
933
933
  Stage all changes (git add -A) and commit them. Large files are
934
934
  automatically handled by git-annex based on the dataset's largefiles config.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nemar-cli",
3
- "version": "0.9.7-dev.1925",
3
+ "version": "0.9.7-dev.1927",
4
4
  "description": "CLI for NEMAR (Neuroelectromagnetic Data Archive and Tools Resource) dataset management",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",