diff --git a/Dockerfile b/Dockerfile index 1f22551..9509140 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,8 +8,11 @@ FROM oven/bun:1.4.4@sha256:1d22548f177f4ff38e0c15baa3c2c46c6c2060ba2d1bc573bb472 WORKDIR /app ENV NEXT_TELEMETRY_DISABLED=1 -# Install dependencies +# Install dependencies. TEMPORARY (I/O Schema proposal, krini#47): the +# Cloud Components come from the tarballs in `vendor/` until they are +# released; remove the `vendor` line with them COPY package.json bun.lock ./ +COPY vendor ./vendor RUN bun install --frozen-lockfile # No settings: all are read when the server starts (see diff --git a/bun.lock b/bun.lock index 7e566ed..55b7a23 100644 --- a/bun.lock +++ b/bun.lock @@ -7,7 +7,7 @@ "dependencies": { "@base-ui/react": "^1.9.0", "@elixir-cloud/tes": "^2.0.0-alpha.51", - "@elixir-cloud/wes": "^2.0.0-alpha.51", + "@elixir-cloud/wes": "file:./vendor/cloud-components/elixir-cloud-wes-2.0.0-alpha.51-io.f28c15c.tgz", "axios": "^1.20.0", "class-variance-authority": "^0.7.1", "cn": "^0.5.0", @@ -41,6 +41,7 @@ "sharp", ], "overrides": { + "@elixir-cloud/design": "file:./vendor/cloud-components/elixir-cloud-design-2.0.0-alpha.51-io.f28c15c.tgz", "body-parser": "^2.4.0", "systeminformation": "^5.33.16", }, @@ -133,11 +134,11 @@ "@dotenvx/primitives": ["@dotenvx/primitives@0.8.0", "", {}, "sha512-VYJy0uhFm9zTJ1TxBaW/pA8bjbOM/OttaNMwZ1RHG4JKyRG7DhSdiqD1ipQoAyoD22olUtxbP78W9xY3Wd11bg=="], - "@elixir-cloud/design": ["@elixir-cloud/design@2.0.0-alpha.51", "", { "dependencies": { "@lit/react": "^1.0.2", "ace-builds": "^1.35.0", "lit": "^2.8.0" } }, "sha512-HA331j9pOR0rDDNc/88Kvm1XpwzOVNxGuTcRbrKNgzakzw4TY/R2nIQh2H9TG96Z6lhSMDyWIacOl5M5mpgWPw=="], + "@elixir-cloud/design": ["@elixir-cloud/design@./vendor/cloud-components/elixir-cloud-design-2.0.0-alpha.51-io.f28c15c.tgz", { "dependencies": { "@lit/react": "^1.0.2", "ace-builds": "^1.35.0", "dom-accessibility-api": "^0.7.1", "lit": "^2.8.0" } }, "sha512-f91k3OllkRiTLMiT1qlvdD3cbz4fcrkotXr5Hjgoy66t9MlMO5BjQwNLq1ObpQkCEpjXWeIOEmuWzUdTKA+O/w=="], "@elixir-cloud/tes": ["@elixir-cloud/tes@2.0.0-alpha.51", "", { "dependencies": { "@elixir-cloud/design": "2.0.0-alpha.51", "@lit/react": "^1.0.2", "lit": "^2.8.0" } }, "sha512-ysheVxGyjJ43JGKdSJ9rFyzn1Ps6x+SS/lfyc/NiicZgZMkng+zmPlVkYHo9X5pIOj2Pasnbed5OqxWDCk5OnQ=="], - "@elixir-cloud/wes": ["@elixir-cloud/wes@2.0.0-alpha.51", "", { "dependencies": { "@elixir-cloud/design": "2.0.0-alpha.51", "@lit/react": "^1.0.2", "lit": "^2.8.0" } }, "sha512-jzEg0nzv4TlhgnZsJnjU0WTcTDHypIYOe7OpYVwzx3O5HJ9q74H9BgnTP9i4tnCZ+wBxcSiT2eE8aDI3tZ90ig=="], + "@elixir-cloud/wes": ["@elixir-cloud/wes@./vendor/cloud-components/elixir-cloud-wes-2.0.0-alpha.51-io.f28c15c.tgz", { "dependencies": { "@elixir-cloud/design": "2.0.0-alpha.51-io.f28c15c", "@hyperjump/browser": "^1.6.0", "@hyperjump/json-schema": "^1.18.1", "@lit/react": "^1.0.2", "lit": "^2.8.0", "markdown-it": "^15.0.3" } }, "sha512-zRA68yrADBQMX7FBL9k9IFZdKulTGkoXJbKEwJiBqdxQabKO8aFPD3LEEh4NRbihcVZirJ/Vp0uzbEg69/LApw=="], "@emnapi/core": ["@emnapi/core@2.0.0-beta.2", "", { "dependencies": { "@emnapi/wasi-threads": "2.2.0", "tslib": "^2.4.0" } }, "sha512-MzCVoWtcg4Pm2B3je5mMvYMvj3MmBKw+fU7vbsJc9/iT8ip6/eYIHo/Dsm/mr+wsHB6SEyJDuxB09Yy6r/8+4A=="], @@ -155,6 +156,18 @@ "@hono/node-server": ["@hono/node-server@2.1.6", "", { "peerDependencies": { "hono": "^4 || ^5.0.0-0" } }, "sha512-p/KH9MnfNcsm3sR6x4lNgm5j+QN4Et8srKredl9DZfXiyZ1UQ3aQ2YVpFLbqktYN5JI+DB+VZFKM2PqE5hLKjQ=="], + "@hyperjump/browser": ["@hyperjump/browser@1.6.0", "", { "dependencies": { "@hyperjump/json-pointer": "^1.1.0", "@hyperjump/uri": "^1.2.0", "content-type": "^1.0.5" } }, "sha512-FcD0B9cOTIj8bJCrX7RtsLSnA2CrX43KCdaFOpS2cH9VnNMuKX4EJ3mgSdQFWF6vz/fbXUNYU1LpIYXYn3TTXA=="], + + "@hyperjump/json-pointer": ["@hyperjump/json-pointer@1.1.4", "", {}, "sha512-c6slpSqSiNL10JA78HdQOx50xaXHy1dKsPZOiEVjr/RqcVg5MgnWcP7vbvpxa42CD7pMkU6TtTCS+redjpjc2w=="], + + "@hyperjump/json-schema": ["@hyperjump/json-schema@1.18.1", "", { "dependencies": { "@hyperjump/json-pointer": "^1.1.0", "@hyperjump/json-schema-formats": "^1.1.0", "@hyperjump/pact": "^1.2.0", "@hyperjump/uri": "^1.2.0", "content-type": "^1.0.4", "just-curry-it": "^5.3.0", "uuid": "^14.0.0" }, "peerDependencies": { "@hyperjump/browser": "^1.6.0" } }, "sha512-RJkZloGX6BupKOdkWINajsityuyn8RG9XZA1EbLf98HCEzfcWI9V7sSMpQOTOU/DrUY/0ceBNuw0VXAhnJE34Q=="], + + "@hyperjump/json-schema-formats": ["@hyperjump/json-schema-formats@1.2.0", "", { "dependencies": { "@hyperjump/uri": "^2.0.2", "idn-hostname": "^16.0.4" } }, "sha512-2nhOLInnldMRwyDWM43ciaX8vuxvOZNfqrouKCF1pwBZLS2mP6P1M++BB+y9WzX1aY8WZEXv5zgnnTgjxiHCRg=="], + + "@hyperjump/pact": ["@hyperjump/pact@1.5.1", "", {}, "sha512-AmMAUpM5FzqMo5Ip4r9XQ7P8eAEuRlyeeMaOPqcv9ItS0Gogl+Sbod19CZZlzSO5n16SNPFijFwEwrid1eCY9Q=="], + + "@hyperjump/uri": ["@hyperjump/uri@1.4.1", "", {}, "sha512-AvzrZhbAXctdMe1WQXKtfymmK+nSTVE3f2edfMdAt4QwK8147HKPH+vr5AyzjEgReFetX5x5NGtIBYy/NO4tNQ=="], + "@img/colour": ["@img/colour@1.1.0", "", {}, "sha512-Td76q7j57o/tLVdgS746cYARfSyxk8iEfRxewL9h4OMzYhbW4TAcppl0mT4eyqXddh6L/jwoM75mo7ixa/pCeQ=="], "@img/sharp-darwin-arm64": ["@img/sharp-darwin-arm64@0.35.5", "", { "optionalDependencies": { "@img/sharp-libvips-darwin-arm64": "1.3.4" }, "os": "darwin", "cpu": "arm64" }, "sha512-QRUlFQ0WxvdWyqqG/WtI3iupfD5rBzmCHXSdPsY91sAtVtTo7Q4cb6zOccZ3gqEqkr0f1As1ehLqmEpDsRf+lg=="], @@ -381,6 +394,8 @@ "ansi-regex": ["ansi-regex@6.4.0", "", {}, "sha512-KzTVk2tCWAHtYrvvvaP8bJKJq2pVinhLcGEQdtLIYPbmNGNyYe8QwNaTUYQp2J7/vIsUKt5QCqAfUkYyG9DkOw=="], + "argparse": ["argparse@3.0.4", "", {}, "sha512-fwWK3Zq22l4XJJjx5mcBHGikIk+hJqO+32dPm0Jur7+rtG5x1scOjSfdT9ZKeWHPpsya/l0HHK4tDImBkTrtvA=="], + "assertion-error": ["assertion-error@2.0.1", "", {}, "sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA=="], "ast-types": ["ast-types@0.16.3", "", { "dependencies": { "tslib": "^2.0.1" } }, "sha512-FvWoWYfSCM6kRxCSH+MGLHIKKGRL6A6AW7Zek2O32REPQRdg131428uRTKMBYAeRd3XXAaHDS60Wpri7CdKDrA=="], @@ -483,6 +498,8 @@ "diff": ["diff@8.0.4", "", {}, "sha512-DPi0FmjiSU5EvQV0++GFDOJ9ASQUVFh5kD+OzOnYdi7n3Wpm9hWWGfB/O2blfHcMVTL5WkQXSnRiK9makhrcnw=="], + "dom-accessibility-api": ["dom-accessibility-api@0.7.1", "", {}, "sha512-vdnCeZD+3wZ+8h8xXL/ZtBlvvoobOFyPzSiIfO6sGOZDqjFx4aLMAjZhl4rawj5xYz3UwP6Tgvyh0iH4IOCVnQ=="], + "dot-prop": ["dot-prop@6.0.1", "", { "dependencies": { "is-obj": "^2.0.0" } }, "sha512-tE7ztYzXHIeyvc7N+hR3oi7FIbf/NIjVP9hmAt3yMXzrQ072/fpjGLx2GxNxGxUl5V73MEqYzioOMoVhGMJ5cA=="], "dotenv": ["dotenv@17.4.2", "", {}, "sha512-nI4U3TottKAcAD9LLud4Cb7b2QztQMUEfHbvhTH09bqXTxnSie8WnjPALV/WMCrJZ6UV/qHJ6L03OqO3LcdYZw=="], @@ -501,6 +518,8 @@ "enquirer": ["enquirer@2.4.1", "", { "dependencies": { "ansi-colors": "^4.1.1", "strip-ansi": "^6.0.1" } }, "sha512-rRqJg/6gd538VHvR3PSrdRBb/1Vy2YfzHqzvbhGIQpDRKIa4FgV/54b5Q1xYSxOOwKvjXweS26E0Q+nAMwp2pQ=="], + "entities": ["entities@8.1.0", "", {}, "sha512-kxL7msIffSuh9aaFAMD7rxAIuTRMAHMeBtgHW2yUdWw732ZNh4MehkF2gdjvtdmikkaIP9bFDDJOPlsvm7avrA=="], + "env-paths": ["env-paths@2.2.1", "", {}, "sha512-+h1lkLKhZMTYjog1VEpJNG7NZJWcuc2DDk/qsqSTRRCOXiLjeQ1d1/udrUGhqMxUgAlwKNZ0cf2uqan5GLuS2A=="], "es-define-property": ["es-define-property@1.0.1", "", {}, "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g=="], @@ -607,6 +626,8 @@ "iconv-lite": ["iconv-lite@0.7.3", "", { "dependencies": { "safer-buffer": ">= 2.1.2 < 3.0.0" } }, "sha512-IKXpvIzjnC9XTAUbVBcMfGS0EPaIXtW6v+zr+RRp+hqULEpo0owZax6wyRwPOJbWbzjYspQwusTsfVr0ifh4uQ=="], + "idn-hostname": ["idn-hostname@16.0.4", "", { "dependencies": { "punycode": "^2.3.1" } }, "sha512-U+LwefPYZbZyZQcRryjB4rNKkrK7ylbYkKFU2NnaQKjIw466vqDWnxaLa62rCG++Iv8NAm8emnn1NZScKjPTIw=="], + "ignore": ["ignore@5.3.2", "", {}, "sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g=="], "inherits": ["inherits@2.0.4", "", {}, "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="], @@ -667,6 +688,8 @@ "jsonfile": ["jsonfile@6.2.1", "", { "dependencies": { "universalify": "^2.0.0" }, "optionalDependencies": { "graceful-fs": "^4.1.6" } }, "sha512-zwOTdL3rFQ/lRdBnntKVOX6k5cKJwEc1HdilT71BWEu7J41gXIB2MRp+vxduPSwZJPWBxEzv4yH1wYLJGUHX4Q=="], + "just-curry-it": ["just-curry-it@5.3.0", "", {}, "sha512-silMIRiFjUWlfaDhkgSzpuAyQ6EX/o09Eu8ZBfmFwQMbax7+LQzeIU2CBrICT6Ne4l86ITCGvUCBpCubWYy0Yw=="], + "kleur": ["kleur@4.1.5", "", {}, "sha512-o+NO+8WrRiQEE4/7nwRJhN1HWpVmJm511pBHUxPLtp0BUISzlBplORYSmTclCnJvQq2tKu/sgl3xVpkc7ZWuQQ=="], "lightningcss": ["lightningcss@1.32.0", "", { "dependencies": { "detect-libc": "^2.0.3" }, "optionalDependencies": { "lightningcss-android-arm64": "1.32.0", "lightningcss-darwin-arm64": "1.32.0", "lightningcss-darwin-x64": "1.32.0", "lightningcss-freebsd-x64": "1.32.0", "lightningcss-linux-arm-gnueabihf": "1.32.0", "lightningcss-linux-arm64-gnu": "1.32.0", "lightningcss-linux-arm64-musl": "1.32.0", "lightningcss-linux-x64-gnu": "1.32.0", "lightningcss-linux-x64-musl": "1.32.0", "lightningcss-win32-arm64-msvc": "1.32.0", "lightningcss-win32-x64-msvc": "1.32.0" } }, "sha512-NXYBzinNrblfraPGyrbPoD19C1h9lfI/1mzgWYvXUTe414Gz/X1FD2XBZSZM7rRTrMA8JL3OtAaGifrIKhQ5yQ=="], @@ -693,6 +716,8 @@ "lightningcss-win32-x64-msvc": ["lightningcss-win32-x64-msvc@1.32.0", "", { "os": "win32", "cpu": "x64" }, "sha512-Amq9B/SoZYdDi1kFrojnoqPLxYhQ4Wo5XiL8EVJrVsB8ARoC1PWW6VGtT0WKCemjy8aC+louJnjS7U18x3b06Q=="], + "linkify-it": ["linkify-it@6.1.0", "", { "dependencies": { "uc.micro": "^3.0.0" } }, "sha512-wJ/TwpSDTLepCrQoYWYIExIKg5Zchex2Nn5yk2mFnB+6PtdkHtyLx742md9csRjjOnGkKIS/RrbY7l8D6gT9Vw=="], + "lit": ["lit@2.8.0", "", { "dependencies": { "@lit/reactive-element": "^1.6.0", "lit-element": "^3.3.0", "lit-html": "^2.8.0" } }, "sha512-4Sc3OFX9QHOJaHbmTMk28SYgVxLN3ePDjg7hofEft2zWlehFL3LiAuapWc4U/kYwMYJSh2hTCPZ6/LIC7ii0MA=="], "lit-element": ["lit-element@3.3.3", "", { "dependencies": { "@lit-labs/ssr-dom-shim": "^1.1.0", "@lit/reactive-element": "^1.3.0", "lit-html": "^2.8.0" } }, "sha512-XbeRxmTHubXENkV4h8RIPyr8lXc+Ff28rkcQzw3G6up2xg5E8Zu1IgOWIwBLEQsu3cOVFqdYwiVi0hv0SlpqUA=="], @@ -713,8 +738,12 @@ "make-dir": ["make-dir@4.0.0", "", { "dependencies": { "semver": "^7.5.3" } }, "sha512-hXdUTZYIVOt1Ex//jAQi+wTZZpUpwBj/0QsOzqegb3rGMMeJiSEu5xLHnYfBrRV4RH2+OCSOO95Is/7x1WJ4bw=="], + "markdown-it": ["markdown-it@15.0.3", "", { "dependencies": { "argparse": "^3.0.3", "entities": "^8.1.0", "linkify-it": "^6.1.0", "mdurl": "^2.1.0", "punycode.js": "^2.3.1", "uc.micro": "^3.0.0" }, "bin": { "markdown-it": "bin/markdown-it.mjs" } }, "sha512-+Az7Ojz3iRGu8KYMvJ6xVhvrxP3eE+vEtJX75Ow88XBpcQNV/0lGX5ZynIIBftREo4DC2jsveAMDaeltmm8QvQ=="], + "math-intrinsics": ["math-intrinsics@1.1.0", "", {}, "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g=="], + "mdurl": ["mdurl@2.1.0", "", {}, "sha512-1+HBaOx0zi/dQWht8rNv9MYf9qqpqL/kxI0hXImU6Y547zM6Sni8BQibt7ifgMcYtQg41ao3Ivd6cnSM86inpg=="], + "media-typer": ["media-typer@1.1.1", "", {}, "sha512-yz3xRaG20c6/BOzvYoDaGtPmGscs7YivItZEEqe6GbwNfHuxu9YNmvnEkMzKldAGY4/80pRcQRZSEnhquk9XuQ=="], "merge-descriptors": ["merge-descriptors@2.0.0", "", {}, "sha512-Snk314V5ayFLhp3fkUREub6WtjBfPdCPY1Ln8/8munuLuiYhsABgBVWsozAG+MWMbVEvcdcpbi9R7ww22l9Q3g=="], @@ -815,6 +844,10 @@ "proxy-from-env": ["proxy-from-env@2.1.0", "", {}, "sha512-cJ+oHTW1VAEa8cJslgmUZrc+sjRKgAKl3Zyse6+PV38hZe/V6Z14TbCuXcan9F9ghlz4QrFr2c92TNF82UkYHA=="], + "punycode": ["punycode@2.3.1", "", {}, "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg=="], + + "punycode.js": ["punycode.js@2.3.1", "", {}, "sha512-uxFIHU0YlHYhDQtV4R9J6a52SLx28BCjT+4ieh7IGbgwVJWO+km431c4yRlREUAsAmt/uMjQUyQHNEPf0M39CA=="], + "qs": ["qs@6.16.1", "", { "dependencies": { "es-define-property": "^1.0.1", "side-channel": "^1.1.1" } }, "sha512-5Px6J7rfHBAGUhNQ3es4YzcOdBBw0SDcVtThJml4RdnKw4tKs2epA0kPZ+K8X+WiHktT93RHVcQ/3ym5aTCgtg=="], "queue-microtask": ["queue-microtask@1.2.3", "", {}, "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A=="], @@ -945,6 +978,8 @@ "typescript": ["typescript@5.9.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw=="], + "uc.micro": ["uc.micro@3.0.0", "", {}, "sha512-U3PppEkleoTnIfi8BozMx3yju3qc/L6SwqWo2Sw+54PX+PX0q9I+r1Um5HCmqD7n9VDX5/v3vQH/AjA6deDdtw=="], + "undici": ["undici@7.30.1", "", {}, "sha512-03KrMbjIFDWQR5RNPrSw3bd1r12JpyFQl9/yxjUbJtqkjmllqC5lFjZh6ujeuJCKr8EOQvRW872Oy/az+nLYxg=="], "undici-types": ["undici-types@6.21.0", "", {}, "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ=="], @@ -961,6 +996,8 @@ "util-deprecate": ["util-deprecate@1.0.2", "", {}, "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw=="], + "uuid": ["uuid@14.0.3", "", { "bin": { "uuid": "dist-node/bin/uuid" } }, "sha512-Sc5u1VVln93y1Xnz4R+CunOZc7R9LUcTmhj7Rc7Eg3HVcf7rVn2FOoa812fe0W8p3jD7xeoGSYbfqCGGH2B6xw=="], + "validate-npm-package-name": ["validate-npm-package-name@7.0.2", "", {}, "sha512-hVDIBwsRruT73PbK7uP5ebUt+ezEtCmzZz3F59BSr2F6OVFnJ/6h8liuvdLrQ88Xmnk6/+xGGuq+pG9WwTuy3A=="], "vary": ["vary@1.1.2", "", {}, "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg=="], @@ -997,6 +1034,8 @@ "@dotenvx/dotenvx/open": ["open@8.4.2", "", { "dependencies": { "define-lazy-prop": "^2.0.0", "is-docker": "^2.1.1", "is-wsl": "^2.2.0" } }, "sha512-7x81NCL719oNbsq/3mh+hVrAWmFuEYUqrq/Iw3kUzH8ReypT9QQ0BLoJS7/G9k6N81XjW4qHWtjWwe/9eLy1EQ=="], + "@hyperjump/json-schema-formats/@hyperjump/uri": ["@hyperjump/uri@2.0.2", "", {}, "sha512-gNQzKwYQzfYWVV8bzr17WZiyc7ep6Cx36ZMilz2LYs0xRbwUDNMfLM7lSSpj6lDD2ChPNj6hMQkmyvbB7pVjLA=="], + "@img/sharp-wasm32/@emnapi/runtime": ["@emnapi/runtime@1.11.3", "", { "dependencies": { "tslib": "^2.4.0" } }, "sha512-Xz4Tpyki7XyrpbUK1jR1AhdAdaXyhhY4lZ3neLodmhpuWfy2PAQN5B46sAiU4liOXGLkHypn/qU+jvfWSCYYLA=="], "@shadcn/registry/cn": ["cn@0.2.6", "", { "bin": { "cn": "bin/cn.mjs" } }, "sha512-+i4L0zUGgRcEnhsxueVrP7iBGxBx5iD0WOTYg1MwFEu2ZyCmH5Ov2V1cul2Ht5UchRQQgftCf4be/RxspuW6QQ=="], diff --git a/docs/development/index.md b/docs/development/index.md index ddde365..997ad9a 100644 --- a/docs/development/index.md +++ b/docs/development/index.md @@ -29,6 +29,17 @@ Install the packages: bun i ``` +!!! note "Unreleased Cloud Components (I/O Schema proposal)" + On the proposal branch of krini#47, `@elixir-cloud/wes` and + `@elixir-cloud/design` come from tarballs in `vendor/cloud-components/` + (a `file:` dependency and an `overrides` entry in `package.json`), + built from the cloud-components proposal branches (#613, #614) at the + commit in their file names, as those versions aren't released yet. The + `Dockerfile` copies `vendor/` before installing. Once the components + are released, set both packages to the released version, remove the + `overrides` entry, `vendor/` and its line in the `Dockerfile`, and run + `bun i`. + Configure the app (see [Environment variables](#environment-variables)), then start the development server: diff --git a/docs/operator-guide/configuration.md b/docs/operator-guide/configuration.md index 72a12cc..56829aa 100644 --- a/docs/operator-guide/configuration.md +++ b/docs/operator-guide/configuration.md @@ -214,6 +214,35 @@ values yet: Krini sets their internal state (see take it any more, "Use an example" shows an error instead of filling the form, and Krini's end-to-end tests fail. +## Tool registries (proposal) + +!!! warning "Proposal" + Workflows from I/O Schemas are a proposal (krini#47) on unreleased + Cloud Components; this section may change before they are released. + +For workflows with a GA4GH I/O Schema (see +[Workflows from I/O Schemas](../user-guide/index.md#workflows-from-io-schemas)), +Krini uses the tool registries (GA4GH TRS services, type `trs`) of the +service registry. There is nothing to set; what to know: + +- **Registration**: register a tool registry in the service registry to + offer its workflows. Without one, the panel **Workflow from a tool + registry** isn't shown and the workflow form works as before. +- **Outbound requests**: Krini's server reads tool versions and their + schemas from the registered tool registries (`https` only, no + redirects, 10 s timeout, 2 MiB per answer), as tool registries need not + allow cross-origin requests: allow that egress where a network policy + restricts it. +- **Schemas by URL**: a schema by URL is fetched by the user's browser, + from any `https` origin (Krini's Content Security Policy allows `https:` + in `connect-src`, see + [Security headers](deployment.md#security-headers)); a stricter policy + in front of Krini must allow it, or users upload the schema instead. +- **Demo**: **Use the demo workflow** is offered only with the built-in + workflow examples (`WORKFLOW_EXAMPLES` unset), as it names a tool in + the tool registry of ELIXIR On-Cloud (see + [Examples](#examples)). + ## Env files `.env.example` is the only env file in the repository; Git and the Docker diff --git a/docs/user-guide/index.md b/docs/user-guide/index.md index fc2f7ce..5f9ba70 100644 --- a/docs/user-guide/index.md +++ b/docs/user-guide/index.md @@ -34,7 +34,9 @@ Your name in the sidebar opens a menu with your e-mail address and tasks the list shows depends on the service: a gateway such as proTES shows only your own tasks. - **Workflows**: choose a WES service, then submit a workflow run (workflow - URL, type and version, parameters) and follow your runs. + URL, type and version, parameters) and follow your runs. For a workflow + with a GA4GH I/O Schema, Krini generates the form for you (see + [Workflows from I/O Schemas](#workflows-from-io-schemas)). - **Federated learning**: a federated learning run is a workflow run on a WES service that runs federated learning jobs, such as the NVFlare hub of [nvflare-wes-testbed](https://github.com/elixir-cloud-aai/nvflare-wes-testbed) @@ -56,6 +58,48 @@ offers only the examples of the workflow languages and versions that the selected service runs. Your deployment may offer its own examples, or none. [Examples](workflow-examples.md) describes the built-in ones. +## Workflows from I/O Schemas + +!!! warning "Proposal" + This feature is a proposal (krini#47). It builds on unreleased Cloud + Components (cloud-components#613 and #614) and may change before it + is released. + +A [GA4GH I/O Schema](https://ga4gh-io-schema.readthedocs.io/) describes +the inputs and outputs of a workflow. With one, you don't need to know the +workflow's type, version or parameter names: Krini shows a form for the +inputs, checks your values as you type, and builds the run request. + +1. Choose a WES service. +2. Under **Workflow from a tool registry**, choose a tool registry (the + GA4GH TRS services of the service registry) and enter the tool ID and + version ID of the workflow; **Use the demo workflow**, if your + deployment offers it, enters those of the demo of the I/O Schema (see + [I/O Schema demo](workflow-examples.md#io-schema-demo)). +3. Choose where the schema comes from: **From the tool registry** (a file + of type `IO_SCHEMA`, or `ga4gh-io.schema.json` of type `OTHER` next to + the workflow), **Upload** (a JSON file of at most 1 MiB) or **URL** (an + `https` URL that allows cross-origin requests, fetched by your browser + without credentials). An uploaded schema or one by URL can name the + tool and version itself (`trs_tool_id`, `trs_version_id` of + `x-ga4gh-workflow`); leave the fields empty to use them. +4. **Load workflow**. The form below then shows the workflow's inputs and + the workflow that will run (type, version and URL), and says if the + WES service doesn't run that type or version. Fill in the inputs and + **Submit Run**; values that the schema or the service don't allow (e.g. + a file URL with a scheme that the service can't fetch) are shown at + their input. + +The workflow runs from the tool registry: its URL is the plain primary +descriptor in TRS. Conquest runs workflows from GitHub repositories only; +for services whose service info names them `Conquest`, Krini takes the +repository, the commit and the main file from the descriptor's source URL +in TRS, so only workflows with a GitHub source at a full commit run there. +File inputs may use the URI schemes that the service lists in its service +info (`supported_filesystem_protocols`). **Use the plain form** goes back +to the form without a schema; without a schema, Krini always uses that +form. + ## Privacy The privacy notice at `/privacy`, linked from the login page and the diff --git a/docs/user-guide/workflow-examples.md b/docs/user-guide/workflow-examples.md index f5b7758..fa7f20a 100644 --- a/docs/user-guide/workflow-examples.md +++ b/docs/user-guide/workflow-examples.md @@ -98,6 +98,27 @@ a workflow with one task, which greets the name it gets as its only input } ``` +## I/O Schema demo + +**Use the demo workflow** (under **Workflow from a tool registry**; see +[Workflows from I/O Schemas](index.md#workflows-from-io-schemas)) enters +the tool `ga4gh-io-schema-demo`, version `1.0.0`: the demo workflow of the +[GA4GH I/O Schema](https://github.com/elixir-cloud-aai/ga4gh-io-schema) +(`examples/demo/`, Apache-2.0), published with its schema in the tool +registry of ELIXIR On-Cloud (TRS-Filer). It is a WDL 1.1 workflow that +filters aligned reads (BAM) by mapping quality and flags, sorts and +indexes them, and reports statistics before and after filtering. Its only +required input is the BAM file, by an `https` or `s3` URL; the schema +proposes a small public test file (from nf-core's test data), which the +form shows as an example. + +It runs on WES services that run WDL 1.1 and can fetch the workflow, such +as Conquest: Krini takes the repository and the commit from the +descriptor's source URL in TRS (`raw.githubusercontent.com`, at a full +commit). Other tool registries need not have it; Krini offers the button +only with its built-in examples (a deployment with examples of its own +doesn't show it). + ## Federated learning **Federated learning**: the demo job `logreg-fedavg-4` of the NVFlare hub diff --git a/e2e/io-schema.spec.ts b/e2e/io-schema.spec.ts new file mode 100644 index 0000000..78e8a76 --- /dev/null +++ b/e2e/io-schema.spec.ts @@ -0,0 +1,137 @@ +/** + * @description Workflows from I/O Schemas (krini#47): a member loads a tool + * version with its GA4GH I/O Schema from a tool registry of the service + * registry, fills in the form generated from the schema, and Krini submits + * the run request that the Cloud Components build from the values and the + * TRS tool version. The mock tool registry serves the word count example + * of the GA4GH I/O Schema (`e2e/mock/word-count.schema.json`) + */ +import { resolve } from "node:path"; +import { accessToken, expect, login, test, wesRequests } from "./fixtures"; +import { mockHttpsPort } from "./settings"; + +const trsUrl = `https://127.0.0.1:${mockHttpsPort}/ga4gh/trs/v2`; +const text = "https://example.org/notes.txt"; + +test.describe("members", () => { + test.beforeEach(async ({ page }) => { + await login(page); + await page.goto("/dashboard/workflows/create"); + await page.getByRole("combobox").click(); + await page.getByRole("option", { name: /Mock WES/ }).click(); + await expect( + page.getByRole("heading", { + name: "Workflow from a tool registry", + }), + ).toBeVisible(); + // the tool registries of the service registry + await expect( + page.getByRole("combobox", { name: "Tool registry" }), + ).toHaveValue(trsUrl); + }); + + test("submit a workflow from its I/O Schema", async ({ page }) => { + const token = await accessToken(page); + await page + .getByRole("textbox", { name: "Tool ID" }) + .fill("io-schema-word-count"); + await page.getByRole("textbox", { name: "Version ID" }).fill("1.0.0"); + await page.getByRole("button", { name: "Load workflow" }).click(); + + // the form of the schema, instead of the raw fields + const file = page.getByRole("textbox", { name: /Text file/ }); + await expect(file).toBeVisible(); + await expect( + page.getByRole("textbox", { + name: "https://example.com/workflow.cwl", + }), + ).toHaveCount(0); + await file.fill(text); + await page.getByRole("button", { name: "Submit Run" }).click(); + + const submissions = async () => + (await wesRequests()).filter( + (val) => val.method === "POST" && val.path === "/runs", + ); + await expect.poll(submissions).toHaveLength(1); + const [submission] = await submissions(); + expect(submission).toMatchObject({ + authorization: `Bearer ${token}`, + fields: { + workflow_url: `${trsUrl}/tools/io-schema-word-count/versions/1.0.0/PLAIN_CWL/descriptor/wc.cwl`, + workflow_type: "CWL", + workflow_type_version: "v1.2", + }, + }); + expect(JSON.parse(submission.fields?.workflow_params ?? "")).toEqual({ + text: { class: "File", location: text }, + unit: "words", + }); + + // back to the plain form + await page.getByRole("button", { name: "Use the plain form" }).click(); + await expect( + page.getByRole("textbox", { + name: "https://example.com/workflow.cwl", + }), + ).toBeVisible(); + }); + + test("load an uploaded schema, with the tool and version it names", async ({ + page, + }) => { + // the deployment has examples of its own (`e2e/settings.ts`): no demo + await expect( + page.getByRole("button", { name: "Use the demo workflow" }), + ).toHaveCount(0); + await page.getByRole("radio", { name: "Upload" }).check(); + await page + .getByLabel("Schema file") + .setInputFiles(resolve(__dirname, "mock/word-count.schema.json")); + await page.getByRole("button", { name: "Load workflow" }).click(); + await expect( + page.getByRole("textbox", { name: /Text file/ }), + ).toBeVisible(); + }); + + test("see why a schema file can't be used", async ({ page }) => { + await page.getByRole("radio", { name: "Upload" }).check(); + await page.getByLabel("Schema file").setInputFiles({ + name: "schema.json", + mimeType: "application/json", + buffer: Buffer.from("{"), + }); + await page.getByRole("button", { name: "Load workflow" }).click(); + await expect( + page.getByRole("alert").filter({ hasText: /schema/ }), + ).toHaveText("The schema isn't JSON."); + }); + + test("see that a schema file is too large", async ({ page }) => { + await page.getByRole("radio", { name: "Upload" }).check(); + await page.getByLabel("Schema file").setInputFiles({ + name: "schema.json", + mimeType: "application/json", + buffer: Buffer.alloc(1024 * 1024 + 1, " "), + }); + await page.getByRole("button", { name: "Load workflow" }).click(); + await expect( + page.getByRole("alert").filter({ hasText: /schema/ }), + ).toHaveText("The schema is larger than 1 MiB."); + }); + + test("see why a tool version can't be loaded", async ({ page }) => { + await page.getByRole("textbox", { name: "Tool ID" }).fill("missing"); + await page.getByRole("textbox", { name: "Version ID" }).fill("1.0.0"); + await page.getByRole("button", { name: "Load workflow" }).click(); + await expect( + page.getByRole("alert").filter({ hasText: /tool/ }), + ).toHaveText("The tool version isn't in the tool registry."); + // the plain form stays + await expect( + page.getByRole("textbox", { + name: "https://example.com/workflow.cwl", + }), + ).toBeVisible(); + }); +}); diff --git a/e2e/mock/server.ts b/e2e/mock/server.ts index 6b2cce5..e621e89 100644 --- a/e2e/mock/server.ts +++ b/e2e/mock/server.ts @@ -8,8 +8,11 @@ * JWKS, so the provider signs real RS256 JWTs. Revoked refresh tokens * get 400 `invalid_grant`, as at a real provider; * - a service registry (`/ga4gh/registry/v1/services`); - * - a WES service (`/ga4gh/wes/v1/...`) and a TES service - * (`/ga4gh/tes/v1/...`) over `https` with a self-signed certificate, + * - a WES service (`/ga4gh/wes/v1/...`), a TES service + * (`/ga4gh/tes/v1/...`) and a tool registry (`/ga4gh/trs/v2/...`, read + * by the app's server: one CWL tool version with an I/O Schema, the + * word count example of the GA4GH I/O Schema, `word-count.schema.json`) + * over `https` with a self-signed certificate, * which the browser calls directly, as with real services, and which * allow the app's origin (CORS); * - `/mock/requests`, `/mock/tes-requests` and `/mock/reset` to inspect and @@ -93,6 +96,10 @@ const user = { const wesUrl = `https://127.0.0.1:${httpsPort}/ga4gh/wes/v1`; const tesUrl = `https://127.0.0.1:${httpsPort}/ga4gh/tes/v1`; +const trsUrl = `https://127.0.0.1:${httpsPort}/ga4gh/trs/v2`; +const wordCountSchema: unknown = JSON.parse( + readFileSync(join(import.meta.dirname, "word-count.schema.json"), "utf8"), +); /** Entries of the registry: the WES service, and entries the app drops */ const services = [ @@ -122,6 +129,12 @@ const services = [ type: { group: "org.ga4gh", artifact: "tes", version: "1.1.0" }, url: tesUrl, }, + { + id: "mock-trs", + name: "Mock TRS", + type: { group: "org.ga4gh", artifact: "trs", version: "2.0.1" }, + url: trsUrl, + }, { id: "plain-tes", name: "Plain TES", @@ -441,6 +454,53 @@ async function handleTes( return send(res, 404, { msg: "not found", status_code: 404 }, cors); } +/** The tool version of the tool registry: the word count example of the + * GA4GH I/O Schema, with its schema as a file of type `OTHER` */ +const trsVersion = "/tools/io-schema-word-count/versions/1.0.0"; + +/** The tool registry: read by the app's server, without a token */ +function handleTrs( + req: IncomingMessage, + res: ServerResponse, + path: string, + cors: Record, +) { + if (req.method !== "GET") + return send(res, 405, { msg: "not allowed" }, cors); + if (path === trsVersion) + return send( + res, + 200, + { + id: "1.0.0", + url: `${trsUrl}${trsVersion}`, + descriptor_type: ["CWL"], + descriptor_type_version: { CWL: ["v1.2"] }, + }, + cors, + ); + if (path === `${trsVersion}/CWL/files`) + return send( + res, + 200, + [ + { file_type: "PRIMARY_DESCRIPTOR", path: "wc.cwl" }, + { file_type: "OTHER", path: "ga4gh-io.schema.json" }, + ], + cors, + ); + if (path === `${trsVersion}/CWL/descriptor`) + return send(res, 200, { content: "cwlVersion: v1.2" }, cors); + if (path === `${trsVersion}/CWL/descriptor/ga4gh-io.schema.json`) + return send( + res, + 200, + { content: JSON.stringify(wordCountSchema) }, + cors, + ); + return send(res, 404, { title: "Not found", status: 404 }, cors); +} + /** WES and TES services */ async function handleHttps(req: IncomingMessage, res: ServerResponse) { const url = new URL(req.url ?? "/", wesUrl); @@ -452,6 +512,10 @@ async function handleHttps(req: IncomingMessage, res: ServerResponse) { }; if (req.method === "OPTIONS") return send(res, 204, undefined, cors); + const trsPrefix = new URL(trsUrl).pathname; + if (url.pathname.startsWith(trsPrefix)) + return handleTrs(req, res, url.pathname.slice(trsPrefix.length), cors); + const tesPrefix = new URL(tesUrl).pathname; if (url.pathname.startsWith(tesPrefix)) return handleTes(req, res, url.pathname.slice(tesPrefix.length), cors); diff --git a/e2e/mock/word-count.schema.json b/e2e/mock/word-count.schema.json new file mode 100644 index 0000000..034fd6b --- /dev/null +++ b/e2e/mock/word-count.schema.json @@ -0,0 +1,70 @@ +{ + "$schema": "https://raw.githubusercontent.com/elixir-cloud-aai/ga4gh-io-schema/main/schemas/ga4gh-io-profile.schema.json", + "title": "Count words", + "description": "Counts the lines, words or characters of a text file.", + "x-ga4gh-workflow": { + "trs_tool_id": "io-schema-word-count", + "trs_version_id": "1.0.0", + "descriptor_type": "CWL", + "descriptor_type_version": "v1.2", + "primary_descriptor_path": "wc.cwl", + "checksum": [ + { + "type": "sha-256", + "checksum": "75431e88e519962aa8a2b1109dce230685eba243300c615f1cf6db393d79034f" + } + ] + }, + "type": "object", + "properties": { + "inputs": { + "type": "object", + "properties": { + "text": { + "type": "string", + "title": "Text file", + "description": "A plain text file, by its URL.", + "x-ga4gh-file": { + "kind": "file", + "ontology": "http://edamontology.org/format_2330", + "schemes": ["https"] + }, + "x-ga4gh-parameter": { + "type": "File" + }, + "examples": [ + "https://raw.githubusercontent.com/elixir-cloud-aai/ga4gh-io-schema/main/README.md" + ] + }, + "unit": { + "type": "string", + "title": "What to count", + "enum": ["lines", "words", "characters"], + "default": "words", + "x-ga4gh-ui-widget": "dropdown" + } + }, + "required": ["text"], + "additionalProperties": false + }, + "outputs": { + "type": "object", + "properties": { + "count": { + "type": "string", + "title": "Count", + "description": "The count and the name of the file, as wc prints them.", + "x-ga4gh-file": { + "kind": "file", + "mediaType": "text/plain" + }, + "x-ga4gh-parameter": { + "type": "File" + } + } + }, + "required": ["count"], + "additionalProperties": false + } + } +} diff --git a/package.json b/package.json index 3ee59c9..cdde1cb 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "dependencies": { "@base-ui/react": "^1.9.0", "@elixir-cloud/tes": "^2.0.0-alpha.51", - "@elixir-cloud/wes": "^2.0.0-alpha.51", + "@elixir-cloud/wes": "file:./vendor/cloud-components/elixir-cloud-wes-2.0.0-alpha.51-io.f28c15c.tgz", "axios": "^1.20.0", "class-variance-authority": "^0.7.1", "cn": "^0.5.0", @@ -54,6 +54,7 @@ ], "overrides": { "body-parser": "^2.4.0", - "systeminformation": "^5.33.16" + "systeminformation": "^5.33.16", + "@elixir-cloud/design": "file:./vendor/cloud-components/elixir-cloud-design-2.0.0-alpha.51-io.f28c15c.tgz" } } diff --git a/src/app/api/workflows/get-trs-servers/route.test.ts b/src/app/api/workflows/get-trs-servers/route.test.ts new file mode 100644 index 0000000..82ba0fa --- /dev/null +++ b/src/app/api/workflows/get-trs-servers/route.test.ts @@ -0,0 +1,74 @@ +import { beforeEach, describe, expect, it, vi } from "vitest"; +import { http, registryUrl, setUp } from "@/test/routes"; + +/** + * Mock the registry and load the route + * @param services Services in the registry, or an error to throw + */ +async function load(services: unknown) { + const get = vi.spyOn(await http(), "get"); + get.mockImplementation(async (url) => { + expect(url).toBe(`${registryUrl}/services`); + if (services instanceof Error) throw services; + return { status: 200, data: services }; + }); + const { GET } = await import("./route"); + return GET; +} + +const service = ( + id: string, + url: unknown, + artifact = "trs", + name?: unknown, +) => ({ + id, + name, + url, + type: { group: "org.ga4gh", artifact, version: "2.0.1" }, +}); + +beforeEach(() => { + setUp(); +}); + +describe("GET /api/workflows/get-trs-servers", () => { + it("lists the TRS services over allowed URLs", async () => { + const GET = await load([ + service( + "trs", + "https://trs.example.org/ga4gh/trs/v2/", + "trs", + "Tools", + ), + service("plain", "http://plain.example.org/ga4gh/trs/v2"), + service("wes", "https://wes.example.org/ga4gh/wes/v1", "wes"), + service("unnamed", "https://other.example.org/ga4gh/trs/v2"), + { id: "no-type" }, + null, + ]); + const response = await GET(); + expect(response.status).toBe(200); + await expect(response.json()).resolves.toEqual([ + { + id: "trs", + name: "Tools", + url: "https://trs.example.org/ga4gh/trs/v2", + }, + { + id: "unnamed", + name: "", + url: "https://other.example.org/ga4gh/trs/v2", + }, + ]); + }); + + it("answers 502 when the registry fails", async () => { + const GET = await load(new Error("down")); + const response = await GET(); + expect(response.status).toBe(502); + await expect(response.json()).resolves.toEqual({ + error: "Unable to fetch the service registry.", + }); + }); +}); diff --git a/src/app/api/workflows/get-trs-servers/route.ts b/src/app/api/workflows/get-trs-servers/route.ts new file mode 100644 index 0000000..818c6d9 --- /dev/null +++ b/src/app/api/workflows/get-trs-servers/route.ts @@ -0,0 +1,17 @@ +/** + * The tool registries (TRS services) of the service registry, for the + * workflow form's choice of a tool registry + */ +import { NextResponse } from "next/server"; +import { trsServers } from "@/lib/trs-registry"; + +export async function GET() { + try { + return NextResponse.json(await trsServers()); + } catch { + return NextResponse.json( + { error: "Unable to fetch the service registry." }, + { status: 502 }, + ); + } +} diff --git a/src/app/api/workflows/trs-tool-version/route.test.ts b/src/app/api/workflows/trs-tool-version/route.test.ts new file mode 100644 index 0000000..dc877ce --- /dev/null +++ b/src/app/api/workflows/trs-tool-version/route.test.ts @@ -0,0 +1,162 @@ +import { beforeEach, describe, expect, it, vi } from "vitest"; +import { http, httpError, registryUrl, setUp } from "@/test/routes"; + +const trsUrl = "https://trs.example.org/ga4gh/trs/v2"; +const versionUrl = `${trsUrl}/tools/demo/versions/1.0.0`; +const trsService = { + id: "trs", + url: `${trsUrl}/`, + type: { group: "org.ga4gh", artifact: "trs", version: "2.0.1" }, +}; + +/** + * Mock the registry and a TRS API and load the route + * @param services Services in the registry, or an error to throw + */ +async function load(services: unknown = [trsService]) { + const get = vi.spyOn(await http(), "get"); + get.mockImplementation(async (url) => { + const replies: Record = { + [versionUrl]: { descriptor_type: ["WDL"] }, + [`${versionUrl}/WDL/files`]: [ + { file_type: "PRIMARY_DESCRIPTOR", path: "demo.wdl" }, + ], + [`${versionUrl}/WDL/descriptor`]: { content: "" }, + }; + if (url === `${registryUrl}/services`) { + if (services instanceof Error) throw services; + return { status: 200, data: services }; + } + if (url in replies) return { status: 200, data: replies[url] }; + throw httpError(404); + }); + const { GET } = await import("./route"); + return { GET, get }; +} + +const request = (params: Record) => + new Request( + `https://app.example.org/api/workflows/trs-tool-version?${new URLSearchParams(params)}`, + ); + +beforeEach(() => { + setUp(); +}); + +describe("GET /api/workflows/trs-tool-version", () => { + it("loads a tool version of a registered tool registry", async () => { + const { GET } = await load(); + const response = await GET( + request({ trs: trsUrl, tool: "demo", version: "1.0.0" }), + ); + expect(response.status).toBe(200); + expect(response.headers.get("cache-control")).toBe("no-store"); + await expect(response.json()).resolves.toEqual({ + descriptorType: "WDL", + schema: null, + trsToolVersion: { + trsUrl, + toolId: "demo", + versionId: "1.0.0", + primaryDescriptorPath: "demo.wdl", + descriptorTypeVersions: [], + }, + }); + }); + + it("leaves out the schema with schema=0", async () => { + const { GET, get } = await load(); + const response = await GET( + request({ + trs: trsUrl, + tool: "demo", + version: "1.0.0", + schema: "0", + }), + ); + expect(response.status).toBe(200); + await expect(response.json()).resolves.toMatchObject({ schema: null }); + expect(get.mock.calls.map(([url]) => url)).not.toContain( + `${versionUrl}/WDL/descriptor/ga4gh-io.schema.json`, + ); + }); + + it("passes the type on", async () => { + const { GET } = await load(); + const response = await GET( + request({ + trs: trsUrl, + tool: "demo", + version: "1.0.0", + type: "CWL", + }), + ); + expect(response.status).toBe(422); + await expect(response.json()).resolves.toEqual({ + error: "The tool version has no CWL workflow.", + }); + }); + + it.each([ + ["no tool registry", { tool: "demo", version: "1.0.0" }], + ["no tool", { trs: trsUrl, version: "1.0.0" }], + ["no version", { trs: trsUrl, tool: "demo" }], + ])("refuses requests with %s", async (_, params) => { + const { GET, get } = await load(); + const response = await GET(request(params)); + expect(response.status).toBe(400); + expect(get).not.toHaveBeenCalled(); + }); + + it.each([ + ["isn't in the registry", "https://other.example.org/ga4gh/trs/v2"], + ["isn't HTTPS", "http://trs.example.org/ga4gh/trs/v2"], + ])("refuses a tool registry that %s", async (_, trs) => { + const { GET, get } = await load([ + trsService, + // a TRS URL under another type doesn't count + { + ...trsService, + url: "https://other.example.org/ga4gh/trs/v2", + type: { artifact: "wes" }, + }, + null, + ]); + const response = await GET( + request({ trs, tool: "demo", version: "1.0.0" }), + ); + expect(response.status).toBe(400); + await expect(response.json()).resolves.toEqual({ + error: "The tool registry isn't in the service registry.", + }); + expect(get).toHaveBeenCalledTimes(1); + }); + + it("answers 502 when the service registry fails", async () => { + const { GET } = await load(new Error("down")); + const response = await GET( + request({ trs: trsUrl, tool: "demo", version: "1.0.0" }), + ); + expect(response.status).toBe(502); + await expect(response.json()).resolves.toEqual({ + error: "Unable to fetch the service registry.", + }); + }); + + it("rethrows unexpected errors", async () => { + vi.doMock("@/lib/trs", async (original) => ({ + ...(await original()), + loadTrsToolVersion: async () => { + throw new TypeError("bug"); + }, + })); + try { + const { GET } = await load(); + await expect( + GET(request({ trs: trsUrl, tool: "demo", version: "1.0.0" })), + ).rejects.toThrow("bug"); + } finally { + vi.doUnmock("@/lib/trs"); + } + }); +}); diff --git a/src/app/api/workflows/trs-tool-version/route.ts b/src/app/api/workflows/trs-tool-version/route.ts new file mode 100644 index 0000000..84c6f0c --- /dev/null +++ b/src/app/api/workflows/trs-tool-version/route.ts @@ -0,0 +1,59 @@ +/** + * A tool version of a tool registry, for the workflow form in schema mode + * (`GET ?trs=&tool=&version=[&type=] + * [&schema=0]`, the last without the schema): + * the descriptor type, the TRS tool version reference and the I/O Schema + * (see `src/lib/trs.ts`). Only tool registries of the service registry are + * read, so that the route can't be used to reach other hosts. + */ +import { NextResponse } from "next/server"; +import { RegistryError } from "@/lib/registry"; +import { loadTrsToolVersion, TrsError } from "@/lib/trs"; +import { trsServers } from "@/lib/trs-registry"; + +const headers = { "Cache-Control": "no-store" }; +const failure = (status: number, error: string) => + NextResponse.json({ error }, { status, headers }); + +export async function GET(request: Request) { + const params = new URL(request.url).searchParams; + const trs = params.get("trs"); + const toolId = params.get("tool"); + const versionId = params.get("version"); + const descriptorType = params.get("type") ?? undefined; + // `schema=0`: the user brings the schema (upload or URL) + const withSchema = params.get("schema") !== "0"; + if (!trs || toolId === null || versionId === null) { + return failure( + 400, + "Name the tool registry, the tool and the version.", + ); + } + + try { + const servers = await trsServers(); + const server = servers.find( + (candidate) => candidate.url === trs.replace(/\/+$/, ""), + ); + if (!server) { + return failure( + 400, + "The tool registry isn't in the service registry.", + ); + } + const result = await loadTrsToolVersion({ + trsUrl: server.url, + toolId, + versionId, + descriptorType, + withSchema, + }); + return NextResponse.json(result, { headers }); + } catch (error) { + if (error instanceof TrsError) + return failure(error.status, error.message); + if (error instanceof RegistryError) + return failure(502, "Unable to fetch the service registry."); + throw error; + } +} diff --git a/src/app/dashboard/workflows/_components/ecc-wes-create-run-wrapper.tsx b/src/app/dashboard/workflows/_components/ecc-wes-create-run-wrapper.tsx index 2a5e83c..e8a3799 100644 --- a/src/app/dashboard/workflows/_components/ecc-wes-create-run-wrapper.tsx +++ b/src/app/dashboard/workflows/_components/ecc-wes-create-run-wrapper.tsx @@ -1,12 +1,19 @@ "use client"; import dynamic from "next/dynamic"; -import { useRef } from "react"; +import { useRef, useState } from "react"; import { ExampleButtons } from "@/components/shared/example-buttons"; import { useWESProvider } from "@/hooks"; import { withSelfHostedAce } from "@/lib/ace-workers"; import { examplesForService, fillWorkflowForm } from "@/lib/example-forms"; import type { WorkflowExample } from "@/lib/examples"; +import { + allowedSchemesFor, + engineProfileFor, + type IoSchemaDemo, +} from "@/lib/io-schema"; +import type { SchemaRun } from "@/lib/schema-run"; import { useWESStore } from "@/stores/wes"; +import { IoSchemaSource } from "./io-schema-source"; const ECCClientGa4ghWesCreateRuns = dynamic( () => @@ -26,13 +33,21 @@ const ECCClientGa4ghWesCreateRuns = dynamic( type Props = { /** Examples that fill the form (`WORKFLOW_EXAMPLES`) */ examples?: WorkflowExample[]; + /** The demo of the I/O Schema panel (`ioSchemaDemo`), or none */ + ioSchemaDemo?: IoSchemaDemo | null; }; -export function ECCClientGa4ghWesCreateRunsClient({ examples = [] }: Props) { +export function ECCClientGa4ghWesCreateRunsClient({ + examples = [], + ioSchemaDemo = null, +}: Props) { const { wesProvider } = useWESProvider(); const selectedServer = useWESStore((state) => state.selectedServer); const servers = useWESStore((state) => state.servers); const container = useRef(null); + // schema mode: the I/O Schema and the TRS tool version to run (#47) + const [schemaRun, setSchemaRun] = useState(null); + const [schemaKey, setSchemaKey] = useState(0); if ( selectedServer === null || @@ -45,30 +60,60 @@ export function ECCClientGa4ghWesCreateRunsClient({ examples = [] }: Props) { ); + const serviceInfo = servers.find( + (server) => server.url === selectedServer, + )?.serviceInfo; // only the examples of the workflow types and versions that the // service runs const offered = examplesForService( examples, - servers.find((server) => server.url === selectedServer)?.serviceInfo - ?.workflow_type_versions, + serviceInfo?.workflow_type_versions, ); return (
- - fillWorkflowForm( - container.current?.querySelector( - "ecc-client-ga4gh-wes-run-create", - ) ?? null, - example.run, - ) - } + { + setSchemaRun(run); + // a new form for each loaded schema + setSchemaKey((key) => key + 1); + }} + onClear={() => setSchemaRun(null)} /> + {schemaRun === null && ( + + fillWorkflowForm( + container.current?.querySelector( + "ecc-client-ga4gh-wes-run-create", + ) ?? null, + example.run, + ) + } + /> + )}
- + {schemaRun === null ? ( + + ) : ( + + )}
); diff --git a/src/app/dashboard/workflows/_components/io-schema-source.tsx b/src/app/dashboard/workflows/_components/io-schema-source.tsx new file mode 100644 index 0000000..4e2c3ea --- /dev/null +++ b/src/app/dashboard/workflows/_components/io-schema-source.tsx @@ -0,0 +1,234 @@ +"use client"; +import { FileJson, LoaderCircle } from "lucide-react"; +import { useEffect, useId, useState } from "react"; +import { Button } from "@/components/ui/button"; +import { Input } from "@/components/ui/input"; +import { type IoSchemaDemo, MAX_SCHEMA_BYTES } from "@/lib/io-schema"; +import { + loadSchemaRun, + type SchemaRun, + type SchemaSource, +} from "@/lib/schema-run"; +import type { TrsServer } from "@/lib/trs-registry"; + +type Props = { + /** Whether the form is in schema mode */ + active: boolean; + /** Switch the form to schema mode with the loaded schema */ + onLoad: (run: SchemaRun) => void; + /** Switch the form back to the plain WES form */ + onClear: () => void; + /** The demo workflow to offer, or none */ + demo: IoSchemaDemo | null; +}; + +type SourceKind = SchemaSource["kind"]; + +const SOURCES: { kind: SourceKind; label: string }[] = [ + { kind: "trs", label: "From the tool registry" }, + { kind: "upload", label: "Upload" }, + { kind: "url", label: "URL" }, +]; + +/** + * The panel "Workflow from a tool registry": a tool registry of the + * service registry, a tool version and where its I/O Schema comes from. + * Loading it switches the workflow form to schema mode; without it, the + * plain WES form is used + */ +export function IoSchemaSource({ active, onLoad, onClear, demo }: Props) { + const id = useId(); + const [servers, setServers] = useState(null); + const [trsUrl, setTrsUrl] = useState(""); + const [toolId, setToolId] = useState(""); + const [versionId, setVersionId] = useState(""); + const [kind, setKind] = useState("trs"); + const [file, setFile] = useState(null); + const [url, setUrl] = useState(""); + const [loading, setLoading] = useState(false); + const [error, setError] = useState(null); + + useEffect(() => { + let cancelled = false; + fetch("/api/workflows/get-trs-servers") + .then((res) => (res.ok ? res.json() : [])) + .catch(() => []) + .then((data: unknown) => { + if (cancelled) return; + const list = Array.isArray(data) ? (data as TrsServer[]) : []; + setServers(list); + if (list.length > 0) setTrsUrl((value) => value || list[0].url); + }); + return () => { + cancelled = true; + }; + }, []); + + const load = async () => { + setLoading(true); + setError(null); + try { + let source: SchemaSource; + if (kind === "upload") { + if (!file) throw new Error("Choose a schema file."); + // don't read a huge file into the tab + if (file.size > MAX_SCHEMA_BYTES) + throw new Error("The schema is larger than 1 MiB."); + source = { kind, text: await file.text() }; + } else if (kind === "url") { + source = { kind, url }; + } else { + source = { kind }; + } + onLoad(await loadSchemaRun({ trsUrl, toolId, versionId, source })); + } catch (err) { + setError(err instanceof Error ? err.message : String(err)); + } finally { + setLoading(false); + } + }; + + if (servers !== null && servers.length === 0 && !active) return null; + + return ( +
+
+ +
+

+ Workflow from a tool registry +

+

+ Load a workflow with its GA4GH I/O Schema to fill in its + inputs in a form; Krini builds the run request. Without + a schema, use the form below as it is. +

+
+
+
+
+ + +
+
+ + setToolId(e.target.value)} + placeholder={kind === "trs" ? "" : "as in the schema"} + /> +
+
+ + setVersionId(e.target.value)} + placeholder={kind === "trs" ? "" : "as in the schema"} + /> +
+
+
+ I/O Schema + I/O Schema: + {SOURCES.map((source) => ( + + ))} +
+ {kind === "upload" && ( + setFile(e.target.files?.[0] ?? null)} + /> + )} + {kind === "url" && ( + setUrl(e.target.value)} + /> + )} +
+ + {demo && ( + + )} + {active && ( + + )} +
+ {error && ( +

+ {error} +

+ )} +
+ ); +} diff --git a/src/app/dashboard/workflows/create/page.tsx b/src/app/dashboard/workflows/create/page.tsx index cb4e428..27d99b2 100644 --- a/src/app/dashboard/workflows/create/page.tsx +++ b/src/app/dashboard/workflows/create/page.tsx @@ -4,6 +4,7 @@ import { connection } from "next/server"; import { ComputeGate } from "@/components/shared/compute-gate"; import { Button } from "@/components/ui/button"; import { workflowExamples } from "@/lib/examples"; +import { ioSchemaDemo } from "@/lib/io-schema"; import { ECCClientGa4ghWesCreateRunsClient, WESServerList, @@ -14,6 +15,7 @@ import { WorkflowValidator } from "../_components/workflow-validator"; async function Page() { await connection(); const { examples } = workflowExamples(); + const demo = ioSchemaDemo(); return (
@@ -56,6 +58,7 @@ async function Page() {
diff --git a/src/lib/io-schema.test.ts b/src/lib/io-schema.test.ts new file mode 100644 index 0000000..2cf2bc7 --- /dev/null +++ b/src/lib/io-schema.test.ts @@ -0,0 +1,165 @@ +import { conquestEngineProfile } from "@elixir-cloud/wes/utils"; +import { describe, expect, it, vi } from "vitest"; +import { + allowedSchemesFor, + engineProfileFor, + IO_SCHEMA_DEMO, + ioSchemaDemo, + MAX_SCHEMA_BYTES, + parseSchemaText, + SchemaSourceError, + schemaUrl, + schemaWorkflow, +} from "./io-schema"; + +describe("parseSchemaText", () => { + it("returns the JSON object", () => { + expect(parseSchemaText('{"type": "object"}')).toEqual({ + type: "object", + }); + }); + + it.each([ + ["not JSON", "{", "isn't JSON"], + ["an array", "[]", "isn't a JSON object"], + ["null", "null", "isn't a JSON object"], + ["a string", '"schema"', "isn't a JSON object"], + ])("refuses %s", (_, text, message) => { + expect(() => parseSchemaText(text)).toThrow(SchemaSourceError); + expect(() => parseSchemaText(text)).toThrow(message); + }); + + it("refuses schemas over the size limit", () => { + const text = `{"description": "${"x".repeat(MAX_SCHEMA_BYTES)}"}`; + expect(() => parseSchemaText(text)).toThrow("larger than 1 MiB"); + }); + + it("counts bytes, not characters", () => { + // 3 bytes per character in UTF-8 + const text = `{"d": "${"€".repeat(MAX_SCHEMA_BYTES / 3)}"}`; + expect(() => parseSchemaText(text)).toThrow("larger than 1 MiB"); + }); +}); + +describe("schemaWorkflow", () => { + it("reads the TRS tool version and type of x-ga4gh-workflow", () => { + expect( + schemaWorkflow({ + "x-ga4gh-workflow": { + trs_tool_id: "demo", + trs_version_id: "1.0.0", + descriptor_type: "WDL", + }, + }), + ).toEqual({ + toolId: "demo", + versionId: "1.0.0", + descriptorType: "WDL", + }); + }); + + it.each([ + ["no block", {}], + ["a block that isn't an object", { "x-ga4gh-workflow": [] }], + [ + "values that aren't strings", + { + "x-ga4gh-workflow": { + trs_tool_id: 1, + trs_version_id: null, + descriptor_type: {}, + }, + }, + ], + ["a schema that isn't an object", "schema"], + ])("leaves out what isn't there (%s)", (_, schema) => { + expect(schemaWorkflow(schema)).toEqual({}); + }); +}); + +describe("schemaUrl", () => { + it("accepts HTTPS URLs", () => { + expect(schemaUrl(" https://example.org/schema.json ")).toBe( + "https://example.org/schema.json", + ); + }); + + it.each([ + "", + "not a URL", + "http://example.org/schema.json", + "file:///etc/passwd", + "https://user:secret@example.org/schema.json", + ])("refuses %j", (value) => { + expect(schemaUrl(value)).toBeNull(); + }); +}); + +describe("engineProfileFor", () => { + it("uses the Conquest profile for Conquest", () => { + expect(engineProfileFor({ name: "Conquest" })).toBe( + conquestEngineProfile, + ); + expect(engineProfileFor({ name: " conquest " })).toBe( + conquestEngineProfile, + ); + }); + + it.each([ + ["another service", { name: "WESkit" }], + ["no name", {}], + ["no service info", null], + ["a name that isn't a string", { name: 1 }], + ])("uses none for %s", (_, info) => { + expect(engineProfileFor(info)).toBeNull(); + }); +}); + +describe("allowedSchemesFor", () => { + it("allows the protocols that the service lists", () => { + expect( + allowedSchemesFor({ + supported_filesystem_protocols: ["S3", "https", 1, "s3"], + }), + ).toEqual(["s3", "https"]); + }); + + it.each([ + ["no list", {}], + ["an empty list", { supported_filesystem_protocols: [] }], + ["no service info", null], + ["a list without strings", { supported_filesystem_protocols: [1] }], + ])("keeps the component's default for %s", (_, info) => { + expect(allowedSchemesFor(info)).toBeUndefined(); + }); +}); + +describe("IO_SCHEMA_DEMO", () => { + it("names a TRS tool version", () => { + expect(IO_SCHEMA_DEMO).toMatchObject({ + toolId: "ga4gh-io-schema-demo", + versionId: "1.0.0", + }); + }); +}); + +describe("ioSchemaDemo", () => { + it("offers the demo with the built-in examples", () => { + expect(ioSchemaDemo({})).toEqual(IO_SCHEMA_DEMO); + }); + + it.each([ + ["[]"], + ['[{"name":"x"}]'], + [""], + ])("offers none with the deployment's examples (%j)", (value) => { + expect(ioSchemaDemo({ WORKFLOW_EXAMPLES: value })).toBeNull(); + }); + + it("reads the environment by default", () => { + vi.stubEnv("WORKFLOW_EXAMPLES", undefined); + expect(ioSchemaDemo()).toEqual(IO_SCHEMA_DEMO); + vi.stubEnv("WORKFLOW_EXAMPLES", "[]"); + expect(ioSchemaDemo()).toBeNull(); + }); +}); diff --git a/src/lib/io-schema.ts b/src/lib/io-schema.ts new file mode 100644 index 0000000..68a598c --- /dev/null +++ b/src/lib/io-schema.ts @@ -0,0 +1,169 @@ +/** + * Workflow forms from GA4GH I/O Schemas: what the workflow form needs + * besides the Cloud Components + * + * The form (`ecc-client-ga4gh-wes-run-create` in schema mode) renders the + * inputs of an I/O Schema and builds the run request from the values and + * the TRS tool version. Krini gets the schema from the tool registry (see + * `src/lib/trs.ts`), or the user uploads it or gives its URL; it then + * picks the engine profile and the allowed URI schemes of file inputs for + * the selected WES service. See "Workflows from I/O Schemas" in + * `docs/user-guide/index.md`. + */ +import { + conquestEngineProfile, + type EngineProfile, +} from "@elixir-cloud/wes/utils"; + +/** Largest schema that Krini accepts, in bytes of UTF-8 */ +export const MAX_SCHEMA_BYTES = 1024 * 1024; + +/** A schema that Krini can't use, with a message for the user */ +export class SchemaSourceError extends Error {} + +const record = (value: unknown): Record => + value !== null && typeof value === "object" && !Array.isArray(value) + ? (value as Record) + : {}; + +/** + * Parse the text of an I/O Schema (an upload, or the answer of its URL) + * + * Only the JSON is checked here; the form checks the schema against the + * profile and shows what is wrong. + * @param text The schema as text + * @returns The schema + * @throws SchemaSourceError If the text is larger than `MAX_SCHEMA_BYTES`, + * isn't JSON or isn't a JSON object + */ +export function parseSchemaText(text: string): Record { + if (new TextEncoder().encode(text).length > MAX_SCHEMA_BYTES) { + throw new SchemaSourceError("The schema is larger than 1 MiB."); + } + let schema: unknown; + try { + schema = JSON.parse(text); + } catch { + throw new SchemaSourceError("The schema isn't JSON."); + } + if (schema === null || typeof schema !== "object" || Array.isArray(schema)) + throw new SchemaSourceError("The schema isn't a JSON object."); + return schema as Record; +} + +/** The workflow that a schema names in `x-ga4gh-workflow` */ +export type SchemaWorkflow = { + toolId?: string; + versionId?: string; + descriptorType?: string; +}; + +/** + * Read the TRS tool version and the descriptor type that a schema names, + * to prefill the tool registry fields for an uploaded schema + * @param schema The schema + * @returns What the schema names; entries that aren't strings are left out + */ +export function schemaWorkflow(schema: unknown): SchemaWorkflow { + const block = record(record(schema)["x-ga4gh-workflow"]); + const result: SchemaWorkflow = {}; + if (typeof block.trs_tool_id === "string") + result.toolId = block.trs_tool_id; + if (typeof block.trs_version_id === "string") + result.versionId = block.trs_version_id; + if (typeof block.descriptor_type === "string") + result.descriptorType = block.descriptor_type; + return result; +} + +/** + * Check the URL of a schema, which the browser fetches + * @param value The URL as the user typed it + * @returns The URL, if it is an HTTPS URL without credentials; else `null` + */ +export function schemaUrl(value: string): string | null { + let url: URL; + try { + url = new URL(value.trim()); + } catch { + return null; + } + if (url.protocol !== "https:" || url.username || url.password) return null; + return url.href; +} + +/** + * Pick the engine profile of a WES service: what the service needs in a + * run request beyond the engine bindings of the profile + * + * Conquest runs workflows from GitHub repositories at a commit, not from + * TRS, so its profile turns the TRS descriptor URL into the repository, + * the commit and the path of the main file. It is recognised by the name + * in its service info, which ELIXIR On-Cloud's service-info naming sets to + * the implementation (`Conquest`). + * @param serviceInfo Service info of the WES service + * @returns The profile, or `null` for services that take the generic request + */ +export function engineProfileFor(serviceInfo: unknown): EngineProfile | null { + const { name } = record(serviceInfo); + return typeof name === "string" && name.trim().toLowerCase() === "conquest" + ? conquestEngineProfile + : null; +} + +/** + * Pick the URI schemes that file inputs may have: those that the WES + * service stages (`supported_filesystem_protocols` of its service info) + * @param serviceInfo Service info of the WES service + * @returns The schemes, lower case and without duplicates; `undefined` (the + * form's default) if the service lists none + */ +export function allowedSchemesFor(serviceInfo: unknown): string[] | undefined { + const { supported_filesystem_protocols: protocols } = record(serviceInfo); + if (!Array.isArray(protocols)) return undefined; + const schemes = [ + ...new Set( + protocols + .filter((item): item is string => typeof item === "string") + .map((item) => item.toLowerCase()), + ), + ]; + return schemes.length > 0 ? schemes : undefined; +} + +/** + * The demo workflow of the GA4GH I/O Schema (`examples/demo/` of + * elixir-cloud-aai/ga4gh-io-schema), which "Use the demo workflow" puts + * into the tool registry fields: a WDL 1.1 workflow that filters, sorts + * and indexes aligned reads, published with its schema in ELIXIR + * On-Cloud's tool registry (TRS-Filer) and runnable on Conquest, whose + * profile takes its GitHub source from the TRS descriptor URL. Like the + * built-in examples of the forms (`src/lib/examples.ts`), it is offered + * only while the deployment has no examples of its own (see `ioSchemaDemo`) + */ +export const IO_SCHEMA_DEMO = { + toolId: "ga4gh-io-schema-demo", + versionId: "1.0.0", + description: + "I/O Schema demo (WDL 1.1): filters aligned reads by mapping quality, sorts and indexes them, and reports statistics", +} as const; + +/** The demo workflow that the panel offers */ +export type IoSchemaDemo = { + toolId: string; + versionId: string; + description: string; +}; + +/** + * The demo workflow to offer: `IO_SCHEMA_DEMO` with the built-in examples + * (`WORKFLOW_EXAMPLES` unset), none when the deployment sets its own + * examples, as the demo runs on the services of ELIXIR On-Cloud only + * @param env The environment, read on the server + * @returns The demo, or `null` + */ +export function ioSchemaDemo( + env: Record = process.env, +): IoSchemaDemo | null { + return env.WORKFLOW_EXAMPLES === undefined ? { ...IO_SCHEMA_DEMO } : null; +} diff --git a/src/lib/schema-run.test.ts b/src/lib/schema-run.test.ts new file mode 100644 index 0000000..5f193a2 --- /dev/null +++ b/src/lib/schema-run.test.ts @@ -0,0 +1,178 @@ +import { describe, expect, it, vi } from "vitest"; +import { loadSchemaRun } from "./schema-run"; + +const trsUrl = "https://trs.example.org/ga4gh/trs/v2"; +const trsSchema = { title: "from TRS" }; +const result = (schema: unknown = trsSchema) => ({ + descriptorType: "WDL", + schema, + trsToolVersion: { + trsUrl, + toolId: "demo", + versionId: "1.0.0", + primaryDescriptorPath: "demo.wdl", + descriptorTypeVersions: ["1.1"], + }, +}); +const json = (body: unknown, status = 200) => + new Response(JSON.stringify(body), { status }); + +/** + * A fetch that answers Krini's route and the schema URL + * @param route Answer of the route + * @param schemaUrl Answer of the schema URL (an error: a network error) + */ +function fetcher(route: Response | Error, schemaUrl?: Response | Error) { + return vi.fn(async (url: string | URL | Request) => { + const reply = String(url).startsWith("/api/") ? route : schemaUrl; + if (reply instanceof Error) throw reply; + return reply as Response; + }) as unknown as typeof fetch & ReturnType; +} + +const request = (source: Parameters[0]["source"]) => ({ + trsUrl, + toolId: "demo", + versionId: "1.0.0", + source, +}); + +describe("loadSchemaRun", () => { + it("takes the schema of the tool registry", async () => { + const fetch = fetcher(json(result())); + await expect( + loadSchemaRun(request({ kind: "trs" }), fetch), + ).resolves.toEqual(result()); + expect(fetch).toHaveBeenCalledWith( + `/api/workflows/trs-tool-version?${new URLSearchParams({ + trs: trsUrl, + tool: "demo", + version: "1.0.0", + })}`, + ); + }); + + it("prefers an uploaded schema and takes tool, version and type from it", async () => { + const uploaded = { + title: "uploaded", + "x-ga4gh-workflow": { + trs_tool_id: "named", + trs_version_id: "2.0.0", + descriptor_type: "WDL", + }, + }; + const fetch = fetcher(json(result(null))); + const run = await loadSchemaRun( + { + trsUrl, + toolId: " ", + versionId: "", + source: { kind: "upload", text: JSON.stringify(uploaded) }, + }, + fetch, + ); + expect(run.schema).toEqual(uploaded); + expect(fetch).toHaveBeenCalledWith( + `/api/workflows/trs-tool-version?${new URLSearchParams({ + trs: trsUrl, + tool: "named", + version: "2.0.0", + type: "WDL", + schema: "0", + })}`, + ); + }); + + it("fetches a schema by URL, without credentials", async () => { + const fetch = fetcher(json(result()), json({ title: "by URL" })); + const run = await loadSchemaRun( + request({ kind: "url", url: "https://example.org/s.json" }), + fetch, + ); + expect(run.schema).toEqual({ title: "by URL" }); + expect(fetch).toHaveBeenCalledWith("https://example.org/s.json", { + credentials: "omit", + headers: { Accept: "application/json" }, + }); + }); + + it.each([ + [ + "a schema URL that isn't HTTPS", + request({ kind: "url", url: "http://example.org/s.json" }), + fetcher(json(result())), + "must be an HTTPS URL", + ], + [ + "an unreachable schema URL", + request({ kind: "url", url: "https://example.org/s.json" }), + fetcher(json(result()), new TypeError("CORS")), + "cross-origin", + ], + [ + "a schema URL that fails", + request({ kind: "url", url: "https://example.org/s.json" }), + fetcher(json(result()), new Response("", { status: 404 })), + "HTTP 404", + ], + [ + "an upload that isn't JSON", + request({ kind: "upload", text: "{" }), + fetcher(json(result())), + "isn't JSON", + ], + [ + "no tool registry", + { ...request({ kind: "trs" }), trsUrl: "" }, + fetcher(json(result())), + "Choose a tool registry", + ], + [ + "no tool", + { ...request({ kind: "trs" }), toolId: "" }, + fetcher(json(result())), + "Name the tool", + ], + [ + "no version", + { ...request({ kind: "upload", text: "{}" }), versionId: "" }, + fetcher(json(result())), + "Name the tool", + ], + [ + "an unreachable server", + request({ kind: "trs" }), + fetcher(new TypeError("offline")), + "Unable to reach Krini's server", + ], + [ + "an error of the route", + request({ kind: "trs" }), + fetcher(json({ error: "The tool version isn't there." }, 404)), + "The tool version isn't there.", + ], + [ + "an error of the route without a message", + request({ kind: "trs" }), + fetcher(new Response("oops", { status: 500 })), + "HTTP 500", + ], + [ + "a tool version without a schema", + request({ kind: "trs" }), + fetcher(json(result(null))), + "has no I/O Schema", + ], + ])("fails with %s", async (_, choice, fetch, message) => { + await expect(loadSchemaRun(choice, fetch)).rejects.toThrow(message); + }); + + it("uses the global fetch by default", async () => { + const stub = vi.fn(async () => json(result())); + vi.stubGlobal("fetch", stub); + await expect(loadSchemaRun(request({ kind: "trs" }))).resolves.toEqual( + result(), + ); + expect(stub).toHaveBeenCalledOnce(); + }); +}); diff --git a/src/lib/schema-run.ts b/src/lib/schema-run.ts new file mode 100644 index 0000000..09dc24a --- /dev/null +++ b/src/lib/schema-run.ts @@ -0,0 +1,116 @@ +/** + * What the workflow form needs for schema mode, from the user's choice in + * the "Workflow from a tool registry" panel: the I/O Schema and the TRS + * tool version to run + * + * The tool version always comes from a tool registry of the service + * registry (the route `/api/workflows/trs-tool-version`), as the run + * request names the workflow by its TRS URL. The schema comes with it, or + * the user uploads it or gives its URL (fetched by the browser, without + * credentials); tool and version default to those that the schema names. + */ +import { + parseSchemaText, + SchemaSourceError, + schemaUrl, + schemaWorkflow, +} from "@/lib/io-schema"; +import type { TrsToolVersionResult } from "@/lib/trs"; + +/** Where the schema comes from */ +export type SchemaSource = + | { kind: "trs" } + | { kind: "upload"; text: string } + | { kind: "url"; url: string }; + +export type SchemaRunRequest = { + /** URL of the tool registry, from `/api/workflows/get-trs-servers` */ + trsUrl: string; + /** Tool and version; empty: those that the schema names */ + toolId: string; + versionId: string; + source: SchemaSource; +}; + +/** The schema and the tool version, for `ecc-client-ga4gh-wes-run-create` */ +export type SchemaRun = TrsToolVersionResult & { + schema: Record; +}; + +type Fetch = typeof fetch; + +async function schemaText(source: SchemaSource, fetcher: Fetch) { + if (source.kind === "upload") return source.text; + if (source.kind === "trs") return null; + const url = schemaUrl(source.url); + if (url === null) + throw new SchemaSourceError("The schema URL must be an HTTPS URL."); + let response: Response; + try { + response = await fetcher(url, { + credentials: "omit", + headers: { Accept: "application/json" }, + }); + } catch { + throw new SchemaSourceError( + "Unable to fetch the schema (it must allow cross-origin requests).", + ); + } + if (!response.ok) + throw new SchemaSourceError( + `Unable to fetch the schema (HTTP ${response.status}).`, + ); + return response.text(); +} + +/** + * Get the schema and the tool version for schema mode + * @param request The user's choice + * @param fetcher `fetch`, replaceable in tests + * @returns The schema and the tool version + * @throws SchemaSourceError With a message for the user + */ +export async function loadSchemaRun( + request: SchemaRunRequest, + fetcher: Fetch = fetch, +): Promise { + const text = await schemaText(request.source, fetcher); + const ownSchema = text === null ? null : parseSchemaText(text); + const named = schemaWorkflow(ownSchema); + const toolId = request.toolId.trim() || named.toolId || ""; + const versionId = request.versionId.trim() || named.versionId || ""; + if (!request.trsUrl) throw new SchemaSourceError("Choose a tool registry."); + if (!toolId || !versionId) + throw new SchemaSourceError("Name the tool and its version."); + + const params = new URLSearchParams({ + trs: request.trsUrl, + tool: toolId, + version: versionId, + }); + if (named.descriptorType) params.set("type", named.descriptorType); + // the tool registry's schema isn't needed (nor read) then + if (ownSchema !== null) params.set("schema", "0"); + let response: Response; + try { + response = await fetcher(`/api/workflows/trs-tool-version?${params}`); + } catch { + throw new SchemaSourceError("Unable to reach Krini's server."); + } + const body: unknown = await response.json().catch(() => null); + if (!response.ok) { + const error = (body as { error?: unknown } | null)?.error; + throw new SchemaSourceError( + typeof error === "string" + ? error + : `Unable to load the tool version (HTTP ${response.status}).`, + ); + } + const result = body as TrsToolVersionResult; + const schema = ownSchema ?? result.schema; + if (schema === null) + throw new SchemaSourceError( + "The tool version has no I/O Schema: upload it, give its URL or use the plain form.", + ); + return { ...result, schema }; +} diff --git a/src/lib/trs-registry.ts b/src/lib/trs-registry.ts new file mode 100644 index 0000000..86dd5a7 --- /dev/null +++ b/src/lib/trs-registry.ts @@ -0,0 +1,35 @@ +/** + * The tool registries (GA4GH TRS services) of the service registry, which + * Krini's server may read tool versions from + */ +import { + allowedServiceUrl, + fetchRegistryServices, + type RegistryService, +} from "@/lib/registry"; + +/** A tool registry, as the workflow form lists it */ +export type TrsServer = { id: string; name: string; url: string }; + +const text = (value: unknown) => (typeof value === "string" ? value : ""); + +/** + * List the TRS services of the service registry over an allowed URL + * (`allowedServiceUrl`) + * @returns The services, in registry order + * @throws RegistryError If the service registry can't be read + */ +export async function trsServers(): Promise { + const services = await fetchRegistryServices(); + return services + .filter( + (service: RegistryService | null) => + service?.type?.artifact === "trs", + ) + .map((service) => ({ + id: text(service.id), + name: text(service.name), + url: allowedServiceUrl(service.url), + })) + .filter((server): server is TrsServer => server.url !== null); +} diff --git a/src/lib/trs.test.ts b/src/lib/trs.test.ts new file mode 100644 index 0000000..487c471 --- /dev/null +++ b/src/lib/trs.test.ts @@ -0,0 +1,308 @@ +import { beforeEach, describe, expect, it, vi } from "vitest"; +import { http, httpError, networkError, setUp } from "@/test/routes"; + +const trsUrl = "https://trs.example.org/ga4gh/trs/v2"; +const versionUrl = `${trsUrl}/tools/demo/versions/1.0.0`; +const schema = { + type: "object", + "x-ga4gh-workflow": { descriptor_type: "WDL" }, +}; +const descriptorUrl = + "https://raw.githubusercontent.com/org/repo/0123456789abcdef0123456789abcdef01234567/demo.wdl"; + +type Reply = unknown | Error; + +/** + * Mock the TRS API and load the module + * @param replies Replies by URL (default: a WDL tool version with a schema) + */ +async function load(replies: Record = {}) { + const defaults: Record = { + [versionUrl]: { + id: "1.0.0", + descriptor_type: ["WDL"], + descriptor_type_version: { WDL: ["1.1"] }, + }, + [`${versionUrl}/WDL/files`]: [ + { file_type: "PRIMARY_DESCRIPTOR", path: "demo.wdl" }, + { file_type: "OTHER", path: "ga4gh-io.schema.json" }, + ], + [`${versionUrl}/WDL/descriptor`]: { + content: "version 1.1", + url: descriptorUrl, + }, + [`${versionUrl}/WDL/descriptor/ga4gh-io.schema.json`]: { + content: JSON.stringify(schema), + }, + }; + const all = { ...defaults, ...replies }; + const get = vi.spyOn(await http(), "get"); + get.mockImplementation(async (url) => { + if (!(url in all)) throw httpError(404); + const reply = all[url]; + if (reply instanceof Error) throw reply; + return { status: 200, data: reply }; + }); + const trs = await import("./trs"); + return { ...trs, get }; +} + +beforeEach(() => { + setUp(); +}); + +describe("loadTrsToolVersion", () => { + it("loads the tool version, its schema and its descriptor URL", async () => { + const { loadTrsToolVersion, get } = await load(); + await expect( + loadTrsToolVersion({ trsUrl, toolId: "demo", versionId: "1.0.0" }), + ).resolves.toEqual({ + descriptorType: "WDL", + schema, + trsToolVersion: { + trsUrl, + toolId: "demo", + versionId: "1.0.0", + primaryDescriptorPath: "demo.wdl", + descriptorTypeVersions: ["1.1"], + primaryDescriptorUrl: descriptorUrl, + }, + }); + // no redirects, a size limit and a timeout on every call + for (const call of get.mock.calls) { + expect(call[1]).toMatchObject({ + maxRedirects: 0, + maxContentLength: expect.any(Number), + timeout: expect.any(Number), + }); + } + }); + + it("percent-encodes the ids, the type and the schema path", async () => { + const base = `${trsUrl}/tools/a%2Fb/versions/v%201`; + const { loadTrsToolVersion } = await load({ + [base]: { descriptor_type: ["SMK"] }, + [`${base}/SMK/files`]: [ + { file_type: "PRIMARY_DESCRIPTOR", path: "wf dir/Snakefile" }, + { file_type: "IO_SCHEMA", path: "wf dir/io schema.json" }, + ], + [`${base}/SMK/descriptor`]: { content: "" }, + [`${base}/SMK/descriptor/wf%20dir/io%20schema.json`]: { + content: "{}", + }, + }); + await expect( + loadTrsToolVersion({ trsUrl, toolId: "a/b", versionId: "v 1" }), + ).resolves.toEqual({ + descriptorType: "SMK", + schema: {}, + trsToolVersion: { + trsUrl, + toolId: "a/b", + versionId: "v 1", + primaryDescriptorPath: "wf dir/Snakefile", + descriptorTypeVersions: [], + primaryDescriptorUrl: undefined, + }, + }); + }); + + it("returns no schema when the tool version has none", async () => { + const { loadTrsToolVersion } = await load({ + [`${versionUrl}/WDL/files`]: [ + { file_type: "PRIMARY_DESCRIPTOR", path: "demo.wdl" }, + ], + }); + const result = await loadTrsToolVersion({ + trsUrl, + toolId: "demo", + versionId: "1.0.0", + }); + expect(result.schema).toBeNull(); + expect(result.trsToolVersion.primaryDescriptorPath).toBe("demo.wdl"); + }); + + it("ignores a schema file whose path leaves the tool version", async () => { + const { loadTrsToolVersion, get } = await load({ + [`${versionUrl}/WDL/files`]: [ + { file_type: "PRIMARY_DESCRIPTOR", path: "demo.wdl" }, + { file_type: "IO_SCHEMA", path: "../../x.json" }, + ], + }); + const result = await loadTrsToolVersion({ + trsUrl, + toolId: "demo", + versionId: "1.0.0", + }); + expect(result.schema).toBeNull(); + expect(get).toHaveBeenCalledTimes(3); + }); + + it("doesn't read the schema when the caller brings one", async () => { + const { loadTrsToolVersion, get } = await load({ + // a broken schema in the registry doesn't matter then + [`${versionUrl}/WDL/descriptor/ga4gh-io.schema.json`]: { + content: "{", + }, + }); + const result = await loadTrsToolVersion({ + trsUrl, + toolId: "demo", + versionId: "1.0.0", + withSchema: false, + }); + expect(result.schema).toBeNull(); + expect(get).toHaveBeenCalledTimes(3); + }); + + it("takes the type that the caller names", async () => { + const { loadTrsToolVersion } = await load({ + [versionUrl]: { + descriptor_type: ["CWL", "WDL"], + descriptor_type_version: "not an object", + }, + }); + const result = await loadTrsToolVersion({ + trsUrl, + toolId: "demo", + versionId: "1.0.0", + descriptorType: "WDL", + }); + expect(result.descriptorType).toBe("WDL"); + expect(result.trsToolVersion.descriptorTypeVersions).toEqual([]); + }); + + it.each([ + ["an empty tool ID", { toolId: "" }, 400, "tool ID"], + [ + "a long version ID", + { versionId: "v".repeat(201) }, + 400, + "version ID", + ], + ["a control character", { toolId: "a\nb" }, 400, "tool ID"], + ["a dot as tool ID", { toolId: "." }, 400, "tool ID"], + ["two dots as version ID", { versionId: ".." }, 400, "version ID"], + ["a type that isn't a word", { descriptorType: "../x" }, 400, "type"], + ])("refuses %s", async (_, change, status, message) => { + const { loadTrsToolVersion, get } = await load(); + const error = await loadTrsToolVersion({ + trsUrl, + toolId: "demo", + versionId: "1.0.0", + ...change, + }).catch((e) => e); + expect(error).toMatchObject({ status }); + expect(error.message).toContain(message); + expect(get).not.toHaveBeenCalled(); + }); + + it.each([ + [ + "the version isn't there", + { [versionUrl]: httpError(404) }, + 404, + "isn't in the tool registry", + ], + [ + "the files aren't there", + { [`${versionUrl}/WDL/files`]: httpError(404) }, + 404, + "has no WDL files", + ], + [ + "the descriptor isn't there", + { [`${versionUrl}/WDL/descriptor`]: httpError(404) }, + 404, + "has no WDL descriptor", + ], + [ + "the schema file isn't there", + { + [`${versionUrl}/WDL/descriptor/ga4gh-io.schema.json`]: + httpError(404), + }, + 404, + "has no file ga4gh-io.schema.json", + ], + [ + "the registry fails", + { [versionUrl]: httpError(500) }, + 502, + "Unable to read", + ], + [ + "the registry is unreachable", + { [versionUrl]: networkError("ECONNREFUSED") }, + 502, + "Unable to read", + ], + [ + "the version isn't an object", + { [versionUrl]: [] }, + 502, + "isn't a tool version", + ], + [ + "the version has no types", + { [versionUrl]: { descriptor_type: "WDL" } }, + 422, + "no workflow type", + ], + [ + "the version has several types", + { [versionUrl]: { descriptor_type: ["CWL", "WDL"] } }, + 422, + "several workflow types", + ], + [ + "the files aren't a list", + { [`${versionUrl}/WDL/files`]: {} }, + 502, + "isn't a list of files", + ], + [ + "the descriptor isn't an object", + { [`${versionUrl}/WDL/descriptor`]: "text" }, + 502, + "isn't a descriptor", + ], + [ + "the schema file has no content", + { [`${versionUrl}/WDL/descriptor/ga4gh-io.schema.json`]: {} }, + 422, + "has no content", + ], + [ + "the schema isn't JSON", + { + [`${versionUrl}/WDL/descriptor/ga4gh-io.schema.json`]: { + content: "{", + }, + }, + 422, + "isn't JSON", + ], + ])("fails when %s", async (_, replies, status, message) => { + const { loadTrsToolVersion } = await load(replies); + const error = await loadTrsToolVersion({ + trsUrl, + toolId: "demo", + versionId: "1.0.0", + }).catch((e) => e); + expect(error).toMatchObject({ status }); + expect(error.message).toContain(message); + }); + + it("refuses a type that the version doesn't have", async () => { + const { loadTrsToolVersion } = await load(); + const error = await loadTrsToolVersion({ + trsUrl, + toolId: "demo", + versionId: "1.0.0", + descriptorType: "CWL", + }).catch((e) => e); + expect(error).toMatchObject({ status: 422 }); + expect(error.message).toContain("has no CWL"); + }); +}); diff --git a/src/lib/trs.ts b/src/lib/trs.ts new file mode 100644 index 0000000..c220f53 --- /dev/null +++ b/src/lib/trs.ts @@ -0,0 +1,242 @@ +/** + * A tool version of a GA4GH Tool Registry Service (TRS), as the workflow + * form needs it in schema mode: the descriptor type, the TRS tool version + * reference of the Cloud Components (`TrsToolVersionRef`) and the I/O + * Schema among the tool version's files, if it has one + * + * Read on Krini's server (the route `/api/workflows/trs-tool-version`), + * as tool registries need not allow cross-origin requests, and only from + * the tool registries of the service registry (checked by the route). The + * schema is found as the profile proposes (`findSchemaFile`: a file of + * type `IO_SCHEMA`, else `ga4gh-io.schema.json` of type `OTHER` next to the + * primary descriptor). + */ +import { + findPrimaryDescriptorPath, + findSchemaFile, +} from "@elixir-cloud/wes/utils"; +import axios from "axios"; +import { axiosBase, deadline } from "@/lib/axios"; +import { parseSchemaText, type SchemaSourceError } from "@/lib/io-schema"; + +const TIMEOUT = 10_000; +const MAX_BYTES = 2 * 1024 * 1024; +const MAX_ID_LENGTH = 200; +// TRS descriptor types are upper-case words (`CWL`, `WDL`, `NFL`, `SMK`, +// `GALAXY`, ...) +const DESCRIPTOR_TYPE = /^[A-Z][A-Z0-9_]{0,31}$/; +// C0 and C1 control characters +// biome-ignore lint/suspicious/noControlCharactersInRegex: they are refused +const CONTROL = /[\u0000-\u001f\u007f-\u009f]/; + +/** A failure, with the HTTP status that the route answers with */ +export class TrsError extends Error { + constructor( + readonly status: number, + message: string, + ) { + super(message); + } +} + +/** What the workflow form needs of a tool version */ +export type TrsToolVersionResult = { + descriptorType: string; + /** `TrsToolVersionRef` of `@elixir-cloud/wes` */ + trsToolVersion: { + trsUrl: string; + toolId: string; + versionId: string; + primaryDescriptorPath: string | null; + descriptorTypeVersions: string[]; + primaryDescriptorUrl?: string; + }; + /** The I/O Schema, or `null` if the tool version has none or it + * wasn't asked for */ + schema: Record | null; +}; + +type Request = { + /** Base URL of the TRS API, checked by the caller */ + trsUrl: string; + toolId: string; + versionId: string; + /** Descriptor type; else the tool version's only one */ + descriptorType?: string; + /** Whether to read the tool version's schema (default: yes); not when + * the user brings one */ + withSchema?: boolean; +}; + +const record = (value: unknown): Record | null => + value !== null && typeof value === "object" && !Array.isArray(value) + ? (value as Record) + : null; +const strings = (value: unknown) => + Array.isArray(value) + ? value.filter((item): item is string => typeof item === "string") + : []; +const segment = (value: string) => encodeURIComponent(value); + +function checkId(value: string, name: string) { + if ( + value.length === 0 || + value.length > MAX_ID_LENGTH || + CONTROL.test(value) || + value === "." || + value === ".." + ) { + throw new TrsError( + 400, + `The ${name} must have 1 to ${MAX_ID_LENGTH} characters, no control characters, and must not be "." or "..".`, + ); + } +} + +/** + * Get a JSON document of the tool registry + * @param url URL of the document + * @param notFound Message for a document that the registry doesn't have + * @returns The document + * @throws TrsError 404 if the registry doesn't have it, 502 if it can't + * be read + */ +async function get( + url: string, + notFound = "The tool version isn't in the tool registry.", +): Promise { + try { + const { data } = await axiosBase.get(url, { + headers: { Accept: "application/json" }, + timeout: TIMEOUT, + signal: deadline(TIMEOUT), + maxContentLength: MAX_BYTES, + maxRedirects: 0, + }); + return data; + } catch (error) { + if (axios.isAxiosError(error) && error.response?.status === 404) { + throw new TrsError(404, notFound); + } + throw new TrsError(502, "Unable to read the tool registry."); + } +} + +/** + * Load a tool version for the workflow form + * @param request The tool registry, the tool version and, optionally, the + * descriptor type + * @returns The descriptor type, the TRS tool version reference and the + * schema + * @throws TrsError For invalid ids (400), a tool version that isn't there + * (404), a type that can't be chosen or a schema that isn't JSON (422), + * and answers of the registry that can't be read or used (502) + */ +export async function loadTrsToolVersion({ + trsUrl, + toolId, + versionId, + descriptorType, + withSchema = true, +}: Request): Promise { + checkId(toolId, "tool ID"); + checkId(versionId, "version ID"); + if (descriptorType !== undefined && !DESCRIPTOR_TYPE.test(descriptorType)) + throw new TrsError(400, "The workflow type isn't a TRS type."); + + const base = `${trsUrl}/tools/${segment(toolId)}/versions/${segment(versionId)}`; + const version = record(await get(base)); + if (version === null) + throw new TrsError( + 502, + "The tool registry's answer isn't a tool version.", + ); + + const types = strings(version.descriptor_type); + let type: string; + if (descriptorType !== undefined) { + if (!types.includes(descriptorType)) + throw new TrsError( + 422, + `The tool version has no ${descriptorType} workflow.`, + ); + type = descriptorType; + } else if (types.length === 1) { + [type] = types; + } else { + throw new TrsError( + 422, + types.length === 0 + ? "The tool version names no workflow type." + : "The tool version has several workflow types: choose one.", + ); + } + + const files = await get( + `${base}/${segment(type)}/files`, + `The tool version has no ${type} files in the tool registry.`, + ); + if (!Array.isArray(files)) + throw new TrsError( + 502, + "The tool registry's answer isn't a list of files.", + ); + + const descriptor = record( + await get( + `${base}/${segment(type)}/descriptor`, + `The tool version has no ${type} descriptor in the tool registry.`, + ), + ); + if (descriptor === null) + throw new TrsError( + 502, + "The tool registry's answer isn't a descriptor.", + ); + + const schemaFile = withSchema ? findSchemaFile(files) : null; + let schema: Record | null = null; + if (schemaFile !== null) { + // findSchemaFile ignores paths with ".." parts + const path = schemaFile.path + .split("/") + .filter((part) => part !== "") + .map(segment) + .join("/"); + const wrapper = record( + await get( + `${base}/${segment(type)}/descriptor/${path}`, + `The tool version has no file ${schemaFile.path} in the tool registry.`, + ), + ); + if (typeof wrapper?.content !== "string") + throw new TrsError( + 422, + "The I/O Schema of the tool version has no content.", + ); + try { + schema = parseSchemaText(wrapper.content); + } catch (error) { + throw new TrsError( + 422, + `The tool registry's I/O Schema can't be used: ${(error as SchemaSourceError).message}`, + ); + } + } + + return { + descriptorType: type, + schema, + trsToolVersion: { + trsUrl, + toolId, + versionId, + primaryDescriptorPath: findPrimaryDescriptorPath(files), + descriptorTypeVersions: strings( + record(version.descriptor_type_version)?.[type], + ), + primaryDescriptorUrl: + typeof descriptor.url === "string" ? descriptor.url : undefined, + }, + }; +} diff --git a/vendor/cloud-components/README.md b/vendor/cloud-components/README.md new file mode 100644 index 0000000..2bdb4d7 --- /dev/null +++ b/vendor/cloud-components/README.md @@ -0,0 +1,34 @@ +# Unreleased Cloud Components (temporary) + +**Temporary, for the I/O Schema proposal (krini#47). Remove this directory +once the components are released.** + +The tarballs here are the Cloud Components packages that Krini's proposal +needs before they are released: + +| Tarball | Package | Source | +| --- | --- | --- | +| `elixir-cloud-wes-2.0.0-alpha.51-io.f28c15c.tgz` | `@elixir-cloud/wes` | `packages/ecc-client-ga4gh-wes` | +| `elixir-cloud-design-2.0.0-alpha.51-io.f28c15c.tgz` | `@elixir-cloud/design` | `packages/ecc-utils-design` | + +Both are built from +[elixir-cloud-aai/cloud-components](https://github.com/elixir-cloud-aai/cloud-components) +at commit `f28c15c` (branch `feat/io-run-request-proposal`, PR #614, +stacked on `feat/io-form-proposal`, PR #613), with `npm run build` and +`npm pack` in each package. The version in their `package.json` is set to +`2.0.0-alpha.51-io.f28c15c` (and the WES package's dependency on the +design package to the same), so that they can't be mistaken for the +published `2.0.0-alpha.51`. Nothing was published. + +`package.json` names the WES tarball as a `file:` dependency and the +design tarball in `overrides`, so that the TES package uses the same +design package. The `Dockerfile` copies this directory before installing. + +## Removing it + +1. In `package.json`, set `@elixir-cloud/wes` to the released version and + remove the `@elixir-cloud/design` entry of `overrides`. +2. Remove this directory and the `COPY vendor ./vendor` line (with its + comment) in the `Dockerfile`, and the note in + `docs/development/index.md`. +3. Run `bun i` and commit `bun.lock`. diff --git a/vendor/cloud-components/elixir-cloud-design-2.0.0-alpha.51-io.f28c15c.tgz b/vendor/cloud-components/elixir-cloud-design-2.0.0-alpha.51-io.f28c15c.tgz new file mode 100644 index 0000000..1c20844 Binary files /dev/null and b/vendor/cloud-components/elixir-cloud-design-2.0.0-alpha.51-io.f28c15c.tgz differ diff --git a/vendor/cloud-components/elixir-cloud-wes-2.0.0-alpha.51-io.f28c15c.tgz b/vendor/cloud-components/elixir-cloud-wes-2.0.0-alpha.51-io.f28c15c.tgz new file mode 100644 index 0000000..3c5e6b1 Binary files /dev/null and b/vendor/cloud-components/elixir-cloud-wes-2.0.0-alpha.51-io.f28c15c.tgz differ