nemar-cli 0.8.64-PR811.205183a → 0.8.64-PR813.7cdea26
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/dist/index.js +3 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -95,7 +95,7 @@ ${W.dim(`eta: ${D.eta}`)}`:"";process.stderr.write(`${F}
|
|
|
95
95
|
${$} ${D.message}
|
|
96
96
|
${J}${Q}
|
|
97
97
|
${F}
|
|
98
|
-
`)}var lf=!1;var SW=S(()=>{ND()});var df;var pf=S(()=>{df={name:"nemar-cli",version:"0.8.64-PR811.205183a",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",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 _4;var eJ=S(()=>{pf();_4=df.version});function L0(D){if(D instanceof Error)return D.message;return String(D)}function cf(){if(process.env.TEST_API_URL)return process.env.TEST_API_URL;if(vW)return kW;return $D().apiUrl||kW}async function x(D,F={},$=!1){let J=`${cf()}${D}`,Q={"Content-Type":"application/json","X-CLI-Version":_4,...F.headers};if($){let X=$D();if(!X.apiKey&&$===!0)throw new f(401,"Not authenticated. Run 'nemar auth login' first.");if(X.apiKey)Q.Authorization=`Bearer ${X.apiKey}`}let Y;try{Y=await fetch(J,{...F,headers:Q})}catch(X){throw new f(0,`Network error: Could not connect to ${cf()}`,{originalError:X instanceof Error?X.message:String(X)})}let B;try{B=await Y.json()}catch{throw new f(Y.status,`Invalid response from server (status ${Y.status})`)}if(!Y.ok){if(Y.status===503&&(B.mode==="read-only"||B.mode==="full")){let X=typeof B.message==="string"?B.message:"NEMAR is in maintenance mode. Please retry shortly.",G=typeof B.eta==="string"?B.eta:null,H=new FQ(B.mode,X,G,B.details);throw tJ(H),H}throw new f(Y.status,B.error||B.message||"Request failed",B.details,typeof B.step==="string"?B.step:void 0)}return B}async function af(D){return x(`/auth/check-username?username=${encodeURIComponent(D)}`)}async function of(D){return x(`/auth/check-github?username=${encodeURIComponent(D)}`)}async function sf(D){return x("/auth/signup",{method:"POST",body:JSON.stringify(D)})}async function rf(D){return x("/auth/login",{method:"POST",body:JSON.stringify({api_key:D})})}async function tf(D){return x("/auth/resend-verification",{method:"POST",body:JSON.stringify({email:D})})}async function ef(D,F){return x("/auth/retrieve-key",{method:"POST",body:JSON.stringify({email:D,password:F})})}async function Dg(D){return x("/auth/request-key-regeneration",{method:"POST",body:JSON.stringify({email:D})})}async function $Q(){return x("/users/me",{},!0)}async function Fg(D,F){let $=new URLSearchParams;if(D)$.set("status",D);if(F)$.set("role",F);let J=$.toString()?`?${$.toString()}`:"";return x(`/admin/users${J}`,{},!0)}async function $g(D){return x(`/admin/approve/${D}`,{method:"POST"},!0)}async function Jg(D){return x(`/admin/revoke/${D}`,{method:"POST"},!0)}async function Qg(D,F){return x(`/admin/users/${D}/role`,{method:"POST",body:JSON.stringify({role:F})},!0)}async function yW(D,F){return x(`/admin/datasets/${D}/visibility`,{method:"PATCH",body:JSON.stringify({visibility:F})},!0)}async function Yg(D){return x(`/datasets/${D}/publish`,{method:"POST"},!0)}async function Bg(D){return x(`/admin/datasets/${D}/ci`,{},!0)}async function f4(D){return x(`/admin/datasets/${D}/ci`,{method:"POST"},!0)}async function xW(D){return x(`/admin/datasets/${D}/ci/validate`,{method:"POST"},!0)}async function _W(D){return x(`/admin/datasets/${D}/ci/sync`,{method:"POST"},!0)}async function JQ(D){return x(`/datasets/${D}/ci/status`,{},!0)}async function Xg(D){return x(`/datasets/${D}/manifest`,{},!0)}async function QQ(D,F){return x(`/datasets/${D}/manifest/${F}`,{},!0)}function Gg(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 TF(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.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()}`:"",J=await x(`/datasets${$}`,{},D.mine?!0:"optional");return J.datasets=J.datasets.map(Gg),J}async function Wg(D){return x(`/datasets/resolve/${D}`,{},"optional")}async function Hg(D,F={}){let $=new URLSearchParams({q:D});if(F.modality)$.set("modality",F.modality);if(F.limit)$.set("limit",String(F.limit));return x(`/datasets/search?${$.toString()}`,{},"optional")}async function gD(D){let F=await x(`/datasets/${D}`,{},"optional");return Gg(F.dataset)}async function qg(D){return x(`/datasets/${D}/versions`,{},!0)}async function YQ(D){return x("/datasets",{method:"POST",body:JSON.stringify(D)},!0)}async function BQ(D){return x(`/datasets/${D}/finalize`,{method:"POST"},!0)}async function c8(D,F){return x(`/datasets/${D}/upload-credentials`,{method:"POST",body:JSON.stringify({duration_seconds:F})},!0)}async function fW(D,F){return x(`/datasets/${D}/download-credentials`,{method:"POST",body:JSON.stringify({duration_seconds:F})},!0)}async function Kg(D,F){return x(`/admin/datasets/${D}/doi/concept`,{method:"POST",body:JSON.stringify(F)},!0)}async function v9(D){return x(`/admin/datasets/${D}/doi`,{},!0)}async function gW(D,F){return x(`/admin/datasets/${D}/doi/update`,{method:"POST",body:JSON.stringify(F)},!0)}async function hW(D){return x(`/datasets/${D}/request-access`,{method:"POST"},!0)}async function zg(D,F){let $=F?`?status=${F}`:"";return x(`/datasets/${D}/access-requests${$}`,{},!0)}async function Eg(D,F){return x(`/datasets/${D}/access-requests/${F}/approve`,{method:"POST"},!0)}async function Vg(D,F){return x(`/datasets/${D}/access-requests/${F}/deny`,{method:"POST"},!0)}async function Zg(D,F){return x(`/datasets/${D}/invite`,{method:"POST",body:JSON.stringify({username:F})},!0)}async function Ug(D){return x(`/datasets/${D}/collaborators`,{},!0)}async function Lg(D){return x("/sandbox/complete",{method:"POST",body:JSON.stringify({dataset_id:D})},!0)}async function Ag(){return x("/sandbox/reset",{method:"POST"},!0)}async function Mg(){return x("/sandbox/status",{},!0)}async function XQ(D){return x(`/datasets/${D}/publish/request`,{method:"POST"},!0)}async function Ng(D){return x(`/datasets/${D}/publish/status`,{},!0)}async function Rg(D){return x(`/datasets/${D}/publish/resend`,{method:"POST"},!0)}async function Cg(D){let F=D?`?status=${D}`:"";return x(`/admin/publish/requests${F}`,{},!0)}async function Og(D,F){return x(`/admin/publish/${D}/deny`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({reason:F})},!0)}function XV0(D,F=[]){if(D){let $=k9.indexOf(D);if($>=0)return $+1}return Math.min(F.length+1,k9.length)}function GV0(D){if(!(D instanceof f))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 GQ(D,F=!1,$=!1,J=!1,Q,Y){let G,H,q=0,K=!1,V,z=F,Z=[],U;function M(A,C,w,I){if(!Y)return;Y({step:A,stepIndex:XV0(A,C),stepTotal:k9.length,s3LockLocked:w,s3LockTotal:I,s3LockResumed:A==="s3_lock"&&K?!0:void 0})}for(let A=1;A<=5;A++)try{let C,w=!0;do{if(C=await x(`/admin/publish/${D}/approve`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({resume:w?z:!0,sandbox:$,s3_lock_continuation_token:G,s3_lock_total:H,skip_ci_check:J})},!0),w=!1,C.step_results)Z.push(...C.step_results);if(C.s3_lock_total!==void 0)H=C.s3_lock_total;if(C.s3_lock_batch_count!==void 0)q+=C.s3_lock_batch_count;let I=C.step??C.step_results?.[C.step_results.length-1]?.step;if(I&&(I!==V||I==="s3_lock"))M(I,C.steps_completed??[],I==="s3_lock"?q:void 0,I==="s3_lock"?H:void 0),V=I;if(C.hasMore&&C.s3_lock_continuation_token!==void 0)G=C.s3_lock_continuation_token;else break}while(C.hasMore);if(Z.length>0)C.step_results=nf(Z);return C}catch(C){if(U=C,A===5||!GV0(C)){if(C instanceof f&&Z.length>0)C.stepResults=nf(Z);throw C}let I=C;if(Q?.({attempt:A,maxAttempts:5,delayMs:1e4,step:I.step,error:I.message}),await new Promise((R)=>setTimeout(R,1e4)),z=!0,G!==void 0)K=!0}throw U}function nf(D){let F=new Map;for(let $ of D)F.set($.step,$);return Array.from(F.values())}async function wg(D,F){return x(`/admin/datasets/${D}/enrichment`,{method:"POST",body:JSON.stringify(F)},!0)}async function jg(D){return x(`/admin/datasets/${D}/files`,{},!0)}async function Tg(D){let F,$=0,J=[],Q=!0;while(Q){let Y=await x(`/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)J.push(...Y.failed);if(Q=Y.hasMore,F=Y.continuation_token,Q&&!F)throw new f(500,"S3 lock paginated response missing continuation_token; aborting to avoid infinite loop")}return{locked:$,failed:J}}async function Pg(D){return x(`/admin/datasets/${D}/reset`,{method:"POST"},!0)}async function Ig(D,F=!1){return x(`/admin/datasets/${D}`,{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({force:F})},!0)}async function Sg(D){return x("/admin/datasets/bulk-delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({dataset_ids:D})},!0)}async function kg(D){return x("/admin/datasets/import",{method:"POST",body:JSON.stringify(D)},!0)}async function vg(D){return x(`/admin/datasets/${D}/sync`,{method:"POST"},!0)}async function yg(){return x("/admin/sync/status",{},!0)}async function xg(D){let F=D?`?status=${encodeURIComponent(D)}`:"";return x(`/admin/imports${F}`,{},!0)}async function _g(D){return x(`/admin/imports/${D}/rollback`,{method:"POST"},!0)}async function fg(D){return x(`/admin/imports/${D}/retry`,{method:"POST"},!0)}async function WQ(D,F){return x(`/admin/datasets/${D}/reindex`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(F??{})},!0)}async function gg(D,F){return x("/admin/datasets/reindex/bulk",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filter:D,...F??{}})},!0)}async function hg(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 x(`/admin/fleet/drift${$}`,{},!0)}async function PF(D,F){return x(`/admin/datasets/${D}/enforce`,{method:"POST",body:JSON.stringify({dry_run:F})},!0)}async function bg(D){return x("/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 ug(D,F=!1){return x(`/admin/datasets/${D}/revalidate${F?"?force=true":""}`,{method:"POST"},!0)}async function mg(D){let F=D?`?user=${encodeURIComponent(D)}`:"";return x(`/admin/email-preferences${F}`,{},!0)}async function lg(D,F){let $=F?`?user=${encodeURIComponent(F)}`:"";return x(`/admin/email-preferences${$}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(D)},!0)}async function pg(){return x("/notices",{},"optional")}async function dg(){return x("/admin/notices",{},!0)}async function cg(D){return x("/admin/notices",{method:"POST",body:JSON.stringify(D)},!0)}async function ng(D){return x(`/admin/notices/${D}`,{method:"DELETE"},!0)}async function bW(D){return x("/admin/notify",{method:"POST",body:JSON.stringify(D)},!0)}async function ig(){return x("/admin/summary/coverage",{},!0)}async function ag(D,F,$){return x("/admin/manifest/dispatch",{method:"POST",body:JSON.stringify({dataset_id:D,version:F,skip_canary:$?.skipCanary??!1})},!0)}var kW="https://api.nemar.org",DQ,f,FQ,vW,k9;var n8=S(()=>{x4();SW();eJ();DQ=/^\d{4}-\d{4}-\d{4}-\d{3}[\dX]$/;f=class f extends Error{statusCode;details;step;constructor(D,F,$,J){super(F);this.statusCode=D;this.details=$;this.step=J;this.name="ApiError"}};FQ=class FQ extends f{mode;eta;constructor(D,F,$,J){super(503,F,J);this.mode=D;this.eta=$;this.name="MaintenanceError"}};vW=kW.includes("workers.dev");k9=["ci_check","enrichment_check","repo_public","s3_public_read","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"]});function rg(D){mW=D}function lW(){return mW}function y9(D){if(mW)process.stderr.write(`${D}
|
|
98
|
+
`)}var lf=!1;var SW=S(()=>{ND()});var df;var pf=S(()=>{df={name:"nemar-cli",version:"0.8.64-PR813.7cdea26",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",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 _4;var eJ=S(()=>{pf();_4=df.version});function L0(D){if(D instanceof Error)return D.message;return String(D)}function cf(){if(process.env.TEST_API_URL)return process.env.TEST_API_URL;if(vW)return kW;return $D().apiUrl||kW}async function x(D,F={},$=!1){let J=`${cf()}${D}`,Q={"Content-Type":"application/json","X-CLI-Version":_4,...F.headers};if($){let X=$D();if(!X.apiKey&&$===!0)throw new f(401,"Not authenticated. Run 'nemar auth login' first.");if(X.apiKey)Q.Authorization=`Bearer ${X.apiKey}`}let Y;try{Y=await fetch(J,{...F,headers:Q})}catch(X){throw new f(0,`Network error: Could not connect to ${cf()}`,{originalError:X instanceof Error?X.message:String(X)})}let B;try{B=await Y.json()}catch{throw new f(Y.status,`Invalid response from server (status ${Y.status})`)}if(!Y.ok){if(Y.status===503&&(B.mode==="read-only"||B.mode==="full")){let X=typeof B.message==="string"?B.message:"NEMAR is in maintenance mode. Please retry shortly.",G=typeof B.eta==="string"?B.eta:null,H=new FQ(B.mode,X,G,B.details);throw tJ(H),H}throw new f(Y.status,B.error||B.message||"Request failed",B.details,typeof B.step==="string"?B.step:void 0)}return B}async function af(D){return x(`/auth/check-username?username=${encodeURIComponent(D)}`)}async function of(D){return x(`/auth/check-github?username=${encodeURIComponent(D)}`)}async function sf(D){return x("/auth/signup",{method:"POST",body:JSON.stringify(D)})}async function rf(D){return x("/auth/login",{method:"POST",body:JSON.stringify({api_key:D})})}async function tf(D){return x("/auth/resend-verification",{method:"POST",body:JSON.stringify({email:D})})}async function ef(D,F){return x("/auth/retrieve-key",{method:"POST",body:JSON.stringify({email:D,password:F})})}async function Dg(D){return x("/auth/request-key-regeneration",{method:"POST",body:JSON.stringify({email:D})})}async function $Q(){return x("/users/me",{},!0)}async function Fg(D,F){let $=new URLSearchParams;if(D)$.set("status",D);if(F)$.set("role",F);let J=$.toString()?`?${$.toString()}`:"";return x(`/admin/users${J}`,{},!0)}async function $g(D){return x(`/admin/approve/${D}`,{method:"POST"},!0)}async function Jg(D){return x(`/admin/revoke/${D}`,{method:"POST"},!0)}async function Qg(D,F){return x(`/admin/users/${D}/role`,{method:"POST",body:JSON.stringify({role:F})},!0)}async function yW(D,F){return x(`/admin/datasets/${D}/visibility`,{method:"PATCH",body:JSON.stringify({visibility:F})},!0)}async function Yg(D){return x(`/datasets/${D}/publish`,{method:"POST"},!0)}async function Bg(D){return x(`/admin/datasets/${D}/ci`,{},!0)}async function f4(D){return x(`/admin/datasets/${D}/ci`,{method:"POST"},!0)}async function xW(D){return x(`/admin/datasets/${D}/ci/validate`,{method:"POST"},!0)}async function _W(D){return x(`/admin/datasets/${D}/ci/sync`,{method:"POST"},!0)}async function JQ(D){return x(`/datasets/${D}/ci/status`,{},!0)}async function Xg(D){return x(`/datasets/${D}/manifest`,{},!0)}async function QQ(D,F){return x(`/datasets/${D}/manifest/${F}`,{},!0)}function Gg(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 TF(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.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()}`:"",J=await x(`/datasets${$}`,{},D.mine?!0:"optional");return J.datasets=J.datasets.map(Gg),J}async function Wg(D){return x(`/datasets/resolve/${D}`,{},"optional")}async function Hg(D,F={}){let $=new URLSearchParams({q:D});if(F.modality)$.set("modality",F.modality);if(F.limit)$.set("limit",String(F.limit));return x(`/datasets/search?${$.toString()}`,{},"optional")}async function gD(D){let F=await x(`/datasets/${D}`,{},"optional");return Gg(F.dataset)}async function qg(D){return x(`/datasets/${D}/versions`,{},!0)}async function YQ(D){return x("/datasets",{method:"POST",body:JSON.stringify(D)},!0)}async function BQ(D){return x(`/datasets/${D}/finalize`,{method:"POST"},!0)}async function c8(D,F){return x(`/datasets/${D}/upload-credentials`,{method:"POST",body:JSON.stringify({duration_seconds:F})},!0)}async function fW(D,F){return x(`/datasets/${D}/download-credentials`,{method:"POST",body:JSON.stringify({duration_seconds:F})},!0)}async function Kg(D,F){return x(`/admin/datasets/${D}/doi/concept`,{method:"POST",body:JSON.stringify(F)},!0)}async function v9(D){return x(`/admin/datasets/${D}/doi`,{},!0)}async function gW(D,F){return x(`/admin/datasets/${D}/doi/update`,{method:"POST",body:JSON.stringify(F)},!0)}async function hW(D){return x(`/datasets/${D}/request-access`,{method:"POST"},!0)}async function zg(D,F){let $=F?`?status=${F}`:"";return x(`/datasets/${D}/access-requests${$}`,{},!0)}async function Eg(D,F){return x(`/datasets/${D}/access-requests/${F}/approve`,{method:"POST"},!0)}async function Vg(D,F){return x(`/datasets/${D}/access-requests/${F}/deny`,{method:"POST"},!0)}async function Zg(D,F){return x(`/datasets/${D}/invite`,{method:"POST",body:JSON.stringify({username:F})},!0)}async function Ug(D){return x(`/datasets/${D}/collaborators`,{},!0)}async function Lg(D){return x("/sandbox/complete",{method:"POST",body:JSON.stringify({dataset_id:D})},!0)}async function Ag(){return x("/sandbox/reset",{method:"POST"},!0)}async function Mg(){return x("/sandbox/status",{},!0)}async function XQ(D){return x(`/datasets/${D}/publish/request`,{method:"POST"},!0)}async function Ng(D){return x(`/datasets/${D}/publish/status`,{},!0)}async function Rg(D){return x(`/datasets/${D}/publish/resend`,{method:"POST"},!0)}async function Cg(D){let F=D?`?status=${D}`:"";return x(`/admin/publish/requests${F}`,{},!0)}async function Og(D,F){return x(`/admin/publish/${D}/deny`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({reason:F})},!0)}function XV0(D,F=[]){if(D){let $=k9.indexOf(D);if($>=0)return $+1}return Math.min(F.length+1,k9.length)}function GV0(D){if(!(D instanceof f))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 GQ(D,F=!1,$=!1,J=!1,Q,Y){let G,H,q=0,K=!1,V,z=F,Z=[],U;function M(A,C,w,I){if(!Y)return;Y({step:A,stepIndex:XV0(A,C),stepTotal:k9.length,s3LockLocked:w,s3LockTotal:I,s3LockResumed:A==="s3_lock"&&K?!0:void 0})}for(let A=1;A<=5;A++)try{let C,w=!0;do{if(C=await x(`/admin/publish/${D}/approve`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({resume:w?z:!0,sandbox:$,s3_lock_continuation_token:G,s3_lock_total:H,skip_ci_check:J})},!0),w=!1,C.step_results)Z.push(...C.step_results);if(C.s3_lock_total!==void 0)H=C.s3_lock_total;if(C.s3_lock_batch_count!==void 0)q+=C.s3_lock_batch_count;let I=C.step??C.step_results?.[C.step_results.length-1]?.step;if(I&&(I!==V||I==="s3_lock"))M(I,C.steps_completed??[],I==="s3_lock"?q:void 0,I==="s3_lock"?H:void 0),V=I;if(C.hasMore&&C.s3_lock_continuation_token!==void 0)G=C.s3_lock_continuation_token;else break}while(C.hasMore);if(Z.length>0)C.step_results=nf(Z);return C}catch(C){if(U=C,A===5||!GV0(C)){if(C instanceof f&&Z.length>0)C.stepResults=nf(Z);throw C}let I=C;if(Q?.({attempt:A,maxAttempts:5,delayMs:1e4,step:I.step,error:I.message}),await new Promise((R)=>setTimeout(R,1e4)),z=!0,G!==void 0)K=!0}throw U}function nf(D){let F=new Map;for(let $ of D)F.set($.step,$);return Array.from(F.values())}async function wg(D,F){return x(`/admin/datasets/${D}/enrichment`,{method:"POST",body:JSON.stringify(F)},!0)}async function jg(D){return x(`/admin/datasets/${D}/files`,{},!0)}async function Tg(D){let F,$=0,J=[],Q=!0;while(Q){let Y=await x(`/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)J.push(...Y.failed);if(Q=Y.hasMore,F=Y.continuation_token,Q&&!F)throw new f(500,"S3 lock paginated response missing continuation_token; aborting to avoid infinite loop")}return{locked:$,failed:J}}async function Pg(D){return x(`/admin/datasets/${D}/reset`,{method:"POST"},!0)}async function Ig(D,F=!1){return x(`/admin/datasets/${D}`,{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({force:F})},!0)}async function Sg(D){return x("/admin/datasets/bulk-delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({dataset_ids:D})},!0)}async function kg(D){return x("/admin/datasets/import",{method:"POST",body:JSON.stringify(D)},!0)}async function vg(D){return x(`/admin/datasets/${D}/sync`,{method:"POST"},!0)}async function yg(){return x("/admin/sync/status",{},!0)}async function xg(D){let F=D?`?status=${encodeURIComponent(D)}`:"";return x(`/admin/imports${F}`,{},!0)}async function _g(D){return x(`/admin/imports/${D}/rollback`,{method:"POST"},!0)}async function fg(D){return x(`/admin/imports/${D}/retry`,{method:"POST"},!0)}async function WQ(D,F){return x(`/admin/datasets/${D}/reindex`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(F??{})},!0)}async function gg(D,F){return x("/admin/datasets/reindex/bulk",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filter:D,...F??{}})},!0)}async function hg(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 x(`/admin/fleet/drift${$}`,{},!0)}async function PF(D,F){return x(`/admin/datasets/${D}/enforce`,{method:"POST",body:JSON.stringify({dry_run:F})},!0)}async function bg(D){return x("/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 ug(D,F=!1){return x(`/admin/datasets/${D}/revalidate${F?"?force=true":""}`,{method:"POST"},!0)}async function mg(D){let F=D?`?user=${encodeURIComponent(D)}`:"";return x(`/admin/email-preferences${F}`,{},!0)}async function lg(D,F){let $=F?`?user=${encodeURIComponent(F)}`:"";return x(`/admin/email-preferences${$}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(D)},!0)}async function pg(){return x("/notices",{},"optional")}async function dg(){return x("/admin/notices",{},!0)}async function cg(D){return x("/admin/notices",{method:"POST",body:JSON.stringify(D)},!0)}async function ng(D){return x(`/admin/notices/${D}`,{method:"DELETE"},!0)}async function bW(D){return x("/admin/notify",{method:"POST",body:JSON.stringify(D)},!0)}async function ig(){return x("/admin/summary/coverage",{},!0)}async function ag(D,F,$){return x("/admin/manifest/dispatch",{method:"POST",body:JSON.stringify({dataset_id:D,version:F,skip_canary:$?.skipCanary??!1})},!0)}var kW="https://api.nemar.org",DQ,f,FQ,vW,k9;var n8=S(()=>{x4();SW();eJ();DQ=/^\d{4}-\d{4}-\d{4}-\d{3}[\dX]$/;f=class f extends Error{statusCode;details;step;constructor(D,F,$,J){super(F);this.statusCode=D;this.details=$;this.step=J;this.name="ApiError"}};FQ=class FQ extends f{mode;eta;constructor(D,F,$,J){super(503,F,J);this.mode=D;this.eta=$;this.name="MaintenanceError"}};vW=kW.includes("workers.dev");k9=["ci_check","enrichment_check","repo_public","s3_public_read","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"]});function rg(D){mW=D}function lW(){return mW}function y9(D){if(mW)process.stderr.write(`${D}
|
|
99
99
|
`)}var mW=!1;function YD(D){if(D===0)return"0 B";let F=["B","KB","MB","GB","TB"],$=Math.min(Math.floor(Math.log(D)/Math.log(1024)),F.length-1);return`${(D/1024**$).toFixed($===0?0:1)} ${F[$]}`}function tg(D){return`${YD(D)}/s`}function WV0(D){if(D<60)return`${Math.round(D)}s`;if(D<3600)return`${Math.floor(D/60)}m ${Math.round(D%60)}s`;return`${Math.floor(D/3600)}h ${Math.floor(D%3600/60)}m`}function HV0(D,F=20){let $=Math.round(D/100*F),J=F-$;return`[${"=".repeat($)}${" ".repeat(J)}]`}class HQ{filesCompleted=0;filesTotal;bytesTotal=0;inFlight=new Map;currentFile="";startTime;lastUpdateTime;lastBytesTransferred=0;totalBytesTransferred=0;speedSamples=[];lastRenderedLine="";constructor(D=0,F=0){this.filesTotal=D,this.bytesTotal=F,this.startTime=Date.now(),this.lastUpdateTime=this.startTime}inFlightBytes(){let D=0;for(let F of this.inFlight.values())D+=F.transferred;return D}processLine(D){let F=D.file??D.action?.file;if(D.ok===!0||D.success===!0){this.filesCompleted++;let $=F??this.currentFile,J=$?this.inFlight.get($):void 0,Q=J?J.total||J.transferred:0;if(this.totalBytesTransferred+=Q,$)this.inFlight.delete($);this.render();return}if(D["byte-progress"]!==void 0){let $=F??this.currentFile;if(!$)return;this.currentFile=$;let J=this.inFlight.get($)??{transferred:0,total:0};if(J.transferred=D["byte-progress"]??J.transferred,D["total-size"]!==void 0)J.total=D["total-size"];this.inFlight.set($,J);let Q=Date.now(),Y=(Q-this.lastUpdateTime)/1000;if(Y>0.5){let B=this.totalBytesTransferred+this.inFlightBytes(),G=(B-this.lastBytesTransferred)/Y;if(G>0){if(this.speedSamples.push(G),this.speedSamples.length>5)this.speedSamples.shift()}this.lastBytesTransferred=B,this.lastUpdateTime=Q}this.render()}}incrementFilesCompleted(){this.filesCompleted++}setFilesTotal(D){this.filesTotal=D}setBytesTotal(D){this.bytesTotal=D}getPercent(){let D=this.totalBytesTransferred+this.inFlightBytes();if(this.bytesTotal>0)return Math.min(100,Math.round(D/this.bytesTotal*100));if(this.filesTotal>0)return Math.min(100,Math.round(this.filesCompleted/this.filesTotal*100));return null}getProgress(){return{filesCompleted:this.filesCompleted,filesTotal:this.filesTotal,bytesTransferred:this.totalBytesTransferred+this.inFlightBytes(),bytesTotal:this.bytesTotal,currentFile:this.currentFile||void 0}}render(){let D=this.speedSamples.length>0?this.speedSamples.reduce((B,X)=>B+X,0)/this.speedSamples.length:0,F=this.totalBytesTransferred+this.inFlightBytes(),$=0,J=!1;if(this.bytesTotal>0)$=Math.min(100,Math.round(F/this.bytesTotal*100)),J=!0;else if(this.filesTotal>0)$=Math.min(100,Math.round(this.filesCompleted/this.filesTotal*100)),J=!0;let Q=this.filesTotal>0?`${this.filesCompleted}/${this.filesTotal} files`:`${this.filesCompleted} files`,Y;if(J)Y=`${HV0($)} ${$}% ${Q}`;else Y=Q;if(F>0){let B=this.bytesTotal>0?`${YD(F)}/${YD(this.bytesTotal)}`:YD(F);Y+=` | ${B}`}if(D>0)Y+=` | ${tg(D)}`;if(D>0){let B=0;if(this.bytesTotal>0)B=Math.max(0,this.bytesTotal-F);else for(let X of this.inFlight.values())if(X.total>X.transferred)B+=X.total-X.transferred;if(B>0){let X=B/D;if(X>0)Y+=` | ETA ${WV0(X)}`}}if(Y!==this.lastRenderedLine)process.stderr.write(`\r${W.cyan(Y)}${" ".repeat(10)}`),this.lastRenderedLine=Y}finish(D){let F=(Date.now()-this.startTime)/1000;if(process.stderr.write(`\r${" ".repeat(this.lastRenderedLine.length+15)}\r`),D>0){let $=F>0?`${tg(this.totalBytesTransferred/F)}`:"",J=[`${D} file${D!==1?"s":""} downloaded`,this.totalBytesTransferred>0?YD(this.totalBytesTransferred):"",$].filter(Boolean).join(" | ");process.stderr.write(`${W.green(J)}
|
|
100
100
|
`)}}}var pW=S(()=>{ND()});var Eh={};r6(Eh,{verifyGitHubAuth:()=>_9,toS3Credentials:()=>PD,switchBranch:()=>MV0,setKeyPresent:()=>zh,selectAnnexS3Remote:()=>tW,saveDataset:()=>a8,runCommand:()=>T,resolveUpstreamRef:()=>BH,resolveGitHubCloneAuth:()=>qh,readRemoteHeadDatasetVersion:()=>YH,readLocalDatasetVersion:()=>QH,pushToGitHub:()=>R1,pushBranch:()=>SF,markInheritedOpenNeuroRemotesIgnored:()=>rW,listDatasetVersions:()=>DH,isWorkingTreeDirty:()=>XH,isNonFastForwardPush:()=>Wh,isGitAnnexDataset:()=>N1,isDataladDataset:()=>wV0,initOrEnableSpecialRemote:()=>Gh,initDataset:()=>n6,githubTokenCredentialHelper:()=>Hh,gitMergeFastForward:()=>WH,gitFetchOrigin:()=>GH,gitAnnexAdd:()=>i6,getVersionCommit:()=>FH,getRemoteUuid:()=>ZQ,getLocalDatasetInfo:()=>eW,getKeyHashDirs:()=>CV0,getKeyHashDir:()=>Kh,getDatasetStats:()=>UV0,getDatasetIdFromRemote:()=>s8,getDatasetData:()=>VQ,getCurrentBranch:()=>o8,getAnnexWhereisAll:()=>KH,getAnnexS3Remotes:()=>g9,formatBytes:()=>YD,ensureLocalMainBranch:()=>h9,ensureGitAnnexInitialized:()=>aW,enableS3Remote:()=>h4,dropUnusedAnnexObjects:()=>HH,dropFiles:()=>sW,detectImportMarker:()=>EQ,createRevertBranch:()=>$H,createDataladDataset:()=>OV0,countPendingDownload:()=>zQ,copyToAnnexRemote:()=>C8,configureS3Remote:()=>o1,configureLargefiles:()=>g4,configureGitHubRemote:()=>i8,commitRevert:()=>JH,collectFileManifest:()=>qH,cloneDataset:()=>C1,clearAnnexCredentials:()=>ID,checkPrerequisites:()=>x9,checkGitHubSSH:()=>Qh,checkGitAnnexInstalled:()=>iW,checkDownloadPrerequisites:()=>IF,checkAWSCredentials:()=>EV0,batchSetKeysPresent:()=>zH,awsCredentialEnv:()=>KQ,annexRemoteExists:()=>Xh,acceptGitHubInvitation:()=>f9,NEMAR_S3_REMOTE_NAME:()=>qQ,ANNEX_REMOTE_EXISTS_RE:()=>Bh});import{existsSync as cW,readFileSync as qV0,statSync as KV0}from"fs";import{join as nW}from"path";var{spawn:Jh}=globalThis.Bun;async function T(D,F={}){let $={...process.env,GIT_TERMINAL_PROMPT:"0",...F.env};for(let H of F.unsetEnv??[])delete $[H];let J=Jh({cmd:D,cwd:F.cwd,stdout:"pipe",stderr:"pipe",env:$}),Q=!1,Y;if(F.timeout)Y=setTimeout(()=>{Q=!0,J.kill()},F.timeout);if(lW()){let H=F.cwd?` (cwd=${F.cwd})`:"";y9(W.dim(`$ ${D.join(" ")}${H}`))}let B=await new Response(J.stdout).text(),X=await new Response(J.stderr).text(),G=await J.exited;if(Y)clearTimeout(Y);if(lW()){if(B.trim())y9(W.dim(B.trimEnd()));if(X.trim())y9(W.yellow(X.trimEnd()));y9(W.dim(`(exit ${G})`))}if(Q)return{stdout:B,stderr:X||`Command timed out after ${Math.round(F.timeout/1000)}s`,exitCode:G??1};return{stdout:B,stderr:X,exitCode:G}}function eg(D){return D.split(".").map((F)=>{let $=Number.parseInt(F.replace(/[^0-9]/g,""),10);return Number.isNaN($)?0:$})}function zV0(D,F){let $=eg(D),J=eg(F);for(let Q=0;Q<Math.max($.length,J.length);Q++){let Y=$[Q]||0,B=J[Q]||0;if(Y>B)return!0;if(Y<B)return!1}return!0}async function iW(){try{let{stdout:F,exitCode:$,stderr:J}=await T(["git-annex","version"]);if($!==0)return console.warn("git-annex version returned non-zero exit code:",$),console.warn("stderr:",J),{installed:!1,minVersion:"10.0",error:`Version check failed: ${J.trim()}`};let Q=F.match(/version:\s*(\d+\.\d+)/),Y=Q?Q[1]:void 0;if(!Y)console.warn("Could not parse git-annex version from output:",F);return{installed:!0,version:Y,minVersion:"10.0",compatible:Y?zV0(Y,"10.0"):void 0}}catch(F){let $=F instanceof Error?F.message:String(F);if($.includes("ENOENT")||$.includes("not found"))return console.info("git-annex not found in PATH"),{installed:!1,minVersion:"10.0"};return console.error("Error checking git-annex installation:",$),{installed:!1,minVersion:"10.0",error:$}}}async function Qh(){if(process.env.GH_TOKEN)return{accessible:!0,username:"token-auth",useHttps:!0};try{let{stdout:D,stderr:F}=await T(["ssh","-T","-o","BatchMode=yes","-o","StrictHostKeyChecking=accept-new","-o","ConnectTimeout=10","git@github.com"]),$=D+F,J=$.match(/Hi ([^!]+)!/);if(J)return{accessible:!0,username:J[1]};if($.includes("Permission denied"))return{accessible:!1};return{accessible:$.includes("successfully authenticated")}}catch(D){let F=D instanceof Error?D.message:String(D);if(F.includes("ENOENT")||F.includes("not found"))console.info("SSH command not found");else console.error("Error checking GitHub SSH access:",F);return{accessible:!1}}}async function EV0(){if(process.env.AWS_ACCESS_KEY_ID&&process.env.AWS_SECRET_ACCESS_KEY)return{configured:!0,source:"environment"};try{let{stdout:D,exitCode:F}=await T(["aws","configure","get","aws_access_key_id"]);if(F===0&&D.trim())return{configured:!0,source:"aws-cli"}}catch(D){let F=D instanceof Error?D.message:String(D);if(F.includes("ENOENT")||F.includes("not found"))console.info("AWS CLI not found in PATH");else console.error("Error checking AWS credentials:",F)}return{configured:!1}}function Yh(){let D=process.platform;if(D==="darwin")return"brew install git-annex";if(D==="linux")return"apt install git-annex (Debian/Ubuntu)";return"See https://git-annex.branchable.com/install/"}async function x9(){let[D,F]=await Promise.all([iW(),Qh()]),$=[];if(!D.installed)$.push(`git-annex is not installed. Install: ${Yh()}`);else if(D.compatible===!1)$.push(`git-annex version ${D.version} is too old. Required: >= ${D.minVersion}`);if(!F.accessible){if(!(await oW()).token)$.push("GitHub authentication not configured. Run 'gh auth login' to authenticate.")}return{gitAnnex:D,githubSSH:F,allPassed:$.length===0,errors:$}}async function N1(D){if(!cW(nW(D,".git")))return!1;try{let{exitCode:F}=await T(["git","annex","info"],{cwd:D});return F===0}catch(F){let $=F instanceof Error?F.message:String(F);if(!$.includes("ENOENT")&&!$.includes("not found"))console.error(`Error checking if ${D} is a git-annex dataset:`,$);return!1}}async function n6(D,F={}){if(!F.force&&await N1(D))return{success:!0};try{let $={};if(F.author)$.GIT_AUTHOR_NAME=F.author.name,$.GIT_AUTHOR_EMAIL=F.author.email,$.GIT_COMMITTER_NAME=F.author.name,$.GIT_COMMITTER_EMAIL=F.author.email;let{stderr:J,exitCode:Q}=await T(["git","init","-b","main",D],{...Object.keys($).length>0?{env:$}:{}});if(Q!==0)return{success:!1,error:J.trim()||"Failed to initialize git repository"};let Y=Object.keys($).length>0?{env:$}:{},{stderr:B,exitCode:X}=await T(["git","annex","init"],{cwd:D,...Y});if(X!==0)return{success:!1,error:B.trim()||"Failed to initialize git-annex"};let{stderr:G,exitCode:H}=await T(["git","commit","--allow-empty","-m","Initialize dataset"],{cwd:D,...Y});if(H!==0)return{success:!1,error:G.trim()||"Failed to create initial commit"};let{stderr:q,exitCode:K}=await T(["git","annex","adjust","--unlock"],{cwd:D,...Y});if(K!==0)return{success:!1,error:q.trim()||"Failed to switch to unlocked mode"};return{success:!0}}catch($){return{success:!1,error:$.message}}}async function aW(D){try{let{exitCode:F,stderr:$}=await T(["git","annex","info"],{cwd:D});if(F===0)return{success:!0};if($.includes("First run: git-annex init")){let{stderr:J,exitCode:Q}=await T(["git","annex","init"],{cwd:D});if(Q!==0)return{success:!1,error:J.trim()||"Failed to initialize git-annex"};return{success:!0}}return{success:!1,error:$.trim()||"Failed to check git-annex status"}}catch(F){return{success:!1,error:F.message}}}async function g4(D,F){let $=["*.edf","*.bdf","*.set","*.fif","*.vhdr","*.eeg","*.cnt","*.fdt"],J=["*.tsv","*.json","*.md","*.txt","*.yml","*.yaml","README*","LICENSE*","CHANGES*",".bidsignore",".gitignore"],Q=$.map((G)=>`include=${G}`).join(" or "),Y=J.map((G)=>`exclude=${G}`).join(" and "),B=`(${Q} or largerthan=100kb) and ${Y}`,X=F||B;try{let{stderr:G,exitCode:H}=await T(["git","annex","config","--set","annex.largefiles",X],{cwd:D});if(H!==0)return{success:!1,error:G.trim()||"Failed to configure largefiles"};return{success:!0}}catch(G){return{success:!1,error:G.message}}}async function i6(D,F="."){try{let{stderr:$,exitCode:J}=await T(["git","annex","add",F],{cwd:D});if(J!==0)return{success:!1,error:$.trim()||"Failed to add files to git-annex"};return{success:!0}}catch($){return{success:!1,error:$.message}}}function PD(D){return{accessKeyId:D.access_key_id,secretAccessKey:D.secret_access_key,sessionToken:D.session_token}}function dW(D){let F=[/^\(merging .* into .*\.\.\.\)$/,/^\(recording state in git\.\.\.\)$/,/^\(scanning for /,/^\(checking /];return D.split(`
|
|
101
101
|
`).filter(($)=>{let J=$.trim();if(!J)return!1;if(J.includes("setting annex-ignore"))return!1;if(F.some((Q)=>Q.test(J)))return!1;return!0}).join(`
|
|
@@ -111,7 +111,7 @@ Fix one of these:
|
|
|
111
111
|
2. Configure SSH for GitHub:
|
|
112
112
|
ssh-keygen -t ed25519 -C "your@email.com"
|
|
113
113
|
Add the public key to https://github.com/settings/keys
|
|
114
|
-
Test with: ssh -T git@github.com`}}}try{let{stdout:Q}=await T(["git","remote","get-url",$],{cwd:D});if(Q.trim()){let{stderr:Y,exitCode:B}=await T(["git","remote","set-url",$,J],{cwd:D});if(B!==0)return{success:!1,error:Y.trim()}}else{let{stderr:Y,exitCode:B}=await T(["git","remote","add",$,J],{cwd:D});if(B!==0)return{success:!1,error:Y.trim()}}return{success:!0}}catch(Q){return{success:!1,error:Q.message}}}async function a8(D,F,$){try{let J={};if($)J.GIT_AUTHOR_NAME=$.name,J.GIT_AUTHOR_EMAIL=$.email,J.GIT_COMMITTER_NAME=$.name,J.GIT_COMMITTER_EMAIL=$.email;let{stderr:Q,exitCode:Y}=await T(["git","add","-A"],{cwd:D,...Object.keys(J).length>0?{env:J}:{}});if(Y!==0)return{success:!1,error:Q.trim()||"Failed to stage changes"};let{stdout:B,exitCode:X,stderr:G}=await T(["git","status","--porcelain"],{cwd:D});if(X!==0)return{success:!1,error:G.trim()||"Failed to check git status"};if(!B.trim())return{success:!0};let{stderr:H,exitCode:q}=await T(["git","commit","-m",F],{cwd:D,...Object.keys(J).length>0?{env:J}:{}});if(q!==0){if(H.includes("nothing to commit"))return{success:!0};return{success:!1,error:H.trim()||"Failed to commit changes"}}return{success:!0}}catch(J){return{success:!1,error:J.message}}}function Wh(D){return/\[rejected\]|fetch first|non-fast-forward|Updates were rejected/i.test(D)}async function R1(D,F="origin",$){try{let J=$;if(!J){let
|
|
114
|
+
Test with: ssh -T git@github.com`}}}try{let{stdout:Q}=await T(["git","remote","get-url",$],{cwd:D});if(Q.trim()){let{stderr:Y,exitCode:B}=await T(["git","remote","set-url",$,J],{cwd:D});if(B!==0)return{success:!1,error:Y.trim()}}else{let{stderr:Y,exitCode:B}=await T(["git","remote","add",$,J],{cwd:D});if(B!==0)return{success:!1,error:Y.trim()}}return{success:!0}}catch(Q){return{success:!1,error:Q.message}}}async function a8(D,F,$){try{let J={};if($)J.GIT_AUTHOR_NAME=$.name,J.GIT_AUTHOR_EMAIL=$.email,J.GIT_COMMITTER_NAME=$.name,J.GIT_COMMITTER_EMAIL=$.email;let{stderr:Q,exitCode:Y}=await T(["git","add","-A"],{cwd:D,...Object.keys(J).length>0?{env:J}:{}});if(Y!==0)return{success:!1,error:Q.trim()||"Failed to stage changes"};let{stdout:B,exitCode:X,stderr:G}=await T(["git","status","--porcelain"],{cwd:D});if(X!==0)return{success:!1,error:G.trim()||"Failed to check git status"};if(!B.trim())return{success:!0};let{stderr:H,exitCode:q}=await T(["git","commit","-m",F],{cwd:D,...Object.keys(J).length>0?{env:J}:{}});if(q!==0){if(H.includes("nothing to commit"))return{success:!0};return{success:!1,error:H.trim()||"Failed to commit changes"}}return{success:!0}}catch(J){return{success:!1,error:J.message}}}function Wh(D){return/\[rejected\]|fetch first|non-fast-forward|Updates were rejected/i.test(D)}async function R1(D,F="origin",$){try{let J=$;if(!J){let K=await o8(D);if(!K||K==="HEAD"){let{exitCode:V}=await T(["git","log","-1","--oneline"],{cwd:D});if(V!==0)return{success:!1,error:"No commits found. The repository may not have been initialized correctly, or no changes were saved before pushing."};if(K==="HEAD")J="HEAD:main";else return{success:!1,error:"Could not detect current branch"}}else if(K.startsWith("adjusted/")){let V=K.replace(/^adjusted\//,"").replace(/\(.*\)$/,"");J=`${K}:${V}`}else J=K}let Q=J.includes(":")?J.slice(J.indexOf(":")+1):J,Y=!J.startsWith("adjusted/")&&J!=="HEAD:main",B="",X=!1,G=0;for(let K=0;K<=Fh;K++){let V=await T(["git","push","-u",F,J],{cwd:D});if(V.exitCode===0){X=!0;break}if(B=V.stderr,!Y||K===Fh||!Wh(V.stderr))break;let z=await T(["git","fetch",F],{cwd:D});if(z.exitCode!==0)return{success:!1,error:`Push rejected (non-fast-forward) and the retry fetch of ${F} failed: ${z.stderr.trim()||`exit ${z.exitCode}`}. Cannot integrate remote commits.`};let Z=await T(["git","rebase",`${F}/${Q}`],{cwd:D});if(Z.exitCode!==0)return await T(["git","rebase","--abort"],{cwd:D}),{success:!1,error:`Push rejected: ${F}/${Q} has diverging commits and auto-rebase failed: ${Z.stderr.trim()}`};G++}if(!X){let K=G>0?` (still rejected after ${G} fetch+rebase retry cycle(s))`:"";return{success:!1,error:`${B.trim()||"Failed to push to GitHub"}${K}`}}let{stderr:H,exitCode:q}=await T(["git","push",F,"git-annex"],{cwd:D});if(q!==0)return{success:!0,warning:`Main branch pushed, but git-annex branch failed: ${H.trim()}. Clone operations may have issues.`};return{success:!0}}catch(J){return{success:!1,error:J.message}}}async function UV0(D){try{let{stdout:J,exitCode:Q}=await T(["git","annex","info","--json"],{cwd:D});if(Q===0){let Y=JSON.parse(J);return{totalFiles:Y["local annex keys"]||0,totalSize:Y["local annex size"]||0,annexedFiles:Y["local annex keys"]||0,annexedSize:Y["local annex size"]||0}}}catch(J){let Q=J instanceof Error?J.message:String(J);console.warn("git annex info failed, falling back to manual counting:",Q)}let{stdout:F}=await T(["find",D,"-type","f"],{cwd:D});return{totalFiles:F.trim().split(`
|
|
115
115
|
`).filter(Boolean).length,totalSize:0,annexedFiles:0,annexedSize:0}}async function IF(){let D=await iW(),F=[];if(!D.installed)F.push(`git-annex is not installed. Install: ${Yh()}`);else if(D.compatible===!1)F.push(`git-annex version ${D.version} is too old. Required: >= ${D.minVersion}`);return{gitAnnex:D,allPassed:F.length===0,errors:F}}function Hh(D){return`!printf 'username=x-access-token\\npassword=${D}'`}function qh(D,F){if(!D.startsWith("git@github.com:"))return{url:D};let $=F?.trim();if(!$||/[\s']/.test($))return{url:D};return{url:`https://github.com/${D.replace("git@github.com:","")}`,credentialHelper:Hh($)}}async function C1(D,F,$={}){try{let J=D,Q;if($.useGitHubToken){let q=process.env.GH_TOKEN?.trim()||null,K;if(!q){let z=await oW();q=z.token,K=z.error}let V=qh(D,q);if(J=V.url,Q=V.credentialHelper,D.startsWith("git@github.com:")&&!Q)return{success:!1,error:`No usable GitHub token for authenticated clone of ${D} (GH_TOKEN unset/malformed${K?`; gh CLI: ${K}`:""}). Set GH_TOKEN on this runner.`}}let Y=Q?{GIT_CONFIG_COUNT:"1",GIT_CONFIG_KEY_0:"credential.https://github.com.helper",GIT_CONFIG_VALUE_0:Q}:void 0,{stderr:B,exitCode:X}=await T(["git","clone",J,F],Y?{env:Y}:{});if(X!==0)return{success:!1,error:B.trim()||"Failed to clone dataset"};if(Q){let{exitCode:q,stderr:K}=await T(["git","config","credential.https://github.com.helper",Q],{cwd:F});if(q!==0)return{success:!1,error:`Cloned but failed to persist the credential helper (later pushes would fail to authenticate): ${K.trim()||"git config returned non-zero"}`}}let{stderr:G,exitCode:H}=await T(["git","annex","init"],{cwd:F});if(H!==0){let{exitCode:q}=await T(["git","annex","info"],{cwd:F});if(q!==0)return{success:!1,error:`Cloned repository but git-annex initialization failed: ${G.trim()}`};console.warn("git annex init returned non-zero but annex is initialized")}return{success:!0}}catch(J){return{success:!1,error:J instanceof Error?J.message:String(J)}}}async function zQ(D,F,$){let J=F&&F.length>0?F:["."],Q=$&&$.length>0?$:[];try{let{stdout:Y,stderr:B,exitCode:X}=await T(["git","annex","find","--not","--in=here",...Q,"--json",...J],{cwd:D});if(X!==0){if(process.env.VERBOSE&&B.trim())console.warn(`countPendingDownload: git annex find failed: ${B.trim()}`);return null}let G=0,H=0,q=!1,K=!1;for(let V of Y.split(`
|
|
116
116
|
`)){let z=V.trim();if(!z)continue;if(K=!0,!z.startsWith("{")){q=!0;continue}try{let Z=JSON.parse(z);if(G++,Z.bytesize){let U=Number.parseInt(Z.bytesize,10);if(Number.isFinite(U))H+=U}}catch{q=!0}}if(G===0&&K&&q)return null;return{fileCount:G,totalBytes:H}}catch(Y){if(process.env.VERBOSE)console.warn(`countPendingDownload: ${Y.message}`);return null}}async function EQ(D){try{let{stdout:F,exitCode:$}=await T(["git","log","-1","--format=%H","--",".nemar/metadata.json"],{cwd:D});if($!==0)return"unknown";return F.trim().length>0?"present":"absent"}catch{return"unknown"}}async function VQ(D,F={}){let $=F.jobs||4,J=F.paths&&F.paths.length>0?F.paths:["."],Q=F.extraArgs??[],Y=Boolean(F.onProgress),B=KQ(F.credentials)??{},X=Object.fromEntries(Object.entries({...process.env,...B}).filter((G)=>G[1]!=null));try{if(Y){let Z=["git","annex","get","--json","--json-progress","-J",$.toString(),...Q,...J],U=Jh({cmd:Z,cwd:D,stdout:"pipe",stderr:"pipe",env:X}),M=0,A="",C=[],w=(async()=>{let c=U.stderr.getReader(),r=new TextDecoder;for(;;){let{done:a,value:Q0}=await c.read();if(a)break;C.push(Q0)}A=r.decode(C.reduce((a,Q0)=>{let $0=new Uint8Array(a.length+Q0.length);return $0.set(a),$0.set(Q0,a.length),$0},new Uint8Array))})(),I=U.stdout.getReader(),R=new TextDecoder,j="";for(;;){let{done:c,value:r}=await I.read();if(c)break;j+=R.decode(r,{stream:!0});let a=j.split(`
|
|
117
117
|
`);j=a.pop()??"";for(let Q0 of a){let $0=Q0.trim();if(!$0||!$0.startsWith("{"))continue;try{let R0=JSON.parse($0);if(F.onProgress?.(R0),R0.ok===!0||R0.success===!0)M++}catch{}}}if(j.trim().startsWith("{"))try{let c=JSON.parse(j.trim());if(F.onProgress?.(c),c.ok===!0||c.success===!0)M++}catch{}if(await w,await U.exited!==0)return{success:!1,error:A.trim()||"Failed to get dataset data"};return{success:!0,filesDownloaded:M}}let G=["git","annex","get","-J",$.toString(),...Q,...J],{stdout:H,stderr:q,exitCode:K}=await T(G,{cwd:D,...Object.keys(B).length>0&&{env:X}});if(K!==0)return{success:!1,error:q.trim()||"Failed to get dataset data"};let V=H.match(/^get .+ ok$/gm);return{success:!0,filesDownloaded:V?V.length:0}}catch(G){return{success:!1,error:G.message}}}async function sW(D,F){let $=F&&F.length>0?F:["."];try{let J=["git","annex","drop",...$],{stdout:Q,stderr:Y,exitCode:B}=await T(J,{cwd:D});if(B!==0){let H=[];for(let V of Y.split(`
|
|
@@ -122,7 +122,7 @@ Fix one of these:
|
|
|
122
122
|
Warning: Could not determine current branch name.`)),console.log(W.yellow(" Proceeding with upload; ensure your branch is named 'main'.")),!0;if($==="main"||$.startsWith("adjusted/main"))return!0;if(console.log(W.yellow(`
|
|
123
123
|
Warning: Your current branch is "${$}", but NEMAR requires "main".`)),console.log(W.yellow(" Without renaming, CI validation, branch protection, and metadata pipelines will not work.")),!F.yes){if(!await AV0($))return!1}let{exitCode:J,stderr:Q}=await T(["git","branch","-m",$,"main"],{cwd:D});if(J!==0){if(console.log(W.red(` Failed to rename branch "${$}" to "main".`)),Q.trim())console.log(W.red(` Git error: ${Q.trim()}`));return!1}return console.log(W.green(` Renamed branch "${$}" to "main".`)),!0}async function AV0(D){let F=(await Promise.resolve().then(() => (k6(),dT))).default;try{let{rename:$}=await F.prompt([{type:"confirm",name:"rename",message:`Rename branch "${D}" to "main"?`,default:!0}]);if(!$)console.log(W.red(" Upload cancelled. Rename your branch to main before uploading:")),console.log(W.dim(` git branch -m '${D}' main`));return $}catch($){return console.log(W.red(` Failed to prompt: ${$ instanceof Error?$.message:String($)}`)),console.log(W.dim(` You can manually rename: git branch -m '${D}' main`)),!1}}async function s8(D){try{let{stdout:F,exitCode:$}=await T(["git","remote","get-url","origin"],{cwd:D});if($!==0||!F.trim())return null;let Q=F.trim().match(/[/:]([^/]+?)(?:\.git)?$/);if(!Q)return null;return Q[1]}catch{return null}}function QH(D){let F=nW(D,"dataset_description.json");if(!cW(F))return{version:null};try{let $=JSON.parse(qV0(F,"utf-8"));return{version:typeof $.DatasetVersion==="string"?$.DatasetVersion:null}}catch($){return{version:null,error:`dataset_description.json is unreadable: ${$.message}`}}}async function YH(D){let F=[];for(let $ of["origin/HEAD","origin/main","origin/master"]){let{stdout:J,stderr:Q,exitCode:Y}=await T(["git","show",`${$}:dataset_description.json`],{cwd:D});if(Y!==0){if(Q&&!/unknown revision|bad revision|does not exist/i.test(Q))F.push(`git show ${$} failed: ${Q.trim()}`);continue}if(!J.trim())continue;try{let B=JSON.parse(J);if(typeof B.DatasetVersion==="string")return{version:B.DatasetVersion,warnings:F}}catch(B){F.push(`${$}:dataset_description.json is malformed: ${B.message}`)}}return{version:null,warnings:F}}async function BH(D){let{stdout:F,exitCode:$}=await T(["git","rev-parse","--abbrev-ref","@{upstream}"],{cwd:D});if($===0&&F.trim())return{ref:F.trim()};for(let J of["origin/HEAD","origin/main","origin/master"]){let{exitCode:Q}=await T(["git","rev-parse","--verify","--quiet",J],{cwd:D});if(Q===0)return{ref:J}}return{ref:null,error:"Could not resolve a remote tracking branch (origin/HEAD, origin/main, origin/master all missing)"}}async function XH(D){let{stdout:F,stderr:$,exitCode:J}=await T(["git","status","--porcelain"],{cwd:D});if(J!==0)return{dirty:!1,error:$.trim()||"git status failed"};return{dirty:F.trim().length>0}}async function GH(D){let{stderr:F,exitCode:$}=await T(["git","fetch","--tags","origin"],{cwd:D});if($!==0)return{success:!1,error:F.trim()||"git fetch failed"};return{success:!0}}async function WH(D,F){let{stderr:$,exitCode:J}=await T(["git","merge","--ff-only",F],{cwd:D});if(J!==0)return{success:!1,error:$.trim()||`Cannot fast-forward to ${F}`};return{success:!0}}async function HH(D){let{stderr:F,exitCode:$}=await T(["git","fetch","--prune","--prune-tags","origin"],{cwd:D});if($!==0)return{success:!1,error:F.trim()||"git fetch --prune-tags failed"};let{exitCode:J,stderr:Q}=await T(["git","annex","unused"],{cwd:D});if(J!==0)return{success:!1,error:Q.trim()||"git annex unused failed"};let{stdout:Y,stderr:B,exitCode:X}=await T(["git","annex","dropunused","--force","all"],{cwd:D});if(X!==0)return{success:!1,error:B.trim()||"git annex dropunused failed"};let G=Y.match(/^dropunused .+ ok$/gm);return{success:!0,dropped:G?G.length:0}}async function MV0(D,F){try{let{stderr:$,exitCode:J}=await T(["git","checkout",F],{cwd:D});if(J!==0)return{success:!1,error:$.trim()||"Failed to switch branch"};return{success:!0}}catch($){return{success:!1,error:$.message}}}async function qH(D){let F=[],$=0,J=0,Q=0,{stdout:Y,exitCode:B}=await T(["find",".","(","-type","f","-o","-type","l",")","-not","-path","./.git/*","-not","-path","./.nemar/*","-not","-name",".gitattributes"],{cwd:D});if(B!==0)return{files:F,totalSize:$,dataFiles:J,metadataFiles:Q};let X=Y.trim().split(`
|
|
124
124
|
`).filter(Boolean);for(let G of X){let H=G.startsWith("./")?G.slice(2):G,q=nW(D,H);try{let V=KV0(q).size;$+=V;let z=H.toLowerCase().match(/\.[^.]+$/)?.[0]||"",Z=RV0.has(z)||V>NV0,U=Z?"data":"metadata";if(Z)J++;else Q++;F.push({path:H,size:V,type:U})}catch{}}return{files:F,totalSize:$,dataFiles:J,metadataFiles:Q}}async function KH(D){let F=await T(["git","annex","whereis","--json","--","."],{cwd:D});if(F.exitCode!==0&&!F.stdout.trim())throw Error(`git annex whereis failed: ${F.stderr.trim()}`);if(F.exitCode!==0){let J=F.stderr.match(/whereis:\s*(\d+)\s*failed/);if(J)console.warn(` Warning: ${J[1]} files had no location info (continuing with available files)`);else throw Error(`git annex whereis failed (exit ${F.exitCode}): ${F.stderr.trim()}`)}let $=new Map;for(let J of F.stdout.split(`
|
|
125
|
-
`)){if(!J.trim())continue;try{let Q=JSON.parse(J),Y=Q.key;if(!Y)continue;let B=[...Q.whereis||[],...Q.untrusted||[]];for(let X of B){if(!Array.isArray(X.urls))continue;for(let G of X.urls)if(typeof G==="string"&&(G.startsWith("http")||G.startsWith("s3://"))){$.set(Y,G);break}if($.has(Y))break}}catch(Q){if(Q instanceof SyntaxError)continue;console.error(`Warning: failed to process whereis entry: ${Q instanceof Error?Q.message:String(Q)}`)}}return $}async function Kh(D,F){let $=await T(["git","annex","examinekey","--format=${hashdirlower}",F],{cwd:D});if($.exitCode!==0)throw Error(`git annex examinekey failed for ${F}: ${$.stderr.trim()}`);return $.stdout.trim()}async function CV0(D,F){let $=new Map,J=50;for(let Q=0;Q<F.length;Q+=50){let Y=F.slice(Q,Q+50),B=await Promise.allSettled(Y.map(async(X)=>{let G=await Kh(D,X);return{key:X,hashDir:G}}));for(let X of B)if(X.status==="fulfilled")$.set(X.value.key,X.value.hashDir);else console.error(`Warning: failed to resolve hash dir: ${X.reason?.message||"unknown"}`)}return $}async function ZQ(D,F){let $=await T(["git","config",`remote.${F}.annex-uuid`],{cwd:D});if($.exitCode!==0)return null;return $.stdout.trim()||null}async function zh(D,F,$){return(await T(["git","annex","setpresentkey",F,$,"1"],{cwd:D})).exitCode===0}async function zH(D,F,$){let J=0,Q=0,Y=50;for(let B=0;B<F.length;B+=Y){let X=F.slice(B,B+Y),G=await Promise.all(X.map((H)=>zh(D,H,$)));for(let H of G)if(H)J++;else Q++}return{success:J,failed:Q}}var Bh,Fh=3,$h,qQ="nemar-s3",NV0=102400,RV0,OV0,wV0;var r8=S(()=>{ND();pW();Bh=/There is already a special remote named "[^"]+"/;$h=/^[a-zA-Z0-9._-]+$/;RV0=new Set([".edf",".bdf",".eeg",".vhdr",".vmrk",".set",".fdt",".cnt",".mff",".fif",".nii",".nii.gz",".mat",".bin"]);OV0=n6,wV0=N1});var Ah={};r6(Ah,{writeManifestToS3:()=>AH,serverSideS3Copy:()=>Zh,readManifestFromS3:()=>LQ,parseShardArg:()=>kV0,parseS3Url:()=>VH,listExistingObjects:()=>UQ,keyInShard:()=>LH,filterAlreadyCopied:()=>UH,curlStreamCopy:()=>Uh,cleanupStaging:()=>MH,batchServerSideCopy:()=>ZH});import{mkdtempSync as jV0,rmSync as TV0,writeFileSync as PV0}from"fs";import{tmpdir as IV0}from"os";import{join as Vh}from"path";function EH(D){try{return decodeURIComponent(D)}catch{return D}}function VH(D){if(!D)return null;if(D.startsWith("s3://")){let H=D.slice(5),q=H.indexOf("/");if(q<0)return null;let K=H.slice(0,q),V=H.slice(q+1);if(!K||!V)return null;return{bucket:K,key:EH(V)}}let F;try{F=new URL(D)}catch{return null}if(F.protocol!=="http:"&&F.protocol!=="https:")return null;let $=F.hostname;if(!$.endsWith(".amazonaws.com"))return null;let J=$.split("."),Q=J.findIndex((H)=>H==="s3"||H.startsWith("s3-"));if(Q===-1)return null;let Y=F.pathname.replace(/^\//,"");if(Q===0){let H=J.length===4?J[1]:void 0,q=Y.indexOf("/");if(q<0)return null;let K=Y.slice(0,q),V=Y.slice(q+1);if(!K||!V)return null;return{bucket:K,key:EH(V),region:H}}let B=J.slice(0,Q).join("."),X=J[Q],G;if(X.startsWith("s3-"))G=X.slice(3);else if(J[Q+1]&&J[Q+1]!=="amazonaws")G=J[Q+1];if(!B||!Y)return null;return{bucket:B,key:EH(Y),region:G}}async function Zh(D,F,$){let J=`s3://${D.bucket}/${D.key}`,Q=await T(["aws","s3","cp",J,F,"--source-region",D.region??"us-east-1","--region",$,"--only-show-errors"],{});if(Q.exitCode!==0)return{success:!1,error:Q.stderr.trim()||`aws exit ${Q.exitCode}`};return{success:!0}}async function Uh(D,F,$){let J=await T(["bash","-c",`set -o pipefail; curl -sfL '${D}' | aws s3 cp - '${F}' --region '${$}'`],{});if(J.exitCode!==0)return{success:!1,error:J.stderr.trim()||`curl/aws exit ${J.exitCode}`};return{success:!0}}async function ZH(D,F,$,J,Q=3){let Y=0,B=0,X=[],G=async(H)=>{let q="no S3 source";if(H.source)for(let K=1;K<=Q;K++){let V=await Zh(H.source,H.destUri,F);if(V.success)return"ok";if(q=V.error??"unknown server-side copy error",K<Q)await new Promise((z)=>setTimeout(z,K*K*1000))}if(H.httpUrl?.startsWith("http")){let K=await Uh(H.httpUrl,H.destUri,F);if(K.success)return H.source?"fallback":"ok";throw Error(`server-side failed (${q}); fallback failed (${K.error})`)}throw Error(q)};for(let H=0;H<D.length;H+=$){let q=D.slice(H,H+$),K=await Promise.allSettled(q.map((V)=>G(V)));for(let V=0;V<K.length;V++){let z=K[V];if(z.status==="fulfilled"){if(Y++,z.value==="fallback")B++}else X.push({key:q[V].key,error:z.reason instanceof Error?z.reason.message:String(z.reason)})}J?.(Y,D.length,q[q.length-1].key)}return{copied:Y,fellBack:B,failed:X}}async function UQ(D,F,$){let J=new Map,Q=await T(["aws","s3api","list-objects-v2","--bucket",D,"--prefix",F,"--region",$,"--output","json"],{});if(Q.exitCode!==0)throw Error(`list-objects-v2 failed for ${F}: ${Q.stderr.trim()}`);let Y=Q.stdout.trim();if(!Y)return J;let B;try{B=JSON.parse(Y)}catch(X){throw Error(`list-objects-v2 returned unparseable JSON for ${F}: ${X instanceof Error?X.message:String(X)}`)}if(B.IsTruncated===!0||B.NextContinuationToken)throw Error(`list-objects-v2 returned a truncated page for ${F} (auto-pagination disabled?). Refusing to proceed on a partial destination view.`);for(let X of B.Contents??[]){if(typeof X.Key!=="string")continue;if(!X.Key.startsWith(F))continue;let G=X.Key.slice(F.length);if(G.length===0)continue;J.set(G,typeof X.Size==="number"?X.Size:0)}return J}function UH(D,F,$){let J=[],Q=[];for(let Y of D){if(!F.has(Y.key)){J.push(Y);continue}let B=$?.get(Y.key);if(B!==void 0&&F.get(Y.key)!==B)J.push(Y);else Q.push(Y.key)}return{toCopy:J,skipped:Q}}function SV0(D){let F=2166136261;for(let $=0;$<D.length;$++)F^=D.charCodeAt($),F=Math.imul(F,16777619);return F>>>0}function kV0(D){let F=D.match(/^(\d+)\/(\d+)$/);if(!F)throw Error(`Invalid --shard "${D}". Expected "i/N" (e.g. "0/8").`);let $=Number(F[1]),J=Number(F[2]);if(J<1)throw Error(`Invalid shard count in "${D}": N must be >= 1.`);if($<0||$>=J)throw Error(`Invalid shard index in "${D}": i must satisfy 0 <= i < N.`);return{index:$,count:J}}function LH(D,F,$){if($<=1)return!0;return SV0(D)%$===F}function Lh(D,F){return`s3://${D}/${F}/staging/import-manifest.json`}async function vV0(D,F,$){let J=jV0(Vh(IV0(),"nemar-staging-")),Q=Vh(J,"payload.json");try{PV0(Q,JSON.stringify(D));let Y=await T(["aws","s3","cp",Q,F,"--region",$,"--content-type","application/json"],{});if(Y.exitCode!==0)throw Error(`Failed to write ${F}: ${Y.stderr.trim()}`)}finally{TV0(J,{recursive:!0,force:!0})}}async function yV0(D,F){let $=await T(["aws","s3","cp",D,"-","--region",F],{});if($.exitCode!==0)throw Error(`Failed to read ${D}: ${$.stderr.trim()}`);try{return JSON.parse($.stdout)}catch(J){throw Error(`Failed to parse JSON from ${D} (corrupt or truncated staging object): ${J instanceof Error?J.message:String(J)}`)}}async function AH(D,F,$){await vV0(D,Lh(F,D.nemarId),$)}async function LQ(D,F,$){return yV0(Lh(F,D),$)}async function MH(D,F,$){let J=await T(["aws","s3","rm",`s3://${F}/${D}/staging/`,"--recursive","--region",$],{});if(J.exitCode!==0)console.warn(` Staging cleanup failed (non-fatal): ${J.stderr.trim()}`)}var NH=S(()=>{r8()});var OH={};r6(OH,{seedMetadata:()=>yh,prepareImport:()=>_h,openNeuroCurrentUrl:()=>Ph,isNeverAnnexedMetadata:()=>wh,importOpenNeuro:()=>nV0,findAnnexedRootMetadata:()=>jh,finalizeImport:()=>gh,ensureRootMetadataUnannexed:()=>Ih,ensureReadmeMd:()=>xh,detectModalitiesFromDataset:()=>kh,decideSkipCiCheck:()=>Oh,copyShard:()=>fh,coerceFunding:()=>vh,OPENNEURO_UPSTREAM_MARKER:()=>Th});import{existsSync as Nh,mkdirSync as xV0,mkdtempSync as Rh,readFileSync as _V0,readdirSync as b9,readlinkSync as fV0,renameSync as gV0,rmSync as hV0,writeFileSync as RH}from"fs";import{tmpdir as Ch}from"os";import{join as sD}from"path";async function mV0(D,F,$=120000,J=5000){let Q=Date.now()+$,Y,B=!1;while(Date.now()<Q){try{let G=await JQ(D);if(B=!0,G.bids_validation.present&&G.bids_validation.status!=="no_runs")return{kind:"found"}}catch(G){Y=G}let X=Math.max(0,Q-Date.now());F.text=`Waiting for BIDS validation run to register... (${Math.ceil(X/1000)}s left)`,await new Promise((G)=>setTimeout(G,Math.min(J,X)))}if(!B&&Y!==void 0)return{kind:"error",lastError:Y};return{kind:"timeout"}}function Oh(D){if(!D.ciDeployed)return{skipCiCheck:!1,abortReason:"CI workflows did not deploy. Aborting before approval: --trust-upstream bypasses validation lookup, not workflow deployment. Re-run after fixing the deploy failure, or run `nemar admin ci add <id>` manually before approving."};let F=D.poll;if(F===null||F.kind==="found")return{skipCiCheck:!1};if(F.kind==="error")return{skipCiCheck:!1,abortReason:`Every BIDS validation poll attempt failed (last error: ${F.lastError instanceof Error?F.lastError.message:String(F.lastError)}). Refusing to bypass under --trust-upstream because validation state was never actually observed. Investigate API/auth health and re-run.`};if(D.trustUpstream)return{skipCiCheck:!0};return{skipCiCheck:!1,abortReason:"BIDS validation run did not register within the bounded poll window. Re-run with --trust-upstream to bypass (OpenNeuro datasets are pre-validated upstream), or investigate why the deployed CI did not trigger."}}function CH(D){let F=D.match(/^ds(\d{6})$/);if(!F)throw Error(`Invalid OpenNeuro ID "${D}". Expected format: ds###### (e.g., ds007262)`);return`on${F[1]}`}function wh(D){let F=D.toLowerCase();if(F.startsWith("readme")||F.startsWith("license")||F.startsWith("changes"))return!0;if(F===".bidsignore"||F===".gitignore")return!0;return/\.(tsv|json|md|txt|yml|yaml)$/.test(F)}function jh(D){let F;try{F=b9(D,{withFileTypes:!0})}catch(J){let Q=J.code;if(Q==="ENOENT"||Q==="ENOTDIR")return[];throw Error(`Cannot scan ${D} for annexed metadata: ${J instanceof Error?J.message:String(J)}`)}let $=[];for(let J of F){if(!J.isSymbolicLink())continue;if(!wh(J.name))continue;try{if(fV0(sD(D,J.name)).includes("annex/objects"))$.push(J.name)}catch{}}return $.sort()}function Ph(D,F){let $=F.split("/").map(encodeURIComponent).join("/");return`https://s3.amazonaws.com/openneuro.org/${D}/${$}`}async function Ih(D,F){let $=jh(D);if($.length===0)return[];let J=[];for(let Y of $){let B=Ph(F,Y);try{let X=await fetch(B);if(!X.ok){J.push(`${Y} (HTTP ${X.status})`);continue}let G=Buffer.from(await X.arrayBuffer()),H=sD(D,Y);hV0(H,{force:!0}),RH(H,G)}catch(X){J.push(`${Y} (${X instanceof Error?X.message:String(X)})`)}}if(J.length>0)throw Error(`${Th} cannot fetch metadata from OpenNeuro: ${J.join(", ")}. These objects are not anonymously readable and NEMAR has no signed OpenNeuro login. This is an OpenNeuro-side access problem, not a NEMAR import bug.`);let Q=await T(["git","-c","annex.largefiles=nothing","add",...$],{cwd:D});if(Q.exitCode!==0)throw Error(`Failed to stage un-annexed metadata (${$.join(", ")}): ${Q.stderr.trim()}. The files are already regular files on disk; recover with: git -C ${D} -c annex.largefiles=nothing add ${$.join(" ")}`);return $}function lV0(D){let F=sD(D,"dataset_description.json");if(!Nh(F))throw Error(`dataset_description.json not found at ${F}`);try{return JSON.parse(_V0(F,"utf-8"))}catch($){throw Error(`Failed to parse dataset_description.json at ${F}: ${$ instanceof Error?$.message:String($)}`)}}function Sh(){let D=process.env.AWS_ACCESS_KEY_ID,F=process.env.AWS_SECRET_ACCESS_KEY;if(!D||!F)throw Error("AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY must be set in environment for S3 operations");return{accessKeyId:D,secretAccessKey:F,sessionToken:process.env.AWS_SESSION_TOKEN}}function pV0(D){return typeof D.DatasetDOI==="string"?D.DatasetDOI.replace(/^doi:/,""):null}function kh(D){let F=new Set,$=[];try{$=b9(D,{withFileTypes:!0}).filter((J)=>J.isDirectory()&&J.name.startsWith("sub-")).map((J)=>J.name)}catch{return[]}for(let J of $){let Q=sD(D,J),Y=[];try{Y=b9(Q,{withFileTypes:!0})}catch{continue}for(let B of Y){if(!B.isDirectory())continue;if(B.name.startsWith("ses-")){let X=[];try{X=b9(sD(Q,B.name),{withFileTypes:!0})}catch{continue}for(let G of X)if(G.isDirectory()&&Mh.includes(G.name))F.add(G.name)}else if(Mh.includes(B.name))F.add(B.name)}}return[...F].sort()}function vh(D){let F=D.Funding;if(!Array.isArray(F))return[];return F.filter(($)=>typeof $==="string"&&$.trim().length>0).map(($)=>({funder_name:$.trim()}))}function yh(D,F,$,J,Q){let Y=sD(D,".nemar");if(!Nh(Y))xV0(Y,{recursive:!0});let B=Q?[{identifier:Q,identifier_type:"DOI",relation_type:"IsIdenticalTo"}]:[],X=kh(D),G=vh(J),H={version:"2.0",dataset_id:F,source:"openneuro",source_id:$,title:J.Name||F,authors:Array.isArray(J.Authors)?Object.fromEntries(J.Authors.map((q)=>[q,{}])):{},license:J.License||"CC0",dataset_type:J.DatasetType||"raw",related_identifiers:B,pipeline_stage:"seeded"};if(typeof J.BIDSVersion==="string")H.bids_version=J.BIDSVersion;if(X.length>0)H.recording_modality=X;if(X.length>0)H.datatypes=X;if(G.length>0)H.funding_references=G;if(typeof J.Acknowledgements==="string"&&J.Acknowledgements.trim().length>0)H.acknowledgements=J.Acknowledgements.trim();RH(sD(Y,"metadata.json"),`${JSON.stringify(H,null,2)}
|
|
125
|
+
`)){if(!J.trim())continue;try{let Q=JSON.parse(J),Y=Q.key;if(!Y)continue;let B=[...Q.whereis||[],...Q.untrusted||[]];for(let X of B){if(!Array.isArray(X.urls))continue;for(let G of X.urls)if(typeof G==="string"&&(G.startsWith("http")||G.startsWith("s3://"))){$.set(Y,G);break}if($.has(Y))break}}catch(Q){if(Q instanceof SyntaxError)continue;console.error(`Warning: failed to process whereis entry: ${Q instanceof Error?Q.message:String(Q)}`)}}return $}async function Kh(D,F){let $=await T(["git","annex","examinekey","--format=${hashdirlower}",F],{cwd:D});if($.exitCode!==0)throw Error(`git annex examinekey failed for ${F}: ${$.stderr.trim()}`);return $.stdout.trim()}async function CV0(D,F){let $=new Map,J=50;for(let Q=0;Q<F.length;Q+=50){let Y=F.slice(Q,Q+50),B=await Promise.allSettled(Y.map(async(X)=>{let G=await Kh(D,X);return{key:X,hashDir:G}}));for(let X of B)if(X.status==="fulfilled")$.set(X.value.key,X.value.hashDir);else console.error(`Warning: failed to resolve hash dir: ${X.reason?.message||"unknown"}`)}return $}async function ZQ(D,F){let $=await T(["git","config",`remote.${F}.annex-uuid`],{cwd:D});if($.exitCode!==0)return null;return $.stdout.trim()||null}async function zh(D,F,$){return(await T(["git","annex","setpresentkey",F,$,"1"],{cwd:D})).exitCode===0}async function zH(D,F,$){let J=0,Q=0,Y=50;for(let B=0;B<F.length;B+=Y){let X=F.slice(B,B+Y),G=await Promise.all(X.map((H)=>zh(D,H,$)));for(let H of G)if(H)J++;else Q++}return{success:J,failed:Q}}var Bh,Fh=3,$h,qQ="nemar-s3",NV0=102400,RV0,OV0,wV0;var r8=S(()=>{ND();pW();Bh=/There is already a special remote named "[^"]+"/;$h=/^[a-zA-Z0-9._-]+$/;RV0=new Set([".edf",".bdf",".eeg",".vhdr",".vmrk",".set",".fdt",".cnt",".mff",".fif",".nii",".nii.gz",".mat",".bin"]);OV0=n6,wV0=N1});var Ah={};r6(Ah,{writeManifestToS3:()=>AH,serverSideS3Copy:()=>Zh,readManifestFromS3:()=>LQ,parseShardArg:()=>kV0,parseS3Url:()=>VH,listExistingObjects:()=>UQ,keyInShard:()=>LH,filterAlreadyCopied:()=>UH,curlStreamCopy:()=>Uh,cleanupStaging:()=>MH,batchServerSideCopy:()=>ZH});import{mkdtempSync as jV0,rmSync as TV0,writeFileSync as PV0}from"fs";import{tmpdir as IV0}from"os";import{join as Vh}from"path";function EH(D){try{return decodeURIComponent(D)}catch{return D}}function VH(D){if(!D)return null;if(D.startsWith("s3://")){let H=D.slice(5),q=H.indexOf("/");if(q<0)return null;let K=H.slice(0,q),V=H.slice(q+1);if(!K||!V)return null;return{bucket:K,key:EH(V)}}let F;try{F=new URL(D)}catch{return null}if(F.protocol!=="http:"&&F.protocol!=="https:")return null;let $=F.hostname;if(!$.endsWith(".amazonaws.com"))return null;let J=$.split("."),Q=J.findIndex((H)=>H==="s3"||H.startsWith("s3-"));if(Q===-1)return null;let Y=F.pathname.replace(/^\//,"");if(Q===0){let H=J.length===4?J[1]:void 0,q=Y.indexOf("/");if(q<0)return null;let K=Y.slice(0,q),V=Y.slice(q+1);if(!K||!V)return null;return{bucket:K,key:EH(V),region:H}}let B=J.slice(0,Q).join("."),X=J[Q],G;if(X.startsWith("s3-"))G=X.slice(3);else if(J[Q+1]&&J[Q+1]!=="amazonaws")G=J[Q+1];if(!B||!Y)return null;return{bucket:B,key:EH(Y),region:G}}async function Zh(D,F,$){let J=`s3://${D.bucket}/${D.key}`,Q=await T(["aws","s3","cp",J,F,"--source-region",D.region??"us-east-1","--region",$,"--only-show-errors"],{});if(Q.exitCode!==0)return{success:!1,error:Q.stderr.trim()||`aws exit ${Q.exitCode}`};return{success:!0}}async function Uh(D,F,$){let J=await T(["bash","-c",`set -o pipefail; curl -sfL '${D}' | aws s3 cp - '${F}' --region '${$}'`],{});if(J.exitCode!==0)return{success:!1,error:J.stderr.trim()||`curl/aws exit ${J.exitCode}`};return{success:!0}}async function ZH(D,F,$,J,Q=3){let Y=0,B=0,X=[],G=async(H)=>{let q="no S3 source";if(H.source)for(let K=1;K<=Q;K++){let V=await Zh(H.source,H.destUri,F);if(V.success)return"ok";if(q=V.error??"unknown server-side copy error",K<Q)await new Promise((z)=>setTimeout(z,K*K*1000))}if(H.httpUrl?.startsWith("http")){let K=await Uh(H.httpUrl,H.destUri,F);if(K.success)return H.source?"fallback":"ok";throw Error(`server-side failed (${q}); fallback failed (${K.error})`)}throw Error(q)};for(let H=0;H<D.length;H+=$){let q=D.slice(H,H+$),K=await Promise.allSettled(q.map((V)=>G(V)));for(let V=0;V<K.length;V++){let z=K[V];if(z.status==="fulfilled"){if(Y++,z.value==="fallback")B++}else X.push({key:q[V].key,error:z.reason instanceof Error?z.reason.message:String(z.reason)})}J?.(Y,D.length,q[q.length-1].key)}return{copied:Y,fellBack:B,failed:X}}async function UQ(D,F,$){let J=new Map,Q=await T(["aws","s3api","list-objects-v2","--bucket",D,"--prefix",F,"--region",$,"--output","json"],{});if(Q.exitCode!==0)throw Error(`list-objects-v2 failed for ${F}: ${Q.stderr.trim()}`);let Y=Q.stdout.trim();if(!Y)return J;let B;try{B=JSON.parse(Y)}catch(X){throw Error(`list-objects-v2 returned unparseable JSON for ${F}: ${X instanceof Error?X.message:String(X)}`)}if(B.IsTruncated===!0||B.NextContinuationToken)throw Error(`list-objects-v2 returned a truncated page for ${F} (auto-pagination disabled?). Refusing to proceed on a partial destination view.`);for(let X of B.Contents??[]){if(typeof X.Key!=="string")continue;if(!X.Key.startsWith(F))continue;let G=X.Key.slice(F.length);if(G.length===0)continue;J.set(G,typeof X.Size==="number"?X.Size:0)}return J}function UH(D,F,$){let J=[],Q=[];for(let Y of D){if(!F.has(Y.key)){J.push(Y);continue}let B=$?.get(Y.key);if(B!==void 0&&F.get(Y.key)!==B)J.push(Y);else Q.push(Y.key)}return{toCopy:J,skipped:Q}}function SV0(D){let F=2166136261;for(let $=0;$<D.length;$++)F^=D.charCodeAt($),F=Math.imul(F,16777619);return F>>>0}function kV0(D){let F=D.match(/^(\d+)\/(\d+)$/);if(!F)throw Error(`Invalid --shard "${D}". Expected "i/N" (e.g. "0/8").`);let $=Number(F[1]),J=Number(F[2]);if(J<1)throw Error(`Invalid shard count in "${D}": N must be >= 1.`);if($<0||$>=J)throw Error(`Invalid shard index in "${D}": i must satisfy 0 <= i < N.`);return{index:$,count:J}}function LH(D,F,$){if($<=1)return!0;return SV0(D)%$===F}function Lh(D,F){return`s3://${D}/${F}/staging/import-manifest.json`}async function vV0(D,F,$){let J=jV0(Vh(IV0(),"nemar-staging-")),Q=Vh(J,"payload.json");try{PV0(Q,JSON.stringify(D));let Y=await T(["aws","s3","cp",Q,F,"--region",$,"--content-type","application/json"],{});if(Y.exitCode!==0)throw Error(`Failed to write ${F}: ${Y.stderr.trim()}`)}finally{TV0(J,{recursive:!0,force:!0})}}async function yV0(D,F){let $=await T(["aws","s3","cp",D,"-","--region",F],{});if($.exitCode!==0)throw Error(`Failed to read ${D}: ${$.stderr.trim()}`);try{return JSON.parse($.stdout)}catch(J){throw Error(`Failed to parse JSON from ${D} (corrupt or truncated staging object): ${J instanceof Error?J.message:String(J)}`)}}async function AH(D,F,$){await vV0(D,Lh(F,D.nemarId),$)}async function LQ(D,F,$){return yV0(Lh(F,D),$)}async function MH(D,F,$){let J=await T(["aws","s3","rm",`s3://${F}/${D}/staging/`,"--recursive","--region",$],{});if(J.exitCode!==0)console.warn(` Staging cleanup failed (non-fatal): ${J.stderr.trim()}`)}var NH=S(()=>{r8()});var OH={};r6(OH,{seedMetadata:()=>yh,prepareImport:()=>_h,openNeuroCurrentUrl:()=>Ph,isNeverAnnexedMetadata:()=>wh,importOpenNeuro:()=>nV0,findAnnexedRootMetadata:()=>jh,finalizeImport:()=>gh,ensureRootMetadataUnannexed:()=>Ih,ensureReadmeMd:()=>xh,detectModalitiesFromDataset:()=>kh,decideSkipCiCheck:()=>Oh,copyShard:()=>fh,coerceFunding:()=>vh,OPENNEURO_UPSTREAM_MARKER:()=>Th});import{existsSync as Nh,mkdirSync as xV0,mkdtempSync as Rh,readFileSync as _V0,readdirSync as b9,readlinkSync as fV0,renameSync as gV0,rmSync as hV0,writeFileSync as RH}from"fs";import{tmpdir as Ch}from"os";import{join as sD}from"path";async function mV0(D,F,$=120000,J=5000){let Q=Date.now()+$,Y,B=!1;while(Date.now()<Q){try{let G=await JQ(D);if(B=!0,G.bids_validation.present&&G.bids_validation.status!=="no_runs")return{kind:"found"}}catch(G){Y=G}let X=Math.max(0,Q-Date.now());F.text=`Waiting for BIDS validation run to register... (${Math.ceil(X/1000)}s left)`,await new Promise((G)=>setTimeout(G,Math.min(J,X)))}if(!B&&Y!==void 0)return{kind:"error",lastError:Y};return{kind:"timeout"}}function Oh(D){if(!D.ciDeployed)return{skipCiCheck:!1,abortReason:"CI workflows did not deploy. Aborting before approval: --trust-upstream bypasses validation lookup, not workflow deployment. Re-run after fixing the deploy failure, or run `nemar admin ci add <id>` manually before approving."};let F=D.poll;if(F===null||F.kind==="found")return{skipCiCheck:!1};if(F.kind==="error")return{skipCiCheck:!1,abortReason:`Every BIDS validation poll attempt failed (last error: ${F.lastError instanceof Error?F.lastError.message:String(F.lastError)}). Refusing to bypass under --trust-upstream because validation state was never actually observed. Investigate API/auth health and re-run.`};if(D.trustUpstream)return{skipCiCheck:!0};return{skipCiCheck:!1,abortReason:"BIDS validation run did not register within the bounded poll window. Re-run with --trust-upstream to bypass (OpenNeuro datasets are pre-validated upstream), or investigate why the deployed CI did not trigger."}}function CH(D){let F=D.match(/^ds(\d{6})$/);if(!F)throw Error(`Invalid OpenNeuro ID "${D}". Expected format: ds###### (e.g., ds007262)`);return`on${F[1]}`}function wh(D){let F=D.toLowerCase();if(F.startsWith("readme")||F.startsWith("license")||F.startsWith("changes"))return!0;if(F===".bidsignore"||F===".gitignore")return!0;return/\.(tsv|json|md|txt|yml|yaml)$/.test(F)}function jh(D){let F;try{F=b9(D,{withFileTypes:!0})}catch(J){let Q=J.code;if(Q==="ENOENT"||Q==="ENOTDIR")return[];throw Error(`Cannot scan ${D} for annexed metadata: ${J instanceof Error?J.message:String(J)}`)}let $=[];for(let J of F){if(!J.isSymbolicLink())continue;if(!wh(J.name))continue;try{if(fV0(sD(D,J.name)).includes("annex/objects"))$.push(J.name)}catch{}}return $.sort()}function Ph(D,F){let $=F.split("/").map(encodeURIComponent).join("/");return`https://s3.amazonaws.com/openneuro.org/${D}/${$}`}async function Ih(D,F){let $=jh(D);if($.length===0)return[];let J=[];for(let Y of $){let B=Ph(F,Y),X;try{let H=await fetch(B);if(!H.ok){J.push(`${Y} (HTTP ${H.status})`);continue}X=Buffer.from(await H.arrayBuffer())}catch(H){J.push(`${Y} (fetch failed: ${H instanceof Error?H.message:String(H)})`);continue}if(X.length===0){J.push(`${Y} (HTTP 200 but empty body)`);continue}let G=sD(D,Y);try{hV0(G,{force:!0}),RH(G,X)}catch(H){throw Error(`Failed to write fetched metadata ${Y} to ${G} (local error, not OpenNeuro): ${H instanceof Error?H.message:String(H)}`)}}if(J.length>0)throw Error(`${Th} cannot fetch metadata from OpenNeuro: ${J.join(", ")}. These objects are not anonymously readable and NEMAR has no signed OpenNeuro login. This is an OpenNeuro-side access problem, not a NEMAR import bug. (Any files that did fetch are left as regular files on disk, unstaged.)`);let Q=await T(["git","-c","annex.largefiles=nothing","add",...$],{cwd:D});if(Q.exitCode!==0)throw Error(`Failed to stage un-annexed metadata (${$.join(", ")}): ${Q.stderr.trim()}. The files are already regular files on disk; recover with: git -C ${D} -c annex.largefiles=nothing add ${$.join(" ")}`);return $}function lV0(D){let F=sD(D,"dataset_description.json");if(!Nh(F))throw Error(`dataset_description.json not found at ${F}`);try{return JSON.parse(_V0(F,"utf-8"))}catch($){throw Error(`Failed to parse dataset_description.json at ${F}: ${$ instanceof Error?$.message:String($)}`)}}function Sh(){let D=process.env.AWS_ACCESS_KEY_ID,F=process.env.AWS_SECRET_ACCESS_KEY;if(!D||!F)throw Error("AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY must be set in environment for S3 operations");return{accessKeyId:D,secretAccessKey:F,sessionToken:process.env.AWS_SESSION_TOKEN}}function pV0(D){return typeof D.DatasetDOI==="string"?D.DatasetDOI.replace(/^doi:/,""):null}function kh(D){let F=new Set,$=[];try{$=b9(D,{withFileTypes:!0}).filter((J)=>J.isDirectory()&&J.name.startsWith("sub-")).map((J)=>J.name)}catch{return[]}for(let J of $){let Q=sD(D,J),Y=[];try{Y=b9(Q,{withFileTypes:!0})}catch{continue}for(let B of Y){if(!B.isDirectory())continue;if(B.name.startsWith("ses-")){let X=[];try{X=b9(sD(Q,B.name),{withFileTypes:!0})}catch{continue}for(let G of X)if(G.isDirectory()&&Mh.includes(G.name))F.add(G.name)}else if(Mh.includes(B.name))F.add(B.name)}}return[...F].sort()}function vh(D){let F=D.Funding;if(!Array.isArray(F))return[];return F.filter(($)=>typeof $==="string"&&$.trim().length>0).map(($)=>({funder_name:$.trim()}))}function yh(D,F,$,J,Q){let Y=sD(D,".nemar");if(!Nh(Y))xV0(Y,{recursive:!0});let B=Q?[{identifier:Q,identifier_type:"DOI",relation_type:"IsIdenticalTo"}]:[],X=kh(D),G=vh(J),H={version:"2.0",dataset_id:F,source:"openneuro",source_id:$,title:J.Name||F,authors:Array.isArray(J.Authors)?Object.fromEntries(J.Authors.map((q)=>[q,{}])):{},license:J.License||"CC0",dataset_type:J.DatasetType||"raw",related_identifiers:B,pipeline_stage:"seeded"};if(typeof J.BIDSVersion==="string")H.bids_version=J.BIDSVersion;if(X.length>0)H.recording_modality=X;if(X.length>0)H.datatypes=X;if(G.length>0)H.funding_references=G;if(typeof J.Acknowledgements==="string"&&J.Acknowledgements.trim().length>0)H.acknowledgements=J.Acknowledgements.trim();RH(sD(Y,"metadata.json"),`${JSON.stringify(H,null,2)}
|
|
126
126
|
`)}function xh(D,F,$){let Q=b9(D,{withFileTypes:!0}).filter((K)=>K.isFile()&&dV0.test(K.name)),Y=Q.find((K)=>K.name.includes("."));if(Y)return{kind:"kept",path:Y.name};let B=Q.find((K)=>!K.name.includes("."));if(B)return gV0(sD(D,B.name),sD(D,"README.md")),{kind:"renamed",from:"README",to:"README.md"};let X="<!-- nemar:provenance -->",G=`https://openneuro.org/datasets/${F}`,H=$?`
|
|
127
127
|
- DOI: [${$}](https://doi.org/${$})`:"",q=`${X}
|
|
128
128
|
## Provenance
|
package/package.json
CHANGED