From e37aa2381a9382fc27d56ac1187382728df58356 Mon Sep 17 00:00:00 2001 From: Petra Jaros Date: Wed, 8 Jan 2025 16:29:22 -0500 Subject: [PATCH 1/6] Generate types for `composeMiddleware` --- package-lock.json | 28 + package.json | 10 + scripts/generateComposeMiddleware.js | 229 ++++ src/composeMiddleware.ts | 1432 ++++++++++++++++++++++++++ test/composeMiddleware.spec.ts | 117 +++ tsconfig.json | 2 +- 6 files changed, 1817 insertions(+), 1 deletion(-) create mode 100644 scripts/generateComposeMiddleware.js create mode 100644 src/composeMiddleware.ts create mode 100644 test/composeMiddleware.spec.ts diff --git a/package-lock.json b/package-lock.json index 1fd5797..2ca5eff 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,8 +26,10 @@ "@ipld/dag-cbor": "^9.0.8", "@ipld/dag-pb": "^4.0.8", "@types/bytes": "^3.1.4", + "expect-type": "^1.1.0", "ipfs-unixfs": "^11.1.2", "ipfs-unixfs-exporter": "^13.3.0", + "prettier": "^3.4.2", "standard": "^17.1.0", "typescript": "^5.3.3" } @@ -4083,6 +4085,16 @@ "url": "https://github.com/sindresorhus/execa?sponsor=1" } }, + "node_modules/expect-type": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/expect-type/-/expect-type-1.1.0.tgz", + "integrity": "sha512-bFi65yM+xZgk+u/KRIpekdSYkTB5W1pEf0Lt8Q8Msh7b+eQ7LXVtIB1Bkm4fvclDEL1b2CZkMhv2mOeF8tMdkA==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=12.0.0" + } + }, "node_modules/fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", @@ -6618,6 +6630,22 @@ "node": ">= 0.8.0" } }, + "node_modules/prettier": { + "version": "3.4.2", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.4.2.tgz", + "integrity": "sha512-e9MewbtFo+Fevyuxn/4rrcDAaq0IYxPGLvObpQjiZBMAzB9IGmzlnG9RZy3FFas+eBMu2vA0CszMeduow5dIuQ==", + "dev": true, + "license": "MIT", + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, "node_modules/private-ip": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/private-ip/-/private-ip-3.0.2.tgz", diff --git a/package.json b/package.json index 11c5156..bacaecc 100644 --- a/package.json +++ b/package.json @@ -51,6 +51,8 @@ "prepare": "npm run build", "test": "node --test test/**/*.spec.js", "lint": "standard", + "generate-compose": "node scripts/generateComposeMiddleware.js", + "generate-compose:watch": "node --watch scripts/generateComposeMiddleware.js", "build": "npm run build:types && npm run build:templates", "build:types": "tsc && cp src/bindings.d.ts types/bindings.d.ts", "build:templates": "rm -f src/handlers/templates/bundle.cjs && echo '// @ts-nocheck' >> src/handlers/templates/bundle.cjs && handlebars src/handlers/templates/*.handlebars -c @web3-storage/handlebars/runtime.js >> src/handlers/templates/bundle.cjs", @@ -82,8 +84,10 @@ "@ipld/dag-cbor": "^9.0.8", "@ipld/dag-pb": "^4.0.8", "@types/bytes": "^3.1.4", + "expect-type": "^1.1.0", "ipfs-unixfs": "^11.1.2", "ipfs-unixfs-exporter": "^13.3.0", + "prettier": "^3.4.2", "standard": "^17.1.0", "typescript": "^5.3.3" }, @@ -105,5 +109,11 @@ "ignore": [ "*.ts" ] + }, + "prettier": { + "trailingComma": "es5", + "tabWidth": 2, + "semi": false, + "singleQuote": true } } diff --git a/scripts/generateComposeMiddleware.js b/scripts/generateComposeMiddleware.js new file mode 100644 index 0000000..3e48521 --- /dev/null +++ b/scripts/generateComposeMiddleware.js @@ -0,0 +1,229 @@ +import fs from 'fs' +import ts from 'typescript' +import * as prettier from 'prettier' + +// The maximum number of arguments to generate overloads for. +const MAX_ARGUMENTS = 20 + +/** + * Simply passes the value {@link x} to the function {@param fn} and returns the + * result. In other words, creates a local binding (variable) for the value. + * Equivalent to a `let` form in Lisp. + * + * @template T, R + * @param {T} x The value + * @param {(x: T) => R} fn A function which uses the value. + * @returns {R} The result of applying the function to the value. + */ +const withBinding = (x, fn) => fn(x) + +const anyMiddlewareType = ts.factory.createTypeReferenceNode('Middleware', [ + ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword), + ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword), + ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword), +]) + +const declarations = [ + /* typescript */ ` + /* + * DO NOT EDIT THIS FILE + * + * This file contains overloads for the arities of the \`composeMiddleware\` + * function. To change it, edit \`scripts/generateComposeMiddleware.js\` and run + * \`npm run generate-compose\` (or \`npm run generate-compose:watch\`). + * + * This file is committed to the repository, as it should rarely change. + */ + + /** + * A Handler handles a request. It's an async function which takes a + * {@link Request} and returns a {@link Response}. It also has access to the + * context and environment for the request. + * + * @template Context The context keys used by the handler. + * @template Env The environment keys used by the handler. + */ + type Handler = ( + request: Request, + env: Env, + ctx: Context, + ) => Promise; + + /** + * A Middleware is a function that takes a {@link Handler} and returns a new + * one. It has access to the context and environment for the request. It can + * add to the context, or modify it, but it should not remove keys, so that + * upstream middleware can pass context to downstream middleware. It should + * generally not modify the environment, as that is shared across all requests. + * + * @template RequiredContext The context required by the middleware. These keys + * must be either provided by upstream middleware, or given to the ultimate + * handler. + * @template AddedContext The context added by the middleware. These keys will + * be available to downstream middleware. + * @template Env The environment keys used by the middleware. The entire + * environment should be passed to the outermost handler, at the top of the + * middleware stack. Middleware shouldn't modify the environment, and should + * pass it in its entirety when it calls the next handler. + */ + type Middleware< + RequiredContext extends {}, + AddedContext extends {} = {}, + Env extends {} = {}, + > = ( + h: Handler, + ) => Handler; + + export type RequiredContextOf> = + M extends Middleware ? T : never; + + export type AddedContextOf> = + M extends Middleware ? T : never; + + export type EnvOf> = + M extends Middleware ? T : never; + + /** + * Returns the result of satisfying the {@link Requirements} with the + * {@link With}. If a key in the {@link Requirements} is BOOKMARK + */ + export type Satisfy = + With extends Pick + ? Omit + : never; + `, + + ...Array.from({ length: MAX_ARGUMENTS }) + .map((_, i) => i + 1) + .map((n) => createComposeMiddlewareOverloadDeclaration(n)), + + /* typescript */ ` + function composeMiddleware( + ...middlewares: Middleware[] + ): Middleware { + return (handler) => middlewares.reduceRight((h, m) => m(h), handler); + } + + export { composeMiddleware, Middleware, Handler }; + `, +] + +/** + * Creates a TypeScript function declaration for the `composeMiddleware` + * function with the given number of middleware arguments. + * + * @param {number} argCount The number of middleware arguments. + * @returns {ts.FunctionDeclaration} The TypeScript function declaration. + */ +function createComposeMiddlewareOverloadDeclaration(argCount) { + const ns = Array.from({ length: argCount }).map((_, i) => i + 1) + + return ts.factory.createFunctionDeclaration( + undefined, + undefined, + 'composeMiddleware', + [ + ...ns.flatMap((n) => { + return [ + ts.factory.createTypeParameterDeclaration( + undefined, + `M${n}`, + anyMiddlewareType + ), + ts.factory.createTypeParameterDeclaration( + undefined, + `M${n}R`, + withBinding( + ts.factory.createTypeReferenceNode('RequiredContextOf', [ + ts.factory.createTypeReferenceNode(`M${n}`), + ]), + (requiredContext) => + n === 1 + ? requiredContext + : ts.factory.createTypeReferenceNode('Satisfy', [ + requiredContext, + ts.factory.createTypeReferenceNode(`M${n - 1}C`), + ]) + ) + ), + ts.factory.createTypeParameterDeclaration( + undefined, + `M${n}C`, + ts.factory.createIntersectionTypeNode([ + ts.factory.createTypeReferenceNode('AddedContextOf', [ + ts.factory.createTypeReferenceNode(`M${n}`), + ]), + ...(n === 1 + ? [] + : [ts.factory.createTypeReferenceNode(`M${n - 1}C`)]), + ]) + ), + ] + }), + ], + ns.map((n) => + ts.factory.createParameterDeclaration( + undefined, + undefined, + `m${n}`, + undefined, + ts.factory.createTypeReferenceNode(`M${n}`), + undefined + ) + ), + ts.factory.createTypeReferenceNode('Middleware', [ + ts.factory.createIntersectionTypeNode( + ns.map((n) => + withBinding( + ts.factory.createTypeReferenceNode('RequiredContextOf', [ + ts.factory.createTypeReferenceNode(`M${n}`), + ]), + (requiredContext) => + n === 1 + ? requiredContext + : ts.factory.createTypeReferenceNode('Satisfy', [ + requiredContext, + ts.factory.createTypeReferenceNode(`M${n - 1}C`), + ]) + ) + ) + ), + ts.factory.createTypeReferenceNode(`M${ns[ns.length - 1]}C`), + ts.factory.createIntersectionTypeNode( + ns.map((n) => + ts.factory.createTypeReferenceNode('EnvOf', [ + ts.factory.createTypeReferenceNode(`M${n}`), + ]) + ) + ), + ]), + undefined + ) +} + +// Output + +const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed }) +const resultFile = ts.createSourceFile( + 'noodle4-output.ts', + '', + ts.ScriptTarget.Latest, + false, + ts.ScriptKind.TSX +) + +const output = declarations + .map((node) => + typeof node === 'string' + ? node + : printer.printNode(ts.EmitHint.Unspecified, node, resultFile) + ) + .join('\n\n') + +const filepath = 'src/composeMiddleware.ts' +const prettierConfig = await prettier.resolveConfig(filepath) +const formattedOutput = await prettier.format(output, { + filepath, + ...prettierConfig, +}) +fs.writeFileSync(filepath, formattedOutput) diff --git a/src/composeMiddleware.ts b/src/composeMiddleware.ts new file mode 100644 index 0000000..8705398 --- /dev/null +++ b/src/composeMiddleware.ts @@ -0,0 +1,1432 @@ +/* + * DO NOT EDIT THIS FILE + * + * This file contains overloads for the arities of the `composeMiddleware` + * function. To change it, edit `scripts/generateComposeMiddleware.js` and run + * `npm run generate-compose` (or `npm run generate-compose:watch`). + * + * This file is committed to the repository, as it should rarely change. + */ + +/** + * A Handler handles a request. It's an async function which takes a + * {@link Request} and returns a {@link Response}. It also has access to the + * context and environment for the request. + * + * @template Context The context keys used by the handler. + * @template Env The environment keys used by the handler. + */ +type Handler = ( + request: Request, + env: Env, + ctx: Context +) => Promise + +/** + * A Middleware is a function that takes a {@link Handler} and returns a new + * one. It has access to the context and environment for the request. It can + * add to the context, or modify it, but it should not remove keys, so that + * upstream middleware can pass context to downstream middleware. It should + * generally not modify the environment, as that is shared across all requests. + * + * @template RequiredContext The context required by the middleware. These keys + * must be either provided by upstream middleware, or given to the ultimate + * handler. + * @template AddedContext The context added by the middleware. These keys will + * be available to downstream middleware. + * @template Env The environment keys used by the middleware. The entire + * environment should be passed to the outermost handler, at the top of the + * middleware stack. Middleware shouldn't modify the environment, and should + * pass it in its entirety when it calls the next handler. + */ +type Middleware< + RequiredContext extends {}, + AddedContext extends {} = {}, + Env extends {} = {}, +> = ( + h: Handler +) => Handler + +export type RequiredContextOf> = + M extends Middleware ? T : never + +export type AddedContextOf> = + M extends Middleware ? T : never + +export type EnvOf> = + M extends Middleware ? T : never + +/** + * Returns the result of satisfying the {@link Requirements} with the + * {@link With}. If a key in the {@link Requirements} is BOOKMARK + */ +export type Satisfy = + With extends Pick + ? Omit + : never + +function composeMiddleware< + M1 extends Middleware, + M1R extends RequiredContextOf, + M1C extends AddedContextOf, +>(m1: M1): Middleware, M1C, EnvOf> + +function composeMiddleware< + M1 extends Middleware, + M1R extends RequiredContextOf, + M1C extends AddedContextOf, + M2 extends Middleware, + M2R extends Satisfy, M1C>, + M2C extends AddedContextOf & M1C, +>( + m1: M1, + m2: M2 +): Middleware< + RequiredContextOf & Satisfy, M1C>, + M2C, + EnvOf & EnvOf +> + +function composeMiddleware< + M1 extends Middleware, + M1R extends RequiredContextOf, + M1C extends AddedContextOf, + M2 extends Middleware, + M2R extends Satisfy, M1C>, + M2C extends AddedContextOf & M1C, + M3 extends Middleware, + M3R extends Satisfy, M2C>, + M3C extends AddedContextOf & M2C, +>( + m1: M1, + m2: M2, + m3: M3 +): Middleware< + RequiredContextOf & + Satisfy, M1C> & + Satisfy, M2C>, + M3C, + EnvOf & EnvOf & EnvOf +> + +function composeMiddleware< + M1 extends Middleware, + M1R extends RequiredContextOf, + M1C extends AddedContextOf, + M2 extends Middleware, + M2R extends Satisfy, M1C>, + M2C extends AddedContextOf & M1C, + M3 extends Middleware, + M3R extends Satisfy, M2C>, + M3C extends AddedContextOf & M2C, + M4 extends Middleware, + M4R extends Satisfy, M3C>, + M4C extends AddedContextOf & M3C, +>( + m1: M1, + m2: M2, + m3: M3, + m4: M4 +): Middleware< + RequiredContextOf & + Satisfy, M1C> & + Satisfy, M2C> & + Satisfy, M3C>, + M4C, + EnvOf & EnvOf & EnvOf & EnvOf +> + +function composeMiddleware< + M1 extends Middleware, + M1R extends RequiredContextOf, + M1C extends AddedContextOf, + M2 extends Middleware, + M2R extends Satisfy, M1C>, + M2C extends AddedContextOf & M1C, + M3 extends Middleware, + M3R extends Satisfy, M2C>, + M3C extends AddedContextOf & M2C, + M4 extends Middleware, + M4R extends Satisfy, M3C>, + M4C extends AddedContextOf & M3C, + M5 extends Middleware, + M5R extends Satisfy, M4C>, + M5C extends AddedContextOf & M4C, +>( + m1: M1, + m2: M2, + m3: M3, + m4: M4, + m5: M5 +): Middleware< + RequiredContextOf & + Satisfy, M1C> & + Satisfy, M2C> & + Satisfy, M3C> & + Satisfy, M4C>, + M5C, + EnvOf & EnvOf & EnvOf & EnvOf & EnvOf +> + +function composeMiddleware< + M1 extends Middleware, + M1R extends RequiredContextOf, + M1C extends AddedContextOf, + M2 extends Middleware, + M2R extends Satisfy, M1C>, + M2C extends AddedContextOf & M1C, + M3 extends Middleware, + M3R extends Satisfy, M2C>, + M3C extends AddedContextOf & M2C, + M4 extends Middleware, + M4R extends Satisfy, M3C>, + M4C extends AddedContextOf & M3C, + M5 extends Middleware, + M5R extends Satisfy, M4C>, + M5C extends AddedContextOf & M4C, + M6 extends Middleware, + M6R extends Satisfy, M5C>, + M6C extends AddedContextOf & M5C, +>( + m1: M1, + m2: M2, + m3: M3, + m4: M4, + m5: M5, + m6: M6 +): Middleware< + RequiredContextOf & + Satisfy, M1C> & + Satisfy, M2C> & + Satisfy, M3C> & + Satisfy, M4C> & + Satisfy, M5C>, + M6C, + EnvOf & EnvOf & EnvOf & EnvOf & EnvOf & EnvOf +> + +function composeMiddleware< + M1 extends Middleware, + M1R extends RequiredContextOf, + M1C extends AddedContextOf, + M2 extends Middleware, + M2R extends Satisfy, M1C>, + M2C extends AddedContextOf & M1C, + M3 extends Middleware, + M3R extends Satisfy, M2C>, + M3C extends AddedContextOf & M2C, + M4 extends Middleware, + M4R extends Satisfy, M3C>, + M4C extends AddedContextOf & M3C, + M5 extends Middleware, + M5R extends Satisfy, M4C>, + M5C extends AddedContextOf & M4C, + M6 extends Middleware, + M6R extends Satisfy, M5C>, + M6C extends AddedContextOf & M5C, + M7 extends Middleware, + M7R extends Satisfy, M6C>, + M7C extends AddedContextOf & M6C, +>( + m1: M1, + m2: M2, + m3: M3, + m4: M4, + m5: M5, + m6: M6, + m7: M7 +): Middleware< + RequiredContextOf & + Satisfy, M1C> & + Satisfy, M2C> & + Satisfy, M3C> & + Satisfy, M4C> & + Satisfy, M5C> & + Satisfy, M6C>, + M7C, + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf +> + +function composeMiddleware< + M1 extends Middleware, + M1R extends RequiredContextOf, + M1C extends AddedContextOf, + M2 extends Middleware, + M2R extends Satisfy, M1C>, + M2C extends AddedContextOf & M1C, + M3 extends Middleware, + M3R extends Satisfy, M2C>, + M3C extends AddedContextOf & M2C, + M4 extends Middleware, + M4R extends Satisfy, M3C>, + M4C extends AddedContextOf & M3C, + M5 extends Middleware, + M5R extends Satisfy, M4C>, + M5C extends AddedContextOf & M4C, + M6 extends Middleware, + M6R extends Satisfy, M5C>, + M6C extends AddedContextOf & M5C, + M7 extends Middleware, + M7R extends Satisfy, M6C>, + M7C extends AddedContextOf & M6C, + M8 extends Middleware, + M8R extends Satisfy, M7C>, + M8C extends AddedContextOf & M7C, +>( + m1: M1, + m2: M2, + m3: M3, + m4: M4, + m5: M5, + m6: M6, + m7: M7, + m8: M8 +): Middleware< + RequiredContextOf & + Satisfy, M1C> & + Satisfy, M2C> & + Satisfy, M3C> & + Satisfy, M4C> & + Satisfy, M5C> & + Satisfy, M6C> & + Satisfy, M7C>, + M8C, + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf +> + +function composeMiddleware< + M1 extends Middleware, + M1R extends RequiredContextOf, + M1C extends AddedContextOf, + M2 extends Middleware, + M2R extends Satisfy, M1C>, + M2C extends AddedContextOf & M1C, + M3 extends Middleware, + M3R extends Satisfy, M2C>, + M3C extends AddedContextOf & M2C, + M4 extends Middleware, + M4R extends Satisfy, M3C>, + M4C extends AddedContextOf & M3C, + M5 extends Middleware, + M5R extends Satisfy, M4C>, + M5C extends AddedContextOf & M4C, + M6 extends Middleware, + M6R extends Satisfy, M5C>, + M6C extends AddedContextOf & M5C, + M7 extends Middleware, + M7R extends Satisfy, M6C>, + M7C extends AddedContextOf & M6C, + M8 extends Middleware, + M8R extends Satisfy, M7C>, + M8C extends AddedContextOf & M7C, + M9 extends Middleware, + M9R extends Satisfy, M8C>, + M9C extends AddedContextOf & M8C, +>( + m1: M1, + m2: M2, + m3: M3, + m4: M4, + m5: M5, + m6: M6, + m7: M7, + m8: M8, + m9: M9 +): Middleware< + RequiredContextOf & + Satisfy, M1C> & + Satisfy, M2C> & + Satisfy, M3C> & + Satisfy, M4C> & + Satisfy, M5C> & + Satisfy, M6C> & + Satisfy, M7C> & + Satisfy, M8C>, + M9C, + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf +> + +function composeMiddleware< + M1 extends Middleware, + M1R extends RequiredContextOf, + M1C extends AddedContextOf, + M2 extends Middleware, + M2R extends Satisfy, M1C>, + M2C extends AddedContextOf & M1C, + M3 extends Middleware, + M3R extends Satisfy, M2C>, + M3C extends AddedContextOf & M2C, + M4 extends Middleware, + M4R extends Satisfy, M3C>, + M4C extends AddedContextOf & M3C, + M5 extends Middleware, + M5R extends Satisfy, M4C>, + M5C extends AddedContextOf & M4C, + M6 extends Middleware, + M6R extends Satisfy, M5C>, + M6C extends AddedContextOf & M5C, + M7 extends Middleware, + M7R extends Satisfy, M6C>, + M7C extends AddedContextOf & M6C, + M8 extends Middleware, + M8R extends Satisfy, M7C>, + M8C extends AddedContextOf & M7C, + M9 extends Middleware, + M9R extends Satisfy, M8C>, + M9C extends AddedContextOf & M8C, + M10 extends Middleware, + M10R extends Satisfy, M9C>, + M10C extends AddedContextOf & M9C, +>( + m1: M1, + m2: M2, + m3: M3, + m4: M4, + m5: M5, + m6: M6, + m7: M7, + m8: M8, + m9: M9, + m10: M10 +): Middleware< + RequiredContextOf & + Satisfy, M1C> & + Satisfy, M2C> & + Satisfy, M3C> & + Satisfy, M4C> & + Satisfy, M5C> & + Satisfy, M6C> & + Satisfy, M7C> & + Satisfy, M8C> & + Satisfy, M9C>, + M10C, + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf +> + +function composeMiddleware< + M1 extends Middleware, + M1R extends RequiredContextOf, + M1C extends AddedContextOf, + M2 extends Middleware, + M2R extends Satisfy, M1C>, + M2C extends AddedContextOf & M1C, + M3 extends Middleware, + M3R extends Satisfy, M2C>, + M3C extends AddedContextOf & M2C, + M4 extends Middleware, + M4R extends Satisfy, M3C>, + M4C extends AddedContextOf & M3C, + M5 extends Middleware, + M5R extends Satisfy, M4C>, + M5C extends AddedContextOf & M4C, + M6 extends Middleware, + M6R extends Satisfy, M5C>, + M6C extends AddedContextOf & M5C, + M7 extends Middleware, + M7R extends Satisfy, M6C>, + M7C extends AddedContextOf & M6C, + M8 extends Middleware, + M8R extends Satisfy, M7C>, + M8C extends AddedContextOf & M7C, + M9 extends Middleware, + M9R extends Satisfy, M8C>, + M9C extends AddedContextOf & M8C, + M10 extends Middleware, + M10R extends Satisfy, M9C>, + M10C extends AddedContextOf & M9C, + M11 extends Middleware, + M11R extends Satisfy, M10C>, + M11C extends AddedContextOf & M10C, +>( + m1: M1, + m2: M2, + m3: M3, + m4: M4, + m5: M5, + m6: M6, + m7: M7, + m8: M8, + m9: M9, + m10: M10, + m11: M11 +): Middleware< + RequiredContextOf & + Satisfy, M1C> & + Satisfy, M2C> & + Satisfy, M3C> & + Satisfy, M4C> & + Satisfy, M5C> & + Satisfy, M6C> & + Satisfy, M7C> & + Satisfy, M8C> & + Satisfy, M9C> & + Satisfy, M10C>, + M11C, + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf +> + +function composeMiddleware< + M1 extends Middleware, + M1R extends RequiredContextOf, + M1C extends AddedContextOf, + M2 extends Middleware, + M2R extends Satisfy, M1C>, + M2C extends AddedContextOf & M1C, + M3 extends Middleware, + M3R extends Satisfy, M2C>, + M3C extends AddedContextOf & M2C, + M4 extends Middleware, + M4R extends Satisfy, M3C>, + M4C extends AddedContextOf & M3C, + M5 extends Middleware, + M5R extends Satisfy, M4C>, + M5C extends AddedContextOf & M4C, + M6 extends Middleware, + M6R extends Satisfy, M5C>, + M6C extends AddedContextOf & M5C, + M7 extends Middleware, + M7R extends Satisfy, M6C>, + M7C extends AddedContextOf & M6C, + M8 extends Middleware, + M8R extends Satisfy, M7C>, + M8C extends AddedContextOf & M7C, + M9 extends Middleware, + M9R extends Satisfy, M8C>, + M9C extends AddedContextOf & M8C, + M10 extends Middleware, + M10R extends Satisfy, M9C>, + M10C extends AddedContextOf & M9C, + M11 extends Middleware, + M11R extends Satisfy, M10C>, + M11C extends AddedContextOf & M10C, + M12 extends Middleware, + M12R extends Satisfy, M11C>, + M12C extends AddedContextOf & M11C, +>( + m1: M1, + m2: M2, + m3: M3, + m4: M4, + m5: M5, + m6: M6, + m7: M7, + m8: M8, + m9: M9, + m10: M10, + m11: M11, + m12: M12 +): Middleware< + RequiredContextOf & + Satisfy, M1C> & + Satisfy, M2C> & + Satisfy, M3C> & + Satisfy, M4C> & + Satisfy, M5C> & + Satisfy, M6C> & + Satisfy, M7C> & + Satisfy, M8C> & + Satisfy, M9C> & + Satisfy, M10C> & + Satisfy, M11C>, + M12C, + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf +> + +function composeMiddleware< + M1 extends Middleware, + M1R extends RequiredContextOf, + M1C extends AddedContextOf, + M2 extends Middleware, + M2R extends Satisfy, M1C>, + M2C extends AddedContextOf & M1C, + M3 extends Middleware, + M3R extends Satisfy, M2C>, + M3C extends AddedContextOf & M2C, + M4 extends Middleware, + M4R extends Satisfy, M3C>, + M4C extends AddedContextOf & M3C, + M5 extends Middleware, + M5R extends Satisfy, M4C>, + M5C extends AddedContextOf & M4C, + M6 extends Middleware, + M6R extends Satisfy, M5C>, + M6C extends AddedContextOf & M5C, + M7 extends Middleware, + M7R extends Satisfy, M6C>, + M7C extends AddedContextOf & M6C, + M8 extends Middleware, + M8R extends Satisfy, M7C>, + M8C extends AddedContextOf & M7C, + M9 extends Middleware, + M9R extends Satisfy, M8C>, + M9C extends AddedContextOf & M8C, + M10 extends Middleware, + M10R extends Satisfy, M9C>, + M10C extends AddedContextOf & M9C, + M11 extends Middleware, + M11R extends Satisfy, M10C>, + M11C extends AddedContextOf & M10C, + M12 extends Middleware, + M12R extends Satisfy, M11C>, + M12C extends AddedContextOf & M11C, + M13 extends Middleware, + M13R extends Satisfy, M12C>, + M13C extends AddedContextOf & M12C, +>( + m1: M1, + m2: M2, + m3: M3, + m4: M4, + m5: M5, + m6: M6, + m7: M7, + m8: M8, + m9: M9, + m10: M10, + m11: M11, + m12: M12, + m13: M13 +): Middleware< + RequiredContextOf & + Satisfy, M1C> & + Satisfy, M2C> & + Satisfy, M3C> & + Satisfy, M4C> & + Satisfy, M5C> & + Satisfy, M6C> & + Satisfy, M7C> & + Satisfy, M8C> & + Satisfy, M9C> & + Satisfy, M10C> & + Satisfy, M11C> & + Satisfy, M12C>, + M13C, + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf +> + +function composeMiddleware< + M1 extends Middleware, + M1R extends RequiredContextOf, + M1C extends AddedContextOf, + M2 extends Middleware, + M2R extends Satisfy, M1C>, + M2C extends AddedContextOf & M1C, + M3 extends Middleware, + M3R extends Satisfy, M2C>, + M3C extends AddedContextOf & M2C, + M4 extends Middleware, + M4R extends Satisfy, M3C>, + M4C extends AddedContextOf & M3C, + M5 extends Middleware, + M5R extends Satisfy, M4C>, + M5C extends AddedContextOf & M4C, + M6 extends Middleware, + M6R extends Satisfy, M5C>, + M6C extends AddedContextOf & M5C, + M7 extends Middleware, + M7R extends Satisfy, M6C>, + M7C extends AddedContextOf & M6C, + M8 extends Middleware, + M8R extends Satisfy, M7C>, + M8C extends AddedContextOf & M7C, + M9 extends Middleware, + M9R extends Satisfy, M8C>, + M9C extends AddedContextOf & M8C, + M10 extends Middleware, + M10R extends Satisfy, M9C>, + M10C extends AddedContextOf & M9C, + M11 extends Middleware, + M11R extends Satisfy, M10C>, + M11C extends AddedContextOf & M10C, + M12 extends Middleware, + M12R extends Satisfy, M11C>, + M12C extends AddedContextOf & M11C, + M13 extends Middleware, + M13R extends Satisfy, M12C>, + M13C extends AddedContextOf & M12C, + M14 extends Middleware, + M14R extends Satisfy, M13C>, + M14C extends AddedContextOf & M13C, +>( + m1: M1, + m2: M2, + m3: M3, + m4: M4, + m5: M5, + m6: M6, + m7: M7, + m8: M8, + m9: M9, + m10: M10, + m11: M11, + m12: M12, + m13: M13, + m14: M14 +): Middleware< + RequiredContextOf & + Satisfy, M1C> & + Satisfy, M2C> & + Satisfy, M3C> & + Satisfy, M4C> & + Satisfy, M5C> & + Satisfy, M6C> & + Satisfy, M7C> & + Satisfy, M8C> & + Satisfy, M9C> & + Satisfy, M10C> & + Satisfy, M11C> & + Satisfy, M12C> & + Satisfy, M13C>, + M14C, + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf +> + +function composeMiddleware< + M1 extends Middleware, + M1R extends RequiredContextOf, + M1C extends AddedContextOf, + M2 extends Middleware, + M2R extends Satisfy, M1C>, + M2C extends AddedContextOf & M1C, + M3 extends Middleware, + M3R extends Satisfy, M2C>, + M3C extends AddedContextOf & M2C, + M4 extends Middleware, + M4R extends Satisfy, M3C>, + M4C extends AddedContextOf & M3C, + M5 extends Middleware, + M5R extends Satisfy, M4C>, + M5C extends AddedContextOf & M4C, + M6 extends Middleware, + M6R extends Satisfy, M5C>, + M6C extends AddedContextOf & M5C, + M7 extends Middleware, + M7R extends Satisfy, M6C>, + M7C extends AddedContextOf & M6C, + M8 extends Middleware, + M8R extends Satisfy, M7C>, + M8C extends AddedContextOf & M7C, + M9 extends Middleware, + M9R extends Satisfy, M8C>, + M9C extends AddedContextOf & M8C, + M10 extends Middleware, + M10R extends Satisfy, M9C>, + M10C extends AddedContextOf & M9C, + M11 extends Middleware, + M11R extends Satisfy, M10C>, + M11C extends AddedContextOf & M10C, + M12 extends Middleware, + M12R extends Satisfy, M11C>, + M12C extends AddedContextOf & M11C, + M13 extends Middleware, + M13R extends Satisfy, M12C>, + M13C extends AddedContextOf & M12C, + M14 extends Middleware, + M14R extends Satisfy, M13C>, + M14C extends AddedContextOf & M13C, + M15 extends Middleware, + M15R extends Satisfy, M14C>, + M15C extends AddedContextOf & M14C, +>( + m1: M1, + m2: M2, + m3: M3, + m4: M4, + m5: M5, + m6: M6, + m7: M7, + m8: M8, + m9: M9, + m10: M10, + m11: M11, + m12: M12, + m13: M13, + m14: M14, + m15: M15 +): Middleware< + RequiredContextOf & + Satisfy, M1C> & + Satisfy, M2C> & + Satisfy, M3C> & + Satisfy, M4C> & + Satisfy, M5C> & + Satisfy, M6C> & + Satisfy, M7C> & + Satisfy, M8C> & + Satisfy, M9C> & + Satisfy, M10C> & + Satisfy, M11C> & + Satisfy, M12C> & + Satisfy, M13C> & + Satisfy, M14C>, + M15C, + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf +> + +function composeMiddleware< + M1 extends Middleware, + M1R extends RequiredContextOf, + M1C extends AddedContextOf, + M2 extends Middleware, + M2R extends Satisfy, M1C>, + M2C extends AddedContextOf & M1C, + M3 extends Middleware, + M3R extends Satisfy, M2C>, + M3C extends AddedContextOf & M2C, + M4 extends Middleware, + M4R extends Satisfy, M3C>, + M4C extends AddedContextOf & M3C, + M5 extends Middleware, + M5R extends Satisfy, M4C>, + M5C extends AddedContextOf & M4C, + M6 extends Middleware, + M6R extends Satisfy, M5C>, + M6C extends AddedContextOf & M5C, + M7 extends Middleware, + M7R extends Satisfy, M6C>, + M7C extends AddedContextOf & M6C, + M8 extends Middleware, + M8R extends Satisfy, M7C>, + M8C extends AddedContextOf & M7C, + M9 extends Middleware, + M9R extends Satisfy, M8C>, + M9C extends AddedContextOf & M8C, + M10 extends Middleware, + M10R extends Satisfy, M9C>, + M10C extends AddedContextOf & M9C, + M11 extends Middleware, + M11R extends Satisfy, M10C>, + M11C extends AddedContextOf & M10C, + M12 extends Middleware, + M12R extends Satisfy, M11C>, + M12C extends AddedContextOf & M11C, + M13 extends Middleware, + M13R extends Satisfy, M12C>, + M13C extends AddedContextOf & M12C, + M14 extends Middleware, + M14R extends Satisfy, M13C>, + M14C extends AddedContextOf & M13C, + M15 extends Middleware, + M15R extends Satisfy, M14C>, + M15C extends AddedContextOf & M14C, + M16 extends Middleware, + M16R extends Satisfy, M15C>, + M16C extends AddedContextOf & M15C, +>( + m1: M1, + m2: M2, + m3: M3, + m4: M4, + m5: M5, + m6: M6, + m7: M7, + m8: M8, + m9: M9, + m10: M10, + m11: M11, + m12: M12, + m13: M13, + m14: M14, + m15: M15, + m16: M16 +): Middleware< + RequiredContextOf & + Satisfy, M1C> & + Satisfy, M2C> & + Satisfy, M3C> & + Satisfy, M4C> & + Satisfy, M5C> & + Satisfy, M6C> & + Satisfy, M7C> & + Satisfy, M8C> & + Satisfy, M9C> & + Satisfy, M10C> & + Satisfy, M11C> & + Satisfy, M12C> & + Satisfy, M13C> & + Satisfy, M14C> & + Satisfy, M15C>, + M16C, + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf +> + +function composeMiddleware< + M1 extends Middleware, + M1R extends RequiredContextOf, + M1C extends AddedContextOf, + M2 extends Middleware, + M2R extends Satisfy, M1C>, + M2C extends AddedContextOf & M1C, + M3 extends Middleware, + M3R extends Satisfy, M2C>, + M3C extends AddedContextOf & M2C, + M4 extends Middleware, + M4R extends Satisfy, M3C>, + M4C extends AddedContextOf & M3C, + M5 extends Middleware, + M5R extends Satisfy, M4C>, + M5C extends AddedContextOf & M4C, + M6 extends Middleware, + M6R extends Satisfy, M5C>, + M6C extends AddedContextOf & M5C, + M7 extends Middleware, + M7R extends Satisfy, M6C>, + M7C extends AddedContextOf & M6C, + M8 extends Middleware, + M8R extends Satisfy, M7C>, + M8C extends AddedContextOf & M7C, + M9 extends Middleware, + M9R extends Satisfy, M8C>, + M9C extends AddedContextOf & M8C, + M10 extends Middleware, + M10R extends Satisfy, M9C>, + M10C extends AddedContextOf & M9C, + M11 extends Middleware, + M11R extends Satisfy, M10C>, + M11C extends AddedContextOf & M10C, + M12 extends Middleware, + M12R extends Satisfy, M11C>, + M12C extends AddedContextOf & M11C, + M13 extends Middleware, + M13R extends Satisfy, M12C>, + M13C extends AddedContextOf & M12C, + M14 extends Middleware, + M14R extends Satisfy, M13C>, + M14C extends AddedContextOf & M13C, + M15 extends Middleware, + M15R extends Satisfy, M14C>, + M15C extends AddedContextOf & M14C, + M16 extends Middleware, + M16R extends Satisfy, M15C>, + M16C extends AddedContextOf & M15C, + M17 extends Middleware, + M17R extends Satisfy, M16C>, + M17C extends AddedContextOf & M16C, +>( + m1: M1, + m2: M2, + m3: M3, + m4: M4, + m5: M5, + m6: M6, + m7: M7, + m8: M8, + m9: M9, + m10: M10, + m11: M11, + m12: M12, + m13: M13, + m14: M14, + m15: M15, + m16: M16, + m17: M17 +): Middleware< + RequiredContextOf & + Satisfy, M1C> & + Satisfy, M2C> & + Satisfy, M3C> & + Satisfy, M4C> & + Satisfy, M5C> & + Satisfy, M6C> & + Satisfy, M7C> & + Satisfy, M8C> & + Satisfy, M9C> & + Satisfy, M10C> & + Satisfy, M11C> & + Satisfy, M12C> & + Satisfy, M13C> & + Satisfy, M14C> & + Satisfy, M15C> & + Satisfy, M16C>, + M17C, + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf +> + +function composeMiddleware< + M1 extends Middleware, + M1R extends RequiredContextOf, + M1C extends AddedContextOf, + M2 extends Middleware, + M2R extends Satisfy, M1C>, + M2C extends AddedContextOf & M1C, + M3 extends Middleware, + M3R extends Satisfy, M2C>, + M3C extends AddedContextOf & M2C, + M4 extends Middleware, + M4R extends Satisfy, M3C>, + M4C extends AddedContextOf & M3C, + M5 extends Middleware, + M5R extends Satisfy, M4C>, + M5C extends AddedContextOf & M4C, + M6 extends Middleware, + M6R extends Satisfy, M5C>, + M6C extends AddedContextOf & M5C, + M7 extends Middleware, + M7R extends Satisfy, M6C>, + M7C extends AddedContextOf & M6C, + M8 extends Middleware, + M8R extends Satisfy, M7C>, + M8C extends AddedContextOf & M7C, + M9 extends Middleware, + M9R extends Satisfy, M8C>, + M9C extends AddedContextOf & M8C, + M10 extends Middleware, + M10R extends Satisfy, M9C>, + M10C extends AddedContextOf & M9C, + M11 extends Middleware, + M11R extends Satisfy, M10C>, + M11C extends AddedContextOf & M10C, + M12 extends Middleware, + M12R extends Satisfy, M11C>, + M12C extends AddedContextOf & M11C, + M13 extends Middleware, + M13R extends Satisfy, M12C>, + M13C extends AddedContextOf & M12C, + M14 extends Middleware, + M14R extends Satisfy, M13C>, + M14C extends AddedContextOf & M13C, + M15 extends Middleware, + M15R extends Satisfy, M14C>, + M15C extends AddedContextOf & M14C, + M16 extends Middleware, + M16R extends Satisfy, M15C>, + M16C extends AddedContextOf & M15C, + M17 extends Middleware, + M17R extends Satisfy, M16C>, + M17C extends AddedContextOf & M16C, + M18 extends Middleware, + M18R extends Satisfy, M17C>, + M18C extends AddedContextOf & M17C, +>( + m1: M1, + m2: M2, + m3: M3, + m4: M4, + m5: M5, + m6: M6, + m7: M7, + m8: M8, + m9: M9, + m10: M10, + m11: M11, + m12: M12, + m13: M13, + m14: M14, + m15: M15, + m16: M16, + m17: M17, + m18: M18 +): Middleware< + RequiredContextOf & + Satisfy, M1C> & + Satisfy, M2C> & + Satisfy, M3C> & + Satisfy, M4C> & + Satisfy, M5C> & + Satisfy, M6C> & + Satisfy, M7C> & + Satisfy, M8C> & + Satisfy, M9C> & + Satisfy, M10C> & + Satisfy, M11C> & + Satisfy, M12C> & + Satisfy, M13C> & + Satisfy, M14C> & + Satisfy, M15C> & + Satisfy, M16C> & + Satisfy, M17C>, + M18C, + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf +> + +function composeMiddleware< + M1 extends Middleware, + M1R extends RequiredContextOf, + M1C extends AddedContextOf, + M2 extends Middleware, + M2R extends Satisfy, M1C>, + M2C extends AddedContextOf & M1C, + M3 extends Middleware, + M3R extends Satisfy, M2C>, + M3C extends AddedContextOf & M2C, + M4 extends Middleware, + M4R extends Satisfy, M3C>, + M4C extends AddedContextOf & M3C, + M5 extends Middleware, + M5R extends Satisfy, M4C>, + M5C extends AddedContextOf & M4C, + M6 extends Middleware, + M6R extends Satisfy, M5C>, + M6C extends AddedContextOf & M5C, + M7 extends Middleware, + M7R extends Satisfy, M6C>, + M7C extends AddedContextOf & M6C, + M8 extends Middleware, + M8R extends Satisfy, M7C>, + M8C extends AddedContextOf & M7C, + M9 extends Middleware, + M9R extends Satisfy, M8C>, + M9C extends AddedContextOf & M8C, + M10 extends Middleware, + M10R extends Satisfy, M9C>, + M10C extends AddedContextOf & M9C, + M11 extends Middleware, + M11R extends Satisfy, M10C>, + M11C extends AddedContextOf & M10C, + M12 extends Middleware, + M12R extends Satisfy, M11C>, + M12C extends AddedContextOf & M11C, + M13 extends Middleware, + M13R extends Satisfy, M12C>, + M13C extends AddedContextOf & M12C, + M14 extends Middleware, + M14R extends Satisfy, M13C>, + M14C extends AddedContextOf & M13C, + M15 extends Middleware, + M15R extends Satisfy, M14C>, + M15C extends AddedContextOf & M14C, + M16 extends Middleware, + M16R extends Satisfy, M15C>, + M16C extends AddedContextOf & M15C, + M17 extends Middleware, + M17R extends Satisfy, M16C>, + M17C extends AddedContextOf & M16C, + M18 extends Middleware, + M18R extends Satisfy, M17C>, + M18C extends AddedContextOf & M17C, + M19 extends Middleware, + M19R extends Satisfy, M18C>, + M19C extends AddedContextOf & M18C, +>( + m1: M1, + m2: M2, + m3: M3, + m4: M4, + m5: M5, + m6: M6, + m7: M7, + m8: M8, + m9: M9, + m10: M10, + m11: M11, + m12: M12, + m13: M13, + m14: M14, + m15: M15, + m16: M16, + m17: M17, + m18: M18, + m19: M19 +): Middleware< + RequiredContextOf & + Satisfy, M1C> & + Satisfy, M2C> & + Satisfy, M3C> & + Satisfy, M4C> & + Satisfy, M5C> & + Satisfy, M6C> & + Satisfy, M7C> & + Satisfy, M8C> & + Satisfy, M9C> & + Satisfy, M10C> & + Satisfy, M11C> & + Satisfy, M12C> & + Satisfy, M13C> & + Satisfy, M14C> & + Satisfy, M15C> & + Satisfy, M16C> & + Satisfy, M17C> & + Satisfy, M18C>, + M19C, + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf +> + +function composeMiddleware< + M1 extends Middleware, + M1R extends RequiredContextOf, + M1C extends AddedContextOf, + M2 extends Middleware, + M2R extends Satisfy, M1C>, + M2C extends AddedContextOf & M1C, + M3 extends Middleware, + M3R extends Satisfy, M2C>, + M3C extends AddedContextOf & M2C, + M4 extends Middleware, + M4R extends Satisfy, M3C>, + M4C extends AddedContextOf & M3C, + M5 extends Middleware, + M5R extends Satisfy, M4C>, + M5C extends AddedContextOf & M4C, + M6 extends Middleware, + M6R extends Satisfy, M5C>, + M6C extends AddedContextOf & M5C, + M7 extends Middleware, + M7R extends Satisfy, M6C>, + M7C extends AddedContextOf & M6C, + M8 extends Middleware, + M8R extends Satisfy, M7C>, + M8C extends AddedContextOf & M7C, + M9 extends Middleware, + M9R extends Satisfy, M8C>, + M9C extends AddedContextOf & M8C, + M10 extends Middleware, + M10R extends Satisfy, M9C>, + M10C extends AddedContextOf & M9C, + M11 extends Middleware, + M11R extends Satisfy, M10C>, + M11C extends AddedContextOf & M10C, + M12 extends Middleware, + M12R extends Satisfy, M11C>, + M12C extends AddedContextOf & M11C, + M13 extends Middleware, + M13R extends Satisfy, M12C>, + M13C extends AddedContextOf & M12C, + M14 extends Middleware, + M14R extends Satisfy, M13C>, + M14C extends AddedContextOf & M13C, + M15 extends Middleware, + M15R extends Satisfy, M14C>, + M15C extends AddedContextOf & M14C, + M16 extends Middleware, + M16R extends Satisfy, M15C>, + M16C extends AddedContextOf & M15C, + M17 extends Middleware, + M17R extends Satisfy, M16C>, + M17C extends AddedContextOf & M16C, + M18 extends Middleware, + M18R extends Satisfy, M17C>, + M18C extends AddedContextOf & M17C, + M19 extends Middleware, + M19R extends Satisfy, M18C>, + M19C extends AddedContextOf & M18C, + M20 extends Middleware, + M20R extends Satisfy, M19C>, + M20C extends AddedContextOf & M19C, +>( + m1: M1, + m2: M2, + m3: M3, + m4: M4, + m5: M5, + m6: M6, + m7: M7, + m8: M8, + m9: M9, + m10: M10, + m11: M11, + m12: M12, + m13: M13, + m14: M14, + m15: M15, + m16: M16, + m17: M17, + m18: M18, + m19: M19, + m20: M20 +): Middleware< + RequiredContextOf & + Satisfy, M1C> & + Satisfy, M2C> & + Satisfy, M3C> & + Satisfy, M4C> & + Satisfy, M5C> & + Satisfy, M6C> & + Satisfy, M7C> & + Satisfy, M8C> & + Satisfy, M9C> & + Satisfy, M10C> & + Satisfy, M11C> & + Satisfy, M12C> & + Satisfy, M13C> & + Satisfy, M14C> & + Satisfy, M15C> & + Satisfy, M16C> & + Satisfy, M17C> & + Satisfy, M18C> & + Satisfy, M19C>, + M20C, + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf +> + +function composeMiddleware( + ...middlewares: Middleware[] +): Middleware { + return (handler) => middlewares.reduceRight((h, m) => m(h), handler) +} + +export { composeMiddleware, Middleware, Handler } diff --git a/test/composeMiddleware.spec.ts b/test/composeMiddleware.spec.ts new file mode 100644 index 0000000..b9bb8d3 --- /dev/null +++ b/test/composeMiddleware.spec.ts @@ -0,0 +1,117 @@ +import { describe, it } from "node:test"; +import assert from "node:assert"; +import { expectTypeOf } from "expect-type"; + +import { composeMiddleware, Middleware, Handler } from "../src/noodle4-output.js"; + +const handler: Handler<{ more: string }, {}> = async (_request, env, ctx) => { + return new Response(JSON.stringify({ env, ctx })); +}; + +const withUser: Middleware<{}, { user: string }, { RESOURCE1: string }> = + (handler) => async (request, env, ctx) => { + return handler(request, env, { ...ctx, user: "joey" }); + }; + +const withData: Middleware<{}, { data: string }> = + (handler) => async (request, env, ctx) => { + return handler(request, env, { ...ctx, data: "some-stuff" }); + }; + +const usingUser: Middleware<{ user: string }, {}, { RESOURCE2: string }> = + (handler) => async (request, env, ctx) => { + return handler(request, env, ctx); + }; + +const usingData: Middleware<{ data: string }, {}, { RESOURCE1: string }> = + (handler) => async (request, env, ctx) => { + return handler(request, env, ctx); + }; + +const req = new Request("http://example.com/"); + +describe(composeMiddleware.name, () => { + it("can compose a single middleware", async () => { + const composed = composeMiddleware(usingUser); + const wrappedHandler = composed(handler); + + expectTypeOf(wrappedHandler).parameters.branded.toEqualTypeOf< + [Request, { RESOURCE2: string }, { user: string; more: string }] + >(); + + const response = await wrappedHandler( + req, + { RESOURCE2: "resource2" }, + { user: "joey", more: "context" }, + ).then((res) => res.json()); + + assert.deepStrictEqual(response, { + env: { RESOURCE2: "resource2" }, + ctx: { user: "joey", more: "context" }, + }); + }); + + it("can compose middlewares which require things", async () => { + const composed = composeMiddleware(usingUser, usingData); + const wrappedHandler = composed(handler); + + expectTypeOf(wrappedHandler).parameters.branded.toEqualTypeOf< + [ + Request, + { RESOURCE1: string; RESOURCE2: string }, + { user: string; data: string; more: string }, + ] + >(); + + const response = await wrappedHandler( + req, + { RESOURCE1: "resource1", RESOURCE2: "resource2" }, + { user: "joey", data: "some-stuff", more: "context" }, + ).then((res) => res.json()); + + assert.deepStrictEqual(response, { + env: { RESOURCE1: "resource1", RESOURCE2: "resource2" }, + ctx: { user: "joey", data: "some-stuff", more: "context" }, + }); + }); + + it("can compose middlewares which provide things", async () => { + const composed = composeMiddleware(withUser, withData); + const wrappedHandler = composed(handler); + + expectTypeOf(wrappedHandler).parameters.branded.toEqualTypeOf< + [Request, { RESOURCE1: string }, { more: string }] + >(); + + const response = await wrappedHandler( + req, + { RESOURCE1: "resource1" }, + { more: "context" }, + ).then((res) => res.json()); + + assert.deepStrictEqual(response, { + env: { RESOURCE1: "resource1" }, + ctx: { user: "joey", data: "some-stuff", more: "context" }, + }); + }); + + it("can compose middlewares which require and provide things", async () => { + const composed = composeMiddleware(withUser, usingUser); + const wrappedHandler = composed(handler); + + expectTypeOf(wrappedHandler).parameters.branded.toEqualTypeOf< + [Request, { RESOURCE1: string; RESOURCE2: string }, { more: string }] + >(); + + const response = await wrappedHandler( + req, + { RESOURCE1: "resource1", RESOURCE2: "resource2" }, + { more: "context" }, + ).then((res) => res.json()); + + assert.deepStrictEqual(response, { + env: { RESOURCE1: "resource1", RESOURCE2: "resource2" }, + ctx: { user: "joey", more: "context" }, + }); + }); +}); diff --git a/tsconfig.json b/tsconfig.json index 2182fe9..6adcb62 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,6 @@ { - "include": ["src/**/*.js"], + "include": ["src/**/*.js", "scripts/**/*.js"], "compilerOptions": { "declaration": true, "declarationMap": true, From 0b1896b9b4a69f2c7665c5ea47a7d4aaaa559031 Mon Sep 17 00:00:00 2001 From: Petra Jaros Date: Wed, 8 Jan 2025 16:30:34 -0500 Subject: [PATCH 2/6] Recommend VSCode extensions --- .vscode/extensions.json | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .vscode/extensions.json diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..a60fb9e --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,6 @@ +{ + "recommendations": [ + "esbenp.prettier-vscode", + "bierner.comment-tagged-templates" + ] +} \ No newline at end of file From d650b62a3237a21885c92e35383f948b6ee0ae9a Mon Sep 17 00:00:00 2001 From: Petra Jaros Date: Thu, 9 Jan 2025 12:27:00 -0500 Subject: [PATCH 3/6] Actually use the new `composeMiddleware()` --- package-lock.json | 507 ++++++++++++++++++ package.json | 3 +- scripts/generateComposeMiddleware.js | 81 +-- src/bindings.d.ts | 78 ++- ...seMiddleware.ts => composeMiddleware.d.ts} | 110 ++-- src/composeMiddleware.js | 11 + src/handlers/block.js | 4 +- src/handlers/car.js | 21 +- src/handlers/unixfs-dir.js | 10 +- src/handlers/unixfs-file.js | 10 +- src/handlers/unixfs.js | 4 +- src/middleware.js | 97 ++-- src/util/errors.js | 1 - src/util/range.js | 13 +- test/composeMiddleware.spec.ts | 121 ++--- 15 files changed, 792 insertions(+), 279 deletions(-) rename src/{composeMiddleware.ts => composeMiddleware.d.ts} (93%) create mode 100644 src/composeMiddleware.js diff --git a/package-lock.json b/package-lock.json index 2ca5eff..0aa92d7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -31,6 +31,7 @@ "ipfs-unixfs-exporter": "^13.3.0", "prettier": "^3.4.2", "standard": "^17.1.0", + "tsx": "^4.19.2", "typescript": "^5.3.3" } }, @@ -276,6 +277,414 @@ "@chainsafe/is-ip": "^2.0.1" } }, + "node_modules/@esbuild/aix-ppc64": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.23.1.tgz", + "integrity": "sha512-6VhYk1diRqrhBAqpJEdjASR/+WVRtfjpqKuNw11cLiaWpAT/Uu+nokB+UJnevzy/P9C/ty6AOe0dwueMrGh/iQ==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "aix" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.23.1.tgz", + "integrity": "sha512-uz6/tEy2IFm9RYOyvKl88zdzZfwEfKZmnX9Cj1BHjeSGNuGLuMD1kR8y5bteYmwqKm1tj8m4cb/aKEorr6fHWQ==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm64": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.23.1.tgz", + "integrity": "sha512-xw50ipykXcLstLeWH7WRdQuysJqejuAGPd30vd1i5zSyKK3WE+ijzHmLKxdiCMtH1pHz78rOg0BKSYOSB/2Khw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-x64": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.23.1.tgz", + "integrity": "sha512-nlN9B69St9BwUoB+jkyU090bru8L0NA3yFvAd7k8dNsVH8bi9a8cUAUSEcEEgTp2z3dbEDGJGfP6VUnkQnlReg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-arm64": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.23.1.tgz", + "integrity": "sha512-YsS2e3Wtgnw7Wq53XXBLcV6JhRsEq8hkfg91ESVadIrzr9wO6jJDMZnCQbHm1Guc5t/CdDiFSSfWP58FNuvT3Q==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-x64": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.23.1.tgz", + "integrity": "sha512-aClqdgTDVPSEGgoCS8QDG37Gu8yc9lTHNAQlsztQ6ENetKEO//b8y31MMu2ZaPbn4kVsIABzVLXYLhCGekGDqw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-arm64": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.23.1.tgz", + "integrity": "sha512-h1k6yS8/pN/NHlMl5+v4XPfikhJulk4G+tKGFIOwURBSFzE8bixw1ebjluLOjfwtLqY0kewfjLSrO6tN2MgIhA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-x64": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.23.1.tgz", + "integrity": "sha512-lK1eJeyk1ZX8UklqFd/3A60UuZ/6UVfGT2LuGo3Wp4/z7eRTRYY+0xOu2kpClP+vMTi9wKOfXi2vjUpO1Ro76g==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.23.1.tgz", + "integrity": "sha512-CXXkzgn+dXAPs3WBwE+Kvnrf4WECwBdfjfeYHpMeVxWE0EceB6vhWGShs6wi0IYEqMSIzdOF1XjQ/Mkm5d7ZdQ==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm64": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.23.1.tgz", + "integrity": "sha512-/93bf2yxencYDnItMYV/v116zff6UyTjo4EtEQjUBeGiVpMmffDNUyD9UN2zV+V3LRV3/on4xdZ26NKzn6754g==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ia32": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.23.1.tgz", + "integrity": "sha512-VTN4EuOHwXEkXzX5nTvVY4s7E/Krz7COC8xkftbbKRYAl96vPiUssGkeMELQMOnLOJ8k3BY1+ZY52tttZnHcXQ==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-loong64": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.23.1.tgz", + "integrity": "sha512-Vx09LzEoBa5zDnieH8LSMRToj7ir/Jeq0Gu6qJ/1GcBq9GkfoEAoXvLiW1U9J1qE/Y/Oyaq33w5p2ZWrNNHNEw==", + "cpu": [ + "loong64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-mips64el": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.23.1.tgz", + "integrity": "sha512-nrFzzMQ7W4WRLNUOU5dlWAqa6yVeI0P78WKGUo7lg2HShq/yx+UYkeNSE0SSfSure0SqgnsxPvmAUu/vu0E+3Q==", + "cpu": [ + "mips64el" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ppc64": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.23.1.tgz", + "integrity": "sha512-dKN8fgVqd0vUIjxuJI6P/9SSSe/mB9rvA98CSH2sJnlZ/OCZWO1DJvxj8jvKTfYUdGfcq2dDxoKaC6bHuTlgcw==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-riscv64": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.23.1.tgz", + "integrity": "sha512-5AV4Pzp80fhHL83JM6LoA6pTQVWgB1HovMBsLQ9OZWLDqVY8MVobBXNSmAJi//Csh6tcY7e7Lny2Hg1tElMjIA==", + "cpu": [ + "riscv64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-s390x": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.23.1.tgz", + "integrity": "sha512-9ygs73tuFCe6f6m/Tb+9LtYxWR4c9yg7zjt2cYkjDbDpV/xVn+68cQxMXCjUpYwEkze2RcU/rMnfIXNRFmSoDw==", + "cpu": [ + "s390x" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-x64": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.23.1.tgz", + "integrity": "sha512-EV6+ovTsEXCPAp58g2dD68LxoP/wK5pRvgy0J/HxPGB009omFPv3Yet0HiaqvrIrgPTBuC6wCH1LTOY91EO5hQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-x64": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.23.1.tgz", + "integrity": "sha512-aevEkCNu7KlPRpYLjwmdcuNz6bDFiE7Z8XC4CPqExjTvrHugh28QzUXVOZtiYghciKUacNktqxdpymplil1beA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-arm64": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.23.1.tgz", + "integrity": "sha512-3x37szhLexNA4bXhLrCC/LImN/YtWis6WXr1VESlfVtVeoFJBRINPJ3f0a/6LV8zpikqoUg4hyXw0sFBt5Cr+Q==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-x64": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.23.1.tgz", + "integrity": "sha512-aY2gMmKmPhxfU+0EdnN+XNtGbjfQgwZj43k8G3fyrDM/UdZww6xrWxmDkuz2eCZchqVeABjV5BpildOrUbBTqA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/sunos-x64": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.23.1.tgz", + "integrity": "sha512-RBRT2gqEl0IKQABT4XTj78tpk9v7ehp+mazn2HbUeZl1YMdaGAQqhapjGTCe7uw7y0frDi4gS0uHzhvpFuI1sA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-arm64": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.23.1.tgz", + "integrity": "sha512-4O+gPR5rEBe2FpKOVyiJ7wNDPA8nGzDuJ6gN4okSA1gEOYZ67N8JPk58tkWtdtPeLz7lBnY6I5L3jdsr3S+A6A==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-ia32": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.23.1.tgz", + "integrity": "sha512-BcaL0Vn6QwCwre3Y717nVHZbAa4UBEigzFm6VdsVdT/MbZ38xoj1X9HPkZhbmaBGUD1W8vxAfffbDe8bA6AKnQ==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-x64": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.23.1.tgz", + "integrity": "sha512-BHpFFeslkWrXWyUPnbKm+xYYVYruCinGcftSBaa8zoF9hZO4BcSCFUvHVTtzpIY6YzUnYtuEhZ+C9iEXjxnasg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, "node_modules/@eslint-community/eslint-utils": { "version": "4.4.0", "resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.4.0.tgz", @@ -3526,6 +3935,46 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/esbuild": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.23.1.tgz", + "integrity": "sha512-VVNz/9Sa0bs5SELtn3f7qhJCDPCF5oMEl5cO9/SSinpE9hbPVvxbd572HH5AKiP7WD8INO53GgfDDhRjkylHEg==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "@esbuild/aix-ppc64": "0.23.1", + "@esbuild/android-arm": "0.23.1", + "@esbuild/android-arm64": "0.23.1", + "@esbuild/android-x64": "0.23.1", + "@esbuild/darwin-arm64": "0.23.1", + "@esbuild/darwin-x64": "0.23.1", + "@esbuild/freebsd-arm64": "0.23.1", + "@esbuild/freebsd-x64": "0.23.1", + "@esbuild/linux-arm": "0.23.1", + "@esbuild/linux-arm64": "0.23.1", + "@esbuild/linux-ia32": "0.23.1", + "@esbuild/linux-loong64": "0.23.1", + "@esbuild/linux-mips64el": "0.23.1", + "@esbuild/linux-ppc64": "0.23.1", + "@esbuild/linux-riscv64": "0.23.1", + "@esbuild/linux-s390x": "0.23.1", + "@esbuild/linux-x64": "0.23.1", + "@esbuild/netbsd-x64": "0.23.1", + "@esbuild/openbsd-arm64": "0.23.1", + "@esbuild/openbsd-x64": "0.23.1", + "@esbuild/sunos-x64": "0.23.1", + "@esbuild/win32-arm64": "0.23.1", + "@esbuild/win32-ia32": "0.23.1", + "@esbuild/win32-x64": "0.23.1" + } + }, "node_modules/escalade": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz", @@ -4198,6 +4647,21 @@ "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", "dev": true }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, "node_modules/function-bind": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", @@ -4301,6 +4765,19 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/get-tsconfig": { + "version": "4.8.1", + "resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.8.1.tgz", + "integrity": "sha512-k9PN+cFBmaLWtVz29SkUoqU5O0slLuHJXt/2P+tMVFT+phsSGXGkp9t3rQIqdz0e+06EHNGs3oM6ZX1s2zHxRg==", + "dev": true, + "license": "MIT", + "dependencies": { + "resolve-pkg-maps": "^1.0.0" + }, + "funding": { + "url": "https://github.com/privatenumber/get-tsconfig?sponsor=1" + } + }, "node_modules/glob": { "version": "7.2.3", "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", @@ -6850,6 +7327,16 @@ "node": ">=4" } }, + "node_modules/resolve-pkg-maps": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz", + "integrity": "sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/privatenumber/resolve-pkg-maps?sponsor=1" + } + }, "node_modules/retimer": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/retimer/-/retimer-3.0.0.tgz", @@ -7346,6 +7833,26 @@ "strip-bom": "^3.0.0" } }, + "node_modules/tsx": { + "version": "4.19.2", + "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.19.2.tgz", + "integrity": "sha512-pOUl6Vo2LUq/bSa8S5q7b91cgNSjctn9ugq/+Mvow99qW6x/UZYwzxy/3NmqoT66eHYfCVvFvACC58UBPFf28g==", + "dev": true, + "license": "MIT", + "dependencies": { + "esbuild": "~0.23.0", + "get-tsconfig": "^4.7.5" + }, + "bin": { + "tsx": "dist/cli.mjs" + }, + "engines": { + "node": ">=18.0.0" + }, + "optionalDependencies": { + "fsevents": "~2.3.3" + } + }, "node_modules/type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", diff --git a/package.json b/package.json index bacaecc..9f546ed 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ }, "scripts": { "prepare": "npm run build", - "test": "node --test test/**/*.spec.js", + "test": "tsx --test test/**/*.spec.[jt]s", "lint": "standard", "generate-compose": "node scripts/generateComposeMiddleware.js", "generate-compose:watch": "node --watch scripts/generateComposeMiddleware.js", @@ -89,6 +89,7 @@ "ipfs-unixfs-exporter": "^13.3.0", "prettier": "^3.4.2", "standard": "^17.1.0", + "tsx": "^4.19.2", "typescript": "^5.3.3" }, "publishConfig": { diff --git a/scripts/generateComposeMiddleware.js b/scripts/generateComposeMiddleware.js index 3e48521..4da436b 100644 --- a/scripts/generateComposeMiddleware.js +++ b/scripts/generateComposeMiddleware.js @@ -35,53 +35,12 @@ const declarations = [ * This file is committed to the repository, as it should rarely change. */ - /** - * A Handler handles a request. It's an async function which takes a - * {@link Request} and returns a {@link Response}. It also has access to the - * context and environment for the request. - * - * @template Context The context keys used by the handler. - * @template Env The environment keys used by the handler. - */ - type Handler = ( - request: Request, - env: Env, - ctx: Context, - ) => Promise; - - /** - * A Middleware is a function that takes a {@link Handler} and returns a new - * one. It has access to the context and environment for the request. It can - * add to the context, or modify it, but it should not remove keys, so that - * upstream middleware can pass context to downstream middleware. It should - * generally not modify the environment, as that is shared across all requests. - * - * @template RequiredContext The context required by the middleware. These keys - * must be either provided by upstream middleware, or given to the ultimate - * handler. - * @template AddedContext The context added by the middleware. These keys will - * be available to downstream middleware. - * @template Env The environment keys used by the middleware. The entire - * environment should be passed to the outermost handler, at the top of the - * middleware stack. Middleware shouldn't modify the environment, and should - * pass it in its entirety when it calls the next handler. - */ - type Middleware< - RequiredContext extends {}, - AddedContext extends {} = {}, - Env extends {} = {}, - > = ( - h: Handler, - ) => Handler; - - export type RequiredContextOf> = - M extends Middleware ? T : never; - - export type AddedContextOf> = - M extends Middleware ? T : never; - - export type EnvOf> = - M extends Middleware ? T : never; + import { + AddedContextOf, + EnvOf, + Middleware, + RequiredContextOf, + } from './bindings' /** * Returns the result of satisfying the {@link Requirements} with the @@ -90,7 +49,18 @@ const declarations = [ export type Satisfy = With extends Pick ? Omit - : never; + : never + `, + + /* typescript */ ` + /** + * Composes multiple middleware functions into a single middleware function. The + * request will be seen by the composed middleware in the order they are given. + * + * Note: Due to TypeScript limitations, each arity of this function must be a + * separate overload. To compose more than ${MAX_ARGUMENTS} middleware functions, simply nest + * smaller compositions. + */ `, ...Array.from({ length: MAX_ARGUMENTS }) @@ -98,13 +68,7 @@ const declarations = [ .map((n) => createComposeMiddlewareOverloadDeclaration(n)), /* typescript */ ` - function composeMiddleware( - ...middlewares: Middleware[] - ): Middleware { - return (handler) => middlewares.reduceRight((h, m) => m(h), handler); - } - - export { composeMiddleware, Middleware, Handler }; + export { composeMiddleware }; `, ] @@ -119,7 +83,7 @@ function createComposeMiddlewareOverloadDeclaration(argCount) { const ns = Array.from({ length: argCount }).map((_, i) => i + 1) return ts.factory.createFunctionDeclaration( - undefined, + [ts.factory.createToken(ts.SyntaxKind.DeclareKeyword)], undefined, 'composeMiddleware', [ @@ -203,9 +167,11 @@ function createComposeMiddlewareOverloadDeclaration(argCount) { // Output +const filepath = 'src/composeMiddleware.d.ts' + const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed }) const resultFile = ts.createSourceFile( - 'noodle4-output.ts', + filepath, '', ts.ScriptTarget.Latest, false, @@ -220,7 +186,6 @@ const output = declarations ) .join('\n\n') -const filepath = 'src/composeMiddleware.ts' const prettierConfig = await prettier.resolveConfig(filepath) const formattedOutput = await prettier.format(output, { filepath, diff --git a/src/bindings.d.ts b/src/bindings.d.ts index 3ac3f24..a68bb4c 100644 --- a/src/bindings.d.ts +++ b/src/bindings.d.ts @@ -5,52 +5,90 @@ import type { TimeoutController } from 'timeout-abort-controller' export {} -export interface Environment { +export interface DebugEnvironment { DEBUG?: string } -export interface Context { +export interface CloudflareContext { waitUntil(promise: Promise): void } -export interface IpfsUrlContext extends Context { +export interface IpfsUrlContext { dataCid: CID path: string searchParams: URLSearchParams } -export interface TimeoutControllerContext extends Context { +export interface TimeoutControllerContext { timeoutController: TimeoutController } -export interface BlockContext extends Context { +export interface BlockContext { blocks: BlockService } -export interface DagContext extends Context { +export interface DagContext { dag: DagService } -export interface UnixfsContext extends Context { +export interface UnixfsContext { unixfs: UnixfsService } -export interface UnixfsEntryContext extends Context { +export interface UnixfsEntryContext { unixfsEntry: UnixFSEntry } -export interface Handler { - (request: Request, env: E, ctx: C): Promise -} +/** + * A Handler handles a request. It's an async function which takes a + * {@link Request} and returns a {@link Response}. It also has access to the + * context and environment for the request. + * + * @template Context The context keys used by the handler. + * @template Env The environment keys used by the handler. + */ +export type Handler = ( + request: Request, + env: Env, + ctx: Context +) => Promise /** - * Middleware is a function that returns a handler with a possibly extended - * context object. The first generic type is the "extended context". i.e. what - * the context looks like after the middleware is run. The second generic type - * is the "base context", or in other words the context _required_ by the - * middleware for it to run. The third type is the environment, which should - * not be modified. + * A Middleware is a function that takes a {@link Handler} and returns a new + * one. It has access to the context and environment for the request. It can + * add to the context, or modify it, but it should not remove keys, so that + * upstream middleware can pass context to downstream middleware. It should + * generally not modify the environment, as that is shared across all requests. + * + * @template RequiredContext The context required by the middleware. These keys + * must be either provided by upstream middleware, or given to the ultimate + * handler. + * @template AddedContext The context added by the middleware. These keys will + * be available to downstream middleware. + * @template Env The environment keys used by the middleware. The entire + * environment should be passed to the outermost handler, at the top of the + * middleware stack. Middleware shouldn't modify the environment, and should + * pass it in its entirety when it calls the next handler. */ -export interface Middleware { - (h: Handler): Handler -} +export type Middleware< + RequiredContext extends {} = {}, + AddedContext extends {} = {}, + Env extends {} = {}, +> = + /** + * @template HandlerRequiredContext The context required by the wrapped + * handler. + * @template HandlerEnv The environment keys used by the wrapped handler. + */ + ( + h: Handler + ) => Handler + +export type RequiredContextOf> = + M extends Middleware ? T : never + +export type AddedContextOf> = + M extends Middleware ? T : never + +export type EnvOf> = + M extends Middleware ? T : never diff --git a/src/composeMiddleware.ts b/src/composeMiddleware.d.ts similarity index 93% rename from src/composeMiddleware.ts rename to src/composeMiddleware.d.ts index 8705398..1ec717a 100644 --- a/src/composeMiddleware.ts +++ b/src/composeMiddleware.d.ts @@ -8,53 +8,12 @@ * This file is committed to the repository, as it should rarely change. */ -/** - * A Handler handles a request. It's an async function which takes a - * {@link Request} and returns a {@link Response}. It also has access to the - * context and environment for the request. - * - * @template Context The context keys used by the handler. - * @template Env The environment keys used by the handler. - */ -type Handler = ( - request: Request, - env: Env, - ctx: Context -) => Promise - -/** - * A Middleware is a function that takes a {@link Handler} and returns a new - * one. It has access to the context and environment for the request. It can - * add to the context, or modify it, but it should not remove keys, so that - * upstream middleware can pass context to downstream middleware. It should - * generally not modify the environment, as that is shared across all requests. - * - * @template RequiredContext The context required by the middleware. These keys - * must be either provided by upstream middleware, or given to the ultimate - * handler. - * @template AddedContext The context added by the middleware. These keys will - * be available to downstream middleware. - * @template Env The environment keys used by the middleware. The entire - * environment should be passed to the outermost handler, at the top of the - * middleware stack. Middleware shouldn't modify the environment, and should - * pass it in its entirety when it calls the next handler. - */ -type Middleware< - RequiredContext extends {}, - AddedContext extends {} = {}, - Env extends {} = {}, -> = ( - h: Handler -) => Handler - -export type RequiredContextOf> = - M extends Middleware ? T : never - -export type AddedContextOf> = - M extends Middleware ? T : never - -export type EnvOf> = - M extends Middleware ? T : never +import { + AddedContextOf, + EnvOf, + Middleware, + RequiredContextOf, +} from './bindings' /** * Returns the result of satisfying the {@link Requirements} with the @@ -65,13 +24,22 @@ export type Satisfy = ? Omit : never -function composeMiddleware< +/** + * Composes multiple middleware functions into a single middleware function. The + * request will be seen by the composed middleware in the order they are given. + * + * Note: Due to TypeScript limitations, each arity of this function must be a + * separate overload. To compose more than 20 middleware functions, simply nest + * smaller compositions. + */ + +declare function composeMiddleware< M1 extends Middleware, M1R extends RequiredContextOf, M1C extends AddedContextOf, >(m1: M1): Middleware, M1C, EnvOf> -function composeMiddleware< +declare function composeMiddleware< M1 extends Middleware, M1R extends RequiredContextOf, M1C extends AddedContextOf, @@ -87,7 +55,7 @@ function composeMiddleware< EnvOf & EnvOf > -function composeMiddleware< +declare function composeMiddleware< M1 extends Middleware, M1R extends RequiredContextOf, M1C extends AddedContextOf, @@ -109,7 +77,7 @@ function composeMiddleware< EnvOf & EnvOf & EnvOf > -function composeMiddleware< +declare function composeMiddleware< M1 extends Middleware, M1R extends RequiredContextOf, M1C extends AddedContextOf, @@ -136,7 +104,7 @@ function composeMiddleware< EnvOf & EnvOf & EnvOf & EnvOf > -function composeMiddleware< +declare function composeMiddleware< M1 extends Middleware, M1R extends RequiredContextOf, M1C extends AddedContextOf, @@ -168,7 +136,7 @@ function composeMiddleware< EnvOf & EnvOf & EnvOf & EnvOf & EnvOf > -function composeMiddleware< +declare function composeMiddleware< M1 extends Middleware, M1R extends RequiredContextOf, M1C extends AddedContextOf, @@ -205,7 +173,7 @@ function composeMiddleware< EnvOf & EnvOf & EnvOf & EnvOf & EnvOf & EnvOf > -function composeMiddleware< +declare function composeMiddleware< M1 extends Middleware, M1R extends RequiredContextOf, M1C extends AddedContextOf, @@ -253,7 +221,7 @@ function composeMiddleware< EnvOf > -function composeMiddleware< +declare function composeMiddleware< M1 extends Middleware, M1R extends RequiredContextOf, M1C extends AddedContextOf, @@ -307,7 +275,7 @@ function composeMiddleware< EnvOf > -function composeMiddleware< +declare function composeMiddleware< M1 extends Middleware, M1R extends RequiredContextOf, M1C extends AddedContextOf, @@ -367,7 +335,7 @@ function composeMiddleware< EnvOf > -function composeMiddleware< +declare function composeMiddleware< M1 extends Middleware, M1R extends RequiredContextOf, M1C extends AddedContextOf, @@ -433,7 +401,7 @@ function composeMiddleware< EnvOf > -function composeMiddleware< +declare function composeMiddleware< M1 extends Middleware, M1R extends RequiredContextOf, M1C extends AddedContextOf, @@ -505,7 +473,7 @@ function composeMiddleware< EnvOf > -function composeMiddleware< +declare function composeMiddleware< M1 extends Middleware, M1R extends RequiredContextOf, M1C extends AddedContextOf, @@ -583,7 +551,7 @@ function composeMiddleware< EnvOf > -function composeMiddleware< +declare function composeMiddleware< M1 extends Middleware, M1R extends RequiredContextOf, M1C extends AddedContextOf, @@ -667,7 +635,7 @@ function composeMiddleware< EnvOf > -function composeMiddleware< +declare function composeMiddleware< M1 extends Middleware, M1R extends RequiredContextOf, M1C extends AddedContextOf, @@ -757,7 +725,7 @@ function composeMiddleware< EnvOf > -function composeMiddleware< +declare function composeMiddleware< M1 extends Middleware, M1R extends RequiredContextOf, M1C extends AddedContextOf, @@ -853,7 +821,7 @@ function composeMiddleware< EnvOf > -function composeMiddleware< +declare function composeMiddleware< M1 extends Middleware, M1R extends RequiredContextOf, M1C extends AddedContextOf, @@ -955,7 +923,7 @@ function composeMiddleware< EnvOf > -function composeMiddleware< +declare function composeMiddleware< M1 extends Middleware, M1R extends RequiredContextOf, M1C extends AddedContextOf, @@ -1063,7 +1031,7 @@ function composeMiddleware< EnvOf > -function composeMiddleware< +declare function composeMiddleware< M1 extends Middleware, M1R extends RequiredContextOf, M1C extends AddedContextOf, @@ -1177,7 +1145,7 @@ function composeMiddleware< EnvOf > -function composeMiddleware< +declare function composeMiddleware< M1 extends Middleware, M1R extends RequiredContextOf, M1C extends AddedContextOf, @@ -1297,7 +1265,7 @@ function composeMiddleware< EnvOf > -function composeMiddleware< +declare function composeMiddleware< M1 extends Middleware, M1R extends RequiredContextOf, M1C extends AddedContextOf, @@ -1423,10 +1391,4 @@ function composeMiddleware< EnvOf > -function composeMiddleware( - ...middlewares: Middleware[] -): Middleware { - return (handler) => middlewares.reduceRight((h, m) => m(h), handler) -} - -export { composeMiddleware, Middleware, Handler } +export { composeMiddleware } diff --git a/src/composeMiddleware.js b/src/composeMiddleware.js new file mode 100644 index 0000000..f3a2617 --- /dev/null +++ b/src/composeMiddleware.js @@ -0,0 +1,11 @@ +/** @import { Middleware } from './bindings.js' */ + +/** + * Composes multiple middleware functions into a single middleware function. + * + * @param {...Middleware} middlewares - The middleware functions to compose. + * @returns {Middleware} A single middleware function that is the result of composing the input middleware functions. + */ +export function composeMiddleware(...middlewares) { + return (handler) => middlewares.reduceRight((h, m) => m(h), handler) +} diff --git a/src/handlers/block.js b/src/handlers/block.js index db88108..797871f 100644 --- a/src/handlers/block.js +++ b/src/handlers/block.js @@ -4,10 +4,10 @@ import { decodeRangeHeader, resolveRange } from '../util/range.js' import { HttpError } from '../util/errors.js' /** - * @typedef {import('../bindings.js').IpfsUrlContext & import('../bindings.js').BlockContext & import('../bindings.js').UnixfsContext & { timeoutController?: import('../bindings.js').TimeoutControllerContext['timeoutController'] }} BlockHandlerContext + * @import { IpfsUrlContext, BlockContext, UnixfsContext, TimeoutControllerContext, Handler } from '../bindings.js' */ -/** @type {import('../bindings.js').Handler} */ +/** @type {Handler>} */ export async function handleBlock (request, env, ctx) { const { dataCid, path, timeoutController: controller, blocks, unixfs, searchParams } = ctx if (!dataCid) throw new Error('missing IPFS path') diff --git a/src/handlers/car.js b/src/handlers/car.js index b0bb880..b1fe5e5 100644 --- a/src/handlers/car.js +++ b/src/handlers/car.js @@ -4,15 +4,18 @@ import { toReadableStream } from '../util/streams.js' import { HttpError } from '../util/errors.js' /** - * @typedef {import('../bindings.js').IpfsUrlContext & import('../bindings.js').DagContext & { timeoutController?: import('../bindings.js').TimeoutControllerContext['timeoutController'] }} CarHandlerContext - * @typedef {import('multiformats').CID} CID - * @typedef {{ version: 1|2, order: import('dagula').BlockOrder, dups: boolean }} CarParams + * @import { IpfsUrlContext, DagContext, TimeoutControllerContext, Handler } from '../bindings.js' + * @import { BlockOrder, DagScope, Range } from 'dagula' + */ + +/** + * @typedef {{ version: 1|2, order: BlockOrder, dups: boolean }} CarParams */ /** @type {CarParams} */ -const DefaultCarParams = { version: 1, order: 'unk', dups: true } +const defaultCarParams = { version: 1, order: 'unk', dups: true } -/** @type {import('../bindings.js').Handler} */ +/** @type {Handler>} */ export async function handleCar (request, env, ctx) { const { dataCid, path, timeoutController: controller, dag, searchParams } = ctx if (!dataCid) throw new Error('missing IPFS path') @@ -75,7 +78,7 @@ export async function handleCar (request, env, ctx) { /** * @param {URLSearchParams} searchParams - * @returns {import('dagula').DagScope} + * @returns {DagScope} */ function getDagScope (searchParams) { const scope = searchParams.get('dag-scope') ?? 'all' @@ -87,7 +90,7 @@ function getDagScope (searchParams) { /** * @param {URLSearchParams} searchParams - * @returns {import('dagula').Range|undefined} + * @returns {Range|undefined} */ function getEntityBytes (searchParams) { const value = searchParams.get('entity-bytes') @@ -118,11 +121,11 @@ function getEntityBytes (searchParams) { */ function getAcceptParams (headers) { const accept = headers.get('accept') - if (!accept) return DefaultCarParams + if (!accept) return defaultCarParams const types = accept.split(',').map(s => s.trim()) const carType = types.find(t => t.startsWith('application/vnd.ipld.car')) - if (!carType) return DefaultCarParams + if (!carType) return defaultCarParams const paramPairs = carType.split(';').slice(1).map(s => s.trim()) const { version, order, dups } = Object.fromEntries(paramPairs.map(p => p.split('=').map(s => s.trim()))) diff --git a/src/handlers/unixfs-dir.js b/src/handlers/unixfs-dir.js index 1cad09d..d1dd248 100644 --- a/src/handlers/unixfs-dir.js +++ b/src/handlers/unixfs-dir.js @@ -8,7 +8,13 @@ import { handleUnixfsFile } from './unixfs-file.js' import { HttpError } from '../util/errors.js' /** - * @typedef {import('../bindings.js').UnixfsEntryContext & import('../bindings.js').IpfsUrlContext & import('../bindings.js').UnixfsContext & { timeoutController?: import('../bindings.js').TimeoutControllerContext['timeoutController'] }} UnixfsDirectoryHandlerContext + * @import { + * UnixfsEntryContext, + * IpfsUrlContext, + * UnixfsContext, + * TimeoutControllerContext, + * Handler + * } from '../bindings.js' */ /** @@ -43,7 +49,7 @@ const knownIcons = Object.fromEntries([ 'tga', 'tgz', 'tiff', 'txt', 'wav', 'wmv', 'xls', 'xlsx', 'xml', 'yml', 'zip' ].map(ext => [ext, true])) -/** @type {import('../bindings.js').Handler} */ +/** @type {Handler>} */ export async function handleUnixfsDir (request, env, ctx) { const { unixfsEntry: entry, timeoutController: controller, unixfs, dataCid, path } = ctx if (!entry) throw new Error('missing UnixFS entry') diff --git a/src/handlers/unixfs-file.js b/src/handlers/unixfs-file.js index 5fd7d3e..9f9b3e5 100644 --- a/src/handlers/unixfs-file.js +++ b/src/handlers/unixfs-file.js @@ -5,10 +5,11 @@ import { HttpError } from '../util/errors.js' import { decodeRangeHeader, resolveRange } from '../util/range.js' /** - * @typedef {import('../bindings.js').UnixfsEntryContext} UnixfsFileHandlerContext + * @import { UnixfsEntryContext, Handler } from '../bindings.js' + * @import { AbsoluteRange, Range } from 'dagula' */ -/** @type {import('../bindings.js').Handler} */ +/** @type {Handler} */ export async function handleUnixfsFile (request, env, ctx) { const { unixfsEntry: entry } = ctx if (!entry) throw new Error('missing UnixFS entry') @@ -35,10 +36,10 @@ export async function handleUnixfsFile (request, env, ctx) { throw new HttpError('method not allowed', { status: 405 }) } - /** @type {import('dagula').AbsoluteRange|undefined} */ + /** @type {AbsoluteRange|undefined} */ let range if (request.headers.has('range')) { - /** @type {import('dagula').Range[]} */ + /** @type {Range[]} */ let ranges = [] try { ranges = decodeRangeHeader(request.headers.get('range') ?? '') @@ -80,7 +81,6 @@ export async function handleUnixfsFile (request, env, ctx) { let bytesWritten = firstChunk.length yield firstChunk try { - // @ts-ignore for await (const chunk of contentIterator) { bytesWritten += chunk.length yield chunk diff --git a/src/handlers/unixfs.js b/src/handlers/unixfs.js index d18ef87..870a035 100644 --- a/src/handlers/unixfs.js +++ b/src/handlers/unixfs.js @@ -4,10 +4,10 @@ import { handleUnixfsFile } from './unixfs-file.js' import { HttpError } from '../util/errors.js' /** - * @typedef {import('../bindings.js').IpfsUrlContext & import('../bindings.js').UnixfsContext & { timeoutController?: import('../bindings.js').TimeoutControllerContext['timeoutController'] }} UnixfsHandlerContext + * @import { IpfsUrlContext, UnixfsContext, TimeoutControllerContext, Handler } from '../bindings.js' */ -/** @type {import('../bindings.js').Handler} */ +/** @type {Handler>} */ export async function handleUnixfs (request, env, ctx) { const { dataCid, path, timeoutController: controller, unixfs } = ctx if (!dataCid) throw new Error('missing data CID') diff --git a/src/middleware.js b/src/middleware.js index c6bf901..d6ed602 100644 --- a/src/middleware.js +++ b/src/middleware.js @@ -4,7 +4,7 @@ import { TimeoutController } from 'timeout-abort-controller' import { HttpError } from './util/errors.js' import { parseCid, tryParseCid } from './util/cid.js' -/** @typedef {import('./bindings.js').Context} Context */ +/** @import { Middleware, CloudflareContext, DebugEnvironment, IpfsUrlContext, TimeoutControllerContext } from './bindings.js' */ const CF_CACHE_MAX_OBJECT_SIZE = 512 * Math.pow(1024, 2) // 512MB to bytes const HTTP_PARTIAL_CONTENT = 206 @@ -18,9 +18,9 @@ const HTTP_PARTIAL_CONTENT = 206 * Some properties in the original context object are not enumerable so need * to be expicitly added. * - * @type {import('./bindings.js').Middleware} + * @type {Middleware} */ -export function withContext (handler) { +export function withContext(handler) { return (request, env, ctx) => { const context = { ...ctx, waitUntil: ctx.waitUntil.bind(ctx) } return handler(request, env, context) @@ -29,9 +29,9 @@ export function withContext (handler) { /** * Adds CORS headers to the response. - * @type {import('./bindings.js').Middleware} + * @type {Middleware} */ -export function withCorsHeaders (handler) { +export function withCorsHeaders(handler) { return async (request, env, ctx) => { const response = await handler(request, env, ctx) const origin = request.headers.get('origin') @@ -50,9 +50,9 @@ export function withCorsHeaders (handler) { /** * Adds Content Disposition header to the response according to the request. * https://github.com/ipfs/specs/blob/main/http-gateways/PATH_GATEWAY.md#request-query-parameters - * @type {import('./bindings.js').Middleware} + * @type {Middleware} */ -export function withContentDispositionHeader (handler) { +export function withContentDispositionHeader(handler) { return async (request, env, ctx) => { const response = await handler(request, env, ctx) const { searchParams } = new URL(request.url) @@ -60,11 +60,17 @@ export function withContentDispositionHeader (handler) { const fileName = searchParams.get('filename') const download = searchParams.get('download') if (fileName && download) { - response.headers.set('Content-Disposition', `attachment; filename="${fileName}"`) + response.headers.set( + 'Content-Disposition', + `attachment; filename="${fileName}"` + ) } else if (download) { response.headers.set('Content-Disposition', 'attachment') } else if (fileName) { - response.headers.set('Content-Disposition', `inline; filename="${fileName}"`) + response.headers.set( + 'Content-Disposition', + `inline; filename="${fileName}"` + ) } } return response @@ -73,17 +79,18 @@ export function withContentDispositionHeader (handler) { /** * Catches any errors, logs them and returns a suitable response. - * @type {import('./bindings.js').Middleware} + * @type {Middleware<{}, {}, DebugEnvironment>} */ -export function withErrorHandler (handler) { +export function withErrorHandler(handler) { return async (request, env, ctx) => { try { return await handler(request, env, ctx) } catch (/** @type {any} */ err) { if (!err.status || err.status >= 500) console.error(err.stack) - const msg = env.DEBUG === 'true' - ? `${err.stack}${err?.cause?.stack ? `\n[cause]: ${err.cause.stack}` : ''}` - : err.message + const msg = + env.DEBUG === 'true' + ? `${err.stack}${err?.cause?.stack ? `\n[cause]: ${err.cause.stack}` : ''}` + : err.message return new Response(msg, { status: err.status || 500 }) } } @@ -92,9 +99,9 @@ export function withErrorHandler (handler) { /** * Validates the request uses a specific HTTP method(s). * @param {...string} method Allowed HTTP method(s). - * @returns {import('./bindings.js').Middleware} + * @returns {Middleware} */ -export function createWithHttpMethod (...method) { +export function createWithHttpMethod(...method) { return (handler) => { return (request, env, ctx) => { if (!method.includes(request.method)) { @@ -107,15 +114,15 @@ export function createWithHttpMethod (...method) { /** * Validates the request uses a HTTP GET method. - * @type {import('./bindings.js').Middleware} + * @type {Middleware} */ export const withHttpGet = createWithHttpMethod('GET') /** * Extracts the data CID, the path and search params from the URL. - * @type {import('./bindings.js').Middleware} + * @type {Middleware<{}, IpfsUrlContext>} */ -export function withParsedIpfsUrl (handler) { +export function withParsedIpfsUrl(handler) { return (request, env, ctx) => { const { hostname, pathname, searchParams } = new URL(request.url) @@ -123,15 +130,23 @@ export function withParsedIpfsUrl (handler) { let dataCid = tryParseCid(hostParts[0]) if (dataCid) { if (hostParts[1] !== 'ipfs') { - throw new HttpError(`unsupported protocol: ${hostParts[1]}`, { status: 400 }) + throw new HttpError(`unsupported protocol: ${hostParts[1]}`, { + status: 400, + }) } - const ipfsUrlCtx = Object.assign(ctx, { dataCid, path: pathname, searchParams }) + const ipfsUrlCtx = Object.assign(ctx, { + dataCid, + path: pathname, + searchParams, + }) return handler(request, env, ipfsUrlCtx) } const pathParts = pathname.split('/') if (pathParts[1] !== 'ipfs') { - throw new HttpError(`unsupported protocol: ${pathParts[1]}`, { status: 400 }) + throw new HttpError(`unsupported protocol: ${pathParts[1]}`, { + status: 400, + }) } try { dataCid = parseCid(pathParts[2]) @@ -139,7 +154,11 @@ export function withParsedIpfsUrl (handler) { throw new HttpError(`invalid CID: ${pathParts[2]}`, { status: 400 }) } const path = pathParts.slice(3).map(decodeURIComponent).join('/') - const ipfsUrlCtx = Object.assign(ctx, { dataCid, path: path ? `/${path}` : '', searchParams }) + const ipfsUrlCtx = Object.assign(ctx, { + dataCid, + path: path ? `/${path}` : '', + searchParams, + }) return handler(request, env, ipfsUrlCtx) } } @@ -148,11 +167,12 @@ export function withParsedIpfsUrl (handler) { * Creates a middleware that adds an TimeoutController (an AbortController) to * the context that times out after the passed milliseconds. Consumers can * optionally call `.reset()` on the controller to restart the timeout. + * * @param {number} timeout Timeout in milliseconds. + * @returns {Middleware<{}, TimeoutControllerContext>} */ -export function createWithTimeoutController (timeout) { - /** @type {import('./bindings.js').Middleware} */ - return handler => { +export function createWithTimeoutController(timeout) { + return (handler) => { return async (request, env, ctx) => { const timeoutController = new TimeoutController(timeout) const timeoutCtx = { ...ctx, timeoutController } @@ -161,10 +181,9 @@ export function createWithTimeoutController (timeout) { return new Response( response.body.pipeThrough( new TransformStream({ - flush () { - // console.log('clearing timeout controller') + flush() { timeoutController.clear() - } + }, }) ), response @@ -176,9 +195,9 @@ export function createWithTimeoutController (timeout) { /** * Intercepts request if content cached by just returning cached response. * Otherwise proceeds to handler. - * @type {import('./bindings.js').Middleware} + * @type {Middleware} */ -export function withCdnCache (handler) { +export function withCdnCache(handler) { return async (request, env, ctx) => { // Should skip cache if instructed by headers if ((request.headers.get('Cache-Control') || '').includes('no-cache')) { @@ -222,16 +241,18 @@ export function withCdnCache (handler) { * Pipes reponse through a FixedLengthStream if `Content-Length` header is set. * https://developers.cloudflare.com/workers/runtime-apis/streams/transformstream/#fixedlengthstream * - * @type {import('./bindings.js').Middleware} + * @type {Middleware} */ -export function withFixedLengthStream (handler) { +export function withFixedLengthStream(handler) { return async (request, env, ctx) => { const response = await handler(request, env, ctx) if (!response.headers.has('Content-Length') || !response.body) { return response } - const contentLength = parseInt(response.headers.get('Content-Length') || '0') + const contentLength = parseInt( + response.headers.get('Content-Length') || '0' + ) return new Response( // @ts-ignore FixedLengthStream is a cloudflare global response.body.pipeThrough(new FixedLengthStream(contentLength)), @@ -240,10 +261,4 @@ export function withFixedLengthStream (handler) { } } -/** - * @param {...import('./bindings.js').Middleware} middlewares - * @returns {import('./bindings.js').Middleware} - */ -export function composeMiddleware (...middlewares) { - return handler => middlewares.reduceRight((h, m) => m(h), handler) -} +export { composeMiddleware } from './composeMiddleware.js' diff --git a/src/util/errors.js b/src/util/errors.js index 32bae57..91c466c 100644 --- a/src/util/errors.js +++ b/src/util/errors.js @@ -4,7 +4,6 @@ export class HttpError extends Error { * @param {{ status?: number, cause?: any }} [options] */ constructor (message, options = {}) { - // @ts-ignore typescript does not understand Error super(message, options) this.status = options.status == null ? 500 : options.status } diff --git a/src/util/range.js b/src/util/range.js index 0268443..2bdd224 100644 --- a/src/util/range.js +++ b/src/util/range.js @@ -1,12 +1,17 @@ import { parseRange } from '@httpland/range-parser' +/** + * @import { Range, AbsoluteRange } from 'dagula' + */ + + /** * @param {string} [str] - * @returns {import('dagula').Range[]} + * @returns {Range[]} */ export const decodeRangeHeader = (str) => { if (!str) throw new Error('missing Range header value') - /** @type {import('dagula').Range[]} */ + /** @type {Range[]} */ const ranges = [] for (const r of parseRange(str).rangeSet) { if (typeof r === 'string') { @@ -23,9 +28,9 @@ export const decodeRangeHeader = (str) => { /** * Resolve a range to an absolute range. * - * @param {import('dagula').Range} range + * @param {Range} range * @param {number} totalSize - * @returns {import('dagula').AbsoluteRange} + * @returns {AbsoluteRange} */ export const resolveRange = ([first, last], totalSize) => [ first < 0 ? totalSize + first : first, diff --git a/test/composeMiddleware.spec.ts b/test/composeMiddleware.spec.ts index b9bb8d3..22163d8 100644 --- a/test/composeMiddleware.spec.ts +++ b/test/composeMiddleware.spec.ts @@ -1,59 +1,60 @@ -import { describe, it } from "node:test"; -import assert from "node:assert"; -import { expectTypeOf } from "expect-type"; +import { describe, it } from 'node:test' +import assert from 'node:assert' +import { expectTypeOf } from 'expect-type' -import { composeMiddleware, Middleware, Handler } from "../src/noodle4-output.js"; +import { Middleware, Handler } from '../src/bindings.js' +import { composeMiddleware } from '../src/composeMiddleware.js' const handler: Handler<{ more: string }, {}> = async (_request, env, ctx) => { - return new Response(JSON.stringify({ env, ctx })); -}; + return new Response(JSON.stringify({ env, ctx })) +} const withUser: Middleware<{}, { user: string }, { RESOURCE1: string }> = (handler) => async (request, env, ctx) => { - return handler(request, env, { ...ctx, user: "joey" }); - }; + return handler(request, env, { ...ctx, user: 'joey' }) + } const withData: Middleware<{}, { data: string }> = (handler) => async (request, env, ctx) => { - return handler(request, env, { ...ctx, data: "some-stuff" }); - }; + return handler(request, env, { ...ctx, data: 'some-stuff' }) + } const usingUser: Middleware<{ user: string }, {}, { RESOURCE2: string }> = (handler) => async (request, env, ctx) => { - return handler(request, env, ctx); - }; + return handler(request, env, ctx) + } const usingData: Middleware<{ data: string }, {}, { RESOURCE1: string }> = (handler) => async (request, env, ctx) => { - return handler(request, env, ctx); - }; + return handler(request, env, ctx) + } -const req = new Request("http://example.com/"); +const req = new Request('http://example.com/') describe(composeMiddleware.name, () => { - it("can compose a single middleware", async () => { - const composed = composeMiddleware(usingUser); - const wrappedHandler = composed(handler); + it('can compose a single middleware', async () => { + const composed = composeMiddleware(usingUser) + const wrappedHandler = composed(handler) expectTypeOf(wrappedHandler).parameters.branded.toEqualTypeOf< [Request, { RESOURCE2: string }, { user: string; more: string }] - >(); + >() const response = await wrappedHandler( req, - { RESOURCE2: "resource2" }, - { user: "joey", more: "context" }, - ).then((res) => res.json()); + { RESOURCE2: 'resource2' }, + { user: 'joey', more: 'context' } + ).then((res) => res.json()) assert.deepStrictEqual(response, { - env: { RESOURCE2: "resource2" }, - ctx: { user: "joey", more: "context" }, - }); - }); + env: { RESOURCE2: 'resource2' }, + ctx: { user: 'joey', more: 'context' }, + }) + }) - it("can compose middlewares which require things", async () => { - const composed = composeMiddleware(usingUser, usingData); - const wrappedHandler = composed(handler); + it('can compose middlewares which require things', async () => { + const composed = composeMiddleware(usingUser, usingData) + const wrappedHandler = composed(handler) expectTypeOf(wrappedHandler).parameters.branded.toEqualTypeOf< [ @@ -61,57 +62,57 @@ describe(composeMiddleware.name, () => { { RESOURCE1: string; RESOURCE2: string }, { user: string; data: string; more: string }, ] - >(); + >() const response = await wrappedHandler( req, - { RESOURCE1: "resource1", RESOURCE2: "resource2" }, - { user: "joey", data: "some-stuff", more: "context" }, - ).then((res) => res.json()); + { RESOURCE1: 'resource1', RESOURCE2: 'resource2' }, + { user: 'joey', data: 'some-stuff', more: 'context' } + ).then((res) => res.json()) assert.deepStrictEqual(response, { - env: { RESOURCE1: "resource1", RESOURCE2: "resource2" }, - ctx: { user: "joey", data: "some-stuff", more: "context" }, - }); - }); + env: { RESOURCE1: 'resource1', RESOURCE2: 'resource2' }, + ctx: { user: 'joey', data: 'some-stuff', more: 'context' }, + }) + }) - it("can compose middlewares which provide things", async () => { - const composed = composeMiddleware(withUser, withData); - const wrappedHandler = composed(handler); + it('can compose middlewares which provide things', async () => { + const composed = composeMiddleware(withUser, withData) + const wrappedHandler = composed(handler) expectTypeOf(wrappedHandler).parameters.branded.toEqualTypeOf< [Request, { RESOURCE1: string }, { more: string }] - >(); + >() const response = await wrappedHandler( req, - { RESOURCE1: "resource1" }, - { more: "context" }, - ).then((res) => res.json()); + { RESOURCE1: 'resource1' }, + { more: 'context' } + ).then((res) => res.json()) assert.deepStrictEqual(response, { - env: { RESOURCE1: "resource1" }, - ctx: { user: "joey", data: "some-stuff", more: "context" }, - }); - }); + env: { RESOURCE1: 'resource1' }, + ctx: { user: 'joey', data: 'some-stuff', more: 'context' }, + }) + }) - it("can compose middlewares which require and provide things", async () => { - const composed = composeMiddleware(withUser, usingUser); - const wrappedHandler = composed(handler); + it('can compose middlewares which require and provide things', async () => { + const composed = composeMiddleware(withUser, usingUser) + const wrappedHandler = composed(handler) expectTypeOf(wrappedHandler).parameters.branded.toEqualTypeOf< [Request, { RESOURCE1: string; RESOURCE2: string }, { more: string }] - >(); + >() const response = await wrappedHandler( req, - { RESOURCE1: "resource1", RESOURCE2: "resource2" }, - { more: "context" }, - ).then((res) => res.json()); + { RESOURCE1: 'resource1', RESOURCE2: 'resource2' }, + { more: 'context' } + ).then((res) => res.json()) assert.deepStrictEqual(response, { - env: { RESOURCE1: "resource1", RESOURCE2: "resource2" }, - ctx: { user: "joey", more: "context" }, - }); - }); -}); + env: { RESOURCE1: 'resource1', RESOURCE2: 'resource2' }, + ctx: { user: 'joey', more: 'context' }, + }) + }) +}) From 0b98537e84ab8aff8c09c5d399faec09f3b8c8f5 Mon Sep 17 00:00:00 2001 From: Petra Jaros Date: Fri, 10 Jan 2025 11:22:04 -0500 Subject: [PATCH 4/6] Upgrade TypeScript, and use it in VSCode --- .vscode/settings.json | 3 +++ package-lock.json | 9 +++++---- package.json | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..3662b37 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "typescript.tsdk": "node_modules/typescript/lib" +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 0aa92d7..d66607f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -32,7 +32,7 @@ "prettier": "^3.4.2", "standard": "^17.1.0", "tsx": "^4.19.2", - "typescript": "^5.3.3" + "typescript": "^5.7.3" } }, "node_modules/@aashutoshrathi/word-wrap": { @@ -7942,10 +7942,11 @@ } }, "node_modules/typescript": { - "version": "5.3.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.3.tgz", - "integrity": "sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==", + "version": "5.7.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.7.3.tgz", + "integrity": "sha512-84MVSjMEHP+FQRPy3pX9sTVV/INIex71s9TL2Gm5FG/WG1SqXeKyZ0k7/blY/4FdOzI12CBy1vGc4og/eus0fw==", "dev": true, + "license": "Apache-2.0", "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" diff --git a/package.json b/package.json index 9f546ed..d4c8c29 100644 --- a/package.json +++ b/package.json @@ -90,7 +90,7 @@ "prettier": "^3.4.2", "standard": "^17.1.0", "tsx": "^4.19.2", - "typescript": "^5.3.3" + "typescript": "^5.7.3" }, "publishConfig": { "access": "public" From 1b5fccc64bf701f210fca43ba957da799883424f Mon Sep 17 00:00:00 2001 From: Petra Jaros Date: Fri, 10 Jan 2025 11:24:01 -0500 Subject: [PATCH 5/6] Oh, right. `standard`. --- scripts/generateComposeMiddleware.js | 36 ++++++++++++++-------------- src/composeMiddleware.js | 2 +- src/middleware.js | 30 +++++++++++------------ src/util/range.js | 1 - 4 files changed, 34 insertions(+), 35 deletions(-) diff --git a/scripts/generateComposeMiddleware.js b/scripts/generateComposeMiddleware.js index 4da436b..074d1b6 100644 --- a/scripts/generateComposeMiddleware.js +++ b/scripts/generateComposeMiddleware.js @@ -20,7 +20,7 @@ const withBinding = (x, fn) => fn(x) const anyMiddlewareType = ts.factory.createTypeReferenceNode('Middleware', [ ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword), ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword), - ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword), + ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword) ]) const declarations = [ @@ -69,7 +69,7 @@ const declarations = [ /* typescript */ ` export { composeMiddleware }; - `, + ` ] /** @@ -79,7 +79,7 @@ const declarations = [ * @param {number} argCount The number of middleware arguments. * @returns {ts.FunctionDeclaration} The TypeScript function declaration. */ -function createComposeMiddlewareOverloadDeclaration(argCount) { +function createComposeMiddlewareOverloadDeclaration (argCount) { const ns = Array.from({ length: argCount }).map((_, i) => i + 1) return ts.factory.createFunctionDeclaration( @@ -99,15 +99,15 @@ function createComposeMiddlewareOverloadDeclaration(argCount) { `M${n}R`, withBinding( ts.factory.createTypeReferenceNode('RequiredContextOf', [ - ts.factory.createTypeReferenceNode(`M${n}`), + ts.factory.createTypeReferenceNode(`M${n}`) ]), (requiredContext) => n === 1 ? requiredContext : ts.factory.createTypeReferenceNode('Satisfy', [ - requiredContext, - ts.factory.createTypeReferenceNode(`M${n - 1}C`), - ]) + requiredContext, + ts.factory.createTypeReferenceNode(`M${n - 1}C`) + ]) ) ), ts.factory.createTypeParameterDeclaration( @@ -115,15 +115,15 @@ function createComposeMiddlewareOverloadDeclaration(argCount) { `M${n}C`, ts.factory.createIntersectionTypeNode([ ts.factory.createTypeReferenceNode('AddedContextOf', [ - ts.factory.createTypeReferenceNode(`M${n}`), + ts.factory.createTypeReferenceNode(`M${n}`) ]), ...(n === 1 ? [] - : [ts.factory.createTypeReferenceNode(`M${n - 1}C`)]), + : [ts.factory.createTypeReferenceNode(`M${n - 1}C`)]) ]) - ), + ) ] - }), + }) ], ns.map((n) => ts.factory.createParameterDeclaration( @@ -140,15 +140,15 @@ function createComposeMiddlewareOverloadDeclaration(argCount) { ns.map((n) => withBinding( ts.factory.createTypeReferenceNode('RequiredContextOf', [ - ts.factory.createTypeReferenceNode(`M${n}`), + ts.factory.createTypeReferenceNode(`M${n}`) ]), (requiredContext) => n === 1 ? requiredContext : ts.factory.createTypeReferenceNode('Satisfy', [ - requiredContext, - ts.factory.createTypeReferenceNode(`M${n - 1}C`), - ]) + requiredContext, + ts.factory.createTypeReferenceNode(`M${n - 1}C`) + ]) ) ) ), @@ -156,10 +156,10 @@ function createComposeMiddlewareOverloadDeclaration(argCount) { ts.factory.createIntersectionTypeNode( ns.map((n) => ts.factory.createTypeReferenceNode('EnvOf', [ - ts.factory.createTypeReferenceNode(`M${n}`), + ts.factory.createTypeReferenceNode(`M${n}`) ]) ) - ), + ) ]), undefined ) @@ -189,6 +189,6 @@ const output = declarations const prettierConfig = await prettier.resolveConfig(filepath) const formattedOutput = await prettier.format(output, { filepath, - ...prettierConfig, + ...prettierConfig }) fs.writeFileSync(filepath, formattedOutput) diff --git a/src/composeMiddleware.js b/src/composeMiddleware.js index f3a2617..cb2bf9f 100644 --- a/src/composeMiddleware.js +++ b/src/composeMiddleware.js @@ -6,6 +6,6 @@ * @param {...Middleware} middlewares - The middleware functions to compose. * @returns {Middleware} A single middleware function that is the result of composing the input middleware functions. */ -export function composeMiddleware(...middlewares) { +export function composeMiddleware (...middlewares) { return (handler) => middlewares.reduceRight((h, m) => m(h), handler) } diff --git a/src/middleware.js b/src/middleware.js index d6ed602..01be081 100644 --- a/src/middleware.js +++ b/src/middleware.js @@ -20,7 +20,7 @@ const HTTP_PARTIAL_CONTENT = 206 * * @type {Middleware} */ -export function withContext(handler) { +export function withContext (handler) { return (request, env, ctx) => { const context = { ...ctx, waitUntil: ctx.waitUntil.bind(ctx) } return handler(request, env, context) @@ -31,7 +31,7 @@ export function withContext(handler) { * Adds CORS headers to the response. * @type {Middleware} */ -export function withCorsHeaders(handler) { +export function withCorsHeaders (handler) { return async (request, env, ctx) => { const response = await handler(request, env, ctx) const origin = request.headers.get('origin') @@ -52,7 +52,7 @@ export function withCorsHeaders(handler) { * https://github.com/ipfs/specs/blob/main/http-gateways/PATH_GATEWAY.md#request-query-parameters * @type {Middleware} */ -export function withContentDispositionHeader(handler) { +export function withContentDispositionHeader (handler) { return async (request, env, ctx) => { const response = await handler(request, env, ctx) const { searchParams } = new URL(request.url) @@ -81,7 +81,7 @@ export function withContentDispositionHeader(handler) { * Catches any errors, logs them and returns a suitable response. * @type {Middleware<{}, {}, DebugEnvironment>} */ -export function withErrorHandler(handler) { +export function withErrorHandler (handler) { return async (request, env, ctx) => { try { return await handler(request, env, ctx) @@ -101,7 +101,7 @@ export function withErrorHandler(handler) { * @param {...string} method Allowed HTTP method(s). * @returns {Middleware} */ -export function createWithHttpMethod(...method) { +export function createWithHttpMethod (...method) { return (handler) => { return (request, env, ctx) => { if (!method.includes(request.method)) { @@ -122,7 +122,7 @@ export const withHttpGet = createWithHttpMethod('GET') * Extracts the data CID, the path and search params from the URL. * @type {Middleware<{}, IpfsUrlContext>} */ -export function withParsedIpfsUrl(handler) { +export function withParsedIpfsUrl (handler) { return (request, env, ctx) => { const { hostname, pathname, searchParams } = new URL(request.url) @@ -131,13 +131,13 @@ export function withParsedIpfsUrl(handler) { if (dataCid) { if (hostParts[1] !== 'ipfs') { throw new HttpError(`unsupported protocol: ${hostParts[1]}`, { - status: 400, + status: 400 }) } const ipfsUrlCtx = Object.assign(ctx, { dataCid, path: pathname, - searchParams, + searchParams }) return handler(request, env, ipfsUrlCtx) } @@ -145,7 +145,7 @@ export function withParsedIpfsUrl(handler) { const pathParts = pathname.split('/') if (pathParts[1] !== 'ipfs') { throw new HttpError(`unsupported protocol: ${pathParts[1]}`, { - status: 400, + status: 400 }) } try { @@ -157,7 +157,7 @@ export function withParsedIpfsUrl(handler) { const ipfsUrlCtx = Object.assign(ctx, { dataCid, path: path ? `/${path}` : '', - searchParams, + searchParams }) return handler(request, env, ipfsUrlCtx) } @@ -171,7 +171,7 @@ export function withParsedIpfsUrl(handler) { * @param {number} timeout Timeout in milliseconds. * @returns {Middleware<{}, TimeoutControllerContext>} */ -export function createWithTimeoutController(timeout) { +export function createWithTimeoutController (timeout) { return (handler) => { return async (request, env, ctx) => { const timeoutController = new TimeoutController(timeout) @@ -181,9 +181,9 @@ export function createWithTimeoutController(timeout) { return new Response( response.body.pipeThrough( new TransformStream({ - flush() { + flush () { timeoutController.clear() - }, + } }) ), response @@ -197,7 +197,7 @@ export function createWithTimeoutController(timeout) { * Otherwise proceeds to handler. * @type {Middleware} */ -export function withCdnCache(handler) { +export function withCdnCache (handler) { return async (request, env, ctx) => { // Should skip cache if instructed by headers if ((request.headers.get('Cache-Control') || '').includes('no-cache')) { @@ -243,7 +243,7 @@ export function withCdnCache(handler) { * * @type {Middleware} */ -export function withFixedLengthStream(handler) { +export function withFixedLengthStream (handler) { return async (request, env, ctx) => { const response = await handler(request, env, ctx) if (!response.headers.has('Content-Length') || !response.body) { diff --git a/src/util/range.js b/src/util/range.js index 2bdd224..c355670 100644 --- a/src/util/range.js +++ b/src/util/range.js @@ -4,7 +4,6 @@ import { parseRange } from '@httpland/range-parser' * @import { Range, AbsoluteRange } from 'dagula' */ - /** * @param {string} [str] * @returns {Range[]} From b6565d01986b59ba09e1a9c0193c85d8d64f2092 Mon Sep 17 00:00:00 2001 From: Petra Jaros Date: Wed, 15 Jan 2025 09:34:35 -0500 Subject: [PATCH 6/6] Tweaks to work better in practice with `freeway` * Generate `composeMiddleware` overloads up to 30 arguments. * Use file extensions in `import`s. * Use `Simplify` in the return type of `composeMiddleware` for better ergonomics. * Add `extends {}` to the type parameters of a `Middleware` function--I don't actually remember why, but the types didn't infer correctly otherwise. * Use `const`s instead of `function`s for middleware functions. The `@type` tag doesn't apply correctly to a `function` declaration--which makes sense, since there's no equivalent syntax that would do it in TypeScript: https://github.com/microsoft/TypeScript/issues/27387 --- scripts/generateComposeMiddleware.js | 63 +- src/bindings.d.ts | 2 +- src/composeMiddleware.d.ts | 2556 +++++++++++++++++++++----- src/middleware.js | 25 +- 4 files changed, 2190 insertions(+), 456 deletions(-) diff --git a/scripts/generateComposeMiddleware.js b/scripts/generateComposeMiddleware.js index 074d1b6..043255f 100644 --- a/scripts/generateComposeMiddleware.js +++ b/scripts/generateComposeMiddleware.js @@ -3,7 +3,7 @@ import ts from 'typescript' import * as prettier from 'prettier' // The maximum number of arguments to generate overloads for. -const MAX_ARGUMENTS = 20 +const MAX_ARGUMENTS = 30 /** * Simply passes the value {@link x} to the function {@param fn} and returns the @@ -40,7 +40,7 @@ const declarations = [ EnvOf, Middleware, RequiredContextOf, - } from './bindings' + } from './bindings.js' /** * Returns the result of satisfying the {@link Requirements} with the @@ -50,6 +50,12 @@ const declarations = [ With extends Pick ? Omit : never + + /** + * Forces TypeScript to resolve a complex type into a simple single object + * type. This makes the type of a composed middleware much easier to read. + */ + type Simplify = {[KeyType in keyof T]: T[KeyType]} & {}; `, /* typescript */ ` @@ -87,6 +93,7 @@ function createComposeMiddlewareOverloadDeclaration (argCount) { undefined, 'composeMiddleware', [ + // Type parameters ...ns.flatMap((n) => { return [ ts.factory.createTypeParameterDeclaration( @@ -125,6 +132,8 @@ function createComposeMiddlewareOverloadDeclaration (argCount) { ] }) ], + + // Function parameters ns.map((n) => ts.factory.createParameterDeclaration( undefined, @@ -135,31 +144,39 @@ function createComposeMiddlewareOverloadDeclaration (argCount) { undefined ) ), + + // Return type ts.factory.createTypeReferenceNode('Middleware', [ - ts.factory.createIntersectionTypeNode( - ns.map((n) => - withBinding( - ts.factory.createTypeReferenceNode('RequiredContextOf', [ - ts.factory.createTypeReferenceNode(`M${n}`) - ]), - (requiredContext) => - n === 1 - ? requiredContext - : ts.factory.createTypeReferenceNode('Satisfy', [ - requiredContext, - ts.factory.createTypeReferenceNode(`M${n - 1}C`) - ]) + ts.factory.createTypeReferenceNode('Simplify', [ + ts.factory.createIntersectionTypeNode( + ns.map((n) => + withBinding( + ts.factory.createTypeReferenceNode('RequiredContextOf', [ + ts.factory.createTypeReferenceNode(`M${n}`) + ]), + (requiredContext) => + n === 1 + ? requiredContext + : ts.factory.createTypeReferenceNode('Satisfy', [ + requiredContext, + ts.factory.createTypeReferenceNode(`M${n - 1}C`) + ]) + ) ) ) - ), - ts.factory.createTypeReferenceNode(`M${ns[ns.length - 1]}C`), - ts.factory.createIntersectionTypeNode( - ns.map((n) => - ts.factory.createTypeReferenceNode('EnvOf', [ - ts.factory.createTypeReferenceNode(`M${n}`) - ]) + ]), + ts.factory.createTypeReferenceNode('Simplify', [ + ts.factory.createTypeReferenceNode(`M${ns[ns.length - 1]}C`) + ]), + ts.factory.createTypeReferenceNode('Simplify', [ + ts.factory.createIntersectionTypeNode( + ns.map((n) => + ts.factory.createTypeReferenceNode('EnvOf', [ + ts.factory.createTypeReferenceNode(`M${n}`) + ]) + ) ) - ) + ]) ]), undefined ) diff --git a/src/bindings.d.ts b/src/bindings.d.ts index a68bb4c..4d95029 100644 --- a/src/bindings.d.ts +++ b/src/bindings.d.ts @@ -80,7 +80,7 @@ export type Middleware< * handler. * @template HandlerEnv The environment keys used by the wrapped handler. */ - ( + ( h: Handler ) => Handler diff --git a/src/composeMiddleware.d.ts b/src/composeMiddleware.d.ts index 1ec717a..044e19e 100644 --- a/src/composeMiddleware.d.ts +++ b/src/composeMiddleware.d.ts @@ -13,7 +13,7 @@ import { EnvOf, Middleware, RequiredContextOf, -} from './bindings' +} from './bindings.js' /** * Returns the result of satisfying the {@link Requirements} with the @@ -24,12 +24,18 @@ export type Satisfy = ? Omit : never +/** + * Forces TypeScript to resolve a complex type into a simple single object + * type. This makes the type of a composed middleware much easier to read. + */ +type Simplify = { [KeyType in keyof T]: T[KeyType] } & {} + /** * Composes multiple middleware functions into a single middleware function. The * request will be seen by the composed middleware in the order they are given. * * Note: Due to TypeScript limitations, each arity of this function must be a - * separate overload. To compose more than 20 middleware functions, simply nest + * separate overload. To compose more than 30 middleware functions, simply nest * smaller compositions. */ @@ -37,7 +43,13 @@ declare function composeMiddleware< M1 extends Middleware, M1R extends RequiredContextOf, M1C extends AddedContextOf, ->(m1: M1): Middleware, M1C, EnvOf> +>( + m1: M1 +): Middleware< + Simplify>, + Simplify, + Simplify> +> declare function composeMiddleware< M1 extends Middleware, @@ -50,9 +62,9 @@ declare function composeMiddleware< m1: M1, m2: M2 ): Middleware< - RequiredContextOf & Satisfy, M1C>, - M2C, - EnvOf & EnvOf + Simplify & Satisfy, M1C>>, + Simplify, + Simplify & EnvOf> > declare function composeMiddleware< @@ -70,11 +82,13 @@ declare function composeMiddleware< m2: M2, m3: M3 ): Middleware< - RequiredContextOf & - Satisfy, M1C> & - Satisfy, M2C>, - M3C, - EnvOf & EnvOf & EnvOf + Simplify< + RequiredContextOf & + Satisfy, M1C> & + Satisfy, M2C> + >, + Simplify, + Simplify & EnvOf & EnvOf> > declare function composeMiddleware< @@ -96,12 +110,14 @@ declare function composeMiddleware< m3: M3, m4: M4 ): Middleware< - RequiredContextOf & - Satisfy, M1C> & - Satisfy, M2C> & - Satisfy, M3C>, - M4C, - EnvOf & EnvOf & EnvOf & EnvOf + Simplify< + RequiredContextOf & + Satisfy, M1C> & + Satisfy, M2C> & + Satisfy, M3C> + >, + Simplify, + Simplify & EnvOf & EnvOf & EnvOf> > declare function composeMiddleware< @@ -127,13 +143,15 @@ declare function composeMiddleware< m4: M4, m5: M5 ): Middleware< - RequiredContextOf & - Satisfy, M1C> & - Satisfy, M2C> & - Satisfy, M3C> & - Satisfy, M4C>, - M5C, - EnvOf & EnvOf & EnvOf & EnvOf & EnvOf + Simplify< + RequiredContextOf & + Satisfy, M1C> & + Satisfy, M2C> & + Satisfy, M3C> & + Satisfy, M4C> + >, + Simplify, + Simplify & EnvOf & EnvOf & EnvOf & EnvOf> > declare function composeMiddleware< @@ -163,14 +181,18 @@ declare function composeMiddleware< m5: M5, m6: M6 ): Middleware< - RequiredContextOf & - Satisfy, M1C> & - Satisfy, M2C> & - Satisfy, M3C> & - Satisfy, M4C> & - Satisfy, M5C>, - M6C, - EnvOf & EnvOf & EnvOf & EnvOf & EnvOf & EnvOf + Simplify< + RequiredContextOf & + Satisfy, M1C> & + Satisfy, M2C> & + Satisfy, M3C> & + Satisfy, M4C> & + Satisfy, M5C> + >, + Simplify, + Simplify< + EnvOf & EnvOf & EnvOf & EnvOf & EnvOf & EnvOf + > > declare function composeMiddleware< @@ -204,21 +226,25 @@ declare function composeMiddleware< m6: M6, m7: M7 ): Middleware< - RequiredContextOf & - Satisfy, M1C> & - Satisfy, M2C> & - Satisfy, M3C> & - Satisfy, M4C> & - Satisfy, M5C> & - Satisfy, M6C>, - M7C, - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf + Simplify< + RequiredContextOf & + Satisfy, M1C> & + Satisfy, M2C> & + Satisfy, M3C> & + Satisfy, M4C> & + Satisfy, M5C> & + Satisfy, M6C> + >, + Simplify, + Simplify< + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf + > > declare function composeMiddleware< @@ -256,23 +282,27 @@ declare function composeMiddleware< m7: M7, m8: M8 ): Middleware< - RequiredContextOf & - Satisfy, M1C> & - Satisfy, M2C> & - Satisfy, M3C> & - Satisfy, M4C> & - Satisfy, M5C> & - Satisfy, M6C> & - Satisfy, M7C>, - M8C, - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf + Simplify< + RequiredContextOf & + Satisfy, M1C> & + Satisfy, M2C> & + Satisfy, M3C> & + Satisfy, M4C> & + Satisfy, M5C> & + Satisfy, M6C> & + Satisfy, M7C> + >, + Simplify, + Simplify< + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf + > > declare function composeMiddleware< @@ -314,25 +344,29 @@ declare function composeMiddleware< m8: M8, m9: M9 ): Middleware< - RequiredContextOf & - Satisfy, M1C> & - Satisfy, M2C> & - Satisfy, M3C> & - Satisfy, M4C> & - Satisfy, M5C> & - Satisfy, M6C> & - Satisfy, M7C> & - Satisfy, M8C>, - M9C, - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf + Simplify< + RequiredContextOf & + Satisfy, M1C> & + Satisfy, M2C> & + Satisfy, M3C> & + Satisfy, M4C> & + Satisfy, M5C> & + Satisfy, M6C> & + Satisfy, M7C> & + Satisfy, M8C> + >, + Simplify, + Simplify< + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf + > > declare function composeMiddleware< @@ -378,27 +412,31 @@ declare function composeMiddleware< m9: M9, m10: M10 ): Middleware< - RequiredContextOf & - Satisfy, M1C> & - Satisfy, M2C> & - Satisfy, M3C> & - Satisfy, M4C> & - Satisfy, M5C> & - Satisfy, M6C> & - Satisfy, M7C> & - Satisfy, M8C> & - Satisfy, M9C>, - M10C, - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf + Simplify< + RequiredContextOf & + Satisfy, M1C> & + Satisfy, M2C> & + Satisfy, M3C> & + Satisfy, M4C> & + Satisfy, M5C> & + Satisfy, M6C> & + Satisfy, M7C> & + Satisfy, M8C> & + Satisfy, M9C> + >, + Simplify, + Simplify< + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf + > > declare function composeMiddleware< @@ -448,29 +486,33 @@ declare function composeMiddleware< m10: M10, m11: M11 ): Middleware< - RequiredContextOf & - Satisfy, M1C> & - Satisfy, M2C> & - Satisfy, M3C> & - Satisfy, M4C> & - Satisfy, M5C> & - Satisfy, M6C> & - Satisfy, M7C> & - Satisfy, M8C> & - Satisfy, M9C> & - Satisfy, M10C>, - M11C, - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf + Simplify< + RequiredContextOf & + Satisfy, M1C> & + Satisfy, M2C> & + Satisfy, M3C> & + Satisfy, M4C> & + Satisfy, M5C> & + Satisfy, M6C> & + Satisfy, M7C> & + Satisfy, M8C> & + Satisfy, M9C> & + Satisfy, M10C> + >, + Simplify, + Simplify< + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf + > > declare function composeMiddleware< @@ -524,31 +566,35 @@ declare function composeMiddleware< m11: M11, m12: M12 ): Middleware< - RequiredContextOf & - Satisfy, M1C> & - Satisfy, M2C> & - Satisfy, M3C> & - Satisfy, M4C> & - Satisfy, M5C> & - Satisfy, M6C> & - Satisfy, M7C> & - Satisfy, M8C> & - Satisfy, M9C> & - Satisfy, M10C> & - Satisfy, M11C>, - M12C, - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf + Simplify< + RequiredContextOf & + Satisfy, M1C> & + Satisfy, M2C> & + Satisfy, M3C> & + Satisfy, M4C> & + Satisfy, M5C> & + Satisfy, M6C> & + Satisfy, M7C> & + Satisfy, M8C> & + Satisfy, M9C> & + Satisfy, M10C> & + Satisfy, M11C> + >, + Simplify, + Simplify< + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf + > > declare function composeMiddleware< @@ -606,33 +652,37 @@ declare function composeMiddleware< m12: M12, m13: M13 ): Middleware< - RequiredContextOf & - Satisfy, M1C> & - Satisfy, M2C> & - Satisfy, M3C> & - Satisfy, M4C> & - Satisfy, M5C> & - Satisfy, M6C> & - Satisfy, M7C> & - Satisfy, M8C> & - Satisfy, M9C> & - Satisfy, M10C> & - Satisfy, M11C> & - Satisfy, M12C>, - M13C, - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf + Simplify< + RequiredContextOf & + Satisfy, M1C> & + Satisfy, M2C> & + Satisfy, M3C> & + Satisfy, M4C> & + Satisfy, M5C> & + Satisfy, M6C> & + Satisfy, M7C> & + Satisfy, M8C> & + Satisfy, M9C> & + Satisfy, M10C> & + Satisfy, M11C> & + Satisfy, M12C> + >, + Simplify, + Simplify< + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf + > > declare function composeMiddleware< @@ -694,35 +744,39 @@ declare function composeMiddleware< m13: M13, m14: M14 ): Middleware< - RequiredContextOf & - Satisfy, M1C> & - Satisfy, M2C> & - Satisfy, M3C> & - Satisfy, M4C> & - Satisfy, M5C> & - Satisfy, M6C> & - Satisfy, M7C> & - Satisfy, M8C> & - Satisfy, M9C> & - Satisfy, M10C> & - Satisfy, M11C> & - Satisfy, M12C> & - Satisfy, M13C>, - M14C, - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf + Simplify< + RequiredContextOf & + Satisfy, M1C> & + Satisfy, M2C> & + Satisfy, M3C> & + Satisfy, M4C> & + Satisfy, M5C> & + Satisfy, M6C> & + Satisfy, M7C> & + Satisfy, M8C> & + Satisfy, M9C> & + Satisfy, M10C> & + Satisfy, M11C> & + Satisfy, M12C> & + Satisfy, M13C> + >, + Simplify, + Simplify< + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf + > > declare function composeMiddleware< @@ -788,37 +842,41 @@ declare function composeMiddleware< m14: M14, m15: M15 ): Middleware< - RequiredContextOf & - Satisfy, M1C> & - Satisfy, M2C> & - Satisfy, M3C> & - Satisfy, M4C> & - Satisfy, M5C> & - Satisfy, M6C> & - Satisfy, M7C> & - Satisfy, M8C> & - Satisfy, M9C> & - Satisfy, M10C> & - Satisfy, M11C> & - Satisfy, M12C> & - Satisfy, M13C> & - Satisfy, M14C>, - M15C, - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf + Simplify< + RequiredContextOf & + Satisfy, M1C> & + Satisfy, M2C> & + Satisfy, M3C> & + Satisfy, M4C> & + Satisfy, M5C> & + Satisfy, M6C> & + Satisfy, M7C> & + Satisfy, M8C> & + Satisfy, M9C> & + Satisfy, M10C> & + Satisfy, M11C> & + Satisfy, M12C> & + Satisfy, M13C> & + Satisfy, M14C> + >, + Simplify, + Simplify< + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf + > > declare function composeMiddleware< @@ -888,39 +946,43 @@ declare function composeMiddleware< m15: M15, m16: M16 ): Middleware< - RequiredContextOf & - Satisfy, M1C> & - Satisfy, M2C> & - Satisfy, M3C> & - Satisfy, M4C> & - Satisfy, M5C> & - Satisfy, M6C> & - Satisfy, M7C> & - Satisfy, M8C> & - Satisfy, M9C> & - Satisfy, M10C> & - Satisfy, M11C> & - Satisfy, M12C> & - Satisfy, M13C> & - Satisfy, M14C> & - Satisfy, M15C>, - M16C, - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf + Simplify< + RequiredContextOf & + Satisfy, M1C> & + Satisfy, M2C> & + Satisfy, M3C> & + Satisfy, M4C> & + Satisfy, M5C> & + Satisfy, M6C> & + Satisfy, M7C> & + Satisfy, M8C> & + Satisfy, M9C> & + Satisfy, M10C> & + Satisfy, M11C> & + Satisfy, M12C> & + Satisfy, M13C> & + Satisfy, M14C> & + Satisfy, M15C> + >, + Simplify, + Simplify< + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf + > > declare function composeMiddleware< @@ -994,41 +1056,45 @@ declare function composeMiddleware< m16: M16, m17: M17 ): Middleware< - RequiredContextOf & - Satisfy, M1C> & - Satisfy, M2C> & - Satisfy, M3C> & - Satisfy, M4C> & - Satisfy, M5C> & - Satisfy, M6C> & - Satisfy, M7C> & - Satisfy, M8C> & - Satisfy, M9C> & - Satisfy, M10C> & - Satisfy, M11C> & - Satisfy, M12C> & - Satisfy, M13C> & - Satisfy, M14C> & - Satisfy, M15C> & - Satisfy, M16C>, - M17C, - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf + Simplify< + RequiredContextOf & + Satisfy, M1C> & + Satisfy, M2C> & + Satisfy, M3C> & + Satisfy, M4C> & + Satisfy, M5C> & + Satisfy, M6C> & + Satisfy, M7C> & + Satisfy, M8C> & + Satisfy, M9C> & + Satisfy, M10C> & + Satisfy, M11C> & + Satisfy, M12C> & + Satisfy, M13C> & + Satisfy, M14C> & + Satisfy, M15C> & + Satisfy, M16C> + >, + Simplify, + Simplify< + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf + > > declare function composeMiddleware< @@ -1106,43 +1172,47 @@ declare function composeMiddleware< m17: M17, m18: M18 ): Middleware< - RequiredContextOf & - Satisfy, M1C> & - Satisfy, M2C> & - Satisfy, M3C> & - Satisfy, M4C> & - Satisfy, M5C> & - Satisfy, M6C> & - Satisfy, M7C> & - Satisfy, M8C> & - Satisfy, M9C> & - Satisfy, M10C> & - Satisfy, M11C> & - Satisfy, M12C> & - Satisfy, M13C> & - Satisfy, M14C> & - Satisfy, M15C> & - Satisfy, M16C> & - Satisfy, M17C>, - M18C, - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf + Simplify< + RequiredContextOf & + Satisfy, M1C> & + Satisfy, M2C> & + Satisfy, M3C> & + Satisfy, M4C> & + Satisfy, M5C> & + Satisfy, M6C> & + Satisfy, M7C> & + Satisfy, M8C> & + Satisfy, M9C> & + Satisfy, M10C> & + Satisfy, M11C> & + Satisfy, M12C> & + Satisfy, M13C> & + Satisfy, M14C> & + Satisfy, M15C> & + Satisfy, M16C> & + Satisfy, M17C> + >, + Simplify, + Simplify< + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf + > > declare function composeMiddleware< @@ -1224,45 +1294,49 @@ declare function composeMiddleware< m18: M18, m19: M19 ): Middleware< - RequiredContextOf & - Satisfy, M1C> & - Satisfy, M2C> & - Satisfy, M3C> & - Satisfy, M4C> & - Satisfy, M5C> & - Satisfy, M6C> & - Satisfy, M7C> & - Satisfy, M8C> & - Satisfy, M9C> & - Satisfy, M10C> & - Satisfy, M11C> & - Satisfy, M12C> & - Satisfy, M13C> & - Satisfy, M14C> & - Satisfy, M15C> & - Satisfy, M16C> & - Satisfy, M17C> & - Satisfy, M18C>, - M19C, - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf + Simplify< + RequiredContextOf & + Satisfy, M1C> & + Satisfy, M2C> & + Satisfy, M3C> & + Satisfy, M4C> & + Satisfy, M5C> & + Satisfy, M6C> & + Satisfy, M7C> & + Satisfy, M8C> & + Satisfy, M9C> & + Satisfy, M10C> & + Satisfy, M11C> & + Satisfy, M12C> & + Satisfy, M13C> & + Satisfy, M14C> & + Satisfy, M15C> & + Satisfy, M16C> & + Satisfy, M17C> & + Satisfy, M18C> + >, + Simplify, + Simplify< + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf + > > declare function composeMiddleware< @@ -1348,47 +1422,1681 @@ declare function composeMiddleware< m19: M19, m20: M20 ): Middleware< - RequiredContextOf & - Satisfy, M1C> & - Satisfy, M2C> & - Satisfy, M3C> & - Satisfy, M4C> & - Satisfy, M5C> & - Satisfy, M6C> & - Satisfy, M7C> & - Satisfy, M8C> & - Satisfy, M9C> & - Satisfy, M10C> & - Satisfy, M11C> & - Satisfy, M12C> & - Satisfy, M13C> & - Satisfy, M14C> & - Satisfy, M15C> & - Satisfy, M16C> & - Satisfy, M17C> & - Satisfy, M18C> & - Satisfy, M19C>, - M20C, - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf & - EnvOf + Simplify< + RequiredContextOf & + Satisfy, M1C> & + Satisfy, M2C> & + Satisfy, M3C> & + Satisfy, M4C> & + Satisfy, M5C> & + Satisfy, M6C> & + Satisfy, M7C> & + Satisfy, M8C> & + Satisfy, M9C> & + Satisfy, M10C> & + Satisfy, M11C> & + Satisfy, M12C> & + Satisfy, M13C> & + Satisfy, M14C> & + Satisfy, M15C> & + Satisfy, M16C> & + Satisfy, M17C> & + Satisfy, M18C> & + Satisfy, M19C> + >, + Simplify, + Simplify< + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf + > +> + +declare function composeMiddleware< + M1 extends Middleware, + M1R extends RequiredContextOf, + M1C extends AddedContextOf, + M2 extends Middleware, + M2R extends Satisfy, M1C>, + M2C extends AddedContextOf & M1C, + M3 extends Middleware, + M3R extends Satisfy, M2C>, + M3C extends AddedContextOf & M2C, + M4 extends Middleware, + M4R extends Satisfy, M3C>, + M4C extends AddedContextOf & M3C, + M5 extends Middleware, + M5R extends Satisfy, M4C>, + M5C extends AddedContextOf & M4C, + M6 extends Middleware, + M6R extends Satisfy, M5C>, + M6C extends AddedContextOf & M5C, + M7 extends Middleware, + M7R extends Satisfy, M6C>, + M7C extends AddedContextOf & M6C, + M8 extends Middleware, + M8R extends Satisfy, M7C>, + M8C extends AddedContextOf & M7C, + M9 extends Middleware, + M9R extends Satisfy, M8C>, + M9C extends AddedContextOf & M8C, + M10 extends Middleware, + M10R extends Satisfy, M9C>, + M10C extends AddedContextOf & M9C, + M11 extends Middleware, + M11R extends Satisfy, M10C>, + M11C extends AddedContextOf & M10C, + M12 extends Middleware, + M12R extends Satisfy, M11C>, + M12C extends AddedContextOf & M11C, + M13 extends Middleware, + M13R extends Satisfy, M12C>, + M13C extends AddedContextOf & M12C, + M14 extends Middleware, + M14R extends Satisfy, M13C>, + M14C extends AddedContextOf & M13C, + M15 extends Middleware, + M15R extends Satisfy, M14C>, + M15C extends AddedContextOf & M14C, + M16 extends Middleware, + M16R extends Satisfy, M15C>, + M16C extends AddedContextOf & M15C, + M17 extends Middleware, + M17R extends Satisfy, M16C>, + M17C extends AddedContextOf & M16C, + M18 extends Middleware, + M18R extends Satisfy, M17C>, + M18C extends AddedContextOf & M17C, + M19 extends Middleware, + M19R extends Satisfy, M18C>, + M19C extends AddedContextOf & M18C, + M20 extends Middleware, + M20R extends Satisfy, M19C>, + M20C extends AddedContextOf & M19C, + M21 extends Middleware, + M21R extends Satisfy, M20C>, + M21C extends AddedContextOf & M20C, +>( + m1: M1, + m2: M2, + m3: M3, + m4: M4, + m5: M5, + m6: M6, + m7: M7, + m8: M8, + m9: M9, + m10: M10, + m11: M11, + m12: M12, + m13: M13, + m14: M14, + m15: M15, + m16: M16, + m17: M17, + m18: M18, + m19: M19, + m20: M20, + m21: M21 +): Middleware< + Simplify< + RequiredContextOf & + Satisfy, M1C> & + Satisfy, M2C> & + Satisfy, M3C> & + Satisfy, M4C> & + Satisfy, M5C> & + Satisfy, M6C> & + Satisfy, M7C> & + Satisfy, M8C> & + Satisfy, M9C> & + Satisfy, M10C> & + Satisfy, M11C> & + Satisfy, M12C> & + Satisfy, M13C> & + Satisfy, M14C> & + Satisfy, M15C> & + Satisfy, M16C> & + Satisfy, M17C> & + Satisfy, M18C> & + Satisfy, M19C> & + Satisfy, M20C> + >, + Simplify, + Simplify< + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf + > +> + +declare function composeMiddleware< + M1 extends Middleware, + M1R extends RequiredContextOf, + M1C extends AddedContextOf, + M2 extends Middleware, + M2R extends Satisfy, M1C>, + M2C extends AddedContextOf & M1C, + M3 extends Middleware, + M3R extends Satisfy, M2C>, + M3C extends AddedContextOf & M2C, + M4 extends Middleware, + M4R extends Satisfy, M3C>, + M4C extends AddedContextOf & M3C, + M5 extends Middleware, + M5R extends Satisfy, M4C>, + M5C extends AddedContextOf & M4C, + M6 extends Middleware, + M6R extends Satisfy, M5C>, + M6C extends AddedContextOf & M5C, + M7 extends Middleware, + M7R extends Satisfy, M6C>, + M7C extends AddedContextOf & M6C, + M8 extends Middleware, + M8R extends Satisfy, M7C>, + M8C extends AddedContextOf & M7C, + M9 extends Middleware, + M9R extends Satisfy, M8C>, + M9C extends AddedContextOf & M8C, + M10 extends Middleware, + M10R extends Satisfy, M9C>, + M10C extends AddedContextOf & M9C, + M11 extends Middleware, + M11R extends Satisfy, M10C>, + M11C extends AddedContextOf & M10C, + M12 extends Middleware, + M12R extends Satisfy, M11C>, + M12C extends AddedContextOf & M11C, + M13 extends Middleware, + M13R extends Satisfy, M12C>, + M13C extends AddedContextOf & M12C, + M14 extends Middleware, + M14R extends Satisfy, M13C>, + M14C extends AddedContextOf & M13C, + M15 extends Middleware, + M15R extends Satisfy, M14C>, + M15C extends AddedContextOf & M14C, + M16 extends Middleware, + M16R extends Satisfy, M15C>, + M16C extends AddedContextOf & M15C, + M17 extends Middleware, + M17R extends Satisfy, M16C>, + M17C extends AddedContextOf & M16C, + M18 extends Middleware, + M18R extends Satisfy, M17C>, + M18C extends AddedContextOf & M17C, + M19 extends Middleware, + M19R extends Satisfy, M18C>, + M19C extends AddedContextOf & M18C, + M20 extends Middleware, + M20R extends Satisfy, M19C>, + M20C extends AddedContextOf & M19C, + M21 extends Middleware, + M21R extends Satisfy, M20C>, + M21C extends AddedContextOf & M20C, + M22 extends Middleware, + M22R extends Satisfy, M21C>, + M22C extends AddedContextOf & M21C, +>( + m1: M1, + m2: M2, + m3: M3, + m4: M4, + m5: M5, + m6: M6, + m7: M7, + m8: M8, + m9: M9, + m10: M10, + m11: M11, + m12: M12, + m13: M13, + m14: M14, + m15: M15, + m16: M16, + m17: M17, + m18: M18, + m19: M19, + m20: M20, + m21: M21, + m22: M22 +): Middleware< + Simplify< + RequiredContextOf & + Satisfy, M1C> & + Satisfy, M2C> & + Satisfy, M3C> & + Satisfy, M4C> & + Satisfy, M5C> & + Satisfy, M6C> & + Satisfy, M7C> & + Satisfy, M8C> & + Satisfy, M9C> & + Satisfy, M10C> & + Satisfy, M11C> & + Satisfy, M12C> & + Satisfy, M13C> & + Satisfy, M14C> & + Satisfy, M15C> & + Satisfy, M16C> & + Satisfy, M17C> & + Satisfy, M18C> & + Satisfy, M19C> & + Satisfy, M20C> & + Satisfy, M21C> + >, + Simplify, + Simplify< + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf + > +> + +declare function composeMiddleware< + M1 extends Middleware, + M1R extends RequiredContextOf, + M1C extends AddedContextOf, + M2 extends Middleware, + M2R extends Satisfy, M1C>, + M2C extends AddedContextOf & M1C, + M3 extends Middleware, + M3R extends Satisfy, M2C>, + M3C extends AddedContextOf & M2C, + M4 extends Middleware, + M4R extends Satisfy, M3C>, + M4C extends AddedContextOf & M3C, + M5 extends Middleware, + M5R extends Satisfy, M4C>, + M5C extends AddedContextOf & M4C, + M6 extends Middleware, + M6R extends Satisfy, M5C>, + M6C extends AddedContextOf & M5C, + M7 extends Middleware, + M7R extends Satisfy, M6C>, + M7C extends AddedContextOf & M6C, + M8 extends Middleware, + M8R extends Satisfy, M7C>, + M8C extends AddedContextOf & M7C, + M9 extends Middleware, + M9R extends Satisfy, M8C>, + M9C extends AddedContextOf & M8C, + M10 extends Middleware, + M10R extends Satisfy, M9C>, + M10C extends AddedContextOf & M9C, + M11 extends Middleware, + M11R extends Satisfy, M10C>, + M11C extends AddedContextOf & M10C, + M12 extends Middleware, + M12R extends Satisfy, M11C>, + M12C extends AddedContextOf & M11C, + M13 extends Middleware, + M13R extends Satisfy, M12C>, + M13C extends AddedContextOf & M12C, + M14 extends Middleware, + M14R extends Satisfy, M13C>, + M14C extends AddedContextOf & M13C, + M15 extends Middleware, + M15R extends Satisfy, M14C>, + M15C extends AddedContextOf & M14C, + M16 extends Middleware, + M16R extends Satisfy, M15C>, + M16C extends AddedContextOf & M15C, + M17 extends Middleware, + M17R extends Satisfy, M16C>, + M17C extends AddedContextOf & M16C, + M18 extends Middleware, + M18R extends Satisfy, M17C>, + M18C extends AddedContextOf & M17C, + M19 extends Middleware, + M19R extends Satisfy, M18C>, + M19C extends AddedContextOf & M18C, + M20 extends Middleware, + M20R extends Satisfy, M19C>, + M20C extends AddedContextOf & M19C, + M21 extends Middleware, + M21R extends Satisfy, M20C>, + M21C extends AddedContextOf & M20C, + M22 extends Middleware, + M22R extends Satisfy, M21C>, + M22C extends AddedContextOf & M21C, + M23 extends Middleware, + M23R extends Satisfy, M22C>, + M23C extends AddedContextOf & M22C, +>( + m1: M1, + m2: M2, + m3: M3, + m4: M4, + m5: M5, + m6: M6, + m7: M7, + m8: M8, + m9: M9, + m10: M10, + m11: M11, + m12: M12, + m13: M13, + m14: M14, + m15: M15, + m16: M16, + m17: M17, + m18: M18, + m19: M19, + m20: M20, + m21: M21, + m22: M22, + m23: M23 +): Middleware< + Simplify< + RequiredContextOf & + Satisfy, M1C> & + Satisfy, M2C> & + Satisfy, M3C> & + Satisfy, M4C> & + Satisfy, M5C> & + Satisfy, M6C> & + Satisfy, M7C> & + Satisfy, M8C> & + Satisfy, M9C> & + Satisfy, M10C> & + Satisfy, M11C> & + Satisfy, M12C> & + Satisfy, M13C> & + Satisfy, M14C> & + Satisfy, M15C> & + Satisfy, M16C> & + Satisfy, M17C> & + Satisfy, M18C> & + Satisfy, M19C> & + Satisfy, M20C> & + Satisfy, M21C> & + Satisfy, M22C> + >, + Simplify, + Simplify< + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf + > +> + +declare function composeMiddleware< + M1 extends Middleware, + M1R extends RequiredContextOf, + M1C extends AddedContextOf, + M2 extends Middleware, + M2R extends Satisfy, M1C>, + M2C extends AddedContextOf & M1C, + M3 extends Middleware, + M3R extends Satisfy, M2C>, + M3C extends AddedContextOf & M2C, + M4 extends Middleware, + M4R extends Satisfy, M3C>, + M4C extends AddedContextOf & M3C, + M5 extends Middleware, + M5R extends Satisfy, M4C>, + M5C extends AddedContextOf & M4C, + M6 extends Middleware, + M6R extends Satisfy, M5C>, + M6C extends AddedContextOf & M5C, + M7 extends Middleware, + M7R extends Satisfy, M6C>, + M7C extends AddedContextOf & M6C, + M8 extends Middleware, + M8R extends Satisfy, M7C>, + M8C extends AddedContextOf & M7C, + M9 extends Middleware, + M9R extends Satisfy, M8C>, + M9C extends AddedContextOf & M8C, + M10 extends Middleware, + M10R extends Satisfy, M9C>, + M10C extends AddedContextOf & M9C, + M11 extends Middleware, + M11R extends Satisfy, M10C>, + M11C extends AddedContextOf & M10C, + M12 extends Middleware, + M12R extends Satisfy, M11C>, + M12C extends AddedContextOf & M11C, + M13 extends Middleware, + M13R extends Satisfy, M12C>, + M13C extends AddedContextOf & M12C, + M14 extends Middleware, + M14R extends Satisfy, M13C>, + M14C extends AddedContextOf & M13C, + M15 extends Middleware, + M15R extends Satisfy, M14C>, + M15C extends AddedContextOf & M14C, + M16 extends Middleware, + M16R extends Satisfy, M15C>, + M16C extends AddedContextOf & M15C, + M17 extends Middleware, + M17R extends Satisfy, M16C>, + M17C extends AddedContextOf & M16C, + M18 extends Middleware, + M18R extends Satisfy, M17C>, + M18C extends AddedContextOf & M17C, + M19 extends Middleware, + M19R extends Satisfy, M18C>, + M19C extends AddedContextOf & M18C, + M20 extends Middleware, + M20R extends Satisfy, M19C>, + M20C extends AddedContextOf & M19C, + M21 extends Middleware, + M21R extends Satisfy, M20C>, + M21C extends AddedContextOf & M20C, + M22 extends Middleware, + M22R extends Satisfy, M21C>, + M22C extends AddedContextOf & M21C, + M23 extends Middleware, + M23R extends Satisfy, M22C>, + M23C extends AddedContextOf & M22C, + M24 extends Middleware, + M24R extends Satisfy, M23C>, + M24C extends AddedContextOf & M23C, +>( + m1: M1, + m2: M2, + m3: M3, + m4: M4, + m5: M5, + m6: M6, + m7: M7, + m8: M8, + m9: M9, + m10: M10, + m11: M11, + m12: M12, + m13: M13, + m14: M14, + m15: M15, + m16: M16, + m17: M17, + m18: M18, + m19: M19, + m20: M20, + m21: M21, + m22: M22, + m23: M23, + m24: M24 +): Middleware< + Simplify< + RequiredContextOf & + Satisfy, M1C> & + Satisfy, M2C> & + Satisfy, M3C> & + Satisfy, M4C> & + Satisfy, M5C> & + Satisfy, M6C> & + Satisfy, M7C> & + Satisfy, M8C> & + Satisfy, M9C> & + Satisfy, M10C> & + Satisfy, M11C> & + Satisfy, M12C> & + Satisfy, M13C> & + Satisfy, M14C> & + Satisfy, M15C> & + Satisfy, M16C> & + Satisfy, M17C> & + Satisfy, M18C> & + Satisfy, M19C> & + Satisfy, M20C> & + Satisfy, M21C> & + Satisfy, M22C> & + Satisfy, M23C> + >, + Simplify, + Simplify< + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf + > +> + +declare function composeMiddleware< + M1 extends Middleware, + M1R extends RequiredContextOf, + M1C extends AddedContextOf, + M2 extends Middleware, + M2R extends Satisfy, M1C>, + M2C extends AddedContextOf & M1C, + M3 extends Middleware, + M3R extends Satisfy, M2C>, + M3C extends AddedContextOf & M2C, + M4 extends Middleware, + M4R extends Satisfy, M3C>, + M4C extends AddedContextOf & M3C, + M5 extends Middleware, + M5R extends Satisfy, M4C>, + M5C extends AddedContextOf & M4C, + M6 extends Middleware, + M6R extends Satisfy, M5C>, + M6C extends AddedContextOf & M5C, + M7 extends Middleware, + M7R extends Satisfy, M6C>, + M7C extends AddedContextOf & M6C, + M8 extends Middleware, + M8R extends Satisfy, M7C>, + M8C extends AddedContextOf & M7C, + M9 extends Middleware, + M9R extends Satisfy, M8C>, + M9C extends AddedContextOf & M8C, + M10 extends Middleware, + M10R extends Satisfy, M9C>, + M10C extends AddedContextOf & M9C, + M11 extends Middleware, + M11R extends Satisfy, M10C>, + M11C extends AddedContextOf & M10C, + M12 extends Middleware, + M12R extends Satisfy, M11C>, + M12C extends AddedContextOf & M11C, + M13 extends Middleware, + M13R extends Satisfy, M12C>, + M13C extends AddedContextOf & M12C, + M14 extends Middleware, + M14R extends Satisfy, M13C>, + M14C extends AddedContextOf & M13C, + M15 extends Middleware, + M15R extends Satisfy, M14C>, + M15C extends AddedContextOf & M14C, + M16 extends Middleware, + M16R extends Satisfy, M15C>, + M16C extends AddedContextOf & M15C, + M17 extends Middleware, + M17R extends Satisfy, M16C>, + M17C extends AddedContextOf & M16C, + M18 extends Middleware, + M18R extends Satisfy, M17C>, + M18C extends AddedContextOf & M17C, + M19 extends Middleware, + M19R extends Satisfy, M18C>, + M19C extends AddedContextOf & M18C, + M20 extends Middleware, + M20R extends Satisfy, M19C>, + M20C extends AddedContextOf & M19C, + M21 extends Middleware, + M21R extends Satisfy, M20C>, + M21C extends AddedContextOf & M20C, + M22 extends Middleware, + M22R extends Satisfy, M21C>, + M22C extends AddedContextOf & M21C, + M23 extends Middleware, + M23R extends Satisfy, M22C>, + M23C extends AddedContextOf & M22C, + M24 extends Middleware, + M24R extends Satisfy, M23C>, + M24C extends AddedContextOf & M23C, + M25 extends Middleware, + M25R extends Satisfy, M24C>, + M25C extends AddedContextOf & M24C, +>( + m1: M1, + m2: M2, + m3: M3, + m4: M4, + m5: M5, + m6: M6, + m7: M7, + m8: M8, + m9: M9, + m10: M10, + m11: M11, + m12: M12, + m13: M13, + m14: M14, + m15: M15, + m16: M16, + m17: M17, + m18: M18, + m19: M19, + m20: M20, + m21: M21, + m22: M22, + m23: M23, + m24: M24, + m25: M25 +): Middleware< + Simplify< + RequiredContextOf & + Satisfy, M1C> & + Satisfy, M2C> & + Satisfy, M3C> & + Satisfy, M4C> & + Satisfy, M5C> & + Satisfy, M6C> & + Satisfy, M7C> & + Satisfy, M8C> & + Satisfy, M9C> & + Satisfy, M10C> & + Satisfy, M11C> & + Satisfy, M12C> & + Satisfy, M13C> & + Satisfy, M14C> & + Satisfy, M15C> & + Satisfy, M16C> & + Satisfy, M17C> & + Satisfy, M18C> & + Satisfy, M19C> & + Satisfy, M20C> & + Satisfy, M21C> & + Satisfy, M22C> & + Satisfy, M23C> & + Satisfy, M24C> + >, + Simplify, + Simplify< + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf + > +> + +declare function composeMiddleware< + M1 extends Middleware, + M1R extends RequiredContextOf, + M1C extends AddedContextOf, + M2 extends Middleware, + M2R extends Satisfy, M1C>, + M2C extends AddedContextOf & M1C, + M3 extends Middleware, + M3R extends Satisfy, M2C>, + M3C extends AddedContextOf & M2C, + M4 extends Middleware, + M4R extends Satisfy, M3C>, + M4C extends AddedContextOf & M3C, + M5 extends Middleware, + M5R extends Satisfy, M4C>, + M5C extends AddedContextOf & M4C, + M6 extends Middleware, + M6R extends Satisfy, M5C>, + M6C extends AddedContextOf & M5C, + M7 extends Middleware, + M7R extends Satisfy, M6C>, + M7C extends AddedContextOf & M6C, + M8 extends Middleware, + M8R extends Satisfy, M7C>, + M8C extends AddedContextOf & M7C, + M9 extends Middleware, + M9R extends Satisfy, M8C>, + M9C extends AddedContextOf & M8C, + M10 extends Middleware, + M10R extends Satisfy, M9C>, + M10C extends AddedContextOf & M9C, + M11 extends Middleware, + M11R extends Satisfy, M10C>, + M11C extends AddedContextOf & M10C, + M12 extends Middleware, + M12R extends Satisfy, M11C>, + M12C extends AddedContextOf & M11C, + M13 extends Middleware, + M13R extends Satisfy, M12C>, + M13C extends AddedContextOf & M12C, + M14 extends Middleware, + M14R extends Satisfy, M13C>, + M14C extends AddedContextOf & M13C, + M15 extends Middleware, + M15R extends Satisfy, M14C>, + M15C extends AddedContextOf & M14C, + M16 extends Middleware, + M16R extends Satisfy, M15C>, + M16C extends AddedContextOf & M15C, + M17 extends Middleware, + M17R extends Satisfy, M16C>, + M17C extends AddedContextOf & M16C, + M18 extends Middleware, + M18R extends Satisfy, M17C>, + M18C extends AddedContextOf & M17C, + M19 extends Middleware, + M19R extends Satisfy, M18C>, + M19C extends AddedContextOf & M18C, + M20 extends Middleware, + M20R extends Satisfy, M19C>, + M20C extends AddedContextOf & M19C, + M21 extends Middleware, + M21R extends Satisfy, M20C>, + M21C extends AddedContextOf & M20C, + M22 extends Middleware, + M22R extends Satisfy, M21C>, + M22C extends AddedContextOf & M21C, + M23 extends Middleware, + M23R extends Satisfy, M22C>, + M23C extends AddedContextOf & M22C, + M24 extends Middleware, + M24R extends Satisfy, M23C>, + M24C extends AddedContextOf & M23C, + M25 extends Middleware, + M25R extends Satisfy, M24C>, + M25C extends AddedContextOf & M24C, + M26 extends Middleware, + M26R extends Satisfy, M25C>, + M26C extends AddedContextOf & M25C, +>( + m1: M1, + m2: M2, + m3: M3, + m4: M4, + m5: M5, + m6: M6, + m7: M7, + m8: M8, + m9: M9, + m10: M10, + m11: M11, + m12: M12, + m13: M13, + m14: M14, + m15: M15, + m16: M16, + m17: M17, + m18: M18, + m19: M19, + m20: M20, + m21: M21, + m22: M22, + m23: M23, + m24: M24, + m25: M25, + m26: M26 +): Middleware< + Simplify< + RequiredContextOf & + Satisfy, M1C> & + Satisfy, M2C> & + Satisfy, M3C> & + Satisfy, M4C> & + Satisfy, M5C> & + Satisfy, M6C> & + Satisfy, M7C> & + Satisfy, M8C> & + Satisfy, M9C> & + Satisfy, M10C> & + Satisfy, M11C> & + Satisfy, M12C> & + Satisfy, M13C> & + Satisfy, M14C> & + Satisfy, M15C> & + Satisfy, M16C> & + Satisfy, M17C> & + Satisfy, M18C> & + Satisfy, M19C> & + Satisfy, M20C> & + Satisfy, M21C> & + Satisfy, M22C> & + Satisfy, M23C> & + Satisfy, M24C> & + Satisfy, M25C> + >, + Simplify, + Simplify< + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf + > +> + +declare function composeMiddleware< + M1 extends Middleware, + M1R extends RequiredContextOf, + M1C extends AddedContextOf, + M2 extends Middleware, + M2R extends Satisfy, M1C>, + M2C extends AddedContextOf & M1C, + M3 extends Middleware, + M3R extends Satisfy, M2C>, + M3C extends AddedContextOf & M2C, + M4 extends Middleware, + M4R extends Satisfy, M3C>, + M4C extends AddedContextOf & M3C, + M5 extends Middleware, + M5R extends Satisfy, M4C>, + M5C extends AddedContextOf & M4C, + M6 extends Middleware, + M6R extends Satisfy, M5C>, + M6C extends AddedContextOf & M5C, + M7 extends Middleware, + M7R extends Satisfy, M6C>, + M7C extends AddedContextOf & M6C, + M8 extends Middleware, + M8R extends Satisfy, M7C>, + M8C extends AddedContextOf & M7C, + M9 extends Middleware, + M9R extends Satisfy, M8C>, + M9C extends AddedContextOf & M8C, + M10 extends Middleware, + M10R extends Satisfy, M9C>, + M10C extends AddedContextOf & M9C, + M11 extends Middleware, + M11R extends Satisfy, M10C>, + M11C extends AddedContextOf & M10C, + M12 extends Middleware, + M12R extends Satisfy, M11C>, + M12C extends AddedContextOf & M11C, + M13 extends Middleware, + M13R extends Satisfy, M12C>, + M13C extends AddedContextOf & M12C, + M14 extends Middleware, + M14R extends Satisfy, M13C>, + M14C extends AddedContextOf & M13C, + M15 extends Middleware, + M15R extends Satisfy, M14C>, + M15C extends AddedContextOf & M14C, + M16 extends Middleware, + M16R extends Satisfy, M15C>, + M16C extends AddedContextOf & M15C, + M17 extends Middleware, + M17R extends Satisfy, M16C>, + M17C extends AddedContextOf & M16C, + M18 extends Middleware, + M18R extends Satisfy, M17C>, + M18C extends AddedContextOf & M17C, + M19 extends Middleware, + M19R extends Satisfy, M18C>, + M19C extends AddedContextOf & M18C, + M20 extends Middleware, + M20R extends Satisfy, M19C>, + M20C extends AddedContextOf & M19C, + M21 extends Middleware, + M21R extends Satisfy, M20C>, + M21C extends AddedContextOf & M20C, + M22 extends Middleware, + M22R extends Satisfy, M21C>, + M22C extends AddedContextOf & M21C, + M23 extends Middleware, + M23R extends Satisfy, M22C>, + M23C extends AddedContextOf & M22C, + M24 extends Middleware, + M24R extends Satisfy, M23C>, + M24C extends AddedContextOf & M23C, + M25 extends Middleware, + M25R extends Satisfy, M24C>, + M25C extends AddedContextOf & M24C, + M26 extends Middleware, + M26R extends Satisfy, M25C>, + M26C extends AddedContextOf & M25C, + M27 extends Middleware, + M27R extends Satisfy, M26C>, + M27C extends AddedContextOf & M26C, +>( + m1: M1, + m2: M2, + m3: M3, + m4: M4, + m5: M5, + m6: M6, + m7: M7, + m8: M8, + m9: M9, + m10: M10, + m11: M11, + m12: M12, + m13: M13, + m14: M14, + m15: M15, + m16: M16, + m17: M17, + m18: M18, + m19: M19, + m20: M20, + m21: M21, + m22: M22, + m23: M23, + m24: M24, + m25: M25, + m26: M26, + m27: M27 +): Middleware< + Simplify< + RequiredContextOf & + Satisfy, M1C> & + Satisfy, M2C> & + Satisfy, M3C> & + Satisfy, M4C> & + Satisfy, M5C> & + Satisfy, M6C> & + Satisfy, M7C> & + Satisfy, M8C> & + Satisfy, M9C> & + Satisfy, M10C> & + Satisfy, M11C> & + Satisfy, M12C> & + Satisfy, M13C> & + Satisfy, M14C> & + Satisfy, M15C> & + Satisfy, M16C> & + Satisfy, M17C> & + Satisfy, M18C> & + Satisfy, M19C> & + Satisfy, M20C> & + Satisfy, M21C> & + Satisfy, M22C> & + Satisfy, M23C> & + Satisfy, M24C> & + Satisfy, M25C> & + Satisfy, M26C> + >, + Simplify, + Simplify< + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf + > +> + +declare function composeMiddleware< + M1 extends Middleware, + M1R extends RequiredContextOf, + M1C extends AddedContextOf, + M2 extends Middleware, + M2R extends Satisfy, M1C>, + M2C extends AddedContextOf & M1C, + M3 extends Middleware, + M3R extends Satisfy, M2C>, + M3C extends AddedContextOf & M2C, + M4 extends Middleware, + M4R extends Satisfy, M3C>, + M4C extends AddedContextOf & M3C, + M5 extends Middleware, + M5R extends Satisfy, M4C>, + M5C extends AddedContextOf & M4C, + M6 extends Middleware, + M6R extends Satisfy, M5C>, + M6C extends AddedContextOf & M5C, + M7 extends Middleware, + M7R extends Satisfy, M6C>, + M7C extends AddedContextOf & M6C, + M8 extends Middleware, + M8R extends Satisfy, M7C>, + M8C extends AddedContextOf & M7C, + M9 extends Middleware, + M9R extends Satisfy, M8C>, + M9C extends AddedContextOf & M8C, + M10 extends Middleware, + M10R extends Satisfy, M9C>, + M10C extends AddedContextOf & M9C, + M11 extends Middleware, + M11R extends Satisfy, M10C>, + M11C extends AddedContextOf & M10C, + M12 extends Middleware, + M12R extends Satisfy, M11C>, + M12C extends AddedContextOf & M11C, + M13 extends Middleware, + M13R extends Satisfy, M12C>, + M13C extends AddedContextOf & M12C, + M14 extends Middleware, + M14R extends Satisfy, M13C>, + M14C extends AddedContextOf & M13C, + M15 extends Middleware, + M15R extends Satisfy, M14C>, + M15C extends AddedContextOf & M14C, + M16 extends Middleware, + M16R extends Satisfy, M15C>, + M16C extends AddedContextOf & M15C, + M17 extends Middleware, + M17R extends Satisfy, M16C>, + M17C extends AddedContextOf & M16C, + M18 extends Middleware, + M18R extends Satisfy, M17C>, + M18C extends AddedContextOf & M17C, + M19 extends Middleware, + M19R extends Satisfy, M18C>, + M19C extends AddedContextOf & M18C, + M20 extends Middleware, + M20R extends Satisfy, M19C>, + M20C extends AddedContextOf & M19C, + M21 extends Middleware, + M21R extends Satisfy, M20C>, + M21C extends AddedContextOf & M20C, + M22 extends Middleware, + M22R extends Satisfy, M21C>, + M22C extends AddedContextOf & M21C, + M23 extends Middleware, + M23R extends Satisfy, M22C>, + M23C extends AddedContextOf & M22C, + M24 extends Middleware, + M24R extends Satisfy, M23C>, + M24C extends AddedContextOf & M23C, + M25 extends Middleware, + M25R extends Satisfy, M24C>, + M25C extends AddedContextOf & M24C, + M26 extends Middleware, + M26R extends Satisfy, M25C>, + M26C extends AddedContextOf & M25C, + M27 extends Middleware, + M27R extends Satisfy, M26C>, + M27C extends AddedContextOf & M26C, + M28 extends Middleware, + M28R extends Satisfy, M27C>, + M28C extends AddedContextOf & M27C, +>( + m1: M1, + m2: M2, + m3: M3, + m4: M4, + m5: M5, + m6: M6, + m7: M7, + m8: M8, + m9: M9, + m10: M10, + m11: M11, + m12: M12, + m13: M13, + m14: M14, + m15: M15, + m16: M16, + m17: M17, + m18: M18, + m19: M19, + m20: M20, + m21: M21, + m22: M22, + m23: M23, + m24: M24, + m25: M25, + m26: M26, + m27: M27, + m28: M28 +): Middleware< + Simplify< + RequiredContextOf & + Satisfy, M1C> & + Satisfy, M2C> & + Satisfy, M3C> & + Satisfy, M4C> & + Satisfy, M5C> & + Satisfy, M6C> & + Satisfy, M7C> & + Satisfy, M8C> & + Satisfy, M9C> & + Satisfy, M10C> & + Satisfy, M11C> & + Satisfy, M12C> & + Satisfy, M13C> & + Satisfy, M14C> & + Satisfy, M15C> & + Satisfy, M16C> & + Satisfy, M17C> & + Satisfy, M18C> & + Satisfy, M19C> & + Satisfy, M20C> & + Satisfy, M21C> & + Satisfy, M22C> & + Satisfy, M23C> & + Satisfy, M24C> & + Satisfy, M25C> & + Satisfy, M26C> & + Satisfy, M27C> + >, + Simplify, + Simplify< + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf + > +> + +declare function composeMiddleware< + M1 extends Middleware, + M1R extends RequiredContextOf, + M1C extends AddedContextOf, + M2 extends Middleware, + M2R extends Satisfy, M1C>, + M2C extends AddedContextOf & M1C, + M3 extends Middleware, + M3R extends Satisfy, M2C>, + M3C extends AddedContextOf & M2C, + M4 extends Middleware, + M4R extends Satisfy, M3C>, + M4C extends AddedContextOf & M3C, + M5 extends Middleware, + M5R extends Satisfy, M4C>, + M5C extends AddedContextOf & M4C, + M6 extends Middleware, + M6R extends Satisfy, M5C>, + M6C extends AddedContextOf & M5C, + M7 extends Middleware, + M7R extends Satisfy, M6C>, + M7C extends AddedContextOf & M6C, + M8 extends Middleware, + M8R extends Satisfy, M7C>, + M8C extends AddedContextOf & M7C, + M9 extends Middleware, + M9R extends Satisfy, M8C>, + M9C extends AddedContextOf & M8C, + M10 extends Middleware, + M10R extends Satisfy, M9C>, + M10C extends AddedContextOf & M9C, + M11 extends Middleware, + M11R extends Satisfy, M10C>, + M11C extends AddedContextOf & M10C, + M12 extends Middleware, + M12R extends Satisfy, M11C>, + M12C extends AddedContextOf & M11C, + M13 extends Middleware, + M13R extends Satisfy, M12C>, + M13C extends AddedContextOf & M12C, + M14 extends Middleware, + M14R extends Satisfy, M13C>, + M14C extends AddedContextOf & M13C, + M15 extends Middleware, + M15R extends Satisfy, M14C>, + M15C extends AddedContextOf & M14C, + M16 extends Middleware, + M16R extends Satisfy, M15C>, + M16C extends AddedContextOf & M15C, + M17 extends Middleware, + M17R extends Satisfy, M16C>, + M17C extends AddedContextOf & M16C, + M18 extends Middleware, + M18R extends Satisfy, M17C>, + M18C extends AddedContextOf & M17C, + M19 extends Middleware, + M19R extends Satisfy, M18C>, + M19C extends AddedContextOf & M18C, + M20 extends Middleware, + M20R extends Satisfy, M19C>, + M20C extends AddedContextOf & M19C, + M21 extends Middleware, + M21R extends Satisfy, M20C>, + M21C extends AddedContextOf & M20C, + M22 extends Middleware, + M22R extends Satisfy, M21C>, + M22C extends AddedContextOf & M21C, + M23 extends Middleware, + M23R extends Satisfy, M22C>, + M23C extends AddedContextOf & M22C, + M24 extends Middleware, + M24R extends Satisfy, M23C>, + M24C extends AddedContextOf & M23C, + M25 extends Middleware, + M25R extends Satisfy, M24C>, + M25C extends AddedContextOf & M24C, + M26 extends Middleware, + M26R extends Satisfy, M25C>, + M26C extends AddedContextOf & M25C, + M27 extends Middleware, + M27R extends Satisfy, M26C>, + M27C extends AddedContextOf & M26C, + M28 extends Middleware, + M28R extends Satisfy, M27C>, + M28C extends AddedContextOf & M27C, + M29 extends Middleware, + M29R extends Satisfy, M28C>, + M29C extends AddedContextOf & M28C, +>( + m1: M1, + m2: M2, + m3: M3, + m4: M4, + m5: M5, + m6: M6, + m7: M7, + m8: M8, + m9: M9, + m10: M10, + m11: M11, + m12: M12, + m13: M13, + m14: M14, + m15: M15, + m16: M16, + m17: M17, + m18: M18, + m19: M19, + m20: M20, + m21: M21, + m22: M22, + m23: M23, + m24: M24, + m25: M25, + m26: M26, + m27: M27, + m28: M28, + m29: M29 +): Middleware< + Simplify< + RequiredContextOf & + Satisfy, M1C> & + Satisfy, M2C> & + Satisfy, M3C> & + Satisfy, M4C> & + Satisfy, M5C> & + Satisfy, M6C> & + Satisfy, M7C> & + Satisfy, M8C> & + Satisfy, M9C> & + Satisfy, M10C> & + Satisfy, M11C> & + Satisfy, M12C> & + Satisfy, M13C> & + Satisfy, M14C> & + Satisfy, M15C> & + Satisfy, M16C> & + Satisfy, M17C> & + Satisfy, M18C> & + Satisfy, M19C> & + Satisfy, M20C> & + Satisfy, M21C> & + Satisfy, M22C> & + Satisfy, M23C> & + Satisfy, M24C> & + Satisfy, M25C> & + Satisfy, M26C> & + Satisfy, M27C> & + Satisfy, M28C> + >, + Simplify, + Simplify< + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf + > +> + +declare function composeMiddleware< + M1 extends Middleware, + M1R extends RequiredContextOf, + M1C extends AddedContextOf, + M2 extends Middleware, + M2R extends Satisfy, M1C>, + M2C extends AddedContextOf & M1C, + M3 extends Middleware, + M3R extends Satisfy, M2C>, + M3C extends AddedContextOf & M2C, + M4 extends Middleware, + M4R extends Satisfy, M3C>, + M4C extends AddedContextOf & M3C, + M5 extends Middleware, + M5R extends Satisfy, M4C>, + M5C extends AddedContextOf & M4C, + M6 extends Middleware, + M6R extends Satisfy, M5C>, + M6C extends AddedContextOf & M5C, + M7 extends Middleware, + M7R extends Satisfy, M6C>, + M7C extends AddedContextOf & M6C, + M8 extends Middleware, + M8R extends Satisfy, M7C>, + M8C extends AddedContextOf & M7C, + M9 extends Middleware, + M9R extends Satisfy, M8C>, + M9C extends AddedContextOf & M8C, + M10 extends Middleware, + M10R extends Satisfy, M9C>, + M10C extends AddedContextOf & M9C, + M11 extends Middleware, + M11R extends Satisfy, M10C>, + M11C extends AddedContextOf & M10C, + M12 extends Middleware, + M12R extends Satisfy, M11C>, + M12C extends AddedContextOf & M11C, + M13 extends Middleware, + M13R extends Satisfy, M12C>, + M13C extends AddedContextOf & M12C, + M14 extends Middleware, + M14R extends Satisfy, M13C>, + M14C extends AddedContextOf & M13C, + M15 extends Middleware, + M15R extends Satisfy, M14C>, + M15C extends AddedContextOf & M14C, + M16 extends Middleware, + M16R extends Satisfy, M15C>, + M16C extends AddedContextOf & M15C, + M17 extends Middleware, + M17R extends Satisfy, M16C>, + M17C extends AddedContextOf & M16C, + M18 extends Middleware, + M18R extends Satisfy, M17C>, + M18C extends AddedContextOf & M17C, + M19 extends Middleware, + M19R extends Satisfy, M18C>, + M19C extends AddedContextOf & M18C, + M20 extends Middleware, + M20R extends Satisfy, M19C>, + M20C extends AddedContextOf & M19C, + M21 extends Middleware, + M21R extends Satisfy, M20C>, + M21C extends AddedContextOf & M20C, + M22 extends Middleware, + M22R extends Satisfy, M21C>, + M22C extends AddedContextOf & M21C, + M23 extends Middleware, + M23R extends Satisfy, M22C>, + M23C extends AddedContextOf & M22C, + M24 extends Middleware, + M24R extends Satisfy, M23C>, + M24C extends AddedContextOf & M23C, + M25 extends Middleware, + M25R extends Satisfy, M24C>, + M25C extends AddedContextOf & M24C, + M26 extends Middleware, + M26R extends Satisfy, M25C>, + M26C extends AddedContextOf & M25C, + M27 extends Middleware, + M27R extends Satisfy, M26C>, + M27C extends AddedContextOf & M26C, + M28 extends Middleware, + M28R extends Satisfy, M27C>, + M28C extends AddedContextOf & M27C, + M29 extends Middleware, + M29R extends Satisfy, M28C>, + M29C extends AddedContextOf & M28C, + M30 extends Middleware, + M30R extends Satisfy, M29C>, + M30C extends AddedContextOf & M29C, +>( + m1: M1, + m2: M2, + m3: M3, + m4: M4, + m5: M5, + m6: M6, + m7: M7, + m8: M8, + m9: M9, + m10: M10, + m11: M11, + m12: M12, + m13: M13, + m14: M14, + m15: M15, + m16: M16, + m17: M17, + m18: M18, + m19: M19, + m20: M20, + m21: M21, + m22: M22, + m23: M23, + m24: M24, + m25: M25, + m26: M26, + m27: M27, + m28: M28, + m29: M29, + m30: M30 +): Middleware< + Simplify< + RequiredContextOf & + Satisfy, M1C> & + Satisfy, M2C> & + Satisfy, M3C> & + Satisfy, M4C> & + Satisfy, M5C> & + Satisfy, M6C> & + Satisfy, M7C> & + Satisfy, M8C> & + Satisfy, M9C> & + Satisfy, M10C> & + Satisfy, M11C> & + Satisfy, M12C> & + Satisfy, M13C> & + Satisfy, M14C> & + Satisfy, M15C> & + Satisfy, M16C> & + Satisfy, M17C> & + Satisfy, M18C> & + Satisfy, M19C> & + Satisfy, M20C> & + Satisfy, M21C> & + Satisfy, M22C> & + Satisfy, M23C> & + Satisfy, M24C> & + Satisfy, M25C> & + Satisfy, M26C> & + Satisfy, M27C> & + Satisfy, M28C> & + Satisfy, M29C> + >, + Simplify, + Simplify< + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf & + EnvOf + > > export { composeMiddleware } diff --git a/src/middleware.js b/src/middleware.js index 01be081..028dbe0 100644 --- a/src/middleware.js +++ b/src/middleware.js @@ -3,8 +3,17 @@ import { TimeoutController } from 'timeout-abort-controller' import { HttpError } from './util/errors.js' import { parseCid, tryParseCid } from './util/cid.js' +import { composeMiddleware } from './composeMiddleware.js' -/** @import { Middleware, CloudflareContext, DebugEnvironment, IpfsUrlContext, TimeoutControllerContext } from './bindings.js' */ +/** + * @import { + * Middleware, + * CloudflareContext, + * DebugEnvironment, + * IpfsUrlContext, + * TimeoutControllerContext + * } from './bindings.js' + */ const CF_CACHE_MAX_OBJECT_SIZE = 512 * Math.pow(1024, 2) // 512MB to bytes const HTTP_PARTIAL_CONTENT = 206 @@ -20,7 +29,7 @@ const HTTP_PARTIAL_CONTENT = 206 * * @type {Middleware} */ -export function withContext (handler) { +export const withContext = (handler) => { return (request, env, ctx) => { const context = { ...ctx, waitUntil: ctx.waitUntil.bind(ctx) } return handler(request, env, context) @@ -31,7 +40,7 @@ export function withContext (handler) { * Adds CORS headers to the response. * @type {Middleware} */ -export function withCorsHeaders (handler) { +export const withCorsHeaders = (handler) => { return async (request, env, ctx) => { const response = await handler(request, env, ctx) const origin = request.headers.get('origin') @@ -52,7 +61,7 @@ export function withCorsHeaders (handler) { * https://github.com/ipfs/specs/blob/main/http-gateways/PATH_GATEWAY.md#request-query-parameters * @type {Middleware} */ -export function withContentDispositionHeader (handler) { +export const withContentDispositionHeader = (handler) => { return async (request, env, ctx) => { const response = await handler(request, env, ctx) const { searchParams } = new URL(request.url) @@ -81,7 +90,7 @@ export function withContentDispositionHeader (handler) { * Catches any errors, logs them and returns a suitable response. * @type {Middleware<{}, {}, DebugEnvironment>} */ -export function withErrorHandler (handler) { +export const withErrorHandler = (handler) => { return async (request, env, ctx) => { try { return await handler(request, env, ctx) @@ -122,7 +131,7 @@ export const withHttpGet = createWithHttpMethod('GET') * Extracts the data CID, the path and search params from the URL. * @type {Middleware<{}, IpfsUrlContext>} */ -export function withParsedIpfsUrl (handler) { +export const withParsedIpfsUrl = (handler) => { return (request, env, ctx) => { const { hostname, pathname, searchParams } = new URL(request.url) @@ -197,7 +206,7 @@ export function createWithTimeoutController (timeout) { * Otherwise proceeds to handler. * @type {Middleware} */ -export function withCdnCache (handler) { +export const withCdnCache = (handler) => { return async (request, env, ctx) => { // Should skip cache if instructed by headers if ((request.headers.get('Cache-Control') || '').includes('no-cache')) { @@ -243,7 +252,7 @@ export function withCdnCache (handler) { * * @type {Middleware} */ -export function withFixedLengthStream (handler) { +export const withFixedLengthStream = (handler) => { return async (request, env, ctx) => { const response = await handler(request, env, ctx) if (!response.headers.has('Content-Length') || !response.body) {