diff --git a/docs/API_REFERENCE_GENERATOR.md b/docs/API_REFERENCE_GENERATOR.md new file mode 100644 index 00000000..4b12ce9f --- /dev/null +++ b/docs/API_REFERENCE_GENERATOR.md @@ -0,0 +1,38 @@ +# API Reference Generator + +The SDK exports `ApiDocGenerator` for creating API references from TypeScript +source text and JSDoc comments. It can produce complete Markdown and HTML +documents, or a JSON manifest for integration with other documentation tools. + +```ts +import { ApiDocGenerator } from '@stellar-split/sdk'; + +const generator = new ApiDocGenerator({ + version: '1.2.0', + title: 'SDK API Reference', + sources: { + client: clientSourceText, + wallets: walletSourceText, + }, + categories: { + client: 'Core', + wallets: 'Wallets', + }, + includeDeprecated: false, +}); + +const markdown = generator.generate('markdown'); +const html = generator.generate('html'); +const manifest = generator.generate('json'); +``` + +`generate()` accepts `markdown`, `html`, or `json`. The JSON output is a +serialized `DocManifest` containing the SDK version, parsed entries, navigation +tree, and sorted entry index. `generateManifest()` returns that typed object +directly. `generateModuleMarkdown()`, `generateIndex()`, `search()`, and the +entry accessors are also available for custom documentation workflows. + +Sources are keyed by module name and should contain JSDoc comments immediately +before the declarations they describe. Supported metadata includes +`@param`, `@returns`, `@example`, `@deprecated`, and `@since`. Entries default +to the `General` category when no category mapping is provided. diff --git a/package-lock.json b/package-lock.json index cfedd158..d394aa01 100644 --- a/package-lock.json +++ b/package-lock.json @@ -49,7 +49,7 @@ "ts-node": "^10.9.2", "tsup": "^8.5.1", "tsx": "^4.23.1", - "typedoc": "^0.26.0", + "typedoc": "^0.28.20", "typedoc-plugin-markdown": "^4.0.0", "typescript": "^5.9.3", "vitest": "^1.6.1" @@ -1381,6 +1381,20 @@ "node": ">=18" } }, + "node_modules/@gerrit0/mini-shiki": { + "version": "3.23.0", + "resolved": "https://registry.npmjs.org/@gerrit0/mini-shiki/-/mini-shiki-3.23.0.tgz", + "integrity": "sha512-bEMORlG0cqdjVyCEuU0cDQbORWX+kYCeo0kV1lbxF5bt4r7SID2l9bqsxJEM0zndaxpOUT7riCyIVEuqq/Ynxg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@shikijs/engine-oniguruma": "^3.23.0", + "@shikijs/langs": "^3.23.0", + "@shikijs/themes": "^3.23.0", + "@shikijs/types": "^3.23.0", + "@shikijs/vscode-textmate": "^10.0.2" + } + }, "node_modules/@inquirer/checkbox": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/@inquirer/checkbox/-/checkbox-3.0.1.tgz", @@ -2340,79 +2354,52 @@ "dev": true, "license": "MIT" }, - "node_modules/@shikijs/core": { - "version": "1.29.2", - "resolved": "https://registry.npmjs.org/@shikijs/core/-/core-1.29.2.tgz", - "integrity": "sha512-vju0lY9r27jJfOY4Z7+Rt/nIOjzJpZ3y+nYpqtUZInVoXQ/TJZcfGnNOGnKjFdVZb8qexiCuSlZRKcGfhhTTZQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "@shikijs/engine-javascript": "1.29.2", - "@shikijs/engine-oniguruma": "1.29.2", - "@shikijs/types": "1.29.2", - "@shikijs/vscode-textmate": "^10.0.1", - "@types/hast": "^3.0.4", - "hast-util-to-html": "^9.0.4" - } - }, - "node_modules/@shikijs/engine-javascript": { - "version": "1.29.2", - "resolved": "https://registry.npmjs.org/@shikijs/engine-javascript/-/engine-javascript-1.29.2.tgz", - "integrity": "sha512-iNEZv4IrLYPv64Q6k7EPpOCE/nuvGiKl7zxdq0WFuRPF5PAE9PRo2JGq/d8crLusM59BRemJ4eOqrFrC4wiQ+A==", - "dev": true, - "license": "MIT", - "dependencies": { - "@shikijs/types": "1.29.2", - "@shikijs/vscode-textmate": "^10.0.1", - "oniguruma-to-es": "^2.2.0" - } - }, "node_modules/@shikijs/engine-oniguruma": { - "version": "1.29.2", - "resolved": "https://registry.npmjs.org/@shikijs/engine-oniguruma/-/engine-oniguruma-1.29.2.tgz", - "integrity": "sha512-7iiOx3SG8+g1MnlzZVDYiaeHe7Ez2Kf2HrJzdmGwkRisT7r4rak0e655AcM/tF9JG/kg5fMNYlLLKglbN7gBqA==", + "version": "3.23.0", + "resolved": "https://registry.npmjs.org/@shikijs/engine-oniguruma/-/engine-oniguruma-3.23.0.tgz", + "integrity": "sha512-1nWINwKXxKKLqPibT5f4pAFLej9oZzQTsby8942OTlsJzOBZ0MWKiwzMsd+jhzu8YPCHAswGnnN1YtQfirL35g==", "dev": true, "license": "MIT", "dependencies": { - "@shikijs/types": "1.29.2", - "@shikijs/vscode-textmate": "^10.0.1" + "@shikijs/types": "3.23.0", + "@shikijs/vscode-textmate": "^10.0.2" } }, "node_modules/@shikijs/langs": { - "version": "1.29.2", - "resolved": "https://registry.npmjs.org/@shikijs/langs/-/langs-1.29.2.tgz", - "integrity": "sha512-FIBA7N3LZ+223U7cJDUYd5shmciFQlYkFXlkKVaHsCPgfVLiO+e12FmQE6Tf9vuyEsFe3dIl8qGWKXgEHL9wmQ==", + "version": "3.23.0", + "resolved": "https://registry.npmjs.org/@shikijs/langs/-/langs-3.23.0.tgz", + "integrity": "sha512-2Ep4W3Re5aB1/62RSYQInK9mM3HsLeB91cHqznAJMuylqjzNVAVCMnNWRHFtcNHXsoNRayP9z1qj4Sq3nMqYXg==", "dev": true, "license": "MIT", "dependencies": { - "@shikijs/types": "1.29.2" + "@shikijs/types": "3.23.0" } }, "node_modules/@shikijs/themes": { - "version": "1.29.2", - "resolved": "https://registry.npmjs.org/@shikijs/themes/-/themes-1.29.2.tgz", - "integrity": "sha512-i9TNZlsq4uoyqSbluIcZkmPL9Bfi3djVxRnofUHwvx/h6SRW3cwgBC5SML7vsDcWyukY0eCzVN980rqP6qNl9g==", + "version": "3.23.0", + "resolved": "https://registry.npmjs.org/@shikijs/themes/-/themes-3.23.0.tgz", + "integrity": "sha512-5qySYa1ZgAT18HR/ypENL9cUSGOeI2x+4IvYJu4JgVJdizn6kG4ia5Q1jDEOi7gTbN4RbuYtmHh0W3eccOrjMA==", "dev": true, "license": "MIT", "dependencies": { - "@shikijs/types": "1.29.2" + "@shikijs/types": "3.23.0" } }, "node_modules/@shikijs/types": { - "version": "1.29.2", - "resolved": "https://registry.npmjs.org/@shikijs/types/-/types-1.29.2.tgz", - "integrity": "sha512-VJjK0eIijTZf0QSTODEXCqinjBn0joAHQ+aPSBzrv4O2d/QSbsMw+ZeSRx03kV34Hy7NzUvV/7NqfYGRLrASmw==", + "version": "3.23.0", + "resolved": "https://registry.npmjs.org/@shikijs/types/-/types-3.23.0.tgz", + "integrity": "sha512-3JZ5HXOZfYjsYSk0yPwBrkupyYSLpAE26Qc0HLghhZNGTZg/SKxXIIgoxOpmmeQP0RRSDJTk1/vPfw9tbw+jSQ==", "dev": true, "license": "MIT", "dependencies": { - "@shikijs/vscode-textmate": "^10.0.1", + "@shikijs/vscode-textmate": "^10.0.2", "@types/hast": "^3.0.4" } }, "node_modules/@shikijs/vscode-textmate": { - "version": "10.0.2", - "resolved": "https://registry.npmjs.org/@shikijs/vscode-textmate/-/vscode-textmate-10.0.2.tgz", - "integrity": "sha512-83yeghZ2xxin3Nj8z1NMd/NCuca+gsYXswywDy5bHvwlWL8tpTQmzGeUuHd9FC3E/SBEMvzJRwWEOz5gGes9Qg==", + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/@shikijs/vscode-textmate/-/vscode-textmate-10.1.0.tgz", + "integrity": "sha512-cVBuhDQjBZaNMTwBquYfPydrUP+E3hE6oYGasx8h6ZrODIM7/r+gxLDXdd66oszbrggZHEntdE6j+5gYIVyMWQ==", "dev": true, "license": "MIT" }, @@ -3309,6 +3296,51 @@ "dev": true, "license": "0BSD" }, + "node_modules/@testing-library/dom": { + "version": "10.4.2", + "resolved": "https://registry.npmjs.org/@testing-library/dom/-/dom-10.4.2.tgz", + "integrity": "sha512-yzr2S9HyAIdhz2/6qHgbs665Q7PKVcDF05vsOlHPxG1mo36gKVesdYVeDLnXgfjJ03CrKRk08knc6+E/9m8v2Q==", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "@babel/code-frame": "^7.10.4", + "@babel/runtime": "^7.12.5", + "@types/aria-query": "^5.0.1", + "aria-query": "5.3.0", + "dom-accessibility-api": "^0.5.9", + "lz-string": "^1.5.0", + "picocolors": "1.1.1", + "pretty-format": "^27.0.2" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/@testing-library/dom/node_modules/pretty-format": { + "version": "27.5.1", + "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-27.5.1.tgz", + "integrity": "sha512-Qb1gy5OrP5+zDf2Bvnzdl3jsTf1qXVMazbvCoKhtKqVs4/YK4ozX4gKQJJVyNe+cajNPn0KoC0MC3FUmaHWEmQ==", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "ansi-regex": "^5.0.1", + "ansi-styles": "^5.0.0", + "react-is": "^17.0.1" + }, + "engines": { + "node": "^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0" + } + }, + "node_modules/@testing-library/dom/node_modules/react-is": { + "version": "17.0.2", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz", + "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==", + "dev": true, + "license": "MIT", + "peer": true + }, "node_modules/@testing-library/jest-dom": { "version": "6.9.1", "resolved": "https://registry.npmjs.org/@testing-library/jest-dom/-/jest-dom-6.9.1.tgz", @@ -3418,6 +3450,14 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/aria-query": { + "version": "5.0.4", + "resolved": "https://registry.npmjs.org/@types/aria-query/-/aria-query-5.0.4.tgz", + "integrity": "sha512-rfT93uj5s0PRL7EzccGMs3brplhcrghnDoV26NqKhCAS1hVo+WdNsPvE/yb6ilfr5hi2MEk6d5EWJTKdxg8jVw==", + "dev": true, + "license": "MIT", + "peer": true + }, "node_modules/@types/body-parser": { "version": "1.19.6", "resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.6.tgz", @@ -3486,16 +3526,6 @@ "dev": true, "license": "MIT" }, - "node_modules/@types/mdast": { - "version": "4.0.4", - "resolved": "https://registry.npmjs.org/@types/mdast/-/mdast-4.0.4.tgz", - "integrity": "sha512-kGaNbPh1k7AFzgpud/gMdvIm5xuECykRR+JnWKQno9TAXVa6WIVCGTPvYGekIDL4uwCZQSYbUxNBSb1aUo79oA==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/unist": "*" - } - }, "node_modules/@types/mute-stream": { "version": "0.0.4", "resolved": "https://registry.npmjs.org/@types/mute-stream/-/mute-stream-0.0.4.tgz", @@ -3585,13 +3615,6 @@ "dev": true, "license": "MIT" }, - "node_modules/@ungap/structured-clone": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/@ungap/structured-clone/-/structured-clone-1.4.0.tgz", - "integrity": "sha512-1mEZtMKPM09vDmQt5y7YvmN2+DFTP7Tg0EWXdic8/C6VRnpb33e4ghisCIE3WZjsE2N8mf+QV1Zqh7ZFYLWInQ==", - "dev": true, - "license": "ISC" - }, "node_modules/@vitest/coverage-v8": { "version": "1.6.1", "resolved": "https://registry.npmjs.org/@vitest/coverage-v8/-/coverage-v8-1.6.1.tgz", @@ -4519,17 +4542,6 @@ ], "license": "CC-BY-4.0" }, - "node_modules/ccount": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/ccount/-/ccount-2.0.1.tgz", - "integrity": "sha512-eyrF0jiFpY+3drT6383f1qhkbGsLSifNAjA61IUjZjmLCWjItY6LB9ft9YhoDgwfmclB2zhu51Lc7+95b8NRAg==", - "dev": true, - "license": "MIT", - "funding": { - "type": "github", - "url": "https://github.com/sponsors/wooorm" - } - }, "node_modules/chai": { "version": "4.5.0", "dev": true, @@ -4560,28 +4572,6 @@ "url": "https://github.com/chalk/chalk?sponsor=1" } }, - "node_modules/character-entities-html4": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/character-entities-html4/-/character-entities-html4-2.1.0.tgz", - "integrity": "sha512-1v7fgQRj6hnSwFpq1Eu0ynr/CDEw0rXo2B61qXrLNdHZmPKgb7fqS1a2JwF0rISo9q77jDI8VMEHoApn8qDoZA==", - "dev": true, - "license": "MIT", - "funding": { - "type": "github", - "url": "https://github.com/sponsors/wooorm" - } - }, - "node_modules/character-entities-legacy": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/character-entities-legacy/-/character-entities-legacy-3.0.0.tgz", - "integrity": "sha512-RpPp0asT/6ufRm//AJVwpViZbGM/MkjQFxJccQRHmISF/22NBtsHqAWmL+/pmkPWoIUJdWyeVleTl1wydHATVQ==", - "dev": true, - "license": "MIT", - "funding": { - "type": "github", - "url": "https://github.com/sponsors/wooorm" - } - }, "node_modules/chardet": { "version": "0.7.0", "resolved": "https://registry.npmjs.org/chardet/-/chardet-0.7.0.tgz", @@ -4660,17 +4650,6 @@ "node": ">= 0.8" } }, - "node_modules/comma-separated-tokens": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/comma-separated-tokens/-/comma-separated-tokens-2.0.3.tgz", - "integrity": "sha512-Fu4hJdvzeylCfQPp9SGWidpzrMs7tTrlu6Vb8XGaRGck8QSNZJJp538Wrb60Lax4fPwR64ViY468OIUTbRlGZg==", - "dev": true, - "license": "MIT", - "funding": { - "type": "github", - "url": "https://github.com/sponsors/wooorm" - } - }, "node_modules/commander": { "version": "11.1.0", "resolved": "https://registry.npmjs.org/commander/-/commander-11.1.0.tgz", @@ -4878,20 +4857,6 @@ "integrity": "sha512-53rsFbGdwMwlF7qvCt0ypLM5V5/Mbl0szB7GPN8y9NCcbknYOeVVXdrXEq+90IwAfrrzt6Hd+u2E2ntakICU8w==", "license": "MIT" }, - "node_modules/devlop": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/devlop/-/devlop-1.1.0.tgz", - "integrity": "sha512-RWmIqhcFf1lRYBvNmr7qTNuyCt/7/ns2jbpp1+PalgE/rDQcBT0fioSMUpJ93irlUhC5hrg4cYqe6U+0ImW0rA==", - "dev": true, - "license": "MIT", - "dependencies": { - "dequal": "^2.0.0" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/wooorm" - } - }, "node_modules/diff": { "version": "4.0.4", "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.4.tgz", @@ -4917,6 +4882,14 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/dom-accessibility-api": { + "version": "0.5.16", + "resolved": "https://registry.npmjs.org/dom-accessibility-api/-/dom-accessibility-api-0.5.16.tgz", + "integrity": "sha512-X7BJ2yElsnOJ30pZF4uIIDfBEVgF4XEBxL9Bxhy6dnrm5hkzqmsWHGTiHqRiITNhMyFLyAiWndIJP7Z1NTteDg==", + "dev": true, + "license": "MIT", + "peer": true + }, "node_modules/dunder-proto": { "version": "1.0.1", "license": "MIT", @@ -4943,13 +4916,6 @@ "dev": true, "license": "MIT" }, - "node_modules/emoji-regex-xs": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/emoji-regex-xs/-/emoji-regex-xs-1.0.0.tgz", - "integrity": "sha512-LRlerrMYoIDrT6jgpeZ2YYl/L8EulRTt5hQcYjy5AInh7HWXKimpqx68aknBFpGL2+/IcogTcaydJEgaTmOpDg==", - "dev": true, - "license": "MIT" - }, "node_modules/entities": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/entities/-/entities-8.0.0.tgz", @@ -5566,44 +5532,6 @@ "node": ">= 0.4" } }, - "node_modules/hast-util-to-html": { - "version": "9.0.5", - "resolved": "https://registry.npmjs.org/hast-util-to-html/-/hast-util-to-html-9.0.5.tgz", - "integrity": "sha512-OguPdidb+fbHQSU4Q4ZiLKnzWo8Wwsf5bZfbvu7//a9oTYoqD/fWpe96NuHkoS9h0ccGOTe0C4NGXdtS0iObOw==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/hast": "^3.0.0", - "@types/unist": "^3.0.0", - "ccount": "^2.0.0", - "comma-separated-tokens": "^2.0.0", - "hast-util-whitespace": "^3.0.0", - "html-void-elements": "^3.0.0", - "mdast-util-to-hast": "^13.0.0", - "property-information": "^7.0.0", - "space-separated-tokens": "^2.0.0", - "stringify-entities": "^4.0.0", - "zwitch": "^2.0.4" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/unified" - } - }, - "node_modules/hast-util-whitespace": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/hast-util-whitespace/-/hast-util-whitespace-3.0.0.tgz", - "integrity": "sha512-88JUN06ipLwsnv+dVn+OIYOvAuvBMy/Qoi6O7mQHxdPXpjy+Cd6xRkWwux7DKO+4sYILtLBRIKgsdpS2gQc7qw==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/hast": "^3.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/unified" - } - }, "node_modules/html-encoding-sniffer": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/html-encoding-sniffer/-/html-encoding-sniffer-6.0.0.tgz", @@ -5635,6 +5563,21 @@ } } }, + "node_modules/html-encoding-sniffer/node_modules/@noble/hashes": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-2.4.0.tgz", + "integrity": "sha512-X5XaVWZIBCT7HHZGm5I7ZQXDwLG+bGXuSrMQAW+7Zvl87h1kmc1ZB1VSRJcpUfoUrGQp4Fkoxm5kZ+Ms+aW+eA==", + "dev": true, + "license": "MIT", + "optional": true, + "peer": true, + "engines": { + "node": ">= 20.19.0" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, "node_modules/html-escaper": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-2.0.2.tgz", @@ -5642,17 +5585,6 @@ "dev": true, "license": "MIT" }, - "node_modules/html-void-elements": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/html-void-elements/-/html-void-elements-3.0.0.tgz", - "integrity": "sha512-bEqo66MRXsUGxWHV5IP0PUiAWwoEjba4VCzg0LjFJBpchPaTfyfCKTG6bc5F8ucKec3q5y6qOdGyYTSBEvhCrg==", - "dev": true, - "license": "MIT", - "funding": { - "type": "github", - "url": "https://github.com/sponsors/wooorm" - } - }, "node_modules/https-proxy-agent": { "version": "5.0.1", "license": "MIT", @@ -6003,6 +5935,21 @@ } } }, + "node_modules/jsdom/node_modules/@noble/hashes": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-2.4.0.tgz", + "integrity": "sha512-X5XaVWZIBCT7HHZGm5I7ZQXDwLG+bGXuSrMQAW+7Zvl87h1kmc1ZB1VSRJcpUfoUrGQp4Fkoxm5kZ+Ms+aW+eA==", + "dev": true, + "license": "MIT", + "optional": true, + "peer": true, + "engines": { + "node": ">= 20.19.0" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, "node_modules/jsesc": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-3.1.0.tgz", @@ -6130,6 +6077,17 @@ "dev": true, "license": "MIT" }, + "node_modules/lz-string": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/lz-string/-/lz-string-1.5.0.tgz", + "integrity": "sha512-h5bgJWpxJNswbU7qCrV0tIKQCaS3blPDrqKWx+QxzuzL1zGUzij9XCWLrSLsJPu5t+eWA/ycetzYAO5IOMcWAQ==", + "dev": true, + "license": "MIT", + "peer": true, + "bin": { + "lz-string": "bin/bin.js" + } + }, "node_modules/magic-string": { "version": "0.30.21", "dev": true, @@ -6221,28 +6179,6 @@ "node": ">= 0.4" } }, - "node_modules/mdast-util-to-hast": { - "version": "13.2.1", - "resolved": "https://registry.npmjs.org/mdast-util-to-hast/-/mdast-util-to-hast-13.2.1.tgz", - "integrity": "sha512-cctsq2wp5vTsLIcaymblUriiTcZd0CwWtCbLvrOzYCDZoWyMNV8sZ7krj09FSnsiJi3WVsHLM4k6Dq/yaPyCXA==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/hast": "^3.0.0", - "@types/mdast": "^4.0.0", - "@ungap/structured-clone": "^1.0.0", - "devlop": "^1.0.0", - "micromark-util-sanitize-uri": "^2.0.0", - "trim-lines": "^3.0.0", - "unist-util-position": "^5.0.0", - "unist-util-visit": "^5.0.0", - "vfile": "^6.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/unified" - } - }, "node_modules/mdn-data": { "version": "2.27.1", "resolved": "https://registry.npmjs.org/mdn-data/-/mdn-data-2.27.1.tgz", @@ -6271,100 +6207,6 @@ "node": ">= 8" } }, - "node_modules/micromark-util-character": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/micromark-util-character/-/micromark-util-character-2.1.1.tgz", - "integrity": "sha512-wv8tdUTJ3thSFFFJKtpYKOYiGP2+v96Hvk4Tu8KpCAsTMs6yi+nVmGh1syvSCsaxz45J6Jbw+9DD6g97+NV67Q==", - "dev": true, - "funding": [ - { - "type": "GitHub Sponsors", - "url": "https://github.com/sponsors/unifiedjs" - }, - { - "type": "OpenCollective", - "url": "https://opencollective.com/unified" - } - ], - "license": "MIT", - "dependencies": { - "micromark-util-symbol": "^2.0.0", - "micromark-util-types": "^2.0.0" - } - }, - "node_modules/micromark-util-encode": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/micromark-util-encode/-/micromark-util-encode-2.0.1.tgz", - "integrity": "sha512-c3cVx2y4KqUnwopcO9b/SCdo2O67LwJJ/UyqGfbigahfegL9myoEFoDYZgkT7f36T0bLrM9hZTAaAyH+PCAXjw==", - "dev": true, - "funding": [ - { - "type": "GitHub Sponsors", - "url": "https://github.com/sponsors/unifiedjs" - }, - { - "type": "OpenCollective", - "url": "https://opencollective.com/unified" - } - ], - "license": "MIT" - }, - "node_modules/micromark-util-sanitize-uri": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/micromark-util-sanitize-uri/-/micromark-util-sanitize-uri-2.0.1.tgz", - "integrity": "sha512-9N9IomZ/YuGGZZmQec1MbgxtlgougxTodVwDzzEouPKo3qFWvymFHWcnDi2vzV1ff6kas9ucW+o3yzJK9YB1AQ==", - "dev": true, - "funding": [ - { - "type": "GitHub Sponsors", - "url": "https://github.com/sponsors/unifiedjs" - }, - { - "type": "OpenCollective", - "url": "https://opencollective.com/unified" - } - ], - "license": "MIT", - "dependencies": { - "micromark-util-character": "^2.0.0", - "micromark-util-encode": "^2.0.0", - "micromark-util-symbol": "^2.0.0" - } - }, - "node_modules/micromark-util-symbol": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/micromark-util-symbol/-/micromark-util-symbol-2.0.1.tgz", - "integrity": "sha512-vs5t8Apaud9N28kgCrRUdEed4UJ+wWNvicHLPxCa9ENlYuAY31M0ETy5y1vA33YoNPDFTghEbnh6efaE8h4x0Q==", - "dev": true, - "funding": [ - { - "type": "GitHub Sponsors", - "url": "https://github.com/sponsors/unifiedjs" - }, - { - "type": "OpenCollective", - "url": "https://opencollective.com/unified" - } - ], - "license": "MIT" - }, - "node_modules/micromark-util-types": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/micromark-util-types/-/micromark-util-types-2.0.3.tgz", - "integrity": "sha512-oxB2Ik03hI0gv+VNn9tnh1t1YEe9MDPptViAEgfdf3YQHsn0pzGTgCdlSCJXcwhqm8phaEuM7zeEu3QQzVBrPg==", - "dev": true, - "funding": [ - { - "type": "GitHub Sponsors", - "url": "https://github.com/sponsors/unifiedjs" - }, - { - "type": "OpenCollective", - "url": "https://opencollective.com/unified" - } - ], - "license": "MIT" - }, "node_modules/micromatch": { "version": "4.0.8", "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz", @@ -6678,18 +6520,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/oniguruma-to-es": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/oniguruma-to-es/-/oniguruma-to-es-2.3.0.tgz", - "integrity": "sha512-bwALDxriqfKGfUufKGGepCzu9x7nJQuoRoAFp4AnwehhC2crqrDIAP/uN2qdlsAvSMpeRC3+Yzhqc7hLmle5+g==", - "dev": true, - "license": "MIT", - "dependencies": { - "emoji-regex-xs": "^1.0.0", - "regex": "^5.1.1", - "regex-recursion": "^5.1.1" - } - }, "node_modules/os-tmpdir": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", @@ -7035,17 +6865,6 @@ "node": ">=0.4.0" } }, - "node_modules/property-information": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/property-information/-/property-information-7.2.0.tgz", - "integrity": "sha512-IAtzIB6sUiWaJYrX9smp3V46pBGbBeLFRGdh25kg1334VcBlD8HzhPeNIWQH9zhGmo2itIe25EHt9dQP7G5hmg==", - "dev": true, - "license": "MIT", - "funding": { - "type": "github", - "url": "https://github.com/sponsors/wooorm" - } - }, "node_modules/proxy-from-env": { "version": "2.1.0", "license": "MIT", @@ -7209,34 +7028,6 @@ "node": ">=8" } }, - "node_modules/regex": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/regex/-/regex-5.1.1.tgz", - "integrity": "sha512-dN5I359AVGPnwzJm2jN1k0W9LPZ+ePvoOeVMMfqIMFz53sSwXkxaJoxr50ptnsC771lK95BnTrVSZxq0b9yCGw==", - "dev": true, - "license": "MIT", - "dependencies": { - "regex-utilities": "^2.3.0" - } - }, - "node_modules/regex-recursion": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/regex-recursion/-/regex-recursion-5.1.1.tgz", - "integrity": "sha512-ae7SBCbzVNrIjgSbh7wMznPcQel1DNlDtzensnFxpiNpXt1U2ju/bHugH422r+4LAVS1FpW1YCwilmnNsjum9w==", - "dev": true, - "license": "MIT", - "dependencies": { - "regex": "^5.1.1", - "regex-utilities": "^2.3.0" - } - }, - "node_modules/regex-utilities": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/regex-utilities/-/regex-utilities-2.3.0.tgz", - "integrity": "sha512-8VhliFJAWRaUiVvREIiW2NXXTmHs4vMNnSzuJVhscgmGav3g9VDxLrQndI3dZZVVdp0ZO/5v0xmX516/7M9cng==", - "dev": true, - "license": "MIT" - }, "node_modules/require-addon": { "version": "1.2.0", "license": "Apache-2.0", @@ -7465,23 +7256,6 @@ "node": ">=8" } }, - "node_modules/shiki": { - "version": "1.29.2", - "resolved": "https://registry.npmjs.org/shiki/-/shiki-1.29.2.tgz", - "integrity": "sha512-njXuliz/cP+67jU2hukkxCNuH1yUi4QfdZZY+sMr5PPrIyXSu5iTb/qYC4BiWWB0vZ+7TbdvYUCeL23zpwCfbg==", - "dev": true, - "license": "MIT", - "dependencies": { - "@shikijs/core": "1.29.2", - "@shikijs/engine-javascript": "1.29.2", - "@shikijs/engine-oniguruma": "1.29.2", - "@shikijs/langs": "1.29.2", - "@shikijs/themes": "1.29.2", - "@shikijs/types": "1.29.2", - "@shikijs/vscode-textmate": "^10.0.1", - "@types/hast": "^3.0.4" - } - }, "node_modules/side-channel": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.1.tgz", @@ -7641,17 +7415,6 @@ "node": ">=0.10.0" } }, - "node_modules/space-separated-tokens": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/space-separated-tokens/-/space-separated-tokens-2.0.2.tgz", - "integrity": "sha512-PEGlAwrG8yXGXRjW32fGbg66JAlOAwbObuqVoJpv/mRgoWDQfgH1wDPvtzWyUSNAXBGSk8h755YDbbcEy3SH2Q==", - "dev": true, - "license": "MIT", - "funding": { - "type": "github", - "url": "https://github.com/sponsors/wooorm" - } - }, "node_modules/split2": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/split2/-/split2-4.2.0.tgz", @@ -7693,21 +7456,6 @@ "dev": true, "license": "MIT" }, - "node_modules/stringify-entities": { - "version": "4.0.4", - "resolved": "https://registry.npmjs.org/stringify-entities/-/stringify-entities-4.0.4.tgz", - "integrity": "sha512-IwfBptatlO+QCJUo19AqvrPNqlVMpW9YEL2LIVY+Rpv2qsjCGxaDLNRgeGsQWJhfItebuJhsGSLjaBbNSQ+ieg==", - "dev": true, - "license": "MIT", - "dependencies": { - "character-entities-html4": "^2.0.0", - "character-entities-legacy": "^3.0.0" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/wooorm" - } - }, "node_modules/strip-ansi": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", @@ -8010,17 +7758,6 @@ "tree-kill": "cli.js" } }, - "node_modules/trim-lines": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/trim-lines/-/trim-lines-3.0.1.tgz", - "integrity": "sha512-kRj8B+YHZCc9kQYdWfJB2/oUl9rA99qbowYYBtr4ui4mZyAQ2JpvVBd/6U2YloATfqBhBTSMhTpgBHtU0Mf3Rg==", - "dev": true, - "license": "MIT", - "funding": { - "type": "github", - "url": "https://github.com/sponsors/wooorm" - } - }, "node_modules/ts-interface-checker": { "version": "0.1.13", "dev": true, @@ -8716,26 +8453,27 @@ } }, "node_modules/typedoc": { - "version": "0.26.11", - "resolved": "https://registry.npmjs.org/typedoc/-/typedoc-0.26.11.tgz", - "integrity": "sha512-sFEgRRtrcDl2FxVP58Ze++ZK2UQAEvtvvH8rRlig1Ja3o7dDaMHmaBfvJmdGnNEFaLTpQsN8dpvZaTqJSu/Ugw==", + "version": "0.28.20", + "resolved": "https://registry.npmjs.org/typedoc/-/typedoc-0.28.20.tgz", + "integrity": "sha512-uSKqkh8Cr48vllnEy+jdaAgOeR6Y+QCBW7usgUsKj7gJEfR7stw9U/fE49LBnj2tPRKPY0c0EBJSWe9Appmplg==", "dev": true, "license": "Apache-2.0", "dependencies": { + "@gerrit0/mini-shiki": "^3.23.0", "lunr": "^2.3.9", - "markdown-it": "^14.1.0", - "minimatch": "^9.0.5", - "shiki": "^1.16.2", - "yaml": "^2.5.1" + "markdown-it": "^14.3.0", + "minimatch": "^10.2.5", + "yaml": "^2.9.0" }, "bin": { "typedoc": "bin/typedoc" }, "engines": { - "node": ">= 18" + "node": ">= 18", + "pnpm": ">= 10" }, "peerDependencies": { - "typescript": "4.6.x || 4.7.x || 4.8.x || 4.9.x || 5.0.x || 5.1.x || 5.2.x || 5.3.x || 5.4.x || 5.5.x || 5.6.x" + "typescript": "5.0.x || 5.1.x || 5.2.x || 5.3.x || 5.4.x || 5.5.x || 5.6.x || 5.7.x || 5.8.x || 5.9.x || 6.0.x" } }, "node_modules/typedoc-plugin-markdown": { @@ -8751,11 +8489,50 @@ "typedoc": "0.28.x" } }, + "node_modules/typedoc/node_modules/balanced-match": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-4.0.4.tgz", + "integrity": "sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA==", + "dev": true, + "license": "MIT", + "engines": { + "node": "18 || 20 || >=22" + } + }, + "node_modules/typedoc/node_modules/brace-expansion": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.1.0.tgz", + "integrity": "sha512-aa11Dv491GKnYqxaul3aRJ0szew7yMJMfZPnqD44NjGrZXoj62l41OEDDpdpC4eE2P88vBFfLuSyRhpG91NUvg==", + "dev": true, + "license": "MIT", + "dependencies": { + "balanced-match": "^4.0.2" + }, + "engines": { + "node": "20 || >=22" + } + }, + "node_modules/typedoc/node_modules/minimatch": { + "version": "10.2.6", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.2.6.tgz", + "integrity": "sha512-vpLQEs+VLCr1nU0BXS07maYoFwlDAH0gngQuuttxIwutDFEMHq2blX+8vpgxDdK3J1PwjCJiep77OitTZ4Ll1A==", + "dev": true, + "license": "BlueOak-1.0.0", + "dependencies": { + "brace-expansion": "^5.0.8" + }, + "engines": { + "node": "18 || 20 || >=22" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/typescript": { "version": "5.9.3", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", - "dev": true, + "devOptional": true, "license": "Apache-2.0", "bin": { "tsc": "bin/tsc", @@ -8827,79 +8604,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/unist-util-is": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/unist-util-is/-/unist-util-is-6.0.1.tgz", - "integrity": "sha512-LsiILbtBETkDz8I9p1dQ0uyRUWuaQzd/cuEeS1hoRSyW5E5XGmTzlwY1OrNzzakGowI9Dr/I8HVaw4hTtnxy8g==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/unist": "^3.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/unified" - } - }, - "node_modules/unist-util-position": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/unist-util-position/-/unist-util-position-5.0.0.tgz", - "integrity": "sha512-fucsC7HjXvkB5R3kTCO7kUjRdrS0BJt3M/FPxmHMBOm8JQi2BsHAHFsy27E0EolP8rp0NzXsJ+jNPyDWvOJZPA==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/unist": "^3.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/unified" - } - }, - "node_modules/unist-util-stringify-position": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/unist-util-stringify-position/-/unist-util-stringify-position-4.0.0.tgz", - "integrity": "sha512-0ASV06AAoKCDkS2+xw5RXJywruurpbC4JZSm7nr7MOt1ojAzvyyaO+UxZf18j8FCF6kmzCZKcAgN/yu2gm2XgQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/unist": "^3.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/unified" - } - }, - "node_modules/unist-util-visit": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/unist-util-visit/-/unist-util-visit-5.1.0.tgz", - "integrity": "sha512-m+vIdyeCOpdr/QeQCu2EzxX/ohgS8KbnPDgFni4dQsfSCtpz8UqDyY5GjRru8PDKuYn7Fq19j1CQ+nJSsGKOzg==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/unist": "^3.0.0", - "unist-util-is": "^6.0.0", - "unist-util-visit-parents": "^6.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/unified" - } - }, - "node_modules/unist-util-visit-parents": { - "version": "6.0.2", - "resolved": "https://registry.npmjs.org/unist-util-visit-parents/-/unist-util-visit-parents-6.0.2.tgz", - "integrity": "sha512-goh1s1TBrqSqukSc8wrjwWhL0hiJxgA8m4kFxGlQ+8FYQ3C/m11FcTs4YYem7V664AhHVvgoQLk890Ssdsr2IQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/unist": "^3.0.0", - "unist-util-is": "^6.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/unified" - } - }, "node_modules/unstorage": { "version": "1.17.5", "resolved": "https://registry.npmjs.org/unstorage/-/unstorage-1.17.5.tgz", @@ -9066,36 +8770,6 @@ "dev": true, "license": "MIT" }, - "node_modules/vfile": { - "version": "6.0.3", - "resolved": "https://registry.npmjs.org/vfile/-/vfile-6.0.3.tgz", - "integrity": "sha512-KzIbH/9tXat2u30jf+smMwFCsno4wHVdNmzFyL+T/L3UGqqk6JKfVqOFOZEpZSHADH1k40ab6NUIXZq422ov3Q==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/unist": "^3.0.0", - "vfile-message": "^4.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/unified" - } - }, - "node_modules/vfile-message": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/vfile-message/-/vfile-message-4.0.3.tgz", - "integrity": "sha512-QTHzsGd1EhbZs4AsQ20JX1rC3cOlt/IWJruk893DfLRr57lcnOeMaWG4K0JrRta4mIJZKth2Au3mM3u03/JWKw==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/unist": "^3.0.0", - "unist-util-stringify-position": "^4.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/unified" - } - }, "node_modules/vite": { "version": "5.4.21", "dev": true, @@ -9750,6 +9424,21 @@ } } }, + "node_modules/whatwg-url/node_modules/@noble/hashes": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-2.4.0.tgz", + "integrity": "sha512-X5XaVWZIBCT7HHZGm5I7ZQXDwLG+bGXuSrMQAW+7Zvl87h1kmc1ZB1VSRJcpUfoUrGQp4Fkoxm5kZ+Ms+aW+eA==", + "dev": true, + "license": "MIT", + "optional": true, + "peer": true, + "engines": { + "node": ">= 20.19.0" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, "node_modules/which": { "version": "2.0.2", "dev": true, @@ -9943,17 +9632,6 @@ "funding": { "url": "https://github.com/sponsors/sindresorhus" } - }, - "node_modules/zwitch": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/zwitch/-/zwitch-2.0.4.tgz", - "integrity": "sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==", - "dev": true, - "license": "MIT", - "funding": { - "type": "github", - "url": "https://github.com/sponsors/wooorm" - } } } } diff --git a/package.json b/package.json index 506f3c5f..4f10e48f 100644 --- a/package.json +++ b/package.json @@ -118,7 +118,7 @@ "ts-node": "^10.9.2", "tsup": "^8.5.1", "tsx": "^4.23.1", - "typedoc": "^0.26.0", + "typedoc": "^0.28.20", "typedoc-plugin-markdown": "^4.0.0", "typescript": "^5.9.3", "vitest": "^1.6.1" diff --git a/src/__tests__/priceOracle.test.ts b/src/__tests__/priceOracle.test.ts index 44d23f73..1c1a7dd2 100644 --- a/src/__tests__/priceOracle.test.ts +++ b/src/__tests__/priceOracle.test.ts @@ -1,114 +1,18 @@ -import { - PriceOracle, - parseOraclePrice, - type OraclePrice, - type OracleProvider, -} from "../priceOracle"; +import { beforeEach, describe, expect, it, vi } from "vitest"; +import { PriceOracle, parseOraclePrice, type OracleProvider } from "../priceOracle.js"; describe("parseOraclePrice", () => { it("parses a numeric price and timestamp", () => { const result = parseOraclePrice("XLM", { price: 0.42, timestamp: 1700000000000 }); expect(result).toEqual({ symbol: "XLM", price: 0.42, timestamp: 1700000000000 }); }); - -/** - * Property-based tests for the PriceOracle. - * - * fast-check provides generators (arbitraries) and integrated shrinking, so - * failing cases are automatically minimized to the smallest counterexample. - */ - -// --- Generators ------------------------------------------------------------- - -// A valid positive price (finite, > 0). -const priceArb = fc.double({ min: 0.000001, max: 1_000_000, noNaN: true, noDefaultInfinity: true }); - -// A non-negative weight used when combining sources. -const weightArb = fc.double({ min: 0, max: 100, noNaN: true, noDefaultInfinity: true }); - -// A timestamp in a sane range (ms since epoch). -const timestampArb = fc.integer({ min: 0, max: 4_102_444_800_000 }); - -// A single price observation. -const observationArb = fc.record({ - price: priceArb, - weight: weightArb, - timestamp: timestampArb, -}); - -// A non-empty list of observations. -const observationsArb = fc.array(observationArb, { minLength: 1, maxLength: 20 }); - -// --- Properties ------------------------------------------------------------- - -describe('PriceOracle property-based tests', () => { - it('weighted average always lies within the min/max of the inputs', () => { - fc.assert( - fc.property(observationsArb, (observations) => { - const result = PriceOracle.weightedAverage(observations); - const prices = observations.map((o) => o.price); - const min = Math.min(...prices); - const max = Math.max(...prices); - expect(result).toBeGreaterThanOrEqual(min - 1e-9); - expect(result).toBeLessThanOrEqual(max + 1e-9); - }), - ); - }); - - it('weighted average is order-independent', () => { - fc.assert( - fc.property(observationsArb, (observations) => { - const forward = PriceOracle.weightedAverage(observations); - const reversed = PriceOracle.weightedAverage([...observations].reverse()); - expect(forward).toBeCloseTo(reversed, 9); - }), - ); - }); - - it('a single observation yields its own price', () => { - fc.assert( - fc.property(observationArb, (observation) => { - const result = PriceOracle.weightedAverage([observation]); - expect(result).toBeCloseTo(observation.price, 9); - }), - ); - }); - - it('scaling all prices by a positive factor scales the average', () => { - fc.assert( - fc.property(observationsArb, fc.double({ min: 0.01, max: 100, noNaN: true }), (observations, factor) => { - const base = PriceOracle.weightedAverage(observations); - const scaled = PriceOracle.weightedAverage( - observations.map((o) => ({ ...o, price: o.price * factor })), - ); - expect(scaled).toBeCloseTo(base * factor, 6); - }), - ); - }); - - it('stale observations are excluded from the average', () => { - fc.assert( - fc.property(observationsArb, timestampArb, (observations, now) => { - const maxAge = 60_000; - const fresh = observations.filter((o) => now - o.timestamp <= maxAge); - const result = PriceOracle.weightedAverage(observations, { now, maxAge }); - if (fresh.length === 0) { - expect(result).toBeNaN(); - } else { - const prices = fresh.map((o) => o.price); - expect(result).toBeGreaterThanOrEqual(Math.min(...prices) - 1e-9); - expect(result).toBeLessThanOrEqual(Math.max(...prices) + 1e-9); - } - }), - ); - }); }); describe("PriceOracle multi-provider integration", () => { const makeProvider = ( name: string, - fetch: OracleProvider["fetch"], - ): OracleProvider => ({ name, fetch }); + fetcher: OracleProvider["fetcher"], + ): OracleProvider => ({ name, fetcher }); it("aggregates prices across multiple providers", async () => { const oracle = new PriceOracle([ @@ -148,16 +52,19 @@ describe("PriceOracle multi-provider integration", () => { }), makeProvider("b", async () => ({ price: 0 })), ]); - await expect(oracle.fetchPrice("XLM")).rejects.toThrow(/No valid oracle price/); + await expect(oracle.fetchPrice("XLM")).rejects.toThrow(/Insufficient valid oracle prices/); }); - it("enforces rate limiting between fetches", async () => { + it("serves the cached value when fetches are rate limited", async () => { + const fetcher = vi.fn(async () => ({ price: 1 })); const oracle = new PriceOracle( - [makeProvider("a", async () => ({ price: 1 }))], - { minIntervalMs: 1000 }, + [makeProvider("a", fetcher)], + { rateLimitMs: 1000 }, ); - await oracle.fetchPrice("XLM"); - await expect(oracle.fetchPrice("XLM")).rejects.toThrow(/rate limit/i); + const first = await oracle.fetchPrice("XLM"); + const second = await oracle.fetchPrice("XLM"); + expect(second).toEqual(first); + expect(fetcher).toHaveBeenCalledTimes(1); }); it("reports provider health for monitoring", async () => { @@ -168,8 +75,8 @@ describe("PriceOracle multi-provider integration", () => { }), ]); await oracle.fetchPrice("XLM"); - const health = oracle.getProviderHealth(); - expect(health.find((h) => h.name === "ok")?.healthy).toBe(true); - expect(health.find((h) => h.name === "bad")?.healthy).toBe(false); + const stats = oracle.getProviderStats(); + expect(stats.find((provider) => provider.name === "ok")?.successes).toBe(1); + expect(stats.find((provider) => provider.name === "bad")?.failures).toBe(1); }); }); diff --git a/src/abiCache.ts b/src/abiCache.ts index 5bc3aef7..49f4a0e0 100644 --- a/src/abiCache.ts +++ b/src/abiCache.ts @@ -400,27 +400,70 @@ export class MemoryAbiStorage implements AbiStorage { export class AdapterAbiStorage implements AbiStorage { private readonly adapter: StorageAdapter; private readonly prefix: string; + private readonly knownKeys: Set; constructor(adapter: StorageAdapter = new MemoryStorageAdapter(), prefix = "stellar_abi_cache:") { this.adapter = adapter; this.prefix = prefix; + this.knownKeys = new Set( + adapter.keys?.().filter((key) => key.startsWith(prefix)).map((key) => key.slice(prefix.length)) ?? [], + ); } get(key: string): CachedAbiEntry | null { const raw = this.adapter.getItem(this.prefix + key); if (!raw) return null; + let entry: CachedAbiEntry; try { - const entry = JSON.parse(raw) as CachedAbiEntry; - entry.lastAccessedAt = Date.now(); - entry.accessCount = (entry.accessCount || 0) + 1; - return entry; + entry = JSON.parse(raw) as CachedAbiEntry; } catch { return null; } + this.knownKeys.add(key); + entry.lastAccessedAt = Date.now(); + entry.accessCount = (entry.accessCount || 0) + 1; + this.adapter.setItem(this.prefix + key, JSON.stringify(entry)); + return entry; } set(key: string, entry: CachedAbiEntry): void { - const raw = JSON.stringify(entry); - ent + this.adapter.setItem(this.prefix + key, JSON.stringify(entry)); + this.knownKeys.add(key); + } + + delete(key: string): boolean { + const storageKey = this.prefix + key; + if (this.adapter.getItem(storageKey) === null) return false; + this.adapter.removeItem(storageKey); + this.knownKeys.delete(key); + return true; + } + + clear(): void { + for (const key of this.keys()) this.adapter.removeItem(this.prefix + key); + this.knownKeys.clear(); + } + + keys(): string[] { + if (this.adapter.keys) { + const currentKeys = this.adapter.keys() + .filter((key) => key.startsWith(this.prefix)) + .map((key) => key.slice(this.prefix.length)); + this.knownKeys.clear(); + for (const key of currentKeys) this.knownKeys.add(key); + } + return Array.from(this.knownKeys); + } -/* … truncated 1354 chars — edit only what you need near the top … */ + size(): number { + return this.keys().length; + } + + getStorageBytes(): number { + return this.keys().reduce((total, key) => { + const storageKey = this.prefix + key; + const value = this.adapter.getItem(storageKey); + return total + new TextEncoder().encode(storageKey + (value ?? '')).length; + }, 0); + } +} diff --git a/src/adapters/types.ts b/src/adapters/types.ts index bf9e8c4f..41957f4c 100644 --- a/src/adapters/types.ts +++ b/src/adapters/types.ts @@ -555,6 +555,12 @@ export interface CompressionLayer { * request and no recycling, health checking, or failover occurs. */ export interface ConnectionPoolConfig { - /** Whether connection p - -/* … truncated 4185 chars — edit only what you need near the top … */ + /** Minimum number of connections maintained in the pool. */ + minConnections?: number; + /** Maximum number of concurrent connections. */ + maxConnections?: number; + /** Time in milliseconds before an idle connection is removed. */ + idleTimeoutMs?: number; + /** Interval in milliseconds between connection health checks. */ + healthCheckIntervalMs?: number; +} diff --git a/src/apiDocGenerator.ts b/src/apiDocGenerator.ts index 1b2c946e..92a66ae6 100644 --- a/src/apiDocGenerator.ts +++ b/src/apiDocGenerator.ts @@ -92,6 +92,9 @@ export interface DocManifest { index: string[]; } +/** Supported API reference output formats. */ +export type DocOutputFormat = 'markdown' | 'html' | 'json'; + // --------------------------------------------------------------------------- // Internal helpers // --------------------------------------------------------------------------- @@ -158,13 +161,14 @@ function extractJsDocBlocks(source: string): Array<{ comment: string; afterText: /** Guess the entry kind from the token immediately following the comment. */ function guessKind(afterText: string): DocEntryKind { - const first = afterText.split(/[\s({]/)[0] ?? ''; - if (first === 'class') return 'class'; - if (first === 'interface') return 'interface'; - if (first === 'type') return 'type'; - if (first === 'function' || first === 'async') return 'function'; - if (first === 'export' || first === 'const' || first === 'let' || first === 'var') { - if (/=\s*(async\s+)?function|=\s*\(|=>\s*{/.test(afterText)) return 'function'; + const declaration = /^(?:(?:export|default|declare|abstract|async)\s+)*(class|interface|type|function|const|let|var)\b/.exec(afterText); + const kind = declaration?.[1]; + if (kind === 'class') return 'class'; + if (kind === 'interface') return 'interface'; + if (kind === 'type') return 'type'; + if (kind === 'function') return 'function'; + if (kind === 'const' || kind === 'let' || kind === 'var') { + if (/=\s*(?:async\s+)?function\b|=\s*(?:async\s*)?\([^)]*\)\s*=>|=\s*[A-Za-z_$][\w$]*\s*=>/.test(afterText)) return 'function'; return 'variable'; } return 'function'; @@ -283,6 +287,10 @@ export interface ApiDocGeneratorOptions { * Modules without an entry are grouped under "General". */ categories?: Record; + /** Heading used by complete-document exporters. Defaults to "API Reference". */ + title?: string; + /** Whether deprecated entries are included in generated output. Defaults to true. */ + includeDeprecated?: boolean; } /** @@ -301,12 +309,16 @@ export class ApiDocGenerator { private readonly version: string; private readonly sources: Record; private readonly categories: Record; + private readonly title: string; + private readonly includeDeprecated: boolean; private entries: Map = new Map(); constructor(options: ApiDocGeneratorOptions) { this.version = options.version; this.sources = options.sources; this.categories = options.categories ?? {}; + this.title = options.title ?? 'API Reference'; + this.includeDeprecated = options.includeDeprecated ?? true; } // ------------------------------------------------------------------------- @@ -332,6 +344,7 @@ export class ApiDocGenerator { const name = extractName(afterText); if (!name) continue; const parsed = parseJsDoc(comment); + if (parsed.deprecated && !this.includeDeprecated) continue; const id = `${moduleName}/${name}`; const entry: DocEntry = { id, @@ -529,7 +542,7 @@ export class ApiDocGenerator { const moduleNames = [...new Set(Array.from(this.entries.values()).map((e) => e.module))].sort(); const lines: string[] = [ - `# API Reference — v${this.version}`, + `# ${this.title} — v${this.version}`, '', `> Generated at ${new Date().toISOString()}`, '', @@ -551,6 +564,164 @@ export class ApiDocGenerator { return lines.join('\n'); } + /** + * Generate the complete API reference as a single Markdown document. + */ + generateMarkdown(): string { + if (this.entries.size === 0) this.parse(); + + const lines = [ + `# ${this.title}`, + '', + `Version: \`${this.version}\``, + '', + this.generateIndex().replace(/^#[^\n]*\n\n/, ''), + '---', + '', + ]; + const navigation = this.buildNavigation(); + + for (const category of navigation.children) { + lines.push(`## ${category.label}`, ''); + for (const module of category.children) { + lines.push(`### ${module.label}`, ''); + for (const id of module.entryIds) { + const entry = this.entries.get(id); + if (!entry) continue; + lines.push(`#### ${entry.name}`, ''); + if (entry.deprecated) { + lines.push(`> **Deprecated** ${entry.deprecationMessage ?? ''}`, ''); + } + if (entry.since) lines.push(`*Since: ${entry.since}*`, ''); + if (entry.description) lines.push(entry.description, ''); + if (entry.params.length > 0) { + lines.push('##### Parameters', '', '| Name | Type | Optional | Description |', '|------|------|----------|-------------|'); + for (const param of entry.params) { + const description = param.description.replace(/\|/g, '\\|').replace(/\n/g, ' '); + lines.push(`| \`${param.name}\` | ${param.type ? `\`${param.type}\`` : '—'} | ${param.optional ? 'Yes' : 'No'} | ${description} |`); + } + lines.push(''); + } + if (entry.returns) lines.push('##### Returns', '', entry.returns, ''); + if (entry.examples.length > 0) { + lines.push('##### Examples', ''); + for (const example of entry.examples) lines.push('```ts', example, '```', ''); + } + if (entry.tags.length > 0) { + lines.push('##### Additional documentation', ''); + for (const tag of entry.tags) { + const description = tag.description.replace(/\n/g, ' '); + lines.push(`- **@${tag.tag}**${tag.name ? ` \`${tag.name}\`` : ''}${description ? ` — ${description}` : ''}`); + } + lines.push(''); + } + lines.push('---', ''); + } + } + } + + return lines.join('\n'); + } + + /** + * Generate a self-contained HTML API reference. + */ + generateHtml(): string { + if (this.entries.size === 0) this.parse(); + + const escapeHtml = (value: string): string => + value.replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"').replace(/'/g, '''); + const navigation = this.buildNavigation(); + const html: string[] = [ + '', + '', + '', + '', + '', + `${escapeHtml(this.title)}`, + '', + '', + `

${escapeHtml(this.title)}

`, + `

Version: ${escapeHtml(this.version)}

`, + ''); + for (const category of navigation.children) { + html.push(`

${escapeHtml(category.label)}

`); + for (const module of category.children) { + html.push(`

${escapeHtml(module.label)}

`); + for (const id of module.entryIds) { + const entry = this.entries.get(id); + if (!entry) continue; + html.push(`

${escapeHtml(entry.name)}

`); + if (entry.deprecated) html.push(`

Deprecated ${escapeHtml(entry.deprecationMessage ?? '')}

`); + if (entry.since) html.push(`

Since: ${escapeHtml(entry.since)}

`); + if (entry.description) html.push(`

${escapeHtml(entry.description).replace(/\n/g, '
')}

`); + if (entry.params.length > 0) { + html.push('
Parameters
'); + for (const param of entry.params) { + html.push(``); + } + html.push('
NameTypeOptionalDescription
${escapeHtml(param.name)}${escapeHtml(param.type ?? '')}${param.optional ? 'Yes' : 'No'}${escapeHtml(param.description)}
'); + } + if (entry.returns) html.push(`
Returns

${escapeHtml(entry.returns)}

`); + for (const example of entry.examples) html.push(`
${escapeHtml(example)}
`); + if (entry.tags.length > 0) { + html.push('
Additional documentation
    '); + for (const tag of entry.tags) { + const name = tag.name ? ` ${escapeHtml(tag.name)}` : ''; + const description = tag.description ? ` — ${escapeHtml(tag.description)}` : ''; + html.push(`
  • @${escapeHtml(tag.tag)}${name}${description}
  • `); + } + html.push('
'); + } + html.push('
'); + } + html.push('
'); + } + html.push('
'); + } + + html.push('
', '', ''); + return html.join('\n'); + } + + /** Serialize the versioned documentation manifest as JSON. */ + generateJson(): string { + return JSON.stringify(this.generateManifest(), null, 2); + } + + /** Generate the complete reference in the requested output format. */ + generate(format: DocOutputFormat): string { + switch (format) { + case 'markdown': + return this.generateMarkdown(); + case 'html': + return this.generateHtml(); + case 'json': + return this.generateJson(); + default: { + const exhaustiveCheck: never = format; + throw new Error(`Unsupported API reference format: ${String(exhaustiveCheck)}`); + } + } + } + // ------------------------------------------------------------------------- // Manifest // ------------------------------------------------------------------------- diff --git a/src/docs/index.ts b/src/docs/index.ts index 54af7cb2..4d98ec28 100644 --- a/src/docs/index.ts +++ b/src/docs/index.ts @@ -14,4 +14,5 @@ export type { DocTagName, NavNode, ApiDocGeneratorOptions, + DocOutputFormat, } from '../apiDocGenerator.js'; diff --git a/src/errorCodes.ts b/src/errorCodes.ts new file mode 100644 index 00000000..f1448f31 --- /dev/null +++ b/src/errorCodes.ts @@ -0,0 +1 @@ +export { isRetryableErrorCode } from "./errors.js"; diff --git a/src/priceOracle.ts b/src/priceOracle.ts index dd71b414..2815fc24 100644 --- a/src/priceOracle.ts +++ b/src/priceOracle.ts @@ -386,6 +386,17 @@ export class ContractPriceOracle implements PriceOracle { fee: BASE_FEE, networkPassphrase: this.networkPassphrase, }) - + .addOperation(operation) + .setTimeout(30) + .build(); -/* … truncated 613 chars — edit only what you need near the top … */ + const result = await this.server.simulateTransaction(tx); + if (SorobanRpc.Api.isSimulationError(result)) { + throw new OraclePriceError(`Oracle simulation failed: ${result.error}`); + } + + const returnValue = (result as SorobanRpc.Api.SimulateTransactionSuccessResponse).result?.retval; + if (!returnValue) throw new NoReturnValueError("oracle get_price"); + return BigInt(scValToNative(returnValue)); + } +} diff --git a/src/retryPolicy.ts b/src/retryPolicy.ts index 3464e5fb..1568515d 100644 --- a/src/retryPolicy.ts +++ b/src/retryPolicy.ts @@ -197,6 +197,10 @@ export function createRetryExecutor(options: RetryPolicyOptions): RetryExecutor } export function isRetryable(error: unknown): boolean { + if (error instanceof RpcError) { + return error.statusCode === 429 || error.statusCode === 502 || error.statusCode === 503 || error.statusCode === 504; + } + // Prefer the centralized error-code taxonomy when the error carries a code. if (error instanceof Error) { const code = (error as { code?: unknown }).code; @@ -226,10 +230,6 @@ export function isRetryable(error: unknown): boolean { if (error instanceof InvalidContractAddressError) return false; if (error instanceof TransactionVerificationError) return false; - if (error instanceof RpcError) { - return error.statusCode === 429 || error.statusCode === 502 || error.statusCode === 503 || error.statusCode === 504; - } - if (!(error instanceof Error)) return false; const msg = error.message.toLowerCase(); diff --git a/src/storage/storageAdapter.ts b/src/storage/storageAdapter.ts index 8ff19d1c..8ed68017 100644 --- a/src/storage/storageAdapter.ts +++ b/src/storage/storageAdapter.ts @@ -10,6 +10,7 @@ export interface StorageAdapter { getItem(key: string): string | null; setItem(key: string, value: string): void; removeItem(key: string): void; + keys?(): string[]; } export type StorageKind = "localStorage" | "sessionStorage" | "memory"; @@ -28,6 +29,10 @@ export class MemoryStorageAdapter implements StorageAdapter { removeItem(key: string): void { this.store.delete(key); } + + keys(): string[] { + return Array.from(this.store.keys()); + } } function resolveWebStorage(kind: "localStorage" | "sessionStorage"): StorageAdapter | null { @@ -41,7 +46,14 @@ function resolveWebStorage(kind: "localStorage" | "sessionStorage"): StorageAdap const probeKey = "__stellar_split_storage_probe__"; candidate.setItem(probeKey, "1"); candidate.removeItem(probeKey); - return candidate; + return { + getItem: (key) => candidate.getItem(key), + setItem: (key, value) => candidate.setItem(key, value), + removeItem: (key) => candidate.removeItem(key), + keys: () => Array.from({ length: candidate.length }, (_, index) => candidate.key(index)).filter( + (key): key is string => key !== null, + ), + }; } catch { return null; } diff --git a/src/tracing.ts b/src/tracing.ts new file mode 100644 index 00000000..f9f729a6 --- /dev/null +++ b/src/tracing.ts @@ -0,0 +1,9 @@ +import { globalTraceIdManager } from "./traceId.js"; +import { telemetry } from "./telemetry.js"; + +/** Run an async SDK operation within a shared trace and telemetry span. */ +export function withTrace(name: string, operation: () => Promise): Promise { + return globalTraceIdManager.runWithTrace((traceId) => + telemetry.runInSpan(`${name}:${traceId}`, operation), + ); +} diff --git a/src/types/templates.ts b/src/types/templates.ts index 2fa7a0e4..096a970a 100644 --- a/src/types/templates.ts +++ b/src/types/templates.ts @@ -140,7 +140,4 @@ export interface ResolvedTemplate { params: CreateInvoiceParams; /** Parameter values that were applied. */ appliedParameters?: Record; -} - - - \ No newline at end of file +} \ No newline at end of file diff --git a/src/upgradeMigrationRunner.ts b/src/upgradeMigrationRunner.ts index 23328cb0..74a5ecda 100644 --- a/src/upgradeMigrationRunner.ts +++ b/src/upgradeMigrationRunner.ts @@ -96,7 +96,6 @@ export function validateMigrationChain( ); } } -======= /** * Register a migration function to run when an upgrade from `fromVersion` to diff --git a/src/validators/deadlineValidator.ts b/src/validators/deadlineValidator.ts index 8a901bf2..79bdbd73 100644 --- a/src/validators/deadlineValidator.ts +++ b/src/validators/deadlineValidator.ts @@ -121,7 +121,6 @@ export function getDeadlineValidationStats(): DeadlineValidationStats { export function resetDeadlineValidationStats(): void { validationHistory.length = 0; } -======= /** Options for configuring deadline validation behavior. */ export interface DeadlineValidationOptions { diff --git a/src/wallets/MultiWalletManager.ts b/src/wallets/MultiWalletManager.ts new file mode 100644 index 00000000..8e3034ed --- /dev/null +++ b/src/wallets/MultiWalletManager.ts @@ -0,0 +1 @@ +export { MultiWalletManager } from "../multiWallet.js"; diff --git a/src/wallets/adapters/LedgerAdapter.ts b/src/wallets/adapters/LedgerAdapter.ts new file mode 100644 index 00000000..e01c3a3b --- /dev/null +++ b/src/wallets/adapters/LedgerAdapter.ts @@ -0,0 +1 @@ +export { LedgerAdapter } from "../../adapters/ledger.js"; diff --git a/src/wallets/adapters/WalletConnectAdapter.ts b/src/wallets/adapters/WalletConnectAdapter.ts new file mode 100644 index 00000000..d02f4980 --- /dev/null +++ b/src/wallets/adapters/WalletConnectAdapter.ts @@ -0,0 +1 @@ +export { WalletConnectAdapter } from "../../adapters/walletconnect.js"; diff --git a/test/apiDocGenerator.test.ts b/test/apiDocGenerator.test.ts new file mode 100644 index 00000000..ac85af63 --- /dev/null +++ b/test/apiDocGenerator.test.ts @@ -0,0 +1,98 @@ +import { describe, expect, it } from 'vitest'; +import { ApiDocGenerator } from '../src/apiDocGenerator.js'; + +const source = ` +/** Runs a task. + * @param {string} name - Task name + * @returns Task result + * @example + * runTask("build") + * @since 1.2.0 + * @throws {Error} - + */ +export function runTask(name: string): string { + return name; +} + +/** An old helper. + * @deprecated Use runTask instead. + */ +export const oldTask = () => {}; + +/** A task runner. */ +export class TaskRunner {} + +/** Configuration for a task. */ +export interface TaskConfig {} + +/** A task name. */ +export type TaskName = string; +`; + +describe('ApiDocGenerator', () => { + it('parses exported declaration kinds and JSDoc metadata', () => { + const generator = new ApiDocGenerator({ version: '1.2.0', sources: { tasks: source } }); + const entries = generator.getEntries(); + + expect(entries.map(({ name, kind }) => [name, kind])).toEqual([ + ['runTask', 'function'], + ['oldTask', 'function'], + ['TaskRunner', 'class'], + ['TaskConfig', 'interface'], + ['TaskName', 'type'], + ]); + expect(generator.getEntry('tasks/runTask')).toMatchObject({ + description: 'Runs a task.', + params: [{ name: 'name', type: 'string', description: 'Task name', optional: false }], + returns: 'Task result', + examples: ['runTask("build")'], + since: '1.2.0', + }); + }); + + it('generates customized Markdown, HTML, and JSON references', () => { + const generator = new ApiDocGenerator({ + version: '1.2.0', + sources: { tasks: source }, + categories: { tasks: 'Task Management' }, + title: 'SDK Reference', + }); + + const markdown = generator.generate('markdown'); + expect(markdown).toContain('# SDK Reference'); + expect(markdown).toContain('## Task Management'); + expect(markdown).toContain('#### runTask'); + expect(markdown).toContain('### Parameters'); + expect(markdown).toContain('Since: 1.2.0'); + expect(markdown).toContain('@throws'); + + const html = generator.generate('html'); + expect(html).toContain('SDK Reference'); + expect(html).toContain('

Task Management

'); + expect(html).toContain('