Unified · Split
| @@ -0,0 +1,5 @@ | |||
| 1 | { | ||
| 2 | "rules": { | ||
| 3 | "typescript/no-explicit-any": "error" | ||
| 4 | } | ||
| 5 | } | ||
| @@ -31,7 +31,6 @@ · 30 unmodified lines | |||
| 31 | "name": "@executor/ir", | 31 | "name": "@executor/ir", |
| 32 | "version": "0.0.0", | 32 | "version": "0.0.0", |
| 33 | "dependencies": { | 33 | "dependencies": { |
| 34 | "@executor/codemode-core": "workspace:*", | ||
| 35 | "effect": "catalog:", | 34 | "effect": "catalog:", |
| 36 | }, | 35 | }, |
| 37 | "devDependencies": { | 36 | "devDependencies": { |
| @@ -56,6 +55,23 @@ · 18 unmodified lines | |||
| 56 | "vitest": "catalog:", | 55 | "vitest": "catalog:", |
| 57 | }, | 56 | }, |
| 58 | }, | 57 | }, |
| 58 | "packages/plugins/openapi": { | ||
| 59 | "name": "@executor/plugin-openapi", | ||
| 60 | "version": "0.0.0", | ||
| 61 | "dependencies": { | ||
| 62 | "@apidevtools/swagger-parser": "^12.1.0", | ||
| 63 | "@effect/platform": "^0.96.0", | ||
| 64 | "effect": "catalog:", | ||
| 65 | "openapi-types": "^12.1.3", | ||
| 66 | "yaml": "^2.7.1", | ||
| 67 | }, | ||
| 68 | "devDependencies": { | ||
| 69 | "@effect/vitest": "catalog:", | ||
| 70 | "@types/node": "catalog:", | ||
| 71 | "bun-types": "catalog:", | ||
| 72 | "vitest": "catalog:", | ||
| 73 | }, | ||
| 74 | }, | ||
| 59 | }, | 75 | }, |
| 60 | "catalog": { | 76 | "catalog": { |
| 61 | "@effect/vitest": "^0.27.0", | 77 | "@effect/vitest": "^0.27.0", |
| @@ -65,8 +81,18 @@ · 3 unmodified lines | |||
| 65 | "vitest": "^3.2.4", | 81 | "vitest": "^3.2.4", |
| 66 | }, | 82 | }, |
| 67 | "packages": { | 83 | "packages": { |
| 84 | "@apidevtools/json-schema-ref-parser": ["@apidevtools/json-schema-ref-parser@14.0.1", "", { "dependencies": { "@types/json-schema": "^7.0.15", "js-yaml": "^4.1.0" } }, "sha512-Oc96zvmxx1fqoSEdUmfmvvb59/KDOnUoJ7s2t7bISyAn0XEz57LCCw8k2Y4Pf3mwKaZLMciESALORLgfe2frCw=="], | ||
| 85 | |||
| 86 | "@apidevtools/openapi-schemas": ["@apidevtools/openapi-schemas@2.1.0", "", {}, "sha512-Zc1AlqrJlX3SlpupFGpiLi2EbteyP7fXmUOGup6/DnkRgjP9bgMM/ag+n91rsv0U1Gpz0H3VILA/o3bW7Ua6BQ=="], | ||
| 87 | |||
| 88 | "@apidevtools/swagger-methods": ["@apidevtools/swagger-methods@3.0.2", "", {}, "sha512-QAkD5kK2b1WfjDS/UQn/qQkbwF31uqRjPTrsCs5ZG9BQGAkjwvqGFjjPqAuzac/IYzpPtRzjCP1WrTuAIjMrXg=="], | ||
| 89 | |||
| 90 | "@apidevtools/swagger-parser": ["@apidevtools/swagger-parser@12.1.0", "", { "dependencies": { "@apidevtools/json-schema-ref-parser": "14.0.1", "@apidevtools/openapi-schemas": "^2.1.0", "@apidevtools/swagger-methods": "^3.0.2", "ajv": "^8.17.1", "ajv-draft-04": "^1.0.0", "call-me-maybe": "^1.0.2" }, "peerDependencies": { "openapi-types": ">=7" } }, "sha512-e5mJoswsnAX0jG+J09xHFYQXb/bUc5S3pLpMxUuRUA2H8T2kni3yEoyz2R3Dltw5f4A6j6rPNMpWTK+iVDFlng=="], | ||
| 91 | |||
| 68 | "@effect/language-service": ["@effect/language-service@0.84.2", "", { "bin": { "effect-language-service": "cli.js" } }, "sha512-l04qNxpiA8rY5yXWckRPJ7Mk5MNerXuNymSFf+IdflfI5i8jgL1bpBNLuP6ijg7wgjdHc/KmTnCj2kT0SCntuA=="], | 92 | "@effect/language-service": ["@effect/language-service@0.84.2", "", { "bin": { "effect-language-service": "cli.js" } }, "sha512-l04qNxpiA8rY5yXWckRPJ7Mk5MNerXuNymSFf+IdflfI5i8jgL1bpBNLuP6ijg7wgjdHc/KmTnCj2kT0SCntuA=="], |
| 69 | 93 | ||
| 94 | "@effect/platform": ["@effect/platform@0.96.0", "", { "dependencies": { "find-my-way-ts": "^0.1.6", "msgpackr": "^1.11.4", "multipasta": "^0.2.7" }, "peerDependencies": { "effect": "^3.21.0" } }, "sha512-U7PLhkVzg7zzrgFvyWATOzD6reL87KG/fcdOxgLWBQ/J5CCU6qdPAVG+0o6o+IxcsLoqGwxs+rFxaFzrdtDV1A=="], | ||
| 95 | |||
| 70 | "@effect/vitest": ["@effect/vitest@0.27.0", "", { "peerDependencies": { "effect": "^3.19.0", "vitest": "^3.2.0" } }, "sha512-8bM7n9xlMUYw9GqPIVgXFwFm2jf27m/R7psI64PGpwU5+26iwyxp9eAXEsfT5S6lqztYfpQQ1Ubp5o6HfNYzJQ=="], | 96 | "@effect/vitest": ["@effect/vitest@0.27.0", "", { "peerDependencies": { "effect": "^3.19.0", "vitest": "^3.2.0" } }, "sha512-8bM7n9xlMUYw9GqPIVgXFwFm2jf27m/R7psI64PGpwU5+26iwyxp9eAXEsfT5S6lqztYfpQQ1Ubp5o6HfNYzJQ=="], |
| 71 | 97 | ||
| 72 | "@esbuild/aix-ppc64": ["@esbuild/aix-ppc64@0.27.4", "", { "os": "aix", "cpu": "ppc64" }, "sha512-cQPwL2mp2nSmHHJlCyoXgHGhbEPMrEEU5xhkcy3Hs/O7nGZqEpZ2sUtLaL9MORLtDfRvVl2/3PAuEkYZH0Ty8Q=="], | 98 | "@esbuild/aix-ppc64": ["@esbuild/aix-ppc64@0.27.4", "", { "os": "aix", "cpu": "ppc64" }, "sha512-cQPwL2mp2nSmHHJlCyoXgHGhbEPMrEEU5xhkcy3Hs/O7nGZqEpZ2sUtLaL9MORLtDfRvVl2/3PAuEkYZH0Ty8Q=="], |
| @@ -125,6 +151,8 @@ · 52 unmodified lines | |||
| 125 | 151 | ||
| 126 | "@executor/ir": ["@executor/ir@workspace:packages/kernel/ir"], | 152 | "@executor/ir": ["@executor/ir@workspace:packages/kernel/ir"], |
| 127 | 153 | ||
| 154 | "@executor/plugin-openapi": ["@executor/plugin-openapi@workspace:packages/plugins/openapi"], | ||
| 155 | |||
| 128 | "@executor/runtime-quickjs": ["@executor/runtime-quickjs@workspace:packages/kernel/runtime-quickjs"], | 156 | "@executor/runtime-quickjs": ["@executor/runtime-quickjs@workspace:packages/kernel/runtime-quickjs"], |
| 129 | 157 | ||
| 130 | "@jitl/quickjs-ffi-types": ["@jitl/quickjs-ffi-types@0.31.0", "", {}, "sha512-1yrgvXlmXH2oNj3eFTrkwacGJbmM0crwipA3ohCrjv52gBeDaD7PsTvFYinlAnqU8iPME3LGP437yk05a2oejw=="], | 158 | "@jitl/quickjs-ffi-types": ["@jitl/quickjs-ffi-types@0.31.0", "", {}, "sha512-1yrgvXlmXH2oNj3eFTrkwacGJbmM0crwipA3ohCrjv52gBeDaD7PsTvFYinlAnqU8iPME3LGP437yk05a2oejw=="], |
| @@ -139,6 +167,18 @@ · 8 unmodified lines | |||
| 139 | 167 | ||
| 140 | "@jridgewell/sourcemap-codec": ["@jridgewell/sourcemap-codec@1.5.5", "", {}, "sha512-cYQ9310grqxueWbl+WuIUIaiUaDcj7WOq5fVhEljNVgRfOUhY9fy2zTvfoqWsnebh8Sl70VScFbICvJnLKB0Og=="], | 168 | "@jridgewell/sourcemap-codec": ["@jridgewell/sourcemap-codec@1.5.5", "", {}, "sha512-cYQ9310grqxueWbl+WuIUIaiUaDcj7WOq5fVhEljNVgRfOUhY9fy2zTvfoqWsnebh8Sl70VScFbICvJnLKB0Og=="], |
| 141 | 169 | ||
| 170 | "@msgpackr-extract/msgpackr-extract-darwin-arm64": ["@msgpackr-extract/msgpackr-extract-darwin-arm64@3.0.3", "", { "os": "darwin", "cpu": "arm64" }, "sha512-QZHtlVgbAdy2zAqNA9Gu1UpIuI8Xvsd1v8ic6B2pZmeFnFcMWiPLfWXh7TVw4eGEZ/C9TH281KwhVoeQUKbyjw=="], | ||
| 171 | |||
| 172 | "@msgpackr-extract/msgpackr-extract-darwin-x64": ["@msgpackr-extract/msgpackr-extract-darwin-x64@3.0.3", "", { "os": "darwin", "cpu": "x64" }, "sha512-mdzd3AVzYKuUmiWOQ8GNhl64/IoFGol569zNRdkLReh6LRLHOXxU4U8eq0JwaD8iFHdVGqSy4IjFL4reoWCDFw=="], | ||
| 173 | |||
| 174 | "@msgpackr-extract/msgpackr-extract-linux-arm": ["@msgpackr-extract/msgpackr-extract-linux-arm@3.0.3", "", { "os": "linux", "cpu": "arm" }, "sha512-fg0uy/dG/nZEXfYilKoRe7yALaNmHoYeIoJuJ7KJ+YyU2bvY8vPv27f7UKhGRpY6euFYqEVhxCFZgAUNQBM3nw=="], | ||
| 175 | |||
| 176 | "@msgpackr-extract/msgpackr-extract-linux-arm64": ["@msgpackr-extract/msgpackr-extract-linux-arm64@3.0.3", "", { "os": "linux", "cpu": "arm64" }, "sha512-YxQL+ax0XqBJDZiKimS2XQaf+2wDGVa1enVRGzEvLLVFeqa5kx2bWbtcSXgsxjQB7nRqqIGFIcLteF/sHeVtQg=="], | ||
| 177 | |||
| 178 | "@msgpackr-extract/msgpackr-extract-linux-x64": ["@msgpackr-extract/msgpackr-extract-linux-x64@3.0.3", "", { "os": "linux", "cpu": "x64" }, "sha512-cvwNfbP07pKUfq1uH+S6KJ7dT9K8WOE4ZiAcsrSes+UY55E/0jLYc+vq+DO7jlmqRb5zAggExKm0H7O/CBaesg=="], | ||
| 179 | |||
| 180 | "@msgpackr-extract/msgpackr-extract-win32-x64": ["@msgpackr-extract/msgpackr-extract-win32-x64@3.0.3", "", { "os": "win32", "cpu": "x64" }, "sha512-x0fWaQtYp4E6sktbsdAqnehxDgEc/VwM7uLsRCYWaiGu0ykYdZPiS8zCWdnjHwyiumousxfBm4SO31eXqwEZhQ=="], | ||
| 181 | |||
| 142 | "@oxlint/binding-android-arm-eabi": ["@oxlint/binding-android-arm-eabi@1.58.0", "", { "os": "android", "cpu": "arm" }, "sha512-1T7UN3SsWWxpWyWGn1cT3ASNJOo+pI3eUkmEl7HgtowapcV8kslYpFQcYn431VuxghXakPNlbjRwhqmR37PFOg=="], | 182 | "@oxlint/binding-android-arm-eabi": ["@oxlint/binding-android-arm-eabi@1.58.0", "", { "os": "android", "cpu": "arm" }, "sha512-1T7UN3SsWWxpWyWGn1cT3ASNJOo+pI3eUkmEl7HgtowapcV8kslYpFQcYn431VuxghXakPNlbjRwhqmR37PFOg=="], |
| 143 | 183 | ||
| 144 | "@oxlint/binding-android-arm64": ["@oxlint/binding-android-arm64@1.58.0", "", { "os": "android", "cpu": "arm64" }, "sha512-GryzujxuiRv2YFF7bRy8mKcxlbuAN+euVUtGJt9KKbLT8JBUIosamVhcthLh+VEr6KE6cjeVMAQxKAzJcoN7dg=="], | 184 | "@oxlint/binding-android-arm64": ["@oxlint/binding-android-arm64@1.58.0", "", { "os": "android", "cpu": "arm64" }, "sha512-GryzujxuiRv2YFF7bRy8mKcxlbuAN+euVUtGJt9KKbLT8JBUIosamVhcthLh+VEr6KE6cjeVMAQxKAzJcoN7dg=="], |
| @@ -247,6 +287,8 @@ · 102 unmodified lines | |||
| 247 | 287 | ||
| 248 | "@types/estree": ["@types/estree@1.0.8", "", {}, "sha512-dWHzHa2WqEXI/O1E9OjrocMTKJl2mSrEolh1Iomrv6U+JuNwaHXsXx9bLu5gG7BUWFIN0skIQJQ/L1rIex4X6w=="], | 288 | "@types/estree": ["@types/estree@1.0.8", "", {}, "sha512-dWHzHa2WqEXI/O1E9OjrocMTKJl2mSrEolh1Iomrv6U+JuNwaHXsXx9bLu5gG7BUWFIN0skIQJQ/L1rIex4X6w=="], |
| 249 | 289 | ||
| 290 | "@types/json-schema": ["@types/json-schema@7.0.15", "", {}, "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA=="], | ||
| 291 | |||
| 250 | "@types/node": ["@types/node@24.12.0", "", { "dependencies": { "undici-types": "~7.16.0" } }, "sha512-GYDxsZi3ChgmckRT9HPU0WEhKLP08ev/Yfcq2AstjrDASOYCSXeyjDsHg4v5t4jOj7cyDX3vmprafKlWIG9MXQ=="], | 292 | "@types/node": ["@types/node@24.12.0", "", { "dependencies": { "undici-types": "~7.16.0" } }, "sha512-GYDxsZi3ChgmckRT9HPU0WEhKLP08ev/Yfcq2AstjrDASOYCSXeyjDsHg4v5t4jOj7cyDX3vmprafKlWIG9MXQ=="], |
| 251 | 293 | ||
| 252 | "@vitest/expect": ["@vitest/expect@3.2.4", "", { "dependencies": { "@types/chai": "^5.2.2", "@vitest/spy": "3.2.4", "@vitest/utils": "3.2.4", "chai": "^5.2.0", "tinyrainbow": "^2.0.0" } }, "sha512-Io0yyORnB6sikFlt8QW5K7slY4OjqNX9jmJQ02QDda8lyM6B5oNgVWoSoKPac8/kgnCUzuHQKrSLtu/uOqqrig=="], | 294 | "@vitest/expect": ["@vitest/expect@3.2.4", "", { "dependencies": { "@types/chai": "^5.2.2", "@vitest/spy": "3.2.4", "@vitest/utils": "3.2.4", "chai": "^5.2.0", "tinyrainbow": "^2.0.0" } }, "sha512-Io0yyORnB6sikFlt8QW5K7slY4OjqNX9jmJQ02QDda8lyM6B5oNgVWoSoKPac8/kgnCUzuHQKrSLtu/uOqqrig=="], |
| @@ -265,14 +307,20 @@ · 12 unmodified lines | |||
| 265 | 307 | ||
| 266 | "ajv": ["ajv@8.18.0", "", { "dependencies": { "fast-deep-equal": "^3.1.3", "fast-uri": "^3.0.1", "json-schema-traverse": "^1.0.0", "require-from-string": "^2.0.2" } }, "sha512-PlXPeEWMXMZ7sPYOHqmDyCJzcfNrUr3fGNKtezX14ykXOEIvyK81d+qydx89KY5O71FKMPaQ2vBfBFI5NHR63A=="], | 308 | "ajv": ["ajv@8.18.0", "", { "dependencies": { "fast-deep-equal": "^3.1.3", "fast-uri": "^3.0.1", "json-schema-traverse": "^1.0.0", "require-from-string": "^2.0.2" } }, "sha512-PlXPeEWMXMZ7sPYOHqmDyCJzcfNrUr3fGNKtezX14ykXOEIvyK81d+qydx89KY5O71FKMPaQ2vBfBFI5NHR63A=="], |
| 267 | 309 | ||
| 310 | "ajv-draft-04": ["ajv-draft-04@1.0.0", "", { "peerDependencies": { "ajv": "^8.5.0" }, "optionalPeers": ["ajv"] }, "sha512-mv00Te6nmYbRp5DCwclxtt7yV/joXJPGS7nM+97GdxvuttCOfgI3K4U25zboyeX0O+myI8ERluxQe5wljMmVIw=="], | ||
| 311 | |||
| 268 | "ajv-formats": ["ajv-formats@3.0.1", "", { "dependencies": { "ajv": "^8.0.0" } }, "sha512-8iUql50EUR+uUcdRQ3HDqa6EVyo3docL8g5WJ3FNcWmu62IbkGUue/pEyLBW8VGKKucTPgqeks4fIU1DA4yowQ=="], | 312 | "ajv-formats": ["ajv-formats@3.0.1", "", { "dependencies": { "ajv": "^8.0.0" } }, "sha512-8iUql50EUR+uUcdRQ3HDqa6EVyo3docL8g5WJ3FNcWmu62IbkGUue/pEyLBW8VGKKucTPgqeks4fIU1DA4yowQ=="], |
| 269 | 313 | ||
| 314 | "argparse": ["argparse@2.0.1", "", {}, "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q=="], | ||
| 315 | |||
| 270 | "assertion-error": ["assertion-error@2.0.1", "", {}, "sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA=="], | 316 | "assertion-error": ["assertion-error@2.0.1", "", {}, "sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA=="], |
| 271 | 317 | ||
| 272 | "bun-types": ["bun-types@1.3.11", "", { "dependencies": { "@types/node": "*" } }, "sha512-1KGPpoxQWl9f6wcZh57LvrPIInQMn2TQ7jsgxqpRzg+l0QPOFvJVH7HmvHo/AiPgwXy+/Thf6Ov3EdVn1vOabg=="], | 318 | "bun-types": ["bun-types@1.3.11", "", { "dependencies": { "@types/node": "*" } }, "sha512-1KGPpoxQWl9f6wcZh57LvrPIInQMn2TQ7jsgxqpRzg+l0QPOFvJVH7HmvHo/AiPgwXy+/Thf6Ov3EdVn1vOabg=="], |
| 273 | 319 | ||
| 274 | "cac": ["cac@6.7.14", "", {}, "sha512-b6Ilus+c3RrdDk+JhLKUAQfzzgLEPy6wcXqS7f/xe1EETvsDP6GORG7SFuOs6cID5YkqchW/LXZbX5bc8j7ZcQ=="], | 320 | "cac": ["cac@6.7.14", "", {}, "sha512-b6Ilus+c3RrdDk+JhLKUAQfzzgLEPy6wcXqS7f/xe1EETvsDP6GORG7SFuOs6cID5YkqchW/LXZbX5bc8j7ZcQ=="], |
| 275 | 321 | ||
| 322 | "call-me-maybe": ["call-me-maybe@1.0.2", "", {}, "sha512-HpX65o1Hnr9HH25ojC1YGs7HCQLq0GCOibSaWER0eNpgJ/Z1MZv2mTc7+xh6WOPxbRVcmgbv4hGU+uSQ/2xFZQ=="], | ||
| 323 | |||
| 276 | "chai": ["chai@5.3.3", "", { "dependencies": { "assertion-error": "^2.0.1", "check-error": "^2.1.1", "deep-eql": "^5.0.1", "loupe": "^3.1.0", "pathval": "^2.0.0" } }, "sha512-4zNhdJD/iOjSH0A05ea+Ke6MU5mmpQcbQsSOkgdaUMJ9zTlDTD/GYlwohmIE2u0gaxHYiVHEn1Fw9mZ/ktJWgw=="], | 324 | "chai": ["chai@5.3.3", "", { "dependencies": { "assertion-error": "^2.0.1", "check-error": "^2.1.1", "deep-eql": "^5.0.1", "loupe": "^3.1.0", "pathval": "^2.0.0" } }, "sha512-4zNhdJD/iOjSH0A05ea+Ke6MU5mmpQcbQsSOkgdaUMJ9zTlDTD/GYlwohmIE2u0gaxHYiVHEn1Fw9mZ/ktJWgw=="], |
| 277 | 325 | ||
| 278 | "check-error": ["check-error@2.1.3", "", {}, "sha512-PAJdDJusoxnwm1VwW07VWwUN1sl7smmC3OKggvndJFadxxDRyFJBX/ggnu/KE4kQAB7a3Dp8f/YXC1FlUprWmA=="], | 326 | "check-error": ["check-error@2.1.3", "", {}, "sha512-PAJdDJusoxnwm1VwW07VWwUN1sl7smmC3OKggvndJFadxxDRyFJBX/ggnu/KE4kQAB7a3Dp8f/YXC1FlUprWmA=="], |
| @@ -281,6 +329,8 @@ · 2 unmodified lines | |||
| 281 | 329 | ||
| 282 | "deep-eql": ["deep-eql@5.0.2", "", {}, "sha512-h5k/5U50IJJFpzfL6nO9jaaumfjO/f2NjK/oYB2Djzm4p9L+3T9qWpZqZ2hAbLPuuYq9wrU08WQyBTL5GbPk5Q=="], | 330 | "deep-eql": ["deep-eql@5.0.2", "", {}, "sha512-h5k/5U50IJJFpzfL6nO9jaaumfjO/f2NjK/oYB2Djzm4p9L+3T9qWpZqZ2hAbLPuuYq9wrU08WQyBTL5GbPk5Q=="], |
| 283 | 331 | ||
| 332 | "detect-libc": ["detect-libc@2.1.2", "", {}, "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ=="], | ||
| 333 | |||
| 284 | "effect": ["effect@3.21.0", "", { "dependencies": { "@standard-schema/spec": "^1.0.0", "fast-check": "^3.23.1" } }, "sha512-PPN80qRokCd1f015IANNhrwOnLO7GrrMQfk4/lnZRE/8j7UPWrNNjPV0uBrZutI/nHzernbW+J0hdqQysHiSnQ=="], | 334 | "effect": ["effect@3.21.0", "", { "dependencies": { "@standard-schema/spec": "^1.0.0", "fast-check": "^3.23.1" } }, "sha512-PPN80qRokCd1f015IANNhrwOnLO7GrrMQfk4/lnZRE/8j7UPWrNNjPV0uBrZutI/nHzernbW+J0hdqQysHiSnQ=="], |
| 285 | 335 | ||
| 286 | "es-module-lexer": ["es-module-lexer@1.7.0", "", {}, "sha512-jEQoCwk8hyb2AZziIOLhDqpm5+2ww5uIE6lkO/6jcOCusfk6LhMHpXXfBLXTZ7Ydyt0j4VoUQv6uGNYbdW+kBA=="], | 336 | "es-module-lexer": ["es-module-lexer@1.7.0", "", {}, "sha512-jEQoCwk8hyb2AZziIOLhDqpm5+2ww5uIE6lkO/6jcOCusfk6LhMHpXXfBLXTZ7Ydyt0j4VoUQv6uGNYbdW+kBA=="], |
| @@ -299,10 +349,14 @@ · 12 unmodified lines | |||
| 299 | 349 | ||
| 300 | "fdir": ["fdir@6.5.0", "", { "peerDependencies": { "picomatch": "^3 || ^4" }, "optionalPeers": ["picomatch"] }, "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg=="], | 350 | "fdir": ["fdir@6.5.0", "", { "peerDependencies": { "picomatch": "^3 || ^4" }, "optionalPeers": ["picomatch"] }, "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg=="], |
| 301 | 351 | ||
| 352 | "find-my-way-ts": ["find-my-way-ts@0.1.6", "", {}, "sha512-a85L9ZoXtNAey3Y6Z+eBWW658kO/MwR7zIafkIUPUMf3isZG0NCs2pjW2wtjxAKuJPxMAsHUIP4ZPGv0o5gyTA=="], | ||
| 353 | |||
| 302 | "fsevents": ["fsevents@2.3.3", "", { "os": "darwin" }, "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw=="], | 354 | "fsevents": ["fsevents@2.3.3", "", { "os": "darwin" }, "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw=="], |
| 303 | 355 | ||
| 304 | "js-tokens": ["js-tokens@9.0.1", "", {}, "sha512-mxa9E9ITFOt0ban3j6L5MpjwegGz6lBQmM1IJkWeBZGcMxto50+eWdjC/52xDbS2vy0k7vIMK0Fe2wfL9OQSpQ=="], | 356 | "js-tokens": ["js-tokens@9.0.1", "", {}, "sha512-mxa9E9ITFOt0ban3j6L5MpjwegGz6lBQmM1IJkWeBZGcMxto50+eWdjC/52xDbS2vy0k7vIMK0Fe2wfL9OQSpQ=="], |
| 305 | 357 | ||
| 358 | "js-yaml": ["js-yaml@4.1.1", "", { "dependencies": { "argparse": "^2.0.1" }, "bin": { "js-yaml": "bin/js-yaml.js" } }, "sha512-qQKT4zQxXl8lLwBtHMWwaTcGfFOZviOJet3Oy/xmGk2gZH677CJM9EvtfdSkgWcATZhj/55JZ0rmy3myCT5lsA=="], | ||
| 359 | |||
| 306 | "json-schema-traverse": ["json-schema-traverse@1.0.0", "", {}, "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug=="], | 360 | "json-schema-traverse": ["json-schema-traverse@1.0.0", "", {}, "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug=="], |
| 307 | 361 | ||
| 308 | "loupe": ["loupe@3.2.1", "", {}, "sha512-CdzqowRJCeLU72bHvWqwRBBlLcMEtIvGrlvef74kMnV2AolS9Y8xUv1I0U/MNAWMhBlKIoyuEgoJ0t/bbwHbLQ=="], | 362 | "loupe": ["loupe@3.2.1", "", {}, "sha512-CdzqowRJCeLU72bHvWqwRBBlLcMEtIvGrlvef74kMnV2AolS9Y8xUv1I0U/MNAWMhBlKIoyuEgoJ0t/bbwHbLQ=="], |
| @@ -311,8 +365,18 @@ · 2 unmodified lines | |||
| 311 | 365 | ||
| 312 | "ms": ["ms@2.1.3", "", {}, "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA=="], | 366 | "ms": ["ms@2.1.3", "", {}, "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA=="], |
| 313 | 367 | ||
| 368 | "msgpackr": ["msgpackr@1.11.9", "", { "optionalDependencies": { "msgpackr-extract": "^3.0.2" } }, "sha512-FkoAAyyA6HM8wL882EcEyFZ9s7hVADSwG9xrVx3dxxNQAtgADTrJoEWivID82Iv1zWDsv/OtbrrcZAzGzOMdNw=="], | ||
| 369 | |||
| 370 | "msgpackr-extract": ["msgpackr-extract@3.0.3", "", { "dependencies": { "node-gyp-build-optional-packages": "5.2.2" }, "optionalDependencies": { "@msgpackr-extract/msgpackr-extract-darwin-arm64": "3.0.3", "@msgpackr-extract/msgpackr-extract-darwin-x64": "3.0.3", "@msgpackr-extract/msgpackr-extract-linux-arm": "3.0.3", "@msgpackr-extract/msgpackr-extract-linux-arm64": "3.0.3", "@msgpackr-extract/msgpackr-extract-linux-x64": "3.0.3", "@msgpackr-extract/msgpackr-extract-win32-x64": "3.0.3" }, "bin": { "download-msgpackr-prebuilds": "bin/download-prebuilds.js" } }, "sha512-P0efT1C9jIdVRefqjzOQ9Xml57zpOXnIuS+csaB4MdZbTdmGDLo8XhzBG1N7aO11gKDDkJvBLULeFTo46wwreA=="], | ||
| 371 | |||
| 372 | "multipasta": ["multipasta@0.2.7", "", {}, "sha512-KPA58d68KgGil15oDqXjkUBEBYc00XvbPj5/X+dyzeo/lWm9Nc25pQRlf1D+gv4OpK7NM0J1odrbu9JNNGvynA=="], | ||
| 373 | |||
| 314 | "nanoid": ["nanoid@3.3.11", "", { "bin": { "nanoid": "bin/nanoid.cjs" } }, "sha512-N8SpfPUnUp1bK+PMYW8qSWdl9U+wwNWI4QKxOYDy9JAro3WMX7p2OeVRF9v+347pnakNevPmiHhNmZ2HbFA76w=="], | 374 | "nanoid": ["nanoid@3.3.11", "", { "bin": { "nanoid": "bin/nanoid.cjs" } }, "sha512-N8SpfPUnUp1bK+PMYW8qSWdl9U+wwNWI4QKxOYDy9JAro3WMX7p2OeVRF9v+347pnakNevPmiHhNmZ2HbFA76w=="], |
| 315 | 375 | ||
| 376 | "node-gyp-build-optional-packages": ["node-gyp-build-optional-packages@5.2.2", "", { "dependencies": { "detect-libc": "^2.0.1" }, "bin": { "node-gyp-build-optional-packages": "bin.js", "node-gyp-build-optional-packages-optional": "optional.js", "node-gyp-build-optional-packages-test": "build-test.js" } }, "sha512-s+w+rBWnpTMwSFbaE0UXsRlg7hU4FjekKU4eyAih5T8nJuNZT1nNsskXpxmeqSK9UzkBl6UgRlnKc8hz8IEqOw=="], | ||
| 377 | |||
| 378 | "openapi-types": ["openapi-types@12.1.3", "", {}, "sha512-N4YtSYJqghVu4iek2ZUvcN/0aqH1kRDuNqzcycDxhOUpg7GdvLa2F3DgS6yBNhInhv2r/6I0Flkn7CqL8+nIcw=="], | ||
| 379 | |||
| 316 | "oxlint": ["oxlint@1.58.0", "", { "optionalDependencies": { "@oxlint/binding-android-arm-eabi": "1.58.0", "@oxlint/binding-android-arm64": "1.58.0", "@oxlint/binding-darwin-arm64": "1.58.0", "@oxlint/binding-darwin-x64": "1.58.0", "@oxlint/binding-freebsd-x64": "1.58.0", "@oxlint/binding-linux-arm-gnueabihf": "1.58.0", "@oxlint/binding-linux-arm-musleabihf": "1.58.0", "@oxlint/binding-linux-arm64-gnu": "1.58.0", "@oxlint/binding-linux-arm64-musl": "1.58.0", "@oxlint/binding-linux-ppc64-gnu": "1.58.0", "@oxlint/binding-linux-riscv64-gnu": "1.58.0", "@oxlint/binding-linux-riscv64-musl": "1.58.0", "@oxlint/binding-linux-s390x-gnu": "1.58.0", "@oxlint/binding-linux-x64-gnu": "1.58.0", "@oxlint/binding-linux-x64-musl": "1.58.0", "@oxlint/binding-openharmony-arm64": "1.58.0", "@oxlint/binding-win32-arm64-msvc": "1.58.0", "@oxlint/binding-win32-ia32-msvc": "1.58.0", "@oxlint/binding-win32-x64-msvc": "1.58.0" }, "peerDependencies": { "oxlint-tsgolint": ">=0.18.0" }, "optionalPeers": ["oxlint-tsgolint"], "bin": { "oxlint": "bin/oxlint" } }, "sha512-t4s9leczDMqlvOSjnbCQe7gtoLkWgBGZ7sBdCJ9EOj5IXFSG/X7OAzK4yuH4iW+4cAYe8kLFbC8tuYMwWZm+Cg=="], | 380 | "oxlint": ["oxlint@1.58.0", "", { "optionalDependencies": { "@oxlint/binding-android-arm-eabi": "1.58.0", "@oxlint/binding-android-arm64": "1.58.0", "@oxlint/binding-darwin-arm64": "1.58.0", "@oxlint/binding-darwin-x64": "1.58.0", "@oxlint/binding-freebsd-x64": "1.58.0", "@oxlint/binding-linux-arm-gnueabihf": "1.58.0", "@oxlint/binding-linux-arm-musleabihf": "1.58.0", "@oxlint/binding-linux-arm64-gnu": "1.58.0", "@oxlint/binding-linux-arm64-musl": "1.58.0", "@oxlint/binding-linux-ppc64-gnu": "1.58.0", "@oxlint/binding-linux-riscv64-gnu": "1.58.0", "@oxlint/binding-linux-riscv64-musl": "1.58.0", "@oxlint/binding-linux-s390x-gnu": "1.58.0", "@oxlint/binding-linux-x64-gnu": "1.58.0", "@oxlint/binding-linux-x64-musl": "1.58.0", "@oxlint/binding-openharmony-arm64": "1.58.0", "@oxlint/binding-win32-arm64-msvc": "1.58.0", "@oxlint/binding-win32-ia32-msvc": "1.58.0", "@oxlint/binding-win32-x64-msvc": "1.58.0" }, "peerDependencies": { "oxlint-tsgolint": ">=0.18.0" }, "optionalPeers": ["oxlint-tsgolint"], "bin": { "oxlint": "bin/oxlint" } }, "sha512-t4s9leczDMqlvOSjnbCQe7gtoLkWgBGZ7sBdCJ9EOj5IXFSG/X7OAzK4yuH4iW+4cAYe8kLFbC8tuYMwWZm+Cg=="], |
| 317 | 381 | ||
| 318 | "pathe": ["pathe@2.0.3", "", {}, "sha512-WUjGcAqP1gQacoQe+OBJsFA7Ld4DyXuUIjZ5cc75cLHvJ7dtNsTugphxIADwspS+AraAUePCKrSVtPLFj/F88w=="], | 382 | "pathe": ["pathe@2.0.3", "", {}, "sha512-WUjGcAqP1gQacoQe+OBJsFA7Ld4DyXuUIjZ5cc75cLHvJ7dtNsTugphxIADwspS+AraAUePCKrSVtPLFj/F88w=="], |
| @@ -371,6 +435,8 @@ · 52 unmodified lines | |||
| 371 | 435 | ||
| 372 | "why-is-node-running": ["why-is-node-running@2.3.0", "", { "dependencies": { "siginfo": "^2.0.0", "stackback": "0.0.2" }, "bin": { "why-is-node-running": "cli.js" } }, "sha512-hUrmaWBdVDcxvYqnyh09zunKzROWjbZTiNy8dBEjkS7ehEDQibXJ7XvlmtbwuTclUiIyN+CyXQD4Vmko8fNm8w=="], | 436 | "why-is-node-running": ["why-is-node-running@2.3.0", "", { "dependencies": { "siginfo": "^2.0.0", "stackback": "0.0.2" }, "bin": { "why-is-node-running": "cli.js" } }, "sha512-hUrmaWBdVDcxvYqnyh09zunKzROWjbZTiNy8dBEjkS7ehEDQibXJ7XvlmtbwuTclUiIyN+CyXQD4Vmko8fNm8w=="], |
| 373 | 437 | ||
| 438 | "yaml": ["yaml@2.8.3", "", { "bin": { "yaml": "bin.mjs" } }, "sha512-AvbaCLOO2Otw/lW5bmh9d/WEdcDFdQp2Z2ZUH3pX9U2ihyUY0nvLv7J6TrWowklRGPYbB/IuIMfYgxaCPg5Bpg=="], | ||
| 439 | |||
| 374 | "bun-types/@types/node": ["@types/node@25.5.0", "", { "dependencies": { "undici-types": "~7.18.0" } }, "sha512-jp2P3tQMSxWugkCUKLRPVUpGaL5MVFwF8RDuSRztfwgN1wmqJeMSbKlnEtQqU8UrhTmzEmZdu2I6v2dpp7XIxw=="], | 440 | "bun-types/@types/node": ["@types/node@25.5.0", "", { "dependencies": { "undici-types": "~7.18.0" } }, "sha512-jp2P3tQMSxWugkCUKLRPVUpGaL5MVFwF8RDuSRztfwgN1wmqJeMSbKlnEtQqU8UrhTmzEmZdu2I6v2dpp7XIxw=="], |
| 375 | 441 | ||
| 376 | "bun-types/@types/node/undici-types": ["undici-types@7.18.2", "", {}, "sha512-AsuCzffGHJybSaRrmr5eHr81mwJU3kjw6M+uprWvCXiNeN9SOGwQ3Jn8jb8m3Z6izVgknn1R0FTCEAP2QrLY/w=="], | 442 | "bun-types/@types/node/undici-types": ["undici-types@7.18.2", "", {}, "sha512-AsuCzffGHJybSaRrmr5eHr81mwJU3kjw6M+uprWvCXiNeN9SOGwQ3Jn8jb8m3Z6izVgknn1R0FTCEAP2QrLY/w=="], |
| @@ -1,16 +1,21 @@ | |||
| 1 | import { describe, expect, it } from "@effect/vitest"; | 1 | import { describe, expect, it } from "@effect/vitest"; |
| 2 | import * as Data from "effect/Data"; | ||
| 2 | import * as Effect from "effect/Effect"; | 3 | import * as Effect from "effect/Effect"; |
| 3 | 4 | ||
| 4 | import type { ToolInvoker } from "@executor/codemode-core"; | 5 | import type { ToolInvoker } from "@executor/codemode-core"; |
| 5 | import { makeQuickJsExecutor } from "./index"; | 6 | import { makeQuickJsExecutor } from "./index"; |
| 6 | 7 | ||
| 8 | class UnknownToolError extends Data.TaggedError("UnknownToolError")<{ | ||
| 9 | readonly path: string; | ||
| 10 | }> {} | ||
| 11 | |||
| 7 | const makeTestInvoker = ( | 12 | const makeTestInvoker = ( |
| 8 | handlers: Record<string, (args: unknown) => unknown>, | 13 | handlers: Record<string, (args: unknown) => unknown>, |
| 9 | ): ToolInvoker => ({ | 14 | ): ToolInvoker => ({ |
| 10 | invoke: ({ path, args }) => { | 15 | invoke: ({ path, args }) => { |
| 11 | const handler = handlers[path]; | 16 | const handler = handlers[path]; |
| 12 | if (!handler) { | 17 | if (!handler) { |
| 13 | return Effect.fail(new Error(`Unknown tool: ${path}`)); | 18 | return Effect.fail(new UnknownToolError({ path })); |
| 14 | } | 19 | } |
| 15 | return Effect.try(() => handler(args)); | 20 | return Effect.try(() => handler(args)); |
| 16 | }, | 21 | }, |
| @@ -33,9 +38,10 @@ describe("quickjs executor", () => { · 16 unmodified lines | |||
| 33 | it.effect("invokes a tool and returns its result", () => | 38 | it.effect("invokes a tool and returns its result", () => |
| 34 | Effect.gen(function* () { | 39 | Effect.gen(function* () { |
| 35 | const invoker = makeTestInvoker({ | 40 | const invoker = makeTestInvoker({ |
| 36 | "math.add": (args: any) => ({ | 41 | "math.add": (args) => { |
| 37 | sum: args.a + args.b, | 42 | const { a, b } = args as { a: number; b: number }; |
| 38 | }), | 43 | return { sum: a + b }; |
| 44 | }, | ||
| 39 | }); | 45 | }); |
| 40 | 46 | ||
| 41 | const result = yield* executor.execute( | 47 | const result = yield* executor.execute( |
| @@ -54,13 +60,14 @@ describe("quickjs executor", () => { · 12 unmodified lines | |||
| 54 | it.effect("invokes multiple tools in sequence", () => | 60 | it.effect("invokes multiple tools in sequence", () => |
| 55 | Effect.gen(function* () { | 61 | Effect.gen(function* () { |
| 56 | const invoker = makeTestInvoker({ | 62 | const invoker = makeTestInvoker({ |
| 57 | "users.get": (args: any) => ({ | 63 | "users.get": (args) => { |
| 58 | id: args.id, | 64 | const { id } = args as { id: number }; |
| 59 | name: `User ${args.id}`, | 65 | return { id, name: `User ${id}` }; |
| 60 | }), | 66 | }, |
| 61 | "users.greet": (args: any) => ({ | 67 | "users.greet": (args) => { |
| 62 | message: `Hello, ${args.name}!`, | 68 | const { name } = args as { name: string }; |
| 63 | }), | 69 | return { message: `Hello, ${name}!` }; |
| 70 | }, | ||
| 64 | }); | 71 | }); |
| 65 | 72 | ||
| 66 | const result = yield* executor.execute( | 73 | const result = yield* executor.execute( |
| @@ -150,11 +157,10 @@ describe("quickjs executor", () => { · 83 unmodified lines | |||
| 150 | { id: "cus_2", email: "bob@example.com" }, | 157 | { id: "cus_2", email: "bob@example.com" }, |
| 151 | ], | 158 | ], |
| 152 | }), | 159 | }), |
| 153 | "stripe.invoices.create": (args: any) => ({ | 160 | "stripe.invoices.create": (args) => { |
| 154 | id: "inv_1", | 161 | const { customer, amount } = args as { customer: string; amount: number }; |
| 155 | customer: args.customer, | 162 | return { id: "inv_1", customer, amount }; |
| 156 | amount: args.amount, | 163 | }, |
| 157 | }), | ||
| 158 | }); | 164 | }); |
| 159 | 165 | ||
| 160 | const result = yield* executor.execute( | 166 | const result = yield* executor.execute( |
| @@ -0,0 +1,27 @@ | |||
| 1 | { | ||
| 2 | "name": "@executor/plugin-openapi", | ||
| 3 | "private": true, | ||
| 4 | "type": "module", | ||
| 5 | "version": "0.0.0", | ||
| 6 | "exports": { | ||
| 7 | ".": "./src/index.ts" | ||
| 8 | }, | ||
| 9 | "scripts": { | ||
| 10 | "typecheck": "bunx tsc --noEmit -p tsconfig.json", | ||
| 11 | "test": "vitest run", | ||
| 12 | "test:watch": "vitest" | ||
| 13 | }, | ||
| 14 | "dependencies": { | ||
| 15 | "@apidevtools/swagger-parser": "^12.1.0", | ||
| 16 | "@effect/platform": "^0.96.0", | ||
| 17 | "effect": "catalog:", | ||
| 18 | "openapi-types": "^12.1.3", | ||
| 19 | "yaml": "^2.7.1" | ||
| 20 | }, | ||
| 21 | "devDependencies": { | ||
| 22 | "@effect/vitest": "catalog:", | ||
| 23 | "@types/node": "catalog:", | ||
| 24 | "bun-types": "catalog:", | ||
| 25 | "vitest": "catalog:" | ||
| 26 | } | ||
| 27 | } | ||
| @@ -0,0 +1,25 @@ | |||
| 1 | import { Schema } from "effect"; | ||
| 2 | |||
| 3 | export class OpenApiParseError extends Schema.TaggedError<OpenApiParseError>()( | ||
| 4 | "OpenApiParseError", | ||
| 5 | { | ||
| 6 | message: Schema.String, | ||
| 7 | error: Schema.Defect, | ||
| 8 | }, | ||
| 9 | ) {} | ||
| 10 | |||
| 11 | export class OpenApiExtractionError extends Schema.TaggedError<OpenApiExtractionError>()( | ||
| 12 | "OpenApiExtractionError", | ||
| 13 | { | ||
| 14 | message: Schema.String, | ||
| 15 | }, | ||
| 16 | ) {} | ||
| 17 | |||
| 18 | export class OpenApiInvocationError extends Schema.TaggedError<OpenApiInvocationError>()( | ||
| 19 | "OpenApiInvocationError", | ||
| 20 | { | ||
| 21 | message: Schema.String, | ||
| 22 | statusCode: Schema.optionalWith(Schema.Number, { as: "Option" }), | ||
| 23 | error: Schema.Defect, | ||
| 24 | }, | ||
| 25 | ) {} | ||
| @@ -0,0 +1,272 @@ | |||
| 1 | import type { OpenAPIV3, OpenAPIV3_1 } from "openapi-types"; | ||
| 2 | import { Effect, Option } from "effect"; | ||
| 3 | |||
| 4 | import { OpenApiExtractionError } from "./errors"; | ||
| 5 | import type { DereferencedDocument } from "./parse"; | ||
| 6 | import { | ||
| 7 | ExtractedOperation, | ||
| 8 | ExtractionResult, | ||
| 9 | type HttpMethod, | ||
| 10 | OperationId, | ||
| 11 | OperationParameter, | ||
| 12 | OperationRequestBody, | ||
| 13 | type ParameterLocation, | ||
| 14 | ServerInfo, | ||
| 15 | } from "./types"; | ||
| 16 | |||
| 17 | // --------------------------------------------------------------------------- | ||
| 18 | // Constants | ||
| 19 | // --------------------------------------------------------------------------- | ||
| 20 | |||
| 21 | const HTTP_METHODS: readonly HttpMethod[] = [ | ||
| 22 | "get", "put", "post", "delete", "patch", "head", "options", "trace", | ||
| 23 | ]; | ||
| 24 | |||
| 25 | const VALID_PARAM_LOCATIONS = new Set<string>(["path", "query", "header", "cookie"]); | ||
| 26 | |||
| 27 | // --------------------------------------------------------------------------- | ||
| 28 | // Helpers | ||
| 29 | // --------------------------------------------------------------------------- | ||
| 30 | |||
| 31 | type ParameterObject = OpenAPIV3.ParameterObject | OpenAPIV3_1.ParameterObject; | ||
| 32 | type OperationObject = OpenAPIV3.OperationObject | OpenAPIV3_1.OperationObject; | ||
| 33 | type PathItemObject = OpenAPIV3.PathItemObject | OpenAPIV3_1.PathItemObject; | ||
| 34 | type RequestBodyObject = OpenAPIV3.RequestBodyObject | OpenAPIV3_1.RequestBodyObject; | ||
| 35 | type MediaTypeObject = OpenAPIV3.MediaTypeObject | OpenAPIV3_1.MediaTypeObject; | ||
| 36 | |||
| 37 | /** After dereferencing, $ref objects are resolved — this narrows the type */ | ||
| 38 | const isResolved = <T>(value: T | OpenAPIV3.ReferenceObject | OpenAPIV3_1.ReferenceObject): value is T => | ||
| 39 | typeof value === "object" && value !== null && !("$ref" in value); | ||
| 40 | |||
| 41 | /** Pick the preferred media type entry (prefer application/json) */ | ||
| 42 | const preferredContent = ( | ||
| 43 | content: Record<string, MediaTypeObject> | undefined, | ||
| 44 | ): { mediaType: string; media: MediaTypeObject } | undefined => { | ||
| 45 | if (!content) return undefined; | ||
| 46 | const entries = Object.entries(content); | ||
| 47 | const pick = | ||
| 48 | entries.find(([mt]) => mt === "application/json") ?? | ||
| 49 | entries.find(([mt]) => mt.toLowerCase().includes("+json")) ?? | ||
| 50 | entries.find(([mt]) => mt.toLowerCase().includes("json")) ?? | ||
| 51 | entries[0]; | ||
| 52 | |||
| 53 | return pick ? { mediaType: pick[0], media: pick[1] } : undefined; | ||
| 54 | }; | ||
| 55 | |||
| 56 | // --------------------------------------------------------------------------- | ||
| 57 | // Parameter extraction | ||
| 58 | // --------------------------------------------------------------------------- | ||
| 59 | |||
| 60 | const extractParameters = ( | ||
| 61 | pathItem: PathItemObject, | ||
| 62 | operation: OperationObject, | ||
| 63 | ): OperationParameter[] => { | ||
| 64 | // Operation parameters override path-level ones by name+location | ||
| 65 | const merged = new Map<string, ParameterObject>(); | ||
| 66 | |||
| 67 | for (const raw of pathItem.parameters ?? []) { | ||
| 68 | if (!isResolved(raw)) continue; | ||
| 69 | merged.set(`${raw.in}:${raw.name}`, raw); | ||
| 70 | } | ||
| 71 | for (const raw of operation.parameters ?? []) { | ||
| 72 | if (!isResolved(raw)) continue; | ||
| 73 | merged.set(`${raw.in}:${raw.name}`, raw); | ||
| 74 | } | ||
| 75 | |||
| 76 | return [...merged.values()] | ||
| 77 | .filter((p) => VALID_PARAM_LOCATIONS.has(p.in)) | ||
| 78 | .map( | ||
| 79 | (p) => | ||
| 80 | new OperationParameter({ | ||
| 81 | name: p.name, | ||
| 82 | location: p.in as ParameterLocation, | ||
| 83 | required: p.in === "path" ? true : p.required === true, | ||
| 84 | schema: Option.fromNullable(p.schema), | ||
| 85 | style: Option.fromNullable(p.style), | ||
| 86 | explode: Option.fromNullable(p.explode), | ||
| 87 | allowReserved: Option.fromNullable( | ||
| 88 | "allowReserved" in p ? p.allowReserved : undefined, | ||
| 89 | ), | ||
| 90 | description: Option.fromNullable(p.description), | ||
| 91 | }), | ||
| 92 | ); | ||
| 93 | }; | ||
| 94 | |||
| 95 | // --------------------------------------------------------------------------- | ||
| 96 | // Request body extraction | ||
| 97 | // --------------------------------------------------------------------------- | ||
| 98 | |||
| 99 | const extractRequestBody = ( | ||
| 100 | operation: OperationObject, | ||
| 101 | ): OperationRequestBody | undefined => { | ||
| 102 | const body = operation.requestBody; | ||
| 103 | if (!body || !isResolved<RequestBodyObject>(body)) return undefined; | ||
| 104 | |||
| 105 | const content = preferredContent(body.content); | ||
| 106 | if (!content) return undefined; | ||
| 107 | |||
| 108 | return new OperationRequestBody({ | ||
| 109 | required: body.required === true, | ||
| 110 | contentType: content.mediaType, | ||
| 111 | schema: Option.fromNullable(content.media.schema), | ||
| 112 | }); | ||
| 113 | }; | ||
| 114 | |||
| 115 | // --------------------------------------------------------------------------- | ||
| 116 | // Response schema extraction | ||
| 117 | // --------------------------------------------------------------------------- | ||
| 118 | |||
| 119 | const extractOutputSchema = ( | ||
| 120 | operation: OperationObject, | ||
| 121 | ): unknown | undefined => { | ||
| 122 | const responses = operation.responses; | ||
| 123 | if (!responses) return undefined; | ||
| 124 | |||
| 125 | // Prefer 2xx responses, then default | ||
| 126 | const entries = Object.entries(responses); | ||
| 127 | const preferred = [ | ||
| 128 | ...entries.filter(([s]) => /^2\d\d$/.test(s)).sort(([a], [b]) => a.localeCompare(b)), | ||
| 129 | ...entries.filter(([s]) => s === "default"), | ||
| 130 | ]; | ||
| 131 | |||
| 132 | for (const [, respValue] of preferred) { | ||
| 133 | if (!isResolved(respValue)) continue; | ||
| 134 | const content = preferredContent( | ||
| 135 | (respValue as OpenAPIV3.ResponseObject).content, | ||
| 136 | ); | ||
| 137 | if (content?.media.schema) return content.media.schema; | ||
| 138 | } | ||
| 139 | |||
| 140 | return undefined; | ||
| 141 | }; | ||
| 142 | |||
| 143 | // --------------------------------------------------------------------------- | ||
| 144 | // Input schema builder | ||
| 145 | // --------------------------------------------------------------------------- | ||
| 146 | |||
| 147 | const buildInputSchema = ( | ||
| 148 | parameters: readonly OperationParameter[], | ||
| 149 | requestBody: OperationRequestBody | undefined, | ||
| 150 | ): Record<string, unknown> | undefined => { | ||
| 151 | const properties: Record<string, unknown> = {}; | ||
| 152 | const required: string[] = []; | ||
| 153 | |||
| 154 | for (const param of parameters) { | ||
| 155 | properties[param.name] = Option.getOrElse(param.schema, () => ({ type: "string" })); | ||
| 156 | if (param.required) required.push(param.name); | ||
| 157 | } | ||
| 158 | |||
| 159 | if (requestBody) { | ||
| 160 | properties.body = Option.getOrElse(requestBody.schema, () => ({ type: "object" })); | ||
| 161 | if (requestBody.required) required.push("body"); | ||
| 162 | } | ||
| 163 | |||
| 164 | if (Object.keys(properties).length === 0) return undefined; | ||
| 165 | |||
| 166 | return { | ||
| 167 | type: "object", | ||
| 168 | properties, | ||
| 169 | ...(required.length > 0 ? { required } : {}), | ||
| 170 | additionalProperties: false, | ||
| 171 | }; | ||
| 172 | }; | ||
| 173 | |||
| 174 | // --------------------------------------------------------------------------- | ||
| 175 | // Operation ID derivation | ||
| 176 | // --------------------------------------------------------------------------- | ||
| 177 | |||
| 178 | const deriveOperationId = ( | ||
| 179 | method: HttpMethod, | ||
| 180 | pathTemplate: string, | ||
| 181 | operation: OperationObject, | ||
| 182 | ): string => | ||
| 183 | operation.operationId ?? | ||
| 184 | (`${method}_${pathTemplate.replace(/[^a-zA-Z0-9]+/g, "_")}`.replace( | ||
| 185 | /^_+|_+$/g, | ||
| 186 | "", | ||
| 187 | ) || `${method}_operation`); | ||
| 188 | |||
| 189 | // --------------------------------------------------------------------------- | ||
| 190 | // Server extraction | ||
| 191 | // --------------------------------------------------------------------------- | ||
| 192 | |||
| 193 | const extractServers = (doc: DereferencedDocument): ServerInfo[] => | ||
| 194 | (doc.servers ?? []).flatMap((server) => { | ||
| 195 | if (!server.url) return []; | ||
| 196 | const variables = server.variables | ||
| 197 | ? Object.fromEntries( | ||
| 198 | Object.entries(server.variables).flatMap(([name, v]) => | ||
| 199 | v.default ? [[name, v.default]] : [], | ||
| 200 | ), | ||
| 201 | ) | ||
| 202 | : undefined; | ||
| 203 | return [ | ||
| 204 | new ServerInfo({ | ||
| 205 | url: server.url, | ||
| 206 | variables: | ||
| 207 | variables && Object.keys(variables).length > 0 | ||
| 208 | ? Option.some(variables) | ||
| 209 | : Option.none(), | ||
| 210 | }), | ||
| 211 | ]; | ||
| 212 | }); | ||
| 213 | |||
| 214 | // --------------------------------------------------------------------------- | ||
| 215 | // Main extraction | ||
| 216 | // --------------------------------------------------------------------------- | ||
| 217 | |||
| 218 | /** Extract all operations from a dereferenced OpenAPI 3.x document */ | ||
| 219 | export const extract = Effect.fn("OpenApi.extract")(function* ( | ||
| 220 | doc: DereferencedDocument, | ||
| 221 | ) { | ||
| 222 | const paths = doc.paths; | ||
| 223 | if (!paths) { | ||
| 224 | return yield* new OpenApiExtractionError({ | ||
| 225 | message: "OpenAPI document has no paths defined", | ||
| 226 | }); | ||
| 227 | } | ||
| 228 | |||
| 229 | const operations: ExtractedOperation[] = []; | ||
| 230 | |||
| 231 | for (const [pathTemplate, pathItem] of Object.entries(paths).sort( | ||
| 232 | ([a], [b]) => a.localeCompare(b), | ||
| 233 | )) { | ||
| 234 | if (!pathItem) continue; | ||
| 235 | |||
| 236 | for (const method of HTTP_METHODS) { | ||
| 237 | const operation = pathItem[method]; | ||
| 238 | if (!operation) continue; | ||
| 239 | |||
| 240 | const parameters = extractParameters(pathItem, operation); | ||
| 241 | const requestBody = extractRequestBody(operation); | ||
| 242 | const inputSchema = buildInputSchema(parameters, requestBody); | ||
| 243 | const outputSchema = extractOutputSchema(operation); | ||
| 244 | const tags = (operation.tags ?? []).filter((t) => t.trim().length > 0); | ||
| 245 | |||
| 246 | operations.push( | ||
| 247 | new ExtractedOperation({ | ||
| 248 | operationId: OperationId.make( | ||
| 249 | deriveOperationId(method, pathTemplate, operation), | ||
| 250 | ), | ||
| 251 | method, | ||
| 252 | pathTemplate, | ||
| 253 | summary: Option.fromNullable(operation.summary), | ||
| 254 | description: Option.fromNullable(operation.description), | ||
| 255 | tags, | ||
| 256 | parameters, | ||
| 257 | requestBody: Option.fromNullable(requestBody), | ||
| 258 | inputSchema: Option.fromNullable(inputSchema), | ||
| 259 | outputSchema: Option.fromNullable(outputSchema), | ||
| 260 | deprecated: operation.deprecated === true, | ||
| 261 | }), | ||
| 262 | ); | ||
| 263 | } | ||
| 264 | } | ||
| 265 | |||
| 266 | return new ExtractionResult({ | ||
| 267 | title: Option.fromNullable(doc.info?.title), | ||
| 268 | version: Option.fromNullable(doc.info?.version), | ||
| 269 | servers: extractServers(doc), | ||
| 270 | operations, | ||
| 271 | }); | ||
| 272 | }); | ||
| @@ -0,0 +1,157 @@ | |||
| 1 | import { describe, expect, it } from "@effect/vitest"; | ||
| 2 | import { | ||
| 3 | HttpApi, | ||
| 4 | HttpApiEndpoint, | ||
| 5 | HttpApiGroup, | ||
| 6 | OpenApi, | ||
| 7 | } from "@effect/platform"; | ||
| 8 | import { Effect, Option, Schema } from "effect"; | ||
| 9 | |||
| 10 | import { parse } from "./parse"; | ||
| 11 | import { extract } from "./extract"; | ||
| 12 | |||
| 13 | // --------------------------------------------------------------------------- | ||
| 14 | // Define a test API using Effect's HttpApi | ||
| 15 | // --------------------------------------------------------------------------- | ||
| 16 | |||
| 17 | class Pet extends Schema.Class<Pet>("Pet")({ | ||
| 18 | id: Schema.Number, | ||
| 19 | name: Schema.String, | ||
| 20 | tag: Schema.optional(Schema.String), | ||
| 21 | }) {} | ||
| 22 | |||
| 23 | class CreatePetInput extends Schema.Class<CreatePetInput>("CreatePetInput")({ | ||
| 24 | name: Schema.String, | ||
| 25 | tag: Schema.optional(Schema.String), | ||
| 26 | }) {} | ||
| 27 | |||
| 28 | class PetNotFound extends Schema.TaggedError<PetNotFound>()("PetNotFound", { | ||
| 29 | message: Schema.String, | ||
| 30 | }) {} | ||
| 31 | |||
| 32 | const PetstoreGroup = HttpApiGroup.make("pets") | ||
| 33 | .add( | ||
| 34 | HttpApiEndpoint.get("listPets", "/pets") | ||
| 35 | .addSuccess(Schema.Array(Pet)), | ||
| 36 | ) | ||
| 37 | .add( | ||
| 38 | HttpApiEndpoint.post("createPet", "/pets") | ||
| 39 | .setPayload(CreatePetInput) | ||
| 40 | .addSuccess(Pet), | ||
| 41 | ) | ||
| 42 | .add( | ||
| 43 | HttpApiEndpoint.get("getPet", "/pets/:petId") | ||
| 44 | .addSuccess(Pet) | ||
| 45 | .addError(PetNotFound, { status: 404 }), | ||
| 46 | ); | ||
| 47 | |||
| 48 | const PetstoreApi = HttpApi.make("petstore").add(PetstoreGroup); | ||
| 49 | |||
| 50 | // Generate OpenAPI spec from the Effect API definition | ||
| 51 | const spec = OpenApi.fromApi(PetstoreApi); | ||
| 52 | |||
| 53 | // --------------------------------------------------------------------------- | ||
| 54 | // Tests | ||
| 55 | // --------------------------------------------------------------------------- | ||
| 56 | |||
| 57 | describe("OpenAPI plugin", () => { | ||
| 58 | it.effect("parses and extracts operations from Effect HttpApi spec", () => | ||
| 59 | Effect.gen(function* () { | ||
| 60 | const doc = yield* parse(JSON.stringify(spec)); | ||
| 61 | const result = yield* extract(doc); | ||
| 62 | |||
| 63 | expect(Option.getOrElse(result.title, () => "")).toBe("Api"); | ||
| 64 | expect(result.operations.length).toBeGreaterThanOrEqual(3); | ||
| 65 | }), | ||
| 66 | ); | ||
| 67 | |||
| 68 | it.effect("extracts listPets with output schema", () => | ||
| 69 | Effect.gen(function* () { | ||
| 70 | const doc = yield* parse(JSON.stringify(spec)); | ||
| 71 | const result = yield* extract(doc); | ||
| 72 | |||
| 73 | const listPets = result.operations.find( | ||
| 74 | (op) => op.operationId === "pets.listPets", | ||
| 75 | ); | ||
| 76 | expect(listPets).toBeDefined(); | ||
| 77 | expect(listPets!.method).toBe("get"); | ||
| 78 | expect(listPets!.pathTemplate).toBe("/pets"); | ||
| 79 | expect(listPets!.tags).toContain("pets"); | ||
| 80 | |||
| 81 | // Has output schema (array of pets, dereferenced) | ||
| 82 | expect(Option.isSome(listPets!.outputSchema)).toBe(true); | ||
| 83 | const outputSchema = Option.getOrThrow(listPets!.outputSchema) as Record< | ||
| 84 | string, | ||
| 85 | unknown | ||
| 86 | >; | ||
| 87 | expect(outputSchema.type).toBe("array"); | ||
| 88 | }), | ||
| 89 | ); | ||
| 90 | |||
| 91 | it.effect("extracts createPet with request body from payload", () => | ||
| 92 | Effect.gen(function* () { | ||
| 93 | const doc = yield* parse(JSON.stringify(spec)); | ||
| 94 | const result = yield* extract(doc); | ||
| 95 | |||
| 96 | const createPet = result.operations.find( | ||
| 97 | (op) => op.operationId === "pets.createPet", | ||
| 98 | ); | ||
| 99 | expect(createPet).toBeDefined(); | ||
| 100 | expect(createPet!.method).toBe("post"); | ||
| 101 | |||
| 102 | // Has request body | ||
| 103 | expect(Option.isSome(createPet!.requestBody)).toBe(true); | ||
| 104 | const rb = Option.getOrThrow(createPet!.requestBody); | ||
| 105 | expect(rb.contentType).toBe("application/json"); | ||
| 106 | |||
| 107 | // Input schema includes body | ||
| 108 | expect(Option.isSome(createPet!.inputSchema)).toBe(true); | ||
| 109 | const inputSchema = Option.getOrThrow( | ||
| 110 | createPet!.inputSchema, | ||
| 111 | ) as Record<string, unknown>; | ||
| 112 | expect(inputSchema.properties).toHaveProperty("body"); | ||
| 113 | }), | ||
| 114 | ); | ||
| 115 | |||
| 116 | it.effect("extracts getPet with path template", () => | ||
| 117 | Effect.gen(function* () { | ||
| 118 | const doc = yield* parse(JSON.stringify(spec)); | ||
| 119 | const result = yield* extract(doc); | ||
| 120 | |||
| 121 | const getPet = result.operations.find( | ||
| 122 | (op) => op.operationId === "pets.getPet", | ||
| 123 | ); | ||
| 124 | expect(getPet).toBeDefined(); | ||
| 125 | expect(getPet!.method).toBe("get"); | ||
| 126 | expect(getPet!.pathTemplate).toBe("/pets/{petId}"); | ||
| 127 | }), | ||
| 128 | ); | ||
| 129 | |||
| 130 | it.effect("extracts error responses", () => | ||
| 131 | Effect.gen(function* () { | ||
| 132 | const doc = yield* parse(JSON.stringify(spec)); | ||
| 133 | const result = yield* extract(doc); | ||
| 134 | |||
| 135 | const getPet = result.operations.find( | ||
| 136 | (op) => op.operationId === "pets.getPet", | ||
| 137 | ); | ||
| 138 | expect(getPet).toBeDefined(); | ||
| 139 | |||
| 140 | // Should have a success output schema | ||
| 141 | expect(Option.isSome(getPet!.outputSchema)).toBe(true); | ||
| 142 | }), | ||
| 143 | ); | ||
| 144 | |||
| 145 | it.effect("round-trips: generated spec paths match HttpApi definition", () => | ||
| 146 | Effect.gen(function* () { | ||
| 147 | const doc = yield* parse(JSON.stringify(spec)); | ||
| 148 | const result = yield* extract(doc); | ||
| 149 | |||
| 150 | // Should have all 3 operations | ||
| 151 | const paths = result.operations.map((op) => `${op.method} ${op.pathTemplate}`); | ||
| 152 | expect(paths).toContain("get /pets"); | ||
| 153 | expect(paths).toContain("post /pets"); | ||
| 154 | expect(paths).toContain("get /pets/{petId}"); | ||
| 155 | }), | ||
| 156 | ); | ||
| 157 | }); | ||
| @@ -0,0 +1,26 @@ | |||
| 1 | export { parse } from "./parse"; | ||
| 2 | export { extract } from "./extract"; | ||
| 3 | export { invoke } from "./invoke"; | ||
| 4 | |||
| 5 | export { | ||
| 6 | OpenApiParseError, | ||
| 7 | OpenApiExtractionError, | ||
| 8 | OpenApiInvocationError, | ||
| 9 | } from "./errors"; | ||
| 10 | |||
| 11 | export { | ||
| 12 | AuthConfig, | ||
| 13 | NoAuth, | ||
| 14 | BearerAuth, | ||
| 15 | ApiKeyAuth, | ||
| 16 | ExtractedOperation, | ||
| 17 | ExtractionResult, | ||
| 18 | InvocationConfig, | ||
| 19 | InvocationResult, | ||
| 20 | OperationParameter, | ||
| 21 | OperationRequestBody, | ||
| 22 | ServerInfo, | ||
| 23 | OperationId, | ||
| 24 | HttpMethod, | ||
| 25 | ParameterLocation, | ||
| 26 | } from "./types"; | ||
| @@ -0,0 +1,248 @@ | |||
| 1 | import { Effect, Match, Option } from "effect"; | ||
| 2 | |||
| 3 | import { OpenApiInvocationError } from "./errors"; | ||
| 4 | import { | ||
| 5 | type AuthConfig, | ||
| 6 | type ExtractedOperation, | ||
| 7 | InvocationConfig, | ||
| 8 | InvocationResult, | ||
| 9 | type OperationParameter, | ||
| 10 | } from "./types"; | ||
| 11 | |||
| 12 | // --------------------------------------------------------------------------- | ||
| 13 | // Parameter reading | ||
| 14 | // --------------------------------------------------------------------------- | ||
| 15 | |||
| 16 | const CONTAINER_KEYS: Record<string, readonly string[]> = { | ||
| 17 | path: ["path", "pathParams", "params"], | ||
| 18 | query: ["query", "queryParams", "params"], | ||
| 19 | header: ["headers", "header"], | ||
| 20 | cookie: ["cookies", "cookie"], | ||
| 21 | }; | ||
| 22 | |||
| 23 | const readParamValue = ( | ||
| 24 | args: Record<string, unknown>, | ||
| 25 | param: OperationParameter, | ||
| 26 | ): unknown => { | ||
| 27 | const direct = args[param.name]; | ||
| 28 | if (direct !== undefined) return direct; | ||
| 29 | |||
| 30 | for (const key of CONTAINER_KEYS[param.location] ?? []) { | ||
| 31 | const container = args[key]; | ||
| 32 | if ( | ||
| 33 | typeof container === "object" && | ||
| 34 | container !== null && | ||
| 35 | !Array.isArray(container) | ||
| 36 | ) { | ||
| 37 | const nested = (container as Record<string, unknown>)[param.name]; | ||
| 38 | if (nested !== undefined) return nested; | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | return undefined; | ||
| 43 | }; | ||
| 44 | |||
| 45 | // --------------------------------------------------------------------------- | ||
| 46 | // Path resolution | ||
| 47 | // --------------------------------------------------------------------------- | ||
| 48 | |||
| 49 | const resolvePath = Effect.fn("OpenApi.resolvePath")(function* ( | ||
| 50 | pathTemplate: string, | ||
| 51 | args: Record<string, unknown>, | ||
| 52 | parameters: readonly OperationParameter[], | ||
| 53 | ) { | ||
| 54 | let resolved = pathTemplate; | ||
| 55 | |||
| 56 | for (const param of parameters) { | ||
| 57 | if (param.location !== "path") continue; | ||
| 58 | const value = readParamValue(args, param); | ||
| 59 | if (value === undefined || value === null) { | ||
| 60 | if (param.required) { | ||
| 61 | return yield* new OpenApiInvocationError({ | ||
| 62 | message: `Missing required path parameter: ${param.name}`, | ||
| 63 | statusCode: Option.none(), | ||
| 64 | error: undefined, | ||
| 65 | }); | ||
| 66 | } | ||
| 67 | continue; | ||
| 68 | } | ||
| 69 | resolved = resolved.replaceAll( | ||
| 70 | `{${param.name}}`, | ||
| 71 | encodeURIComponent(String(value)), | ||
| 72 | ); | ||
| 73 | } | ||
| 74 | |||
| 75 | const unresolved = [...resolved.matchAll(/\{([^{}]+)\}/g)] | ||
| 76 | .map((m) => m[1]) | ||
| 77 | .filter((v): v is string => typeof v === "string"); | ||
| 78 | |||
| 79 | if (unresolved.length > 0) { | ||
| 80 | return yield* new OpenApiInvocationError({ | ||
| 81 | message: `Unresolved path parameters: ${[...new Set(unresolved)].join(", ")}`, | ||
| 82 | statusCode: Option.none(), | ||
| 83 | error: undefined, | ||
| 84 | }); | ||
| 85 | } | ||
| 86 | |||
| 87 | return resolved; | ||
| 88 | }); | ||
| 89 | |||
| 90 | // --------------------------------------------------------------------------- | ||
| 91 | // URL construction | ||
| 92 | // --------------------------------------------------------------------------- | ||
| 93 | |||
| 94 | const buildUrl = (baseUrl: string, resolvedPath: string): URL => { | ||
| 95 | try { | ||
| 96 | return new URL(resolvedPath); | ||
| 97 | } catch { | ||
| 98 | const base = new URL(baseUrl); | ||
| 99 | const basePath = | ||
| 100 | base.pathname === "/" ? "" : base.pathname.replace(/\/$/, ""); | ||
| 101 | const pathPart = resolvedPath.startsWith("/") | ||
| 102 | ? resolvedPath | ||
| 103 | : `/${resolvedPath}`; | ||
| 104 | base.pathname = `${basePath}${pathPart}`.replace(/\/{2,}/g, "/"); | ||
| 105 | base.search = ""; | ||
| 106 | base.hash = ""; | ||
| 107 | return base; | ||
| 108 | } | ||
| 109 | }; | ||
| 110 | |||
| 111 | // --------------------------------------------------------------------------- | ||
| 112 | // Auth application | ||
| 113 | // --------------------------------------------------------------------------- | ||
| 114 | |||
| 115 | const applyAuth = (headers: Headers, url: URL, auth: AuthConfig): void => | ||
| 116 | Match.valueTags(auth, { | ||
| 117 | NoAuth: () => {}, | ||
| 118 | BearerAuth: ({ token, headerName, prefix }) => { | ||
| 119 | headers.set(headerName, `${prefix}${token}`); | ||
| 120 | }, | ||
| 121 | ApiKeyAuth: ({ name, value, in: location }) => { | ||
| 122 | if (location === "header") { | ||
| 123 | headers.set(name, value); | ||
| 124 | } else if (location === "query") { | ||
| 125 | url.searchParams.set(name, value); | ||
| 126 | } else { | ||
| 127 | const existing = headers.get("cookie"); | ||
| 128 | const cookie = `${name}=${encodeURIComponent(value)}`; | ||
| 129 | headers.set("cookie", existing ? `${existing}; ${cookie}` : cookie); | ||
| 130 | } | ||
| 131 | }, | ||
| 132 | }); | ||
| 133 | |||
| 134 | // --------------------------------------------------------------------------- | ||
| 135 | // Response decoding | ||
| 136 | // --------------------------------------------------------------------------- | ||
| 137 | |||
| 138 | const isJsonContentType = (ct: string | null): boolean => { | ||
| 139 | if (!ct) return false; | ||
| 140 | const normalized = ct.split(";")[0]?.trim().toLowerCase() ?? ""; | ||
| 141 | return ( | ||
| 142 | normalized === "application/json" || | ||
| 143 | normalized.includes("+json") || | ||
| 144 | normalized.includes("json") | ||
| 145 | ); | ||
| 146 | }; | ||
| 147 | |||
| 148 | const decodeResponse = ( | ||
| 149 | response: Response, | ||
| 150 | ): Effect.Effect<unknown, OpenApiInvocationError> => | ||
| 151 | Effect.tryPromise({ | ||
| 152 | try: async () => { | ||
| 153 | if (response.status === 204) return null; | ||
| 154 | if (isJsonContentType(response.headers.get("content-type"))) { | ||
| 155 | return response.json(); | ||
| 156 | } | ||
| 157 | return response.text(); | ||
| 158 | }, | ||
| 159 | catch: (error) => | ||
| 160 | new OpenApiInvocationError({ | ||
| 161 | message: `Failed to decode response body: ${error instanceof Error ? error.message : String(error)}`, | ||
| 162 | statusCode: Option.some(response.status), | ||
| 163 | error, | ||
| 164 | }), | ||
| 165 | }); | ||
| 166 | |||
| 167 | // --------------------------------------------------------------------------- | ||
| 168 | // Public API | ||
| 169 | // --------------------------------------------------------------------------- | ||
| 170 | |||
| 171 | /** Invoke an extracted OpenAPI operation */ | ||
| 172 | export const invoke = Effect.fn("OpenApi.invoke")(function* ( | ||
| 173 | operation: ExtractedOperation, | ||
| 174 | args: Record<string, unknown>, | ||
| 175 | config: InvocationConfig, | ||
| 176 | ) { | ||
| 177 | const resolvedPath = yield* resolvePath( | ||
| 178 | operation.pathTemplate, | ||
| 179 | args, | ||
| 180 | operation.parameters, | ||
| 181 | ); | ||
| 182 | |||
| 183 | const url = buildUrl(config.baseUrl, resolvedPath); | ||
| 184 | const headers = new Headers(); | ||
| 185 | |||
| 186 | // Query parameters | ||
| 187 | for (const param of operation.parameters) { | ||
| 188 | if (param.location !== "query") continue; | ||
| 189 | const value = readParamValue(args, param); | ||
| 190 | if (value === undefined || value === null) continue; | ||
| 191 | url.searchParams.set(param.name, String(value)); | ||
| 192 | } | ||
| 193 | |||
| 194 | // Header parameters | ||
| 195 | for (const param of operation.parameters) { | ||
| 196 | if (param.location !== "header") continue; | ||
| 197 | const value = readParamValue(args, param); | ||
| 198 | if (value === undefined || value === null) continue; | ||
| 199 | headers.set(param.name, String(value)); | ||
| 200 | } | ||
| 201 | |||
| 202 | // Request body | ||
| 203 | let body: string | undefined; | ||
| 204 | if (Option.isSome(operation.requestBody)) { | ||
| 205 | const rb = operation.requestBody.value; | ||
| 206 | const bodyValue = args.body ?? args.input; | ||
| 207 | if (bodyValue !== undefined) { | ||
| 208 | headers.set("content-type", rb.contentType); | ||
| 209 | // eslint-disable-next-line effect/preferSchemaOverJson -- serializing arbitrary user-provided body for HTTP transport | ||
| 210 | body = isJsonContentType(rb.contentType) | ||
| 211 | ? JSON.stringify(bodyValue) | ||
| 212 | : String(bodyValue); | ||
| 213 | } | ||
| 214 | } | ||
| 215 | |||
| 216 | // Auth | ||
| 217 | applyAuth(headers, url, config.auth); | ||
| 218 | |||
| 219 | // Execute request | ||
| 220 | const response = yield* Effect.tryPromise({ | ||
| 221 | try: () => | ||
| 222 | fetch(url.toString(), { | ||
| 223 | method: operation.method.toUpperCase(), | ||
| 224 | headers, | ||
| 225 | ...(body !== undefined ? { body } : {}), | ||
| 226 | }), | ||
| 227 | catch: (error) => | ||
| 228 | new OpenApiInvocationError({ | ||
| 229 | message: `HTTP request failed: ${error instanceof Error ? error.message : String(error)}`, | ||
| 230 | statusCode: Option.none(), | ||
| 231 | error, | ||
| 232 | }), | ||
| 233 | }); | ||
| 234 | |||
| 235 | const responseBody = yield* decodeResponse(response); | ||
| 236 | |||
| 237 | const responseHeaders: Record<string, string> = {}; | ||
| 238 | response.headers.forEach((value, key) => { | ||
| 239 | responseHeaders[key] = value; | ||
| 240 | }); | ||
| 241 | |||
| 242 | return new InvocationResult({ | ||
| 243 | status: response.status, | ||
| 244 | headers: responseHeaders, | ||
| 245 | data: response.ok ? responseBody : null, | ||
| 246 | error: response.ok ? null : responseBody, | ||
| 247 | }); | ||
| 248 | }); | ||
| @@ -0,0 +1,69 @@ | |||
| 1 | import SwaggerParser from "@apidevtools/swagger-parser"; | ||
| 2 | import type { OpenAPI, OpenAPIV3, OpenAPIV3_1 } from "openapi-types"; | ||
| 3 | import { Effect } from "effect"; | ||
| 4 | |||
| 5 | import { OpenApiParseError } from "./errors"; | ||
| 6 | |||
| 7 | export type DereferencedDocument = OpenAPIV3.Document | OpenAPIV3_1.Document; | ||
| 8 | |||
| 9 | /** Parse, validate, and dereference an OpenAPI document from text or URL */ | ||
| 10 | export const parse = Effect.fn("OpenApi.parse")(function* (input: string) { | ||
| 11 | const api: OpenAPI.Document = yield* Effect.tryPromise({ | ||
| 12 | try: () => { | ||
| 13 | // If it looks like a URL, parse from URL; otherwise parse inline | ||
| 14 | if (input.startsWith("http://") || input.startsWith("https://")) { | ||
| 15 | return SwaggerParser.dereference(input); | ||
| 16 | } | ||
| 17 | // Parse from string: swagger-parser needs an object, so JSON/YAML parse first | ||
| 18 | return SwaggerParser.dereference(parseTextToObject(input)); | ||
| 19 | }, | ||
| 20 | catch: (error) => | ||
| 21 | new OpenApiParseError({ | ||
| 22 | message: `Failed to parse OpenAPI document: ${error instanceof Error ? error.message : String(error)}`, | ||
| 23 | error, | ||
| 24 | }), | ||
| 25 | }); | ||
| 26 | |||
| 27 | // Ensure it's OpenAPI 3.x (not Swagger 2) | ||
| 28 | if (!isOpenApi3(api)) { | ||
| 29 | return yield* new OpenApiExtractionErrorFromParse({ | ||
| 30 | message: | ||
| 31 | "Only OpenAPI 3.x documents are supported. Swagger 2.x documents should be converted first.", | ||
| 32 | }); | ||
| 33 | } | ||
| 34 | |||
| 35 | return api as DereferencedDocument; | ||
| 36 | }); | ||
| 37 | |||
| 38 | // --------------------------------------------------------------------------- | ||
| 39 | // Internals | ||
| 40 | // --------------------------------------------------------------------------- | ||
| 41 | |||
| 42 | import YAML from "yaml"; | ||
| 43 | import { OpenApiExtractionError } from "./errors"; | ||
| 44 | |||
| 45 | // swagger-parser's dereference needs a tagged error for this path | ||
| 46 | class OpenApiExtractionErrorFromParse extends OpenApiExtractionError {} | ||
| 47 | |||
| 48 | const isOpenApi3 = ( | ||
| 49 | doc: OpenAPI.Document, | ||
| 50 | ): doc is OpenAPIV3.Document | OpenAPIV3_1.Document => | ||
| 51 | "openapi" in doc && typeof doc.openapi === "string" && doc.openapi.startsWith("3."); | ||
| 52 | |||
| 53 | const parseTextToObject = (text: string): OpenAPI.Document => { | ||
| 54 | const trimmed = text.trim(); | ||
| 55 | if (trimmed.length === 0) throw new Error("OpenAPI document is empty"); | ||
| 56 | |||
| 57 | let parsed: unknown; | ||
| 58 | try { | ||
| 59 | parsed = JSON.parse(trimmed); | ||
| 60 | } catch { | ||
| 61 | parsed = YAML.parse(trimmed); | ||
| 62 | } | ||
| 63 | |||
| 64 | if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) { | ||
| 65 | throw new Error("OpenAPI document must parse to an object"); | ||
| 66 | } | ||
| 67 | |||
| 68 | return parsed as OpenAPI.Document; | ||
| 69 | }; | ||
| @@ -0,0 +1,125 @@ | |||
| 1 | import { Schema } from "effect"; | ||
| 2 | |||
| 3 | // --------------------------------------------------------------------------- | ||
| 4 | // Branded IDs | ||
| 5 | // --------------------------------------------------------------------------- | ||
| 6 | |||
| 7 | export const OperationId = Schema.String.pipe(Schema.brand("OperationId")); | ||
| 8 | export type OperationId = typeof OperationId.Type; | ||
| 9 | |||
| 10 | // --------------------------------------------------------------------------- | ||
| 11 | // Auth | ||
| 12 | // --------------------------------------------------------------------------- | ||
| 13 | |||
| 14 | export class NoAuth extends Schema.TaggedClass<NoAuth>()("NoAuth", {}) {} | ||
| 15 | |||
| 16 | export class BearerAuth extends Schema.TaggedClass<BearerAuth>()( | ||
| 17 | "BearerAuth", | ||
| 18 | { | ||
| 19 | token: Schema.String, | ||
| 20 | headerName: Schema.optionalWith(Schema.String, { default: () => "Authorization" }), | ||
| 21 | prefix: Schema.optionalWith(Schema.String, { default: () => "Bearer " }), | ||
| 22 | }, | ||
| 23 | ) {} | ||
| 24 | |||
| 25 | export class ApiKeyAuth extends Schema.TaggedClass<ApiKeyAuth>()( | ||
| 26 | "ApiKeyAuth", | ||
| 27 | { | ||
| 28 | name: Schema.String, | ||
| 29 | value: Schema.String, | ||
| 30 | in: Schema.Literal("header", "query", "cookie"), | ||
| 31 | }, | ||
| 32 | ) {} | ||
| 33 | |||
| 34 | export const AuthConfig = Schema.Union(NoAuth, BearerAuth, ApiKeyAuth); | ||
| 35 | export type AuthConfig = typeof AuthConfig.Type; | ||
| 36 | |||
| 37 | // --------------------------------------------------------------------------- | ||
| 38 | // HTTP | ||
| 39 | // --------------------------------------------------------------------------- | ||
| 40 | |||
| 41 | export const HttpMethod = Schema.Literal( | ||
| 42 | "get", "put", "post", "delete", "patch", "head", "options", "trace", | ||
| 43 | ); | ||
| 44 | export type HttpMethod = typeof HttpMethod.Type; | ||
| 45 | |||
| 46 | export const ParameterLocation = Schema.Literal("path", "query", "header", "cookie"); | ||
| 47 | export type ParameterLocation = typeof ParameterLocation.Type; | ||
| 48 | |||
| 49 | // --------------------------------------------------------------------------- | ||
| 50 | // Extracted operation | ||
| 51 | // --------------------------------------------------------------------------- | ||
| 52 | |||
| 53 | export class OperationParameter extends Schema.Class<OperationParameter>( | ||
| 54 | "OperationParameter", | ||
| 55 | )({ | ||
| 56 | name: Schema.String, | ||
| 57 | location: ParameterLocation, | ||
| 58 | required: Schema.Boolean, | ||
| 59 | schema: Schema.optionalWith(Schema.Unknown, { as: "Option" }), | ||
| 60 | style: Schema.optionalWith(Schema.String, { as: "Option" }), | ||
| 61 | explode: Schema.optionalWith(Schema.Boolean, { as: "Option" }), | ||
| 62 | allowReserved: Schema.optionalWith(Schema.Boolean, { as: "Option" }), | ||
| 63 | description: Schema.optionalWith(Schema.String, { as: "Option" }), | ||
| 64 | }) {} | ||
| 65 | |||
| 66 | export class OperationRequestBody extends Schema.Class<OperationRequestBody>( | ||
| 67 | "OperationRequestBody", | ||
| 68 | )({ | ||
| 69 | required: Schema.Boolean, | ||
| 70 | contentType: Schema.String, | ||
| 71 | schema: Schema.optionalWith(Schema.Unknown, { as: "Option" }), | ||
| 72 | }) {} | ||
| 73 | |||
| 74 | export class ExtractedOperation extends Schema.Class<ExtractedOperation>( | ||
| 75 | "ExtractedOperation", | ||
| 76 | )({ | ||
| 77 | operationId: OperationId, | ||
| 78 | method: HttpMethod, | ||
| 79 | pathTemplate: Schema.String, | ||
| 80 | summary: Schema.optionalWith(Schema.String, { as: "Option" }), | ||
| 81 | description: Schema.optionalWith(Schema.String, { as: "Option" }), | ||
| 82 | tags: Schema.Array(Schema.String), | ||
| 83 | parameters: Schema.Array(OperationParameter), | ||
| 84 | requestBody: Schema.optionalWith(OperationRequestBody, { as: "Option" }), | ||
| 85 | inputSchema: Schema.optionalWith(Schema.Unknown, { as: "Option" }), | ||
| 86 | outputSchema: Schema.optionalWith(Schema.Unknown, { as: "Option" }), | ||
| 87 | deprecated: Schema.optionalWith(Schema.Boolean, { default: () => false }), | ||
| 88 | }) {} | ||
| 89 | |||
| 90 | export class ServerInfo extends Schema.Class<ServerInfo>("ServerInfo")({ | ||
| 91 | url: Schema.String, | ||
| 92 | variables: Schema.optionalWith( | ||
| 93 | Schema.Record({ key: Schema.String, value: Schema.String }), | ||
| 94 | { as: "Option" }, | ||
| 95 | ), | ||
| 96 | }) {} | ||
| 97 | |||
| 98 | export class ExtractionResult extends Schema.Class<ExtractionResult>( | ||
| 99 | "ExtractionResult", | ||
| 100 | )({ | ||
| 101 | title: Schema.optionalWith(Schema.String, { as: "Option" }), | ||
| 102 | version: Schema.optionalWith(Schema.String, { as: "Option" }), | ||
| 103 | servers: Schema.Array(ServerInfo), | ||
| 104 | operations: Schema.Array(ExtractedOperation), | ||
| 105 | }) {} | ||
| 106 | |||
| 107 | // --------------------------------------------------------------------------- | ||
| 108 | // Invocation | ||
| 109 | // --------------------------------------------------------------------------- | ||
| 110 | |||
| 111 | export class InvocationConfig extends Schema.Class<InvocationConfig>( | ||
| 112 | "InvocationConfig", | ||
| 113 | )({ | ||
| 114 | baseUrl: Schema.String, | ||
| 115 | auth: AuthConfig, | ||
| 116 | }) {} | ||
| 117 | |||
| 118 | export class InvocationResult extends Schema.Class<InvocationResult>( | ||
| 119 | "InvocationResult", | ||
| 120 | )({ | ||
| 121 | status: Schema.Number, | ||
| 122 | headers: Schema.Record({ key: Schema.String, value: Schema.String }), | ||
| 123 | data: Schema.NullOr(Schema.Unknown), | ||
| 124 | error: Schema.NullOr(Schema.Unknown), | ||
| 125 | }) {} | ||
| @@ -0,0 +1,25 @@ | |||
| 1 | { | ||
| 2 | "compilerOptions": { | ||
| 3 | "target": "ES2022", | ||
| 4 | "module": "ESNext", | ||
| 5 | "moduleResolution": "Bundler", | ||
| 6 | "strict": true, | ||
| 7 | "skipLibCheck": true, | ||
| 8 | "noEmit": true, | ||
| 9 | "lib": ["ES2022"], | ||
| 10 | "types": ["bun-types", "node"], | ||
| 11 | "noUnusedLocals": true, | ||
| 12 | "noImplicitOverride": true, | ||
| 13 | "plugins": [ | ||
| 14 | { | ||
| 15 | "name": "@effect/language-service", | ||
| 16 | "diagnostics": { | ||
| 17 | "preferSchemaOverJson": "off" | ||
| 18 | } | ||
| 19 | } | ||
| 20 | ] | ||
| 21 | }, | ||
| 22 | "include": [ | ||
| 23 | "src/**/*.ts" | ||
| 24 | ] | ||
| 25 | } | ||