Upload folder using huggingface_hub (part 38)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- tools/ui/node_modules/expect-type/dist/branding.d.ts +61 -0
- tools/ui/node_modules/expect-type/dist/branding.js +2 -0
- tools/ui/node_modules/expect-type/dist/index.d.ts +897 -0
- tools/ui/node_modules/expect-type/dist/index.js +96 -0
- tools/ui/node_modules/expect-type/dist/messages.d.ts +168 -0
- tools/ui/node_modules/expect-type/dist/messages.js +66 -0
- tools/ui/node_modules/expect-type/dist/overloads.d.ts +288 -0
- tools/ui/node_modules/expect-type/dist/overloads.js +2 -0
- tools/ui/node_modules/expect-type/dist/utils.d.ts +197 -0
- tools/ui/node_modules/expect-type/dist/utils.js +19 -0
- tools/ui/node_modules/expect-type/package.json +50 -0
- tools/ui/node_modules/express-rate-limit/dist/index.cjs +1016 -0
- tools/ui/node_modules/express-rate-limit/dist/index.d.cts +672 -0
- tools/ui/node_modules/express-rate-limit/dist/index.d.mts +672 -0
- tools/ui/node_modules/express-rate-limit/dist/index.d.ts +672 -0
- tools/ui/node_modules/express-rate-limit/dist/index.mjs +986 -0
- tools/ui/node_modules/express-rate-limit/license.md +20 -0
- tools/ui/node_modules/express-rate-limit/package.json +113 -0
- tools/ui/node_modules/express-rate-limit/readme.md +139 -0
- tools/ui/node_modules/express-rate-limit/tsconfig.json +8 -0
- tools/ui/node_modules/express/LICENSE +24 -0
- tools/ui/node_modules/express/Readme.md +276 -0
- tools/ui/node_modules/express/index.js +11 -0
- tools/ui/node_modules/express/lib/application.js +631 -0
- tools/ui/node_modules/express/lib/express.js +81 -0
- tools/ui/node_modules/express/lib/request.js +514 -0
- tools/ui/node_modules/express/lib/response.js +1053 -0
- tools/ui/node_modules/express/lib/utils.js +271 -0
- tools/ui/node_modules/express/lib/view.js +205 -0
- tools/ui/node_modules/express/package.json +99 -0
- tools/ui/node_modules/extend/.editorconfig +20 -0
- tools/ui/node_modules/extend/.eslintrc +17 -0
- tools/ui/node_modules/extend/.jscs.json +175 -0
- tools/ui/node_modules/extend/.travis.yml +230 -0
- tools/ui/node_modules/extend/CHANGELOG.md +83 -0
- tools/ui/node_modules/extend/LICENSE +23 -0
- tools/ui/node_modules/extend/README.md +81 -0
- tools/ui/node_modules/extend/component.json +32 -0
- tools/ui/node_modules/extend/index.js +117 -0
- tools/ui/node_modules/extend/package.json +42 -0
- tools/ui/node_modules/fast-deep-equal/LICENSE +21 -0
- tools/ui/node_modules/fast-deep-equal/README.md +96 -0
- tools/ui/node_modules/fast-deep-equal/es6/index.d.ts +2 -0
- tools/ui/node_modules/fast-deep-equal/es6/index.js +72 -0
- tools/ui/node_modules/fast-deep-equal/es6/react.d.ts +2 -0
- tools/ui/node_modules/fast-deep-equal/es6/react.js +79 -0
- tools/ui/node_modules/fast-deep-equal/index.d.ts +4 -0
- tools/ui/node_modules/fast-deep-equal/index.js +46 -0
- tools/ui/node_modules/fast-deep-equal/package.json +61 -0
- tools/ui/node_modules/fast-deep-equal/react.d.ts +2 -0
tools/ui/node_modules/expect-type/dist/branding.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { ConstructorOverloadParameters, NumOverloads, OverloadsInfoUnion } from './overloads';
|
| 2 |
+
import type { IsNever, IsAny, IsUnknown, ReadonlyKeys, RequiredKeys, OptionalKeys, MutuallyExtends, UnionToTuple } from './utils';
|
| 3 |
+
/**
|
| 4 |
+
* Represents a deeply branded type.
|
| 5 |
+
*
|
| 6 |
+
* Recursively walk a type and replace it with a branded type related to the
|
| 7 |
+
* original. This is useful for equality-checking stricter than
|
| 8 |
+
* `A extends B ? B extends A ? true : false : false`, because it detects the
|
| 9 |
+
* difference between a few edge-case types that vanilla TypeScript
|
| 10 |
+
* doesn't by default:
|
| 11 |
+
* - `any` vs `unknown`
|
| 12 |
+
* - `{ readonly a: string }` vs `{ a: string }`
|
| 13 |
+
* - `{ a?: string }` vs `{ a: string | undefined }`
|
| 14 |
+
*
|
| 15 |
+
* __Note__: not very performant for complex types - this should only be used
|
| 16 |
+
* when you know you need it. If doing an equality check, it's almost always
|
| 17 |
+
* better to use {@linkcode StrictEqualUsingTSInternalIdenticalToOperator}.
|
| 18 |
+
*/
|
| 19 |
+
export type DeepBrand<T> = IsNever<T> extends true ? {
|
| 20 |
+
type: 'never';
|
| 21 |
+
} : IsAny<T> extends true ? {
|
| 22 |
+
type: 'any';
|
| 23 |
+
} : IsUnknown<T> extends true ? {
|
| 24 |
+
type: 'unknown';
|
| 25 |
+
} : T extends string | number | boolean | symbol | bigint | null | undefined | void ? {
|
| 26 |
+
type: 'primitive';
|
| 27 |
+
value: T;
|
| 28 |
+
} : T extends new (...args: any[]) => any ? {
|
| 29 |
+
type: 'constructor';
|
| 30 |
+
params: ConstructorOverloadParameters<T>;
|
| 31 |
+
instance: DeepBrand<InstanceType<Extract<T, new (...args: any) => any>>>;
|
| 32 |
+
} : T extends (...args: infer P) => infer R ? NumOverloads<T> extends 1 ? {
|
| 33 |
+
type: 'function';
|
| 34 |
+
params: DeepBrand<P>;
|
| 35 |
+
return: DeepBrand<R>;
|
| 36 |
+
this: DeepBrand<ThisParameterType<T>>;
|
| 37 |
+
props: DeepBrand<Omit<T, keyof Function>>;
|
| 38 |
+
} : UnionToTuple<OverloadsInfoUnion<T>> extends infer OverloadsTuple ? {
|
| 39 |
+
type: 'overloads';
|
| 40 |
+
overloads: {
|
| 41 |
+
[K in keyof OverloadsTuple]: DeepBrand<OverloadsTuple[K]>;
|
| 42 |
+
};
|
| 43 |
+
} : never : T extends any[] ? {
|
| 44 |
+
type: 'array';
|
| 45 |
+
items: {
|
| 46 |
+
[K in keyof T]: T[K];
|
| 47 |
+
};
|
| 48 |
+
} : {
|
| 49 |
+
type: 'object';
|
| 50 |
+
properties: {
|
| 51 |
+
[K in keyof T]: DeepBrand<T[K]>;
|
| 52 |
+
};
|
| 53 |
+
readonly: ReadonlyKeys<T>;
|
| 54 |
+
required: RequiredKeys<T>;
|
| 55 |
+
optional: OptionalKeys<T>;
|
| 56 |
+
constructorParams: DeepBrand<ConstructorOverloadParameters<T>>;
|
| 57 |
+
};
|
| 58 |
+
/**
|
| 59 |
+
* Checks if two types are strictly equal using branding.
|
| 60 |
+
*/
|
| 61 |
+
export type StrictEqualUsingBranding<Left, Right> = MutuallyExtends<DeepBrand<Left>, DeepBrand<Right>>;
|
tools/ui/node_modules/expect-type/dist/branding.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
Object.defineProperty(exports, "__esModule", { value: true });
|
tools/ui/node_modules/expect-type/dist/index.d.ts
ADDED
|
@@ -0,0 +1,897 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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BigInt, ExpectBoolean, ExpectFunction, ExpectNever, ExpectNull, ExpectNullable, ExpectNumber, ExpectObject, ExpectString, ExpectSymbol, ExpectUndefined, ExpectUnknown, ExpectVoid, MismatchInfo, Scolder } from './messages';
|
| 3 |
+
import type { ConstructorOverloadParameters, OverloadParameters, OverloadReturnTypes, OverloadsNarrowedByParameters } from './overloads';
|
| 4 |
+
import type { AValue, DeepPickMatchingProps, Extends, IsUnion, MismatchArgs, Not, StrictEqualUsingTSInternalIdenticalToOperator } from './utils';
|
| 5 |
+
export * from './branding';
|
| 6 |
+
export * from './messages';
|
| 7 |
+
export * from './overloads';
|
| 8 |
+
export * from './utils';
|
| 9 |
+
/**
|
| 10 |
+
* Represents the positive assertion methods available for type checking in the
|
| 11 |
+
* {@linkcode expectTypeOf()} utility.
|
| 12 |
+
*/
|
| 13 |
+
export interface PositiveExpectTypeOf<Actual> extends BaseExpectTypeOf<Actual, {
|
| 14 |
+
positive: true;
|
| 15 |
+
branded: false;
|
| 16 |
+
}> {
|
| 17 |
+
/**
|
| 18 |
+
* Similar to jest's `expect(...).toMatchObject(...)` but for types.
|
| 19 |
+
* Deeply "picks" the properties of the actual type based on the expected type, then performs a strict check to make sure the types match `Expected`.
|
| 20 |
+
*
|
| 21 |
+
* **Note**: optional properties on the {@linkcode Expected | expected type} are not allowed to be missing on the {@linkcode Actual | actual type}.
|
| 22 |
+
*
|
| 23 |
+
* @example
|
| 24 |
+
* ```ts
|
| 25 |
+
* expectTypeOf({ a: 1, b: 1 }).toMatchObjectType<{ a: number }>()
|
| 26 |
+
*
|
| 27 |
+
* expectTypeOf({ a: 1, b: 1 }).not.toMatchObjectType<{ a: number; c?: number }>()
|
| 28 |
+
* ```
|
| 29 |
+
*
|
| 30 |
+
* @param MISMATCH - The mismatch arguments.
|
| 31 |
+
* @returns `true`.
|
| 32 |
+
*/
|
| 33 |
+
toMatchObjectType: <Expected extends IsUnion<Expected> extends true ? 'toMatchObject does not support union types' : Not<Extends<Expected, Record<string, unknown>>> extends true ? 'toMatchObject only supports object types' : StrictEqualUsingTSInternalIdenticalToOperator<DeepPickMatchingProps<Actual, Expected>, Expected> extends true ? unknown : MismatchInfo<DeepPickMatchingProps<Actual, Expected>, Expected>>(...MISMATCH: MismatchArgs<StrictEqualUsingTSInternalIdenticalToOperator<DeepPickMatchingProps<Actual, Expected>, Expected>, true>) => true;
|
| 34 |
+
/**
|
| 35 |
+
* Check if your type extends the expected type
|
| 36 |
+
*
|
| 37 |
+
* A less strict version of {@linkcode toEqualTypeOf | .toEqualTypeOf()} that allows for extra properties.
|
| 38 |
+
* This is roughly equivalent to an `extends` constraint in a function type argument.
|
| 39 |
+
*
|
| 40 |
+
* @example
|
| 41 |
+
* ```ts
|
| 42 |
+
* expectTypeOf({ a: 1, b: 1 }).toExtend<{ a: number }>()
|
| 43 |
+
*
|
| 44 |
+
* expectTypeOf({ a: 1 }).not.toExtend<{ b: number }>()
|
| 45 |
+
* ```
|
| 46 |
+
*
|
| 47 |
+
* @param MISMATCH - The mismatch arguments.
|
| 48 |
+
* @returns `true`.
|
| 49 |
+
*/
|
| 50 |
+
toExtend: <Expected extends Extends<Actual, Expected> extends true ? unknown : MismatchInfo<Actual, Expected>>(...MISMATCH: MismatchArgs<Extends<Actual, Expected>, true>) => true;
|
| 51 |
+
toEqualTypeOf: {
|
| 52 |
+
/**
|
| 53 |
+
* Uses TypeScript's internal technique to check for type "identicalness".
|
| 54 |
+
*
|
| 55 |
+
* It will check if the types are fully equal to each other.
|
| 56 |
+
* It will not fail if two objects have different values, but the same type.
|
| 57 |
+
* It will fail however if an object is missing a property.
|
| 58 |
+
*
|
| 59 |
+
* **_Unexpected failure_**? For a more permissive but less performant
|
| 60 |
+
* check that accommodates for equivalent intersection types,
|
| 61 |
+
* use {@linkcode branded | .branded.toEqualTypeOf()}.
|
| 62 |
+
* @see {@link https://github.com/mmkal/expect-type#why-is-my-assertion-failing | The documentation for details}.
|
| 63 |
+
*
|
| 64 |
+
* @example
|
| 65 |
+
* <caption>Using generic type argument syntax</caption>
|
| 66 |
+
* ```ts
|
| 67 |
+
* expectTypeOf({ a: 1 }).toEqualTypeOf<{ a: number }>()
|
| 68 |
+
*
|
| 69 |
+
* expectTypeOf({ a: 1, b: 1 }).not.toEqualTypeOf<{ a: number }>()
|
| 70 |
+
* ```
|
| 71 |
+
*
|
| 72 |
+
* @example
|
| 73 |
+
* <caption>Using inferred type syntax by passing a value</caption>
|
| 74 |
+
* ```ts
|
| 75 |
+
* expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 1 })
|
| 76 |
+
*
|
| 77 |
+
* expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 2 })
|
| 78 |
+
* ```
|
| 79 |
+
*
|
| 80 |
+
* @param value - The value to compare against the expected type.
|
| 81 |
+
* @param MISMATCH - The mismatch arguments.
|
| 82 |
+
* @returns `true`.
|
| 83 |
+
*/
|
| 84 |
+
<Expected extends StrictEqualUsingTSInternalIdenticalToOperator<Actual, Expected> extends true ? unknown : MismatchInfo<Actual, Expected>>(value: Expected & AValue, // reason for `& AValue`: make sure this is only the selected overload when the end-user passes a value for an inferred typearg. The `Mismatch` type does match `AValue`.
|
| 85 |
+
...MISMATCH: MismatchArgs<StrictEqualUsingTSInternalIdenticalToOperator<Actual, Expected>, true>): true;
|
| 86 |
+
/**
|
| 87 |
+
* Uses TypeScript's internal technique to check for type "identicalness".
|
| 88 |
+
*
|
| 89 |
+
* It will check if the types are fully equal to each other.
|
| 90 |
+
* It will not fail if two objects have different values, but the same type.
|
| 91 |
+
* It will fail however if an object is missing a property.
|
| 92 |
+
*
|
| 93 |
+
* **_Unexpected failure_**? For a more permissive but less performant
|
| 94 |
+
* check that accommodates for equivalent intersection types,
|
| 95 |
+
* use {@linkcode branded | .branded.toEqualTypeOf()}.
|
| 96 |
+
* @see {@link https://github.com/mmkal/expect-type#why-is-my-assertion-failing | The documentation for details}.
|
| 97 |
+
*
|
| 98 |
+
* @example
|
| 99 |
+
* <caption>Using generic type argument syntax</caption>
|
| 100 |
+
* ```ts
|
| 101 |
+
* expectTypeOf({ a: 1 }).toEqualTypeOf<{ a: number }>()
|
| 102 |
+
*
|
| 103 |
+
* expectTypeOf({ a: 1, b: 1 }).not.toEqualTypeOf<{ a: number }>()
|
| 104 |
+
* ```
|
| 105 |
+
*
|
| 106 |
+
* @example
|
| 107 |
+
* <caption>Using inferred type syntax by passing a value</caption>
|
| 108 |
+
* ```ts
|
| 109 |
+
* expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 1 })
|
| 110 |
+
*
|
| 111 |
+
* expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 2 })
|
| 112 |
+
* ```
|
| 113 |
+
*
|
| 114 |
+
* @param MISMATCH - The mismatch arguments.
|
| 115 |
+
* @returns `true`.
|
| 116 |
+
*/
|
| 117 |
+
<Expected extends StrictEqualUsingTSInternalIdenticalToOperator<Actual, Expected> extends true ? unknown : MismatchInfo<Actual, Expected>>(...MISMATCH: MismatchArgs<StrictEqualUsingTSInternalIdenticalToOperator<Actual, Expected>, true>): true;
|
| 118 |
+
};
|
| 119 |
+
/**
|
| 120 |
+
* @deprecated Since v1.2.0 - Use either {@linkcode toMatchObjectType} or {@linkcode toExtend} instead
|
| 121 |
+
*
|
| 122 |
+
* - Use {@linkcode toMatchObjectType} to perform a strict check on a subset of your type's keys
|
| 123 |
+
* - Use {@linkcode toExtend} to check if your type extends the expected type
|
| 124 |
+
*/
|
| 125 |
+
toMatchTypeOf: {
|
| 126 |
+
/**
|
| 127 |
+
* @deprecated Since v1.2.0 - Use either {@linkcode toMatchObjectType} or {@linkcode toExtend} instead
|
| 128 |
+
*
|
| 129 |
+
* - Use {@linkcode toMatchObjectType} to perform a strict check on a subset of your type's keys
|
| 130 |
+
* - Use {@linkcode toExtend} to check if your type extends the expected type
|
| 131 |
+
*
|
| 132 |
+
* A less strict version of {@linkcode toEqualTypeOf | .toEqualTypeOf()}
|
| 133 |
+
* that allows for extra properties.
|
| 134 |
+
* This is roughly equivalent to an `extends` constraint
|
| 135 |
+
* in a function type argument.
|
| 136 |
+
*
|
| 137 |
+
* @example
|
| 138 |
+
* <caption>Using generic type argument syntax</caption>
|
| 139 |
+
* ```ts
|
| 140 |
+
* expectTypeOf({ a: 1, b: 1 }).toMatchTypeOf<{ a: number }>()
|
| 141 |
+
* ```
|
| 142 |
+
*
|
| 143 |
+
* @example
|
| 144 |
+
* <caption>Using inferred type syntax by passing a value</caption>
|
| 145 |
+
* ```ts
|
| 146 |
+
* expectTypeOf({ a: 1, b: 1 }).toMatchTypeOf({ a: 2 })
|
| 147 |
+
* ```
|
| 148 |
+
*
|
| 149 |
+
* @param value - The value to compare against the expected type.
|
| 150 |
+
* @param MISMATCH - The mismatch arguments.
|
| 151 |
+
* @returns `true`.
|
| 152 |
+
*/
|
| 153 |
+
<Expected extends Extends<Actual, Expected> extends true ? unknown : MismatchInfo<Actual, Expected>>(value: Expected & AValue, // reason for `& AValue`: make sure this is only the selected overload when the end-user passes a value for an inferred typearg. The `Mismatch` type does match `AValue`.
|
| 154 |
+
...MISMATCH: MismatchArgs<Extends<Actual, Expected>, true>): true;
|
| 155 |
+
/**
|
| 156 |
+
* @deprecated Since v1.2.0 - Use either {@linkcode toMatchObjectType} or {@linkcode toExtend} instead
|
| 157 |
+
*
|
| 158 |
+
* - Use {@linkcode toMatchObjectType} to perform a strict check on a subset of your type's keys
|
| 159 |
+
* - Use {@linkcode toExtend} to check if your type extends the expected type
|
| 160 |
+
*
|
| 161 |
+
* A less strict version of {@linkcode toEqualTypeOf | .toEqualTypeOf()}
|
| 162 |
+
* that allows for extra properties.
|
| 163 |
+
* This is roughly equivalent to an `extends` constraint
|
| 164 |
+
* in a function type argument.
|
| 165 |
+
*
|
| 166 |
+
* @example
|
| 167 |
+
* <caption>Using generic type argument syntax</caption>
|
| 168 |
+
* ```ts
|
| 169 |
+
* expectTypeOf({ a: 1, b: 1 }).toMatchTypeOf<{ a: number }>()
|
| 170 |
+
* ```
|
| 171 |
+
*
|
| 172 |
+
* @example
|
| 173 |
+
* <caption>Using inferred type syntax by passing a value</caption>
|
| 174 |
+
* ```ts
|
| 175 |
+
* expectTypeOf({ a: 1, b: 1 }).toMatchTypeOf({ a: 2 })
|
| 176 |
+
* ```
|
| 177 |
+
*
|
| 178 |
+
* @param MISMATCH - The mismatch arguments.
|
| 179 |
+
* @returns `true`.
|
| 180 |
+
*/
|
| 181 |
+
<Expected extends Extends<Actual, Expected> extends true ? unknown : MismatchInfo<Actual, Expected>>(...MISMATCH: MismatchArgs<Extends<Actual, Expected>, true>): true;
|
| 182 |
+
};
|
| 183 |
+
/**
|
| 184 |
+
* Checks whether an object has a given property.
|
| 185 |
+
*
|
| 186 |
+
* @example
|
| 187 |
+
* <caption>check that properties exist</caption>
|
| 188 |
+
* ```ts
|
| 189 |
+
* const obj = { a: 1, b: '' }
|
| 190 |
+
*
|
| 191 |
+
* expectTypeOf(obj).toHaveProperty('a')
|
| 192 |
+
*
|
| 193 |
+
* expectTypeOf(obj).not.toHaveProperty('c')
|
| 194 |
+
* ```
|
| 195 |
+
*
|
| 196 |
+
* @param key - The property key to check for.
|
| 197 |
+
* @param MISMATCH - The mismatch arguments.
|
| 198 |
+
* @returns `true`.
|
| 199 |
+
*/
|
| 200 |
+
toHaveProperty: <KeyType extends keyof Actual>(key: KeyType, ...MISMATCH: MismatchArgs<Extends<KeyType, keyof Actual>, true>) => KeyType extends keyof Actual ? PositiveExpectTypeOf<Actual[KeyType]> : true;
|
| 201 |
+
/**
|
| 202 |
+
* Inverts the result of the following assertions.
|
| 203 |
+
*
|
| 204 |
+
* @example
|
| 205 |
+
* ```ts
|
| 206 |
+
* expectTypeOf({ a: 1 }).not.toMatchTypeOf({ b: 1 })
|
| 207 |
+
* ```
|
| 208 |
+
*/
|
| 209 |
+
not: NegativeExpectTypeOf<Actual>;
|
| 210 |
+
/**
|
| 211 |
+
* Intersection types can cause issues with
|
| 212 |
+
* {@linkcode toEqualTypeOf | .toEqualTypeOf()}:
|
| 213 |
+
* ```ts
|
| 214 |
+
* // ❌ The following line doesn't compile, even though the types are arguably the same.
|
| 215 |
+
* expectTypeOf<{ a: 1 } & { b: 2 }>().toEqualTypeOf<{ a: 1; b: 2 }>()
|
| 216 |
+
* ```
|
| 217 |
+
* This helper works around this problem by using
|
| 218 |
+
* a more permissive but less performant check.
|
| 219 |
+
*
|
| 220 |
+
* __Note__: This comes at a performance cost, and can cause the compiler
|
| 221 |
+
* to 'give up' if used with excessively deep types, so use sparingly.
|
| 222 |
+
*
|
| 223 |
+
* @see {@link https://github.com/mmkal/expect-type/pull/21 | Reference}
|
| 224 |
+
*/
|
| 225 |
+
branded: {
|
| 226 |
+
/**
|
| 227 |
+
* Uses TypeScript's internal technique to check for type "identicalness".
|
| 228 |
+
*
|
| 229 |
+
* It will check if the types are fully equal to each other.
|
| 230 |
+
* It will not fail if two objects have different values, but the same type.
|
| 231 |
+
* It will fail however if an object is missing a property.
|
| 232 |
+
*
|
| 233 |
+
* **_Unexpected failure_**? For a more permissive but less performant
|
| 234 |
+
* check that accommodates for equivalent intersection types,
|
| 235 |
+
* use {@linkcode PositiveExpectTypeOf.branded | .branded.toEqualTypeOf()}.
|
| 236 |
+
* @see {@link https://github.com/mmkal/expect-type#why-is-my-assertion-failing | The documentation for details}.
|
| 237 |
+
*
|
| 238 |
+
* @example
|
| 239 |
+
* <caption>Using generic type argument syntax</caption>
|
| 240 |
+
* ```ts
|
| 241 |
+
* expectTypeOf({ a: 1 }).toEqualTypeOf<{ a: number }>()
|
| 242 |
+
*
|
| 243 |
+
* expectTypeOf({ a: 1, b: 1 }).not.toEqualTypeOf<{ a: number }>()
|
| 244 |
+
* ```
|
| 245 |
+
*
|
| 246 |
+
* @example
|
| 247 |
+
* <caption>Using inferred type syntax by passing a value</caption>
|
| 248 |
+
* ```ts
|
| 249 |
+
* expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 1 })
|
| 250 |
+
*
|
| 251 |
+
* expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 2 })
|
| 252 |
+
* ```
|
| 253 |
+
*
|
| 254 |
+
* @param MISMATCH - The mismatch arguments.
|
| 255 |
+
* @returns `true`.
|
| 256 |
+
*/
|
| 257 |
+
toEqualTypeOf: <Expected extends StrictEqualUsingBranding<Actual, Expected> extends true ? unknown : MismatchInfo<Actual, Expected>>(...MISMATCH: MismatchArgs<StrictEqualUsingBranding<Actual, Expected>, true>) => true;
|
| 258 |
+
};
|
| 259 |
+
}
|
| 260 |
+
/**
|
| 261 |
+
* Represents the negative expectation type for the {@linkcode Actual} type.
|
| 262 |
+
*/
|
| 263 |
+
export interface NegativeExpectTypeOf<Actual> extends BaseExpectTypeOf<Actual, {
|
| 264 |
+
positive: false;
|
| 265 |
+
}> {
|
| 266 |
+
/**
|
| 267 |
+
* Similar to jest's `expect(...).toMatchObject(...)` but for types.
|
| 268 |
+
* Deeply "picks" the properties of the actual type based on the expected type, then performs a strict check to make sure the types match `Expected`.
|
| 269 |
+
*
|
| 270 |
+
* **Note**: optional properties on the {@linkcode Expected | expected type} are not allowed to be missing on the {@linkcode Actual | actual type}.
|
| 271 |
+
*
|
| 272 |
+
* @example
|
| 273 |
+
* ```ts
|
| 274 |
+
* expectTypeOf({ a: 1, b: 1 }).toMatchObjectType<{ a: number }>()
|
| 275 |
+
*
|
| 276 |
+
* expectTypeOf({ a: 1, b: 1 }).not.toMatchObjectType<{ a: number; c?: number }>()
|
| 277 |
+
* ```
|
| 278 |
+
*
|
| 279 |
+
* @param MISMATCH - The mismatch arguments.
|
| 280 |
+
* @returns `true`.
|
| 281 |
+
*/
|
| 282 |
+
toMatchObjectType: <Expected>(...MISMATCH: MismatchArgs<StrictEqualUsingTSInternalIdenticalToOperator<Pick<Actual, keyof Actual & keyof Expected>, Expected>, false>) => true;
|
| 283 |
+
/**
|
| 284 |
+
* Check if your type extends the expected type
|
| 285 |
+
*
|
| 286 |
+
* A less strict version of {@linkcode PositiveExpectTypeOf.toEqualTypeOf | .toEqualTypeOf()} that allows for extra properties.
|
| 287 |
+
* This is roughly equivalent to an `extends` constraint in a function type argument.
|
| 288 |
+
*
|
| 289 |
+
* @example
|
| 290 |
+
* ```ts
|
| 291 |
+
* expectTypeOf({ a: 1, b: 1 }).toExtend<{ a: number }>()]
|
| 292 |
+
*
|
| 293 |
+
* expectTypeOf({ a: 1 }).not.toExtend<{ b: number }>()
|
| 294 |
+
* ```
|
| 295 |
+
*
|
| 296 |
+
* @param MISMATCH - The mismatch arguments.
|
| 297 |
+
* @returns `true`.
|
| 298 |
+
*/
|
| 299 |
+
toExtend<Expected>(...MISMATCH: MismatchArgs<Extends<Actual, Expected>, false>): true;
|
| 300 |
+
toEqualTypeOf: {
|
| 301 |
+
/**
|
| 302 |
+
* Uses TypeScript's internal technique to check for type "identicalness".
|
| 303 |
+
*
|
| 304 |
+
* It will check if the types are fully equal to each other.
|
| 305 |
+
* It will not fail if two objects have different values, but the same type.
|
| 306 |
+
* It will fail however if an object is missing a property.
|
| 307 |
+
*
|
| 308 |
+
* **_Unexpected failure_**? For a more permissive but less performant
|
| 309 |
+
* check that accommodates for equivalent intersection types,
|
| 310 |
+
* use {@linkcode PositiveExpectTypeOf.branded | .branded.toEqualTypeOf()}.
|
| 311 |
+
* @see {@link https://github.com/mmkal/expect-type#why-is-my-assertion-failing | The documentation for details}.
|
| 312 |
+
*
|
| 313 |
+
* @example
|
| 314 |
+
* <caption>Using generic type argument syntax</caption>
|
| 315 |
+
* ```ts
|
| 316 |
+
* expectTypeOf({ a: 1 }).toEqualTypeOf<{ a: number }>()
|
| 317 |
+
*
|
| 318 |
+
* expectTypeOf({ a: 1, b: 1 }).not.toEqualTypeOf<{ a: number }>()
|
| 319 |
+
* ```
|
| 320 |
+
*
|
| 321 |
+
* @example
|
| 322 |
+
* <caption>Using inferred type syntax by passing a value</caption>
|
| 323 |
+
* ```ts
|
| 324 |
+
* expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 1 })
|
| 325 |
+
*
|
| 326 |
+
* expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 2 })
|
| 327 |
+
* ```
|
| 328 |
+
*
|
| 329 |
+
* @param value - The value to compare against the expected type.
|
| 330 |
+
* @param MISMATCH - The mismatch arguments.
|
| 331 |
+
* @returns `true`.
|
| 332 |
+
*/
|
| 333 |
+
<Expected>(value: Expected & AValue, ...MISMATCH: MismatchArgs<StrictEqualUsingTSInternalIdenticalToOperator<Actual, Expected>, false>): true;
|
| 334 |
+
/**
|
| 335 |
+
* Uses TypeScript's internal technique to check for type "identicalness".
|
| 336 |
+
*
|
| 337 |
+
* It will check if the types are fully equal to each other.
|
| 338 |
+
* It will not fail if two objects have different values, but the same type.
|
| 339 |
+
* It will fail however if an object is missing a property.
|
| 340 |
+
*
|
| 341 |
+
* **_Unexpected failure_**? For a more permissive but less performant
|
| 342 |
+
* check that accommodates for equivalent intersection types,
|
| 343 |
+
* use {@linkcode PositiveExpectTypeOf.branded | .branded.toEqualTypeOf()}.
|
| 344 |
+
* @see {@link https://github.com/mmkal/expect-type#why-is-my-assertion-failing | The documentation for details}.
|
| 345 |
+
*
|
| 346 |
+
* @example
|
| 347 |
+
* <caption>Using generic type argument syntax</caption>
|
| 348 |
+
* ```ts
|
| 349 |
+
* expectTypeOf({ a: 1 }).toEqualTypeOf<{ a: number }>()
|
| 350 |
+
*
|
| 351 |
+
* expectTypeOf({ a: 1, b: 1 }).not.toEqualTypeOf<{ a: number }>()
|
| 352 |
+
* ```
|
| 353 |
+
*
|
| 354 |
+
* @example
|
| 355 |
+
* <caption>Using inferred type syntax by passing a value</caption>
|
| 356 |
+
* ```ts
|
| 357 |
+
* expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 1 })
|
| 358 |
+
*
|
| 359 |
+
* expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 2 })
|
| 360 |
+
* ```
|
| 361 |
+
*
|
| 362 |
+
* @param MISMATCH - The mismatch arguments.
|
| 363 |
+
* @returns `true`.
|
| 364 |
+
*/
|
| 365 |
+
<Expected>(...MISMATCH: MismatchArgs<StrictEqualUsingTSInternalIdenticalToOperator<Actual, Expected>, false>): true;
|
| 366 |
+
};
|
| 367 |
+
/**
|
| 368 |
+
* @deprecated Since v1.2.0 - Use either {@linkcode toMatchObjectType} or {@linkcode toExtend} instead
|
| 369 |
+
*
|
| 370 |
+
* - Use {@linkcode toMatchObjectType} to perform a strict check on a subset of your type's keys
|
| 371 |
+
* - Use {@linkcode toExtend} to check if your type extends the expected type
|
| 372 |
+
*/
|
| 373 |
+
toMatchTypeOf: {
|
| 374 |
+
/**
|
| 375 |
+
* @deprecated Since v1.2.0 - Use either {@linkcode toMatchObjectType} or {@linkcode toExtend} instead
|
| 376 |
+
*
|
| 377 |
+
* - Use {@linkcode toMatchObjectType} to perform a strict check on a subset of your type's keys
|
| 378 |
+
* - Use {@linkcode toExtend} to check if your type extends the expected type
|
| 379 |
+
*
|
| 380 |
+
* A less strict version of
|
| 381 |
+
* {@linkcode PositiveExpectTypeOf.toEqualTypeOf | .toEqualTypeOf()}
|
| 382 |
+
* that allows for extra properties.
|
| 383 |
+
* This is roughly equivalent to an `extends` constraint
|
| 384 |
+
* in a function type argument.
|
| 385 |
+
*
|
| 386 |
+
* @example
|
| 387 |
+
* <caption>Using generic type argument syntax</caption>
|
| 388 |
+
* ```ts
|
| 389 |
+
* expectTypeOf({ a: 1, b: 1 }).toMatchTypeOf<{ a: number }>()
|
| 390 |
+
* ```
|
| 391 |
+
*
|
| 392 |
+
* @example
|
| 393 |
+
* <caption>Using inferred type syntax by passing a value</caption>
|
| 394 |
+
* ```ts
|
| 395 |
+
* expectTypeOf({ a: 1, b: 1 }).toMatchTypeOf({ a: 2 })
|
| 396 |
+
* ```
|
| 397 |
+
*
|
| 398 |
+
* @param value - The value to compare against the expected type.
|
| 399 |
+
* @param MISMATCH - The mismatch arguments.
|
| 400 |
+
* @returns `true`.
|
| 401 |
+
*/
|
| 402 |
+
<Expected>(value: Expected & AValue, // reason for `& AValue`: make sure this is only the selected overload when the end-user passes a value for an inferred typearg. The `Mismatch` type does match `AValue`.
|
| 403 |
+
...MISMATCH: MismatchArgs<Extends<Actual, Expected>, false>): true;
|
| 404 |
+
/**
|
| 405 |
+
* @deprecated Since v1.2.0 - Use either {@linkcode toMatchObjectType} or {@linkcode toExtend} instead
|
| 406 |
+
*
|
| 407 |
+
* - Use {@linkcode toMatchObjectType} to perform a strict check on a subset of your type's keys
|
| 408 |
+
* - Use {@linkcode toExtend} to check if your type extends the expected type
|
| 409 |
+
*
|
| 410 |
+
* A less strict version of
|
| 411 |
+
* {@linkcode PositiveExpectTypeOf.toEqualTypeOf | .toEqualTypeOf()}
|
| 412 |
+
* that allows for extra properties.
|
| 413 |
+
* This is roughly equivalent to an `extends` constraint
|
| 414 |
+
* in a function type argument.
|
| 415 |
+
*
|
| 416 |
+
* @example
|
| 417 |
+
* <caption>Using generic type argument syntax</caption>
|
| 418 |
+
* ```ts
|
| 419 |
+
* expectTypeOf({ a: 1, b: 1 }).toMatchTypeOf<{ a: number }>()
|
| 420 |
+
* ```
|
| 421 |
+
*
|
| 422 |
+
* @example
|
| 423 |
+
* <caption>Using inferred type syntax by passing a value</caption>
|
| 424 |
+
* ```ts
|
| 425 |
+
* expectTypeOf({ a: 1, b: 1 }).toMatchTypeOf({ a: 2 })
|
| 426 |
+
* ```
|
| 427 |
+
*
|
| 428 |
+
* @param MISMATCH - The mismatch arguments.
|
| 429 |
+
* @returns `true`.
|
| 430 |
+
*/
|
| 431 |
+
<Expected>(...MISMATCH: MismatchArgs<Extends<Actual, Expected>, false>): true;
|
| 432 |
+
};
|
| 433 |
+
/**
|
| 434 |
+
* Checks whether an object has a given property.
|
| 435 |
+
*
|
| 436 |
+
* @example
|
| 437 |
+
* <caption>check that properties exist</caption>
|
| 438 |
+
* ```ts
|
| 439 |
+
* const obj = { a: 1, b: '' }
|
| 440 |
+
*
|
| 441 |
+
* expectTypeOf(obj).toHaveProperty('a')
|
| 442 |
+
*
|
| 443 |
+
* expectTypeOf(obj).not.toHaveProperty('c')
|
| 444 |
+
* ```
|
| 445 |
+
*
|
| 446 |
+
* @param key - The property key to check for.
|
| 447 |
+
* @param MISMATCH - The mismatch arguments.
|
| 448 |
+
* @returns `true`.
|
| 449 |
+
*/
|
| 450 |
+
toHaveProperty: <KeyType extends string | number | symbol>(key: KeyType, ...MISMATCH: MismatchArgs<Extends<KeyType, keyof Actual>, false>) => true;
|
| 451 |
+
}
|
| 452 |
+
/**
|
| 453 |
+
* Represents a conditional type that selects either
|
| 454 |
+
* {@linkcode PositiveExpectTypeOf} or {@linkcode NegativeExpectTypeOf} based
|
| 455 |
+
* on the value of the `positive` property in the {@linkcode Options} type.
|
| 456 |
+
*/
|
| 457 |
+
export type ExpectTypeOf<Actual, Options extends {
|
| 458 |
+
positive: boolean;
|
| 459 |
+
}> = Options['positive'] extends true ? PositiveExpectTypeOf<Actual> : NegativeExpectTypeOf<Actual>;
|
| 460 |
+
/**
|
| 461 |
+
* Represents the base interface for the
|
| 462 |
+
* {@linkcode expectTypeOf()} function.
|
| 463 |
+
* Provides a set of assertion methods to perform type checks on a value.
|
| 464 |
+
*/
|
| 465 |
+
export interface BaseExpectTypeOf<Actual, Options extends {
|
| 466 |
+
positive: boolean;
|
| 467 |
+
}> {
|
| 468 |
+
/**
|
| 469 |
+
* Checks whether the type of the value is `any`.
|
| 470 |
+
*/
|
| 471 |
+
toBeAny: Scolder<ExpectAny<Actual>, Options>;
|
| 472 |
+
/**
|
| 473 |
+
* Checks whether the type of the value is `unknown`.
|
| 474 |
+
*/
|
| 475 |
+
toBeUnknown: Scolder<ExpectUnknown<Actual>, Options>;
|
| 476 |
+
/**
|
| 477 |
+
* Checks whether the type of the value is `never`.
|
| 478 |
+
*/
|
| 479 |
+
toBeNever: Scolder<ExpectNever<Actual>, Options>;
|
| 480 |
+
/**
|
| 481 |
+
* Checks whether the type of the value is `function`.
|
| 482 |
+
*/
|
| 483 |
+
toBeFunction: Scolder<ExpectFunction<Actual>, Options>;
|
| 484 |
+
/**
|
| 485 |
+
* Checks whether the type of the value is `object`.
|
| 486 |
+
*/
|
| 487 |
+
toBeObject: Scolder<ExpectObject<Actual>, Options>;
|
| 488 |
+
/**
|
| 489 |
+
* Checks whether the type of the value is an {@linkcode Array}.
|
| 490 |
+
*/
|
| 491 |
+
toBeArray: Scolder<ExpectArray<Actual>, Options>;
|
| 492 |
+
/**
|
| 493 |
+
* Checks whether the type of the value is `number`.
|
| 494 |
+
*/
|
| 495 |
+
toBeNumber: Scolder<ExpectNumber<Actual>, Options>;
|
| 496 |
+
/**
|
| 497 |
+
* Checks whether the type of the value is `string`.
|
| 498 |
+
*/
|
| 499 |
+
toBeString: Scolder<ExpectString<Actual>, Options>;
|
| 500 |
+
/**
|
| 501 |
+
* Checks whether the type of the value is `boolean`.
|
| 502 |
+
*/
|
| 503 |
+
toBeBoolean: Scolder<ExpectBoolean<Actual>, Options>;
|
| 504 |
+
/**
|
| 505 |
+
* Checks whether the type of the value is `void`.
|
| 506 |
+
*/
|
| 507 |
+
toBeVoid: Scolder<ExpectVoid<Actual>, Options>;
|
| 508 |
+
/**
|
| 509 |
+
* Checks whether the type of the value is `symbol`.
|
| 510 |
+
*/
|
| 511 |
+
toBeSymbol: Scolder<ExpectSymbol<Actual>, Options>;
|
| 512 |
+
/**
|
| 513 |
+
* Checks whether the type of the value is `null`.
|
| 514 |
+
*/
|
| 515 |
+
toBeNull: Scolder<ExpectNull<Actual>, Options>;
|
| 516 |
+
/**
|
| 517 |
+
* Checks whether the type of the value is `undefined`.
|
| 518 |
+
*/
|
| 519 |
+
toBeUndefined: Scolder<ExpectUndefined<Actual>, Options>;
|
| 520 |
+
/**
|
| 521 |
+
* Checks whether the type of the value is `null` or `undefined`.
|
| 522 |
+
*/
|
| 523 |
+
toBeNullable: Scolder<ExpectNullable<Actual>, Options>;
|
| 524 |
+
/**
|
| 525 |
+
* Transform that type of the value via a callback.
|
| 526 |
+
*
|
| 527 |
+
* @param fn - A callback that transforms the input value. Note that this function is not actually called - it's only used for type inference.
|
| 528 |
+
* @returns A new type which can be used for further assertions.
|
| 529 |
+
*/
|
| 530 |
+
map: <T>(fn: (value: Actual) => T) => ExpectTypeOf<T, Options>;
|
| 531 |
+
/**
|
| 532 |
+
* Checks whether the type of the value is **`bigint`**.
|
| 533 |
+
*
|
| 534 |
+
* @example
|
| 535 |
+
* <caption>#### Distinguish between **`number`** and **`bigint`**</caption>
|
| 536 |
+
*
|
| 537 |
+
* ```ts
|
| 538 |
+
* import { expectTypeOf } from 'expect-type'
|
| 539 |
+
*
|
| 540 |
+
* const aVeryBigInteger = 10n ** 100n
|
| 541 |
+
*
|
| 542 |
+
* expectTypeOf(aVeryBigInteger).not.toBeNumber()
|
| 543 |
+
*
|
| 544 |
+
* expectTypeOf(aVeryBigInteger).toBeBigInt()
|
| 545 |
+
* ```
|
| 546 |
+
*
|
| 547 |
+
* @since 1.1.0
|
| 548 |
+
*/
|
| 549 |
+
toBeBigInt: Scolder<ExpectBigInt<Actual>, Options>;
|
| 550 |
+
/**
|
| 551 |
+
* Checks whether a function is callable with the given parameters.
|
| 552 |
+
*
|
| 553 |
+
* __Note__: You cannot negate this assertion with
|
| 554 |
+
* {@linkcode PositiveExpectTypeOf.not | .not}, you need to use
|
| 555 |
+
* `ts-expect-error` instead.
|
| 556 |
+
*
|
| 557 |
+
* @example
|
| 558 |
+
* ```ts
|
| 559 |
+
* const f = (a: number) => [a, a]
|
| 560 |
+
*
|
| 561 |
+
* expectTypeOf(f).toBeCallableWith(1)
|
| 562 |
+
* ```
|
| 563 |
+
*
|
| 564 |
+
* __Known Limitation__: This assertion will likely fail if you try to use it
|
| 565 |
+
* with a generic function or an overload.
|
| 566 |
+
* @see {@link https://github.com/mmkal/expect-type/issues/50 | This issue} for an example and a workaround.
|
| 567 |
+
*
|
| 568 |
+
* @param args - The arguments to check for callability.
|
| 569 |
+
* @returns `true`.
|
| 570 |
+
*/
|
| 571 |
+
toBeCallableWith: Options['positive'] extends true ? <Args extends OverloadParameters<Actual>>(...args: Args) => ExpectTypeOf<OverloadsNarrowedByParameters<Actual, Args>, Options> : never;
|
| 572 |
+
/**
|
| 573 |
+
* Checks whether a class is constructible with the given parameters.
|
| 574 |
+
*
|
| 575 |
+
* @example
|
| 576 |
+
* ```ts
|
| 577 |
+
* expectTypeOf(Date).toBeConstructibleWith('1970')
|
| 578 |
+
*
|
| 579 |
+
* expectTypeOf(Date).toBeConstructibleWith(0)
|
| 580 |
+
*
|
| 581 |
+
* expectTypeOf(Date).toBeConstructibleWith(new Date())
|
| 582 |
+
*
|
| 583 |
+
* expectTypeOf(Date).toBeConstructibleWith()
|
| 584 |
+
* ```
|
| 585 |
+
*
|
| 586 |
+
* @param args - The arguments to check for constructibility.
|
| 587 |
+
* @returns `true`.
|
| 588 |
+
*/
|
| 589 |
+
toBeConstructibleWith: Options['positive'] extends true ? <Args extends ConstructorOverloadParameters<Actual>>(...args: Args) => true : never;
|
| 590 |
+
/**
|
| 591 |
+
* Equivalent to the {@linkcode Extract} utility type.
|
| 592 |
+
* Helps narrow down complex union types.
|
| 593 |
+
*
|
| 594 |
+
* @example
|
| 595 |
+
* ```ts
|
| 596 |
+
* type ResponsiveProp<T> = T | T[] | { xs?: T; sm?: T; md?: T }
|
| 597 |
+
*
|
| 598 |
+
* interface CSSProperties {
|
| 599 |
+
* margin?: string
|
| 600 |
+
* padding?: string
|
| 601 |
+
* }
|
| 602 |
+
*
|
| 603 |
+
* function getResponsiveProp<T>(_props: T): ResponsiveProp<T> {
|
| 604 |
+
* return {}
|
| 605 |
+
* }
|
| 606 |
+
*
|
| 607 |
+
* const cssProperties: CSSProperties = { margin: '1px', padding: '2px' }
|
| 608 |
+
*
|
| 609 |
+
* expectTypeOf(getResponsiveProp(cssProperties))
|
| 610 |
+
* .extract<{ xs?: any }>() // extracts the last type from a union
|
| 611 |
+
* .toEqualTypeOf<{
|
| 612 |
+
* xs?: CSSProperties
|
| 613 |
+
* sm?: CSSProperties
|
| 614 |
+
* md?: CSSProperties
|
| 615 |
+
* }>()
|
| 616 |
+
*
|
| 617 |
+
* expectTypeOf(getResponsiveProp(cssProperties))
|
| 618 |
+
* .extract<unknown[]>() // extracts an array from a union
|
| 619 |
+
* .toEqualTypeOf<CSSProperties[]>()
|
| 620 |
+
* ```
|
| 621 |
+
*
|
| 622 |
+
* __Note__: If no type is found in the union, it will return `never`.
|
| 623 |
+
*
|
| 624 |
+
* @param v - The type to extract from the union.
|
| 625 |
+
* @returns The type after extracting the type from the union.
|
| 626 |
+
*/
|
| 627 |
+
extract: <V>(v?: V) => ExpectTypeOf<Extract<Actual, V>, Options>;
|
| 628 |
+
/**
|
| 629 |
+
* Equivalent to the {@linkcode Exclude} utility type.
|
| 630 |
+
* Removes types from a union.
|
| 631 |
+
*
|
| 632 |
+
* @example
|
| 633 |
+
* ```ts
|
| 634 |
+
* type ResponsiveProp<T> = T | T[] | { xs?: T; sm?: T; md?: T }
|
| 635 |
+
*
|
| 636 |
+
* interface CSSProperties {
|
| 637 |
+
* margin?: string
|
| 638 |
+
* padding?: string
|
| 639 |
+
* }
|
| 640 |
+
*
|
| 641 |
+
* function getResponsiveProp<T>(_props: T): ResponsiveProp<T> {
|
| 642 |
+
* return {}
|
| 643 |
+
* }
|
| 644 |
+
*
|
| 645 |
+
* const cssProperties: CSSProperties = { margin: '1px', padding: '2px' }
|
| 646 |
+
*
|
| 647 |
+
* expectTypeOf(getResponsiveProp(cssProperties))
|
| 648 |
+
* .exclude<unknown[]>()
|
| 649 |
+
* .exclude<{ xs?: unknown }>() // or just `.exclude<unknown[] | { xs?: unknown }>()`
|
| 650 |
+
* .toEqualTypeOf<CSSProperties>()
|
| 651 |
+
* ```
|
| 652 |
+
*/
|
| 653 |
+
exclude: <V>(v?: V) => ExpectTypeOf<Exclude<Actual, V>, Options>;
|
| 654 |
+
/**
|
| 655 |
+
* Equivalent to the {@linkcode Pick} utility type.
|
| 656 |
+
* Helps select a subset of properties from an object type.
|
| 657 |
+
*
|
| 658 |
+
* @example
|
| 659 |
+
* ```ts
|
| 660 |
+
* interface Person {
|
| 661 |
+
* name: string
|
| 662 |
+
* age: number
|
| 663 |
+
* }
|
| 664 |
+
*
|
| 665 |
+
* expectTypeOf<Person>()
|
| 666 |
+
* .pick<'name'>()
|
| 667 |
+
* .toEqualTypeOf<{ name: string }>()
|
| 668 |
+
* ```
|
| 669 |
+
*
|
| 670 |
+
* @param keyToPick - The property key to pick.
|
| 671 |
+
* @returns The type after picking the property.
|
| 672 |
+
*/
|
| 673 |
+
pick: <KeyToPick extends keyof Actual>(keyToPick?: KeyToPick) => ExpectTypeOf<Pick<Actual, KeyToPick>, Options>;
|
| 674 |
+
/**
|
| 675 |
+
* Equivalent to the {@linkcode Omit} utility type.
|
| 676 |
+
* Helps remove a subset of properties from an object type.
|
| 677 |
+
*
|
| 678 |
+
* @example
|
| 679 |
+
* ```ts
|
| 680 |
+
* interface Person {
|
| 681 |
+
* name: string
|
| 682 |
+
* age: number
|
| 683 |
+
* }
|
| 684 |
+
*
|
| 685 |
+
* expectTypeOf<Person>().omit<'name'>().toEqualTypeOf<{ age: number }>()
|
| 686 |
+
* ```
|
| 687 |
+
*
|
| 688 |
+
* @param keyToOmit - The property key to omit.
|
| 689 |
+
* @returns The type after omitting the property.
|
| 690 |
+
*/
|
| 691 |
+
omit: <KeyToOmit extends keyof Actual | (PropertyKey & Record<never, never>)>(keyToOmit?: KeyToOmit) => ExpectTypeOf<Omit<Actual, KeyToOmit>, Options>;
|
| 692 |
+
/**
|
| 693 |
+
* Extracts a certain function argument with `.parameter(number)` call to
|
| 694 |
+
* perform other assertions on it.
|
| 695 |
+
*
|
| 696 |
+
* @example
|
| 697 |
+
* ```ts
|
| 698 |
+
* function foo(a: number, b: string) {
|
| 699 |
+
* return [a, b]
|
| 700 |
+
* }
|
| 701 |
+
*
|
| 702 |
+
* expectTypeOf(foo).parameter(0).toBeNumber()
|
| 703 |
+
*
|
| 704 |
+
* expectTypeOf(foo).parameter(1).toBeString()
|
| 705 |
+
* ```
|
| 706 |
+
*
|
| 707 |
+
* @param index - The index of the parameter to extract.
|
| 708 |
+
* @returns The extracted parameter type.
|
| 709 |
+
*/
|
| 710 |
+
parameter: <Index extends number>(index: Index) => ExpectTypeOf<OverloadParameters<Actual>[Index], Options>;
|
| 711 |
+
/**
|
| 712 |
+
* Equivalent to the {@linkcode Parameters} utility type.
|
| 713 |
+
* Extracts function parameters to perform assertions on its value.
|
| 714 |
+
* Parameters are returned as an array.
|
| 715 |
+
*
|
| 716 |
+
* @example
|
| 717 |
+
* ```ts
|
| 718 |
+
* function noParam() {}
|
| 719 |
+
*
|
| 720 |
+
* function hasParam(s: string) {}
|
| 721 |
+
*
|
| 722 |
+
* expectTypeOf(noParam).parameters.toEqualTypeOf<[]>()
|
| 723 |
+
*
|
| 724 |
+
* expectTypeOf(hasParam).parameters.toEqualTypeOf<[string]>()
|
| 725 |
+
* ```
|
| 726 |
+
*/
|
| 727 |
+
parameters: ExpectTypeOf<OverloadParameters<Actual>, Options>;
|
| 728 |
+
/**
|
| 729 |
+
* Equivalent to the {@linkcode ConstructorParameters} utility type.
|
| 730 |
+
* Extracts constructor parameters as an array of values and
|
| 731 |
+
* perform assertions on them with this method.
|
| 732 |
+
*
|
| 733 |
+
* For overloaded constructors it will return a union of all possible parameter-tuples.
|
| 734 |
+
*
|
| 735 |
+
* @example
|
| 736 |
+
* ```ts
|
| 737 |
+
* expectTypeOf(Date).constructorParameters.toEqualTypeOf<
|
| 738 |
+
* [] | [string | number | Date]
|
| 739 |
+
* >()
|
| 740 |
+
* ```
|
| 741 |
+
*/
|
| 742 |
+
constructorParameters: ExpectTypeOf<ConstructorOverloadParameters<Actual>, Options>;
|
| 743 |
+
/**
|
| 744 |
+
* Equivalent to the {@linkcode ThisParameterType} utility type.
|
| 745 |
+
* Extracts the `this` parameter of a function to
|
| 746 |
+
* perform assertions on its value.
|
| 747 |
+
*
|
| 748 |
+
* @example
|
| 749 |
+
* ```ts
|
| 750 |
+
* function greet(this: { name: string }, message: string) {
|
| 751 |
+
* return `Hello ${this.name}, here's your message: ${message}`
|
| 752 |
+
* }
|
| 753 |
+
*
|
| 754 |
+
* expectTypeOf(greet).thisParameter.toEqualTypeOf<{ name: string }>()
|
| 755 |
+
* ```
|
| 756 |
+
*/
|
| 757 |
+
thisParameter: ExpectTypeOf<ThisParameterType<Actual>, Options>;
|
| 758 |
+
/**
|
| 759 |
+
* Equivalent to the {@linkcode InstanceType} utility type.
|
| 760 |
+
* Extracts the instance type of a class to perform assertions on.
|
| 761 |
+
*
|
| 762 |
+
* @example
|
| 763 |
+
* ```ts
|
| 764 |
+
* expectTypeOf(Date).instance.toHaveProperty('toISOString')
|
| 765 |
+
* ```
|
| 766 |
+
*/
|
| 767 |
+
instance: Actual extends new (...args: any[]) => infer I ? ExpectTypeOf<I, Options> : never;
|
| 768 |
+
/**
|
| 769 |
+
* Equivalent to the {@linkcode ReturnType} utility type.
|
| 770 |
+
* Extracts the return type of a function.
|
| 771 |
+
*
|
| 772 |
+
* @example
|
| 773 |
+
* ```ts
|
| 774 |
+
* expectTypeOf(() => {}).returns.toBeVoid()
|
| 775 |
+
*
|
| 776 |
+
* expectTypeOf((a: number) => [a, a]).returns.toEqualTypeOf([1, 2])
|
| 777 |
+
* ```
|
| 778 |
+
*/
|
| 779 |
+
returns: Actual extends Function ? ExpectTypeOf<OverloadReturnTypes<Actual>, Options> : never;
|
| 780 |
+
/**
|
| 781 |
+
* Extracts resolved value of a Promise,
|
| 782 |
+
* so you can perform other assertions on it.
|
| 783 |
+
*
|
| 784 |
+
* @example
|
| 785 |
+
* ```ts
|
| 786 |
+
* async function asyncFunc() {
|
| 787 |
+
* return 123
|
| 788 |
+
* }
|
| 789 |
+
*
|
| 790 |
+
* expectTypeOf(asyncFunc).returns.resolves.toBeNumber()
|
| 791 |
+
*
|
| 792 |
+
* expectTypeOf(Promise.resolve('string')).resolves.toBeString()
|
| 793 |
+
* ```
|
| 794 |
+
*
|
| 795 |
+
* Type Equivalent:
|
| 796 |
+
* ```ts
|
| 797 |
+
* type Resolves<PromiseType> = PromiseType extends PromiseLike<infer ResolvedType>
|
| 798 |
+
* ? ResolvedType
|
| 799 |
+
* : never
|
| 800 |
+
* ```
|
| 801 |
+
*/
|
| 802 |
+
resolves: Actual extends PromiseLike<infer ResolvedType> ? ExpectTypeOf<ResolvedType, Options> : never;
|
| 803 |
+
/**
|
| 804 |
+
* Extracts array item type to perform assertions on.
|
| 805 |
+
*
|
| 806 |
+
* @example
|
| 807 |
+
* ```ts
|
| 808 |
+
* expectTypeOf([1, 2, 3]).items.toEqualTypeOf<number>()
|
| 809 |
+
*
|
| 810 |
+
* expectTypeOf([1, 2, 3]).items.not.toEqualTypeOf<string>()
|
| 811 |
+
* ```
|
| 812 |
+
*
|
| 813 |
+
* __Type Equivalent__:
|
| 814 |
+
* ```ts
|
| 815 |
+
* type Items<ArrayType> = ArrayType extends ArrayLike<infer ItemType>
|
| 816 |
+
* ? ItemType
|
| 817 |
+
* : never
|
| 818 |
+
* ```
|
| 819 |
+
*/
|
| 820 |
+
items: Actual extends ArrayLike<infer ItemType> ? ExpectTypeOf<ItemType, Options> : never;
|
| 821 |
+
/**
|
| 822 |
+
* Extracts the type guarded by a function to perform assertions on.
|
| 823 |
+
*
|
| 824 |
+
* @example
|
| 825 |
+
* ```ts
|
| 826 |
+
* function isString(v: any): v is string {
|
| 827 |
+
* return typeof v === 'string'
|
| 828 |
+
* }
|
| 829 |
+
*
|
| 830 |
+
* expectTypeOf(isString).guards.toBeString()
|
| 831 |
+
* ```
|
| 832 |
+
*/
|
| 833 |
+
guards: Actual extends (v: any, ...args: any[]) => v is infer T ? ExpectTypeOf<T, Options> : never;
|
| 834 |
+
/**
|
| 835 |
+
* Extracts the type asserted by a function to perform assertions on.
|
| 836 |
+
*
|
| 837 |
+
* @example
|
| 838 |
+
* ```ts
|
| 839 |
+
* function assertNumber(v: any): asserts v is number {
|
| 840 |
+
* if (typeof v !== 'number')
|
| 841 |
+
* throw new TypeError('Nope !')
|
| 842 |
+
* }
|
| 843 |
+
*
|
| 844 |
+
* expectTypeOf(assertNumber).asserts.toBeNumber()
|
| 845 |
+
* ```
|
| 846 |
+
*/
|
| 847 |
+
asserts: Actual extends (v: any, ...args: any[]) => asserts v is infer T ? unknown extends T ? never : ExpectTypeOf<T, Options> : never;
|
| 848 |
+
}
|
| 849 |
+
/**
|
| 850 |
+
* Represents a function that allows asserting the expected type of a value.
|
| 851 |
+
*/
|
| 852 |
+
export type _ExpectTypeOf = {
|
| 853 |
+
/**
|
| 854 |
+
* Asserts the expected type of a value.
|
| 855 |
+
*
|
| 856 |
+
* @param actual - The actual value being asserted.
|
| 857 |
+
* @returns An object representing the expected type assertion.
|
| 858 |
+
*/
|
| 859 |
+
<Actual>(actual: Actual): ExpectTypeOf<Actual, {
|
| 860 |
+
positive: true;
|
| 861 |
+
branded: false;
|
| 862 |
+
}>;
|
| 863 |
+
/**
|
| 864 |
+
* Asserts the expected type of a value without providing an actual value.
|
| 865 |
+
*
|
| 866 |
+
* @returns An object representing the expected type assertion.
|
| 867 |
+
*/
|
| 868 |
+
<Actual>(): ExpectTypeOf<Actual, {
|
| 869 |
+
positive: true;
|
| 870 |
+
branded: false;
|
| 871 |
+
}>;
|
| 872 |
+
};
|
| 873 |
+
/**
|
| 874 |
+
* Similar to Jest's `expect`, but with type-awareness.
|
| 875 |
+
* Gives you access to a number of type-matchers that let you make assertions about the
|
| 876 |
+
* form of a reference or generic type parameter.
|
| 877 |
+
*
|
| 878 |
+
* @example
|
| 879 |
+
* ```ts
|
| 880 |
+
* import { foo, bar } from '../foo'
|
| 881 |
+
* import { expectTypeOf } from 'expect-type'
|
| 882 |
+
*
|
| 883 |
+
* test('foo types', () => {
|
| 884 |
+
* // make sure `foo` has type { a: number }
|
| 885 |
+
* expectTypeOf(foo).toMatchTypeOf({ a: 1 })
|
| 886 |
+
* expectTypeOf(foo).toHaveProperty('a').toBeNumber()
|
| 887 |
+
*
|
| 888 |
+
* // make sure `bar` is a function taking a string:
|
| 889 |
+
* expectTypeOf(bar).parameter(0).toBeString()
|
| 890 |
+
* expectTypeOf(bar).returns.not.toBeAny()
|
| 891 |
+
* })
|
| 892 |
+
* ```
|
| 893 |
+
*
|
| 894 |
+
* @description
|
| 895 |
+
* See the [full docs](https://npmjs.com/package/expect-type#documentation) for lots more examples.
|
| 896 |
+
*/
|
| 897 |
+
export declare const expectTypeOf: _ExpectTypeOf;
|
tools/ui/node_modules/expect-type/dist/index.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
| 3 |
+
if (k2 === undefined) k2 = k;
|
| 4 |
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
| 5 |
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
| 6 |
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
| 7 |
+
}
|
| 8 |
+
Object.defineProperty(o, k2, desc);
|
| 9 |
+
}) : (function(o, m, k, k2) {
|
| 10 |
+
if (k2 === undefined) k2 = k;
|
| 11 |
+
o[k2] = m[k];
|
| 12 |
+
}));
|
| 13 |
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
| 14 |
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
| 15 |
+
};
|
| 16 |
+
Object.defineProperty(exports, "__esModule", { value: true });
|
| 17 |
+
exports.expectTypeOf = void 0;
|
| 18 |
+
__exportStar(require("./branding"), exports); // backcompat, consider removing in next major version
|
| 19 |
+
__exportStar(require("./messages"), exports); // backcompat, consider removing in next major version
|
| 20 |
+
__exportStar(require("./overloads"), exports);
|
| 21 |
+
__exportStar(require("./utils"), exports); // backcompat, consider removing in next major version
|
| 22 |
+
const fn = () => true;
|
| 23 |
+
/**
|
| 24 |
+
* Similar to Jest's `expect`, but with type-awareness.
|
| 25 |
+
* Gives you access to a number of type-matchers that let you make assertions about the
|
| 26 |
+
* form of a reference or generic type parameter.
|
| 27 |
+
*
|
| 28 |
+
* @example
|
| 29 |
+
* ```ts
|
| 30 |
+
* import { foo, bar } from '../foo'
|
| 31 |
+
* import { expectTypeOf } from 'expect-type'
|
| 32 |
+
*
|
| 33 |
+
* test('foo types', () => {
|
| 34 |
+
* // make sure `foo` has type { a: number }
|
| 35 |
+
* expectTypeOf(foo).toMatchTypeOf({ a: 1 })
|
| 36 |
+
* expectTypeOf(foo).toHaveProperty('a').toBeNumber()
|
| 37 |
+
*
|
| 38 |
+
* // make sure `bar` is a function taking a string:
|
| 39 |
+
* expectTypeOf(bar).parameter(0).toBeString()
|
| 40 |
+
* expectTypeOf(bar).returns.not.toBeAny()
|
| 41 |
+
* })
|
| 42 |
+
* ```
|
| 43 |
+
*
|
| 44 |
+
* @description
|
| 45 |
+
* See the [full docs](https://npmjs.com/package/expect-type#documentation) for lots more examples.
|
| 46 |
+
*/
|
| 47 |
+
const expectTypeOf = (_actual) => {
|
| 48 |
+
const nonFunctionProperties = [
|
| 49 |
+
'parameters',
|
| 50 |
+
'returns',
|
| 51 |
+
'resolves',
|
| 52 |
+
'not',
|
| 53 |
+
'items',
|
| 54 |
+
'constructorParameters',
|
| 55 |
+
'thisParameter',
|
| 56 |
+
'instance',
|
| 57 |
+
'guards',
|
| 58 |
+
'asserts',
|
| 59 |
+
'branded',
|
| 60 |
+
];
|
| 61 |
+
const obj = {
|
| 62 |
+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
| 63 |
+
toBeAny: fn,
|
| 64 |
+
toBeUnknown: fn,
|
| 65 |
+
toBeNever: fn,
|
| 66 |
+
toBeFunction: fn,
|
| 67 |
+
toBeObject: fn,
|
| 68 |
+
toBeArray: fn,
|
| 69 |
+
toBeString: fn,
|
| 70 |
+
toBeNumber: fn,
|
| 71 |
+
toBeBoolean: fn,
|
| 72 |
+
toBeVoid: fn,
|
| 73 |
+
toBeSymbol: fn,
|
| 74 |
+
toBeNull: fn,
|
| 75 |
+
toBeUndefined: fn,
|
| 76 |
+
toBeNullable: fn,
|
| 77 |
+
toBeBigInt: fn,
|
| 78 |
+
toMatchTypeOf: fn,
|
| 79 |
+
toEqualTypeOf: fn,
|
| 80 |
+
toBeConstructibleWith: fn,
|
| 81 |
+
toMatchObjectType: fn,
|
| 82 |
+
toExtend: fn,
|
| 83 |
+
map: exports.expectTypeOf,
|
| 84 |
+
toBeCallableWith: exports.expectTypeOf,
|
| 85 |
+
extract: exports.expectTypeOf,
|
| 86 |
+
exclude: exports.expectTypeOf,
|
| 87 |
+
pick: exports.expectTypeOf,
|
| 88 |
+
omit: exports.expectTypeOf,
|
| 89 |
+
toHaveProperty: exports.expectTypeOf,
|
| 90 |
+
parameter: exports.expectTypeOf,
|
| 91 |
+
};
|
| 92 |
+
const getterProperties = nonFunctionProperties;
|
| 93 |
+
getterProperties.forEach((prop) => Object.defineProperty(obj, prop, { get: () => (0, exports.expectTypeOf)({}) }));
|
| 94 |
+
return obj;
|
| 95 |
+
};
|
| 96 |
+
exports.expectTypeOf = expectTypeOf;
|
tools/ui/node_modules/expect-type/dist/messages.d.ts
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { StrictEqualUsingBranding } from './branding';
|
| 2 |
+
import type { And, Extends, ExtendsExcludingAnyOrNever, IsAny, IsNever, IsUnknown, Not, OptionalKeys, UsefulKeys } from './utils';
|
| 3 |
+
/**
|
| 4 |
+
* Determines the printable type representation for a given type.
|
| 5 |
+
*/
|
| 6 |
+
export type PrintType<T> = IsUnknown<T> extends true ? 'unknown' : IsNever<T> extends true ? 'never' : IsAny<T> extends true ? never : boolean extends T ? 'boolean' : T extends boolean ? `literal boolean: ${T}` : string extends T ? 'string' : T extends string ? `literal string: ${T}` : number extends T ? 'number' : T extends number ? `literal number: ${T}` : bigint extends T ? 'bigint' : T extends bigint ? `literal bigint: ${T}` : T extends null ? 'null' : T extends undefined ? 'undefined' : T extends (...args: any[]) => any ? 'function' : '...';
|
| 7 |
+
/**
|
| 8 |
+
* Helper for showing end-user a hint why their type assertion is failing.
|
| 9 |
+
* This swaps "leaf" types with a literal message about what the actual and
|
| 10 |
+
* expected types are. Needs to check for `Not<IsAny<Actual>>` because
|
| 11 |
+
* otherwise `LeafTypeOf<Actual>` returns `never`, which extends everything 🤔
|
| 12 |
+
*/
|
| 13 |
+
export type MismatchInfo<Actual, Expected> = And<[Extends<PrintType<Actual>, '...'>, Not<IsAny<Actual>>]> extends true ? And<[Extends<any[], Actual>, Extends<any[], Expected>]> extends true ? Array<MismatchInfo<Extract<Actual, any[]>[number], Extract<Expected, any[]>[number]>> : Optionalify<{
|
| 14 |
+
[K in UsefulKeys<Actual> | UsefulKeys<Expected>]: MismatchInfo<K extends keyof Actual ? Actual[K] : never, K extends keyof Expected ? Expected[K] : never>;
|
| 15 |
+
}, OptionalKeys<Expected>> : StrictEqualUsingBranding<Actual, Expected> extends true ? Actual : `Expected: ${PrintType<Expected>}, Actual: ${PrintType<Exclude<Actual, Expected>>}`;
|
| 16 |
+
/**
|
| 17 |
+
* Helper for making some keys of a type optional. Only useful so far for `MismatchInfo` - it makes sure we
|
| 18 |
+
* don't get bogus errors about optional properties mismatching, when actually it's something else that's wrong.
|
| 19 |
+
*
|
| 20 |
+
* - Note: this helper is a no-op if there are no optional keys in the type.
|
| 21 |
+
*/
|
| 22 |
+
export type Optionalify<T, TOptionalKeys> = [TOptionalKeys] extends [never] ? T : ({
|
| 23 |
+
[K in Exclude<keyof T, TOptionalKeys>]: T[K];
|
| 24 |
+
} & {
|
| 25 |
+
[K in Extract<keyof T, TOptionalKeys>]?: T[K];
|
| 26 |
+
}) extends infer X ? {
|
| 27 |
+
[K in keyof X]: X[K];
|
| 28 |
+
} : never;
|
| 29 |
+
/**
|
| 30 |
+
* @internal
|
| 31 |
+
*/
|
| 32 |
+
declare const inverted: unique symbol;
|
| 33 |
+
/**
|
| 34 |
+
* @internal
|
| 35 |
+
*/
|
| 36 |
+
type Inverted<T> = {
|
| 37 |
+
[inverted]: T;
|
| 38 |
+
};
|
| 39 |
+
/**
|
| 40 |
+
* @internal
|
| 41 |
+
*/
|
| 42 |
+
declare const expectNull: unique symbol;
|
| 43 |
+
export type ExpectNull<T> = {
|
| 44 |
+
[expectNull]: T;
|
| 45 |
+
result: ExtendsExcludingAnyOrNever<T, null>;
|
| 46 |
+
};
|
| 47 |
+
/**
|
| 48 |
+
* @internal
|
| 49 |
+
*/
|
| 50 |
+
declare const expectUndefined: unique symbol;
|
| 51 |
+
export type ExpectUndefined<T> = {
|
| 52 |
+
[expectUndefined]: T;
|
| 53 |
+
result: ExtendsExcludingAnyOrNever<T, undefined>;
|
| 54 |
+
};
|
| 55 |
+
/**
|
| 56 |
+
* @internal
|
| 57 |
+
*/
|
| 58 |
+
declare const expectNumber: unique symbol;
|
| 59 |
+
export type ExpectNumber<T> = {
|
| 60 |
+
[expectNumber]: T;
|
| 61 |
+
result: ExtendsExcludingAnyOrNever<T, number>;
|
| 62 |
+
};
|
| 63 |
+
/**
|
| 64 |
+
* @internal
|
| 65 |
+
*/
|
| 66 |
+
declare const expectString: unique symbol;
|
| 67 |
+
export type ExpectString<T> = {
|
| 68 |
+
[expectString]: T;
|
| 69 |
+
result: ExtendsExcludingAnyOrNever<T, string>;
|
| 70 |
+
};
|
| 71 |
+
/**
|
| 72 |
+
* @internal
|
| 73 |
+
*/
|
| 74 |
+
declare const expectBoolean: unique symbol;
|
| 75 |
+
export type ExpectBoolean<T> = {
|
| 76 |
+
[expectBoolean]: T;
|
| 77 |
+
result: ExtendsExcludingAnyOrNever<T, boolean>;
|
| 78 |
+
};
|
| 79 |
+
/**
|
| 80 |
+
* @internal
|
| 81 |
+
*/
|
| 82 |
+
declare const expectVoid: unique symbol;
|
| 83 |
+
export type ExpectVoid<T> = {
|
| 84 |
+
[expectVoid]: T;
|
| 85 |
+
result: ExtendsExcludingAnyOrNever<T, void>;
|
| 86 |
+
};
|
| 87 |
+
/**
|
| 88 |
+
* @internal
|
| 89 |
+
*/
|
| 90 |
+
declare const expectFunction: unique symbol;
|
| 91 |
+
export type ExpectFunction<T> = {
|
| 92 |
+
[expectFunction]: T;
|
| 93 |
+
result: ExtendsExcludingAnyOrNever<T, (...args: any[]) => any>;
|
| 94 |
+
};
|
| 95 |
+
/**
|
| 96 |
+
* @internal
|
| 97 |
+
*/
|
| 98 |
+
declare const expectObject: unique symbol;
|
| 99 |
+
export type ExpectObject<T> = {
|
| 100 |
+
[expectObject]: T;
|
| 101 |
+
result: ExtendsExcludingAnyOrNever<T, object>;
|
| 102 |
+
};
|
| 103 |
+
/**
|
| 104 |
+
* @internal
|
| 105 |
+
*/
|
| 106 |
+
declare const expectArray: unique symbol;
|
| 107 |
+
export type ExpectArray<T> = {
|
| 108 |
+
[expectArray]: T;
|
| 109 |
+
result: ExtendsExcludingAnyOrNever<T, any[]>;
|
| 110 |
+
};
|
| 111 |
+
/**
|
| 112 |
+
* @internal
|
| 113 |
+
*/
|
| 114 |
+
declare const expectSymbol: unique symbol;
|
| 115 |
+
export type ExpectSymbol<T> = {
|
| 116 |
+
[expectSymbol]: T;
|
| 117 |
+
result: ExtendsExcludingAnyOrNever<T, symbol>;
|
| 118 |
+
};
|
| 119 |
+
/**
|
| 120 |
+
* @internal
|
| 121 |
+
*/
|
| 122 |
+
declare const expectAny: unique symbol;
|
| 123 |
+
export type ExpectAny<T> = {
|
| 124 |
+
[expectAny]: T;
|
| 125 |
+
result: IsAny<T>;
|
| 126 |
+
};
|
| 127 |
+
/**
|
| 128 |
+
* @internal
|
| 129 |
+
*/
|
| 130 |
+
declare const expectUnknown: unique symbol;
|
| 131 |
+
export type ExpectUnknown<T> = {
|
| 132 |
+
[expectUnknown]: T;
|
| 133 |
+
result: IsUnknown<T>;
|
| 134 |
+
};
|
| 135 |
+
/**
|
| 136 |
+
* @internal
|
| 137 |
+
*/
|
| 138 |
+
declare const expectNever: unique symbol;
|
| 139 |
+
export type ExpectNever<T> = {
|
| 140 |
+
[expectNever]: T;
|
| 141 |
+
result: IsNever<T>;
|
| 142 |
+
};
|
| 143 |
+
/**
|
| 144 |
+
* @internal
|
| 145 |
+
*/
|
| 146 |
+
declare const expectNullable: unique symbol;
|
| 147 |
+
export type ExpectNullable<T> = {
|
| 148 |
+
[expectNullable]: T;
|
| 149 |
+
result: Not<StrictEqualUsingBranding<T, NonNullable<T>>>;
|
| 150 |
+
};
|
| 151 |
+
/**
|
| 152 |
+
* @internal
|
| 153 |
+
*/
|
| 154 |
+
declare const expectBigInt: unique symbol;
|
| 155 |
+
export type ExpectBigInt<T> = {
|
| 156 |
+
[expectBigInt]: T;
|
| 157 |
+
result: ExtendsExcludingAnyOrNever<T, bigint>;
|
| 158 |
+
};
|
| 159 |
+
/**
|
| 160 |
+
* Checks if the result of an expecter matches the specified options, and
|
| 161 |
+
* resolves to a fairly readable error message if not.
|
| 162 |
+
*/
|
| 163 |
+
export type Scolder<Expecter extends {
|
| 164 |
+
result: boolean;
|
| 165 |
+
}, Options extends {
|
| 166 |
+
positive: boolean;
|
| 167 |
+
}> = Expecter['result'] extends Options['positive'] ? () => true : Options['positive'] extends true ? Expecter : Inverted<Expecter>;
|
| 168 |
+
export {};
|
tools/ui/node_modules/expect-type/dist/messages.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
Object.defineProperty(exports, "__esModule", { value: true });
|
| 3 |
+
/**
|
| 4 |
+
* @internal
|
| 5 |
+
*/
|
| 6 |
+
const inverted = Symbol('inverted');
|
| 7 |
+
/**
|
| 8 |
+
* @internal
|
| 9 |
+
*/
|
| 10 |
+
const expectNull = Symbol('expectNull');
|
| 11 |
+
/**
|
| 12 |
+
* @internal
|
| 13 |
+
*/
|
| 14 |
+
const expectUndefined = Symbol('expectUndefined');
|
| 15 |
+
/**
|
| 16 |
+
* @internal
|
| 17 |
+
*/
|
| 18 |
+
const expectNumber = Symbol('expectNumber');
|
| 19 |
+
/**
|
| 20 |
+
* @internal
|
| 21 |
+
*/
|
| 22 |
+
const expectString = Symbol('expectString');
|
| 23 |
+
/**
|
| 24 |
+
* @internal
|
| 25 |
+
*/
|
| 26 |
+
const expectBoolean = Symbol('expectBoolean');
|
| 27 |
+
/**
|
| 28 |
+
* @internal
|
| 29 |
+
*/
|
| 30 |
+
const expectVoid = Symbol('expectVoid');
|
| 31 |
+
/**
|
| 32 |
+
* @internal
|
| 33 |
+
*/
|
| 34 |
+
const expectFunction = Symbol('expectFunction');
|
| 35 |
+
/**
|
| 36 |
+
* @internal
|
| 37 |
+
*/
|
| 38 |
+
const expectObject = Symbol('expectObject');
|
| 39 |
+
/**
|
| 40 |
+
* @internal
|
| 41 |
+
*/
|
| 42 |
+
const expectArray = Symbol('expectArray');
|
| 43 |
+
/**
|
| 44 |
+
* @internal
|
| 45 |
+
*/
|
| 46 |
+
const expectSymbol = Symbol('expectSymbol');
|
| 47 |
+
/**
|
| 48 |
+
* @internal
|
| 49 |
+
*/
|
| 50 |
+
const expectAny = Symbol('expectAny');
|
| 51 |
+
/**
|
| 52 |
+
* @internal
|
| 53 |
+
*/
|
| 54 |
+
const expectUnknown = Symbol('expectUnknown');
|
| 55 |
+
/**
|
| 56 |
+
* @internal
|
| 57 |
+
*/
|
| 58 |
+
const expectNever = Symbol('expectNever');
|
| 59 |
+
/**
|
| 60 |
+
* @internal
|
| 61 |
+
*/
|
| 62 |
+
const expectNullable = Symbol('expectNullable');
|
| 63 |
+
/**
|
| 64 |
+
* @internal
|
| 65 |
+
*/
|
| 66 |
+
const expectBigInt = Symbol('expectBigInt');
|
tools/ui/node_modules/expect-type/dist/overloads.d.ts
ADDED
|
@@ -0,0 +1,288 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { StrictEqualUsingTSInternalIdenticalToOperator, IsNever, UnionToIntersection, UnionToTuple } from './utils';
|
| 2 |
+
/**
|
| 3 |
+
* The simple(ish) way to get overload info from a function
|
| 4 |
+
* {@linkcode FunctionType}. Recent versions of TypeScript will match any
|
| 5 |
+
* function against a generic 10-overload type, filling in slots with
|
| 6 |
+
* duplicates of the function. So, we can just match against a single type
|
| 7 |
+
* and get all the overloads.
|
| 8 |
+
*
|
| 9 |
+
* For older versions of TypeScript, we'll need to painstakingly do
|
| 10 |
+
* ten separate matches.
|
| 11 |
+
*/
|
| 12 |
+
export type TSPost53OverloadsInfoUnion<FunctionType> = FunctionType extends {
|
| 13 |
+
(...args: infer A1): infer R1;
|
| 14 |
+
(...args: infer A2): infer R2;
|
| 15 |
+
(...args: infer A3): infer R3;
|
| 16 |
+
(...args: infer A4): infer R4;
|
| 17 |
+
(...args: infer A5): infer R5;
|
| 18 |
+
(...args: infer A6): infer R6;
|
| 19 |
+
(...args: infer A7): infer R7;
|
| 20 |
+
(...args: infer A8): infer R8;
|
| 21 |
+
(...args: infer A9): infer R9;
|
| 22 |
+
(...args: infer A10): infer R10;
|
| 23 |
+
} ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) | ((...p: A4) => R4) | ((...p: A5) => R5) | ((...p: A6) => R6) | ((...p: A7) => R7) | ((...p: A8) => R8) | ((...p: A9) => R9) | ((...p: A10) => R10) : never;
|
| 24 |
+
/**
|
| 25 |
+
* A function with `unknown` parameters and return type.
|
| 26 |
+
*/
|
| 27 |
+
export type UnknownFunction = (...args: unknown[]) => unknown;
|
| 28 |
+
/**
|
| 29 |
+
* `true` iff {@linkcode FunctionType} is
|
| 30 |
+
* equivalent to `(...args: unknown[]) => unknown`,
|
| 31 |
+
* which is what an overload variant looks like for a non-existent overload.
|
| 32 |
+
* This is useful because older versions of TypeScript end up with
|
| 33 |
+
* 9 "useless" overloads and one real one for parameterless/generic functions.
|
| 34 |
+
*
|
| 35 |
+
* @see {@link https://github.com/microsoft/TypeScript/issues/28867 | Related}
|
| 36 |
+
*/
|
| 37 |
+
export type IsUselessOverloadInfo<FunctionType> = StrictEqualUsingTSInternalIdenticalToOperator<FunctionType, UnknownFunction>;
|
| 38 |
+
/**
|
| 39 |
+
* Old versions of TypeScript can sometimes seem to refuse to separate out
|
| 40 |
+
* union members unless you put them each in a pointless tuple and add an
|
| 41 |
+
* extra `infer X` expression. There may be a better way to work around this
|
| 42 |
+
* problem, but since it's not a problem in newer versions of TypeScript,
|
| 43 |
+
* it's not a priority right now.
|
| 44 |
+
*/
|
| 45 |
+
export type Tuplify<Union> = Union extends infer X ? [X] : never;
|
| 46 |
+
/**
|
| 47 |
+
* For older versions of TypeScript, we need two separate workarounds
|
| 48 |
+
* to get overload info. First, we need need to use
|
| 49 |
+
* {@linkcode DecreasingOverloadsInfoUnion} to get the overload info for
|
| 50 |
+
* functions with 1-10 overloads. Then, we need to filter out the
|
| 51 |
+
* "useless" overloads that are present in older versions of TypeScript,
|
| 52 |
+
* for parameterless functions. To do this we use
|
| 53 |
+
* {@linkcode IsUselessOverloadInfo} to remove useless overloads.
|
| 54 |
+
*
|
| 55 |
+
* @see {@link https://github.com/microsoft/TypeScript/issues/28867 | Related}
|
| 56 |
+
*/
|
| 57 |
+
export type TSPre53OverloadsInfoUnion<FunctionType> = Tuplify<DecreasingOverloadsInfoUnion<FunctionType>> extends infer Tup ? Tup extends [infer Fn] ? IsUselessOverloadInfo<Fn> extends true ? never : Fn : never : never;
|
| 58 |
+
/**
|
| 59 |
+
* For versions of TypeScript below 5.3, we need to check for 10 overloads,
|
| 60 |
+
* then 9, then 8, etc., to get a union of the overload variants.
|
| 61 |
+
*/
|
| 62 |
+
export type DecreasingOverloadsInfoUnion<F> = F extends {
|
| 63 |
+
(...args: infer A1): infer R1;
|
| 64 |
+
(...args: infer A2): infer R2;
|
| 65 |
+
(...args: infer A3): infer R3;
|
| 66 |
+
(...args: infer A4): infer R4;
|
| 67 |
+
(...args: infer A5): infer R5;
|
| 68 |
+
(...args: infer A6): infer R6;
|
| 69 |
+
(...args: infer A7): infer R7;
|
| 70 |
+
(...args: infer A8): infer R8;
|
| 71 |
+
(...args: infer A9): infer R9;
|
| 72 |
+
(...args: infer A10): infer R10;
|
| 73 |
+
} ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) | ((...p: A4) => R4) | ((...p: A5) => R5) | ((...p: A6) => R6) | ((...p: A7) => R7) | ((...p: A8) => R8) | ((...p: A9) => R9) | ((...p: A10) => R10) : F extends {
|
| 74 |
+
(...args: infer A1): infer R1;
|
| 75 |
+
(...args: infer A2): infer R2;
|
| 76 |
+
(...args: infer A3): infer R3;
|
| 77 |
+
(...args: infer A4): infer R4;
|
| 78 |
+
(...args: infer A5): infer R5;
|
| 79 |
+
(...args: infer A6): infer R6;
|
| 80 |
+
(...args: infer A7): infer R7;
|
| 81 |
+
(...args: infer A8): infer R8;
|
| 82 |
+
(...args: infer A9): infer R9;
|
| 83 |
+
} ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) | ((...p: A4) => R4) | ((...p: A5) => R5) | ((...p: A6) => R6) | ((...p: A7) => R7) | ((...p: A8) => R8) | ((...p: A9) => R9) : F extends {
|
| 84 |
+
(...args: infer A1): infer R1;
|
| 85 |
+
(...args: infer A2): infer R2;
|
| 86 |
+
(...args: infer A3): infer R3;
|
| 87 |
+
(...args: infer A4): infer R4;
|
| 88 |
+
(...args: infer A5): infer R5;
|
| 89 |
+
(...args: infer A6): infer R6;
|
| 90 |
+
(...args: infer A7): infer R7;
|
| 91 |
+
(...args: infer A8): infer R8;
|
| 92 |
+
} ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) | ((...p: A4) => R4) | ((...p: A5) => R5) | ((...p: A6) => R6) | ((...p: A7) => R7) | ((...p: A8) => R8) : F extends {
|
| 93 |
+
(...args: infer A1): infer R1;
|
| 94 |
+
(...args: infer A2): infer R2;
|
| 95 |
+
(...args: infer A3): infer R3;
|
| 96 |
+
(...args: infer A4): infer R4;
|
| 97 |
+
(...args: infer A5): infer R5;
|
| 98 |
+
(...args: infer A6): infer R6;
|
| 99 |
+
(...args: infer A7): infer R7;
|
| 100 |
+
} ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) | ((...p: A4) => R4) | ((...p: A5) => R5) | ((...p: A6) => R6) | ((...p: A7) => R7) : F extends {
|
| 101 |
+
(...args: infer A1): infer R1;
|
| 102 |
+
(...args: infer A2): infer R2;
|
| 103 |
+
(...args: infer A3): infer R3;
|
| 104 |
+
(...args: infer A4): infer R4;
|
| 105 |
+
(...args: infer A5): infer R5;
|
| 106 |
+
(...args: infer A6): infer R6;
|
| 107 |
+
} ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) | ((...p: A4) => R4) | ((...p: A5) => R5) | ((...p: A6) => R6) : F extends {
|
| 108 |
+
(...args: infer A1): infer R1;
|
| 109 |
+
(...args: infer A2): infer R2;
|
| 110 |
+
(...args: infer A3): infer R3;
|
| 111 |
+
(...args: infer A4): infer R4;
|
| 112 |
+
(...args: infer A5): infer R5;
|
| 113 |
+
} ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) | ((...p: A4) => R4) | ((...p: A5) => R5) : F extends {
|
| 114 |
+
(...args: infer A1): infer R1;
|
| 115 |
+
(...args: infer A2): infer R2;
|
| 116 |
+
(...args: infer A3): infer R3;
|
| 117 |
+
(...args: infer A4): infer R4;
|
| 118 |
+
} ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) | ((...p: A4) => R4) : F extends {
|
| 119 |
+
(...args: infer A1): infer R1;
|
| 120 |
+
(...args: infer A2): infer R2;
|
| 121 |
+
(...args: infer A3): infer R3;
|
| 122 |
+
} ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) : F extends {
|
| 123 |
+
(...args: infer A1): infer R1;
|
| 124 |
+
(...args: infer A2): infer R2;
|
| 125 |
+
} ? ((...p: A1) => R1) | ((...p: A2) => R2) : F extends (...args: infer A1) => infer R1 ? ((...p: A1) => R1) : never;
|
| 126 |
+
/**
|
| 127 |
+
* Get a union of overload variants for a function {@linkcode FunctionType}.
|
| 128 |
+
* Does a check for whether we can do the one-shot
|
| 129 |
+
* 10-overload matcher (which works for ts\>5.3), and if not,
|
| 130 |
+
* falls back to the more complicated utility.
|
| 131 |
+
*/
|
| 132 |
+
export type OverloadsInfoUnion<FunctionType> = IsNever<TSPost53OverloadsInfoUnion<(a: 1) => 2>> extends true ? TSPre53OverloadsInfoUnion<FunctionType> : TSPost53OverloadsInfoUnion<FunctionType>;
|
| 133 |
+
/**
|
| 134 |
+
* Allows inferring any function using the `infer` keyword.
|
| 135 |
+
*/
|
| 136 |
+
export type InferFunctionType<FunctionType extends (...args: any) => any> = FunctionType;
|
| 137 |
+
/**
|
| 138 |
+
* A union type of the parameters allowed for any
|
| 139 |
+
* overload of function {@linkcode FunctionType}.
|
| 140 |
+
*/
|
| 141 |
+
export type OverloadParameters<FunctionType> = OverloadsInfoUnion<FunctionType> extends InferFunctionType<infer Fn> ? Parameters<Fn> : never;
|
| 142 |
+
/**
|
| 143 |
+
* A union type of the return types for any overload of
|
| 144 |
+
* function {@linkcode FunctionType}.
|
| 145 |
+
*/
|
| 146 |
+
export type OverloadReturnTypes<FunctionType> = OverloadsInfoUnion<FunctionType> extends InferFunctionType<infer Fn> ? ReturnType<Fn> : never;
|
| 147 |
+
/**
|
| 148 |
+
* Takes an overload variants {@linkcode Union},
|
| 149 |
+
* produced from {@linkcode OverloadsInfoUnion} and rejects
|
| 150 |
+
* the ones incompatible with parameters {@linkcode Args}.
|
| 151 |
+
*/
|
| 152 |
+
export type SelectOverloadsInfo<Union extends UnknownFunction, Args extends unknown[]> = Union extends InferFunctionType<infer Fn> ? (Args extends Parameters<Fn> ? Fn : never) : never;
|
| 153 |
+
/**
|
| 154 |
+
* Creates a new overload (an intersection type) from an existing one,
|
| 155 |
+
* which only includes variant(s) which can accept
|
| 156 |
+
* {@linkcode Args} as parameters.
|
| 157 |
+
*/
|
| 158 |
+
export type OverloadsNarrowedByParameters<FunctionType, Args extends OverloadParameters<FunctionType>> = UnionToIntersection<SelectOverloadsInfo<OverloadsInfoUnion<FunctionType>, Args>>;
|
| 159 |
+
/**
|
| 160 |
+
* The simple(ish) way to get overload info from a constructor
|
| 161 |
+
* {@linkcode ConstructorType}. Recent versions of TypeScript will match any
|
| 162 |
+
* constructor against a generic 10-overload type, filling in slots with
|
| 163 |
+
* duplicates of the constructor. So, we can just match against a single type
|
| 164 |
+
* and get all the overloads.
|
| 165 |
+
*
|
| 166 |
+
* For older versions of TypeScript,
|
| 167 |
+
* we'll need to painstakingly do ten separate matches.
|
| 168 |
+
*/
|
| 169 |
+
export type TSPost53ConstructorOverloadsInfoUnion<ConstructorType> = ConstructorType extends {
|
| 170 |
+
new (...args: infer A1): infer R1;
|
| 171 |
+
new (...args: infer A2): infer R2;
|
| 172 |
+
new (...args: infer A3): infer R3;
|
| 173 |
+
new (...args: infer A4): infer R4;
|
| 174 |
+
new (...args: infer A5): infer R5;
|
| 175 |
+
new (...args: infer A6): infer R6;
|
| 176 |
+
new (...args: infer A7): infer R7;
|
| 177 |
+
new (...args: infer A8): infer R8;
|
| 178 |
+
new (...args: infer A9): infer R9;
|
| 179 |
+
new (...args: infer A10): infer R10;
|
| 180 |
+
} ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) | (new (...p: A4) => R4) | (new (...p: A5) => R5) | (new (...p: A6) => R6) | (new (...p: A7) => R7) | (new (...p: A8) => R8) | (new (...p: A9) => R9) | (new (...p: A10) => R10) : never;
|
| 181 |
+
/**
|
| 182 |
+
* A constructor function with `unknown` parameters and return type.
|
| 183 |
+
*/
|
| 184 |
+
export type UnknownConstructor = new (...args: unknown[]) => unknown;
|
| 185 |
+
/**
|
| 186 |
+
* Same as {@linkcode IsUselessOverloadInfo}, but for constructors.
|
| 187 |
+
*/
|
| 188 |
+
export type IsUselessConstructorOverloadInfo<FunctionType> = StrictEqualUsingTSInternalIdenticalToOperator<FunctionType, UnknownConstructor>;
|
| 189 |
+
/**
|
| 190 |
+
* For older versions of TypeScript, we need two separate workarounds to
|
| 191 |
+
* get constructor overload info. First, we need need to use
|
| 192 |
+
* {@linkcode DecreasingConstructorOverloadsInfoUnion} to get the overload
|
| 193 |
+
* info for constructors with 1-10 overloads. Then, we need to filter out the
|
| 194 |
+
* "useless" overloads that are present in older versions of TypeScript,
|
| 195 |
+
* for parameterless constructors. To do this we use
|
| 196 |
+
* {@linkcode IsUselessConstructorOverloadInfo} to remove useless overloads.
|
| 197 |
+
*
|
| 198 |
+
* @see {@link https://github.com/microsoft/TypeScript/issues/28867 | Related}
|
| 199 |
+
*/
|
| 200 |
+
export type TSPre53ConstructorOverloadsInfoUnion<ConstructorType> = Tuplify<DecreasingConstructorOverloadsInfoUnion<ConstructorType>> extends infer Tup ? Tup extends [infer Ctor] ? IsUselessConstructorOverloadInfo<Ctor> extends true ? never : Ctor : never : never;
|
| 201 |
+
/**
|
| 202 |
+
* For versions of TypeScript below 5.3, we need to check for 10 overloads,
|
| 203 |
+
* then 9, then 8, etc., to get a union of the overload variants.
|
| 204 |
+
*/
|
| 205 |
+
export type DecreasingConstructorOverloadsInfoUnion<ConstructorType> = ConstructorType extends {
|
| 206 |
+
new (...args: infer A1): infer R1;
|
| 207 |
+
new (...args: infer A2): infer R2;
|
| 208 |
+
new (...args: infer A3): infer R3;
|
| 209 |
+
new (...args: infer A4): infer R4;
|
| 210 |
+
new (...args: infer A5): infer R5;
|
| 211 |
+
new (...args: infer A6): infer R6;
|
| 212 |
+
new (...args: infer A7): infer R7;
|
| 213 |
+
new (...args: infer A8): infer R8;
|
| 214 |
+
new (...args: infer A9): infer R9;
|
| 215 |
+
new (...args: infer A10): infer R10;
|
| 216 |
+
} ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) | (new (...p: A4) => R4) | (new (...p: A5) => R5) | (new (...p: A6) => R6) | (new (...p: A7) => R7) | (new (...p: A8) => R8) | (new (...p: A9) => R9) | (new (...p: A10) => R10) : ConstructorType extends {
|
| 217 |
+
new (...args: infer A1): infer R1;
|
| 218 |
+
new (...args: infer A2): infer R2;
|
| 219 |
+
new (...args: infer A3): infer R3;
|
| 220 |
+
new (...args: infer A4): infer R4;
|
| 221 |
+
new (...args: infer A5): infer R5;
|
| 222 |
+
new (...args: infer A6): infer R6;
|
| 223 |
+
new (...args: infer A7): infer R7;
|
| 224 |
+
new (...args: infer A8): infer R8;
|
| 225 |
+
new (...args: infer A9): infer R9;
|
| 226 |
+
} ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) | (new (...p: A4) => R4) | (new (...p: A5) => R5) | (new (...p: A6) => R6) | (new (...p: A7) => R7) | (new (...p: A8) => R8) | (new (...p: A9) => R9) : ConstructorType extends {
|
| 227 |
+
new (...args: infer A1): infer R1;
|
| 228 |
+
new (...args: infer A2): infer R2;
|
| 229 |
+
new (...args: infer A3): infer R3;
|
| 230 |
+
new (...args: infer A4): infer R4;
|
| 231 |
+
new (...args: infer A5): infer R5;
|
| 232 |
+
new (...args: infer A6): infer R6;
|
| 233 |
+
new (...args: infer A7): infer R7;
|
| 234 |
+
new (...args: infer A8): infer R8;
|
| 235 |
+
} ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) | (new (...p: A4) => R4) | (new (...p: A5) => R5) | (new (...p: A6) => R6) | (new (...p: A7) => R7) | (new (...p: A8) => R8) : ConstructorType extends {
|
| 236 |
+
new (...args: infer A1): infer R1;
|
| 237 |
+
new (...args: infer A2): infer R2;
|
| 238 |
+
new (...args: infer A3): infer R3;
|
| 239 |
+
new (...args: infer A4): infer R4;
|
| 240 |
+
new (...args: infer A5): infer R5;
|
| 241 |
+
new (...args: infer A6): infer R6;
|
| 242 |
+
new (...args: infer A7): infer R7;
|
| 243 |
+
} ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) | (new (...p: A4) => R4) | (new (...p: A5) => R5) | (new (...p: A6) => R6) | (new (...p: A7) => R7) : ConstructorType extends {
|
| 244 |
+
new (...args: infer A1): infer R1;
|
| 245 |
+
new (...args: infer A2): infer R2;
|
| 246 |
+
new (...args: infer A3): infer R3;
|
| 247 |
+
new (...args: infer A4): infer R4;
|
| 248 |
+
new (...args: infer A5): infer R5;
|
| 249 |
+
new (...args: infer A6): infer R6;
|
| 250 |
+
} ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) | (new (...p: A4) => R4) | (new (...p: A5) => R5) | (new (...p: A6) => R6) : ConstructorType extends {
|
| 251 |
+
new (...args: infer A1): infer R1;
|
| 252 |
+
new (...args: infer A2): infer R2;
|
| 253 |
+
new (...args: infer A3): infer R3;
|
| 254 |
+
new (...args: infer A4): infer R4;
|
| 255 |
+
new (...args: infer A5): infer R5;
|
| 256 |
+
} ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) | (new (...p: A4) => R4) | (new (...p: A5) => R5) : ConstructorType extends {
|
| 257 |
+
new (...args: infer A1): infer R1;
|
| 258 |
+
new (...args: infer A2): infer R2;
|
| 259 |
+
new (...args: infer A3): infer R3;
|
| 260 |
+
new (...args: infer A4): infer R4;
|
| 261 |
+
} ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) | (new (...p: A4) => R4) : ConstructorType extends {
|
| 262 |
+
new (...args: infer A1): infer R1;
|
| 263 |
+
new (...args: infer A2): infer R2;
|
| 264 |
+
new (...args: infer A3): infer R3;
|
| 265 |
+
} ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) : ConstructorType extends {
|
| 266 |
+
new (...args: infer A1): infer R1;
|
| 267 |
+
new (...args: infer A2): infer R2;
|
| 268 |
+
} ? (new (...p: A1) => R1) | (new (...p: A2) => R2) : ConstructorType extends new (...args: infer A1) => infer R1 ? (new (...p: A1) => R1) : never;
|
| 269 |
+
/**
|
| 270 |
+
* Get a union of overload variants for a constructor
|
| 271 |
+
* {@linkcode ConstructorType}. Does a check for whether we can do the
|
| 272 |
+
* one-shot 10-overload matcher (which works for ts\>5.3), and if not,
|
| 273 |
+
* falls back to the more complicated utility.
|
| 274 |
+
*/
|
| 275 |
+
export type ConstructorOverloadsUnion<ConstructorType> = IsNever<TSPost53ConstructorOverloadsInfoUnion<new (a: 1) => any>> extends true ? TSPre53ConstructorOverloadsInfoUnion<ConstructorType> : TSPost53ConstructorOverloadsInfoUnion<ConstructorType>;
|
| 276 |
+
/**
|
| 277 |
+
* Allows inferring any constructor using the `infer` keyword.
|
| 278 |
+
*/
|
| 279 |
+
export type InferConstructor<ConstructorType extends new (...args: any) => any> = ConstructorType;
|
| 280 |
+
/**
|
| 281 |
+
* A union type of the parameters allowed for any overload
|
| 282 |
+
* of constructor {@linkcode ConstructorType}.
|
| 283 |
+
*/
|
| 284 |
+
export type ConstructorOverloadParameters<ConstructorType> = ConstructorOverloadsUnion<ConstructorType> extends InferConstructor<infer Ctor> ? ConstructorParameters<Ctor> : never;
|
| 285 |
+
/**
|
| 286 |
+
* Calculates the number of overloads for a given function type.
|
| 287 |
+
*/
|
| 288 |
+
export type NumOverloads<FunctionType> = UnionToTuple<OverloadsInfoUnion<FunctionType>>['length'];
|
tools/ui/node_modules/expect-type/dist/overloads.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
Object.defineProperty(exports, "__esModule", { value: true });
|
tools/ui/node_modules/expect-type/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Negates a boolean type.
|
| 3 |
+
*/
|
| 4 |
+
export type Not<T extends boolean> = T extends true ? false : true;
|
| 5 |
+
/**
|
| 6 |
+
* Returns `true` if at least one of the types in the
|
| 7 |
+
* {@linkcode Types} array is `true`, otherwise returns `false`.
|
| 8 |
+
*/
|
| 9 |
+
export type Or<Types extends boolean[]> = Types[number] extends false ? false : true;
|
| 10 |
+
/**
|
| 11 |
+
* Checks if all the boolean types in the {@linkcode Types} array are `true`.
|
| 12 |
+
*/
|
| 13 |
+
export type And<Types extends boolean[]> = Types[number] extends true ? true : false;
|
| 14 |
+
/**
|
| 15 |
+
* Represents an equality type that returns {@linkcode Right} if
|
| 16 |
+
* {@linkcode Left} is `true`,
|
| 17 |
+
* otherwise returns the negation of {@linkcode Right}.
|
| 18 |
+
*/
|
| 19 |
+
export type Eq<Left extends boolean, Right extends boolean> = Left extends true ? Right : Not<Right>;
|
| 20 |
+
/**
|
| 21 |
+
* Represents the exclusive OR operation on a tuple of boolean types.
|
| 22 |
+
* Returns `true` if exactly one of the boolean types is `true`,
|
| 23 |
+
* otherwise returns `false`.
|
| 24 |
+
*/
|
| 25 |
+
export type Xor<Types extends [boolean, boolean]> = Not<Eq<Types[0], Types[1]>>;
|
| 26 |
+
/**
|
| 27 |
+
* @internal
|
| 28 |
+
*/
|
| 29 |
+
declare const secret: unique symbol;
|
| 30 |
+
/**
|
| 31 |
+
* @internal
|
| 32 |
+
*/
|
| 33 |
+
type Secret = typeof secret;
|
| 34 |
+
/**
|
| 35 |
+
* Checks if the given type is `never`.
|
| 36 |
+
*/
|
| 37 |
+
export type IsNever<T> = [T] extends [never] ? true : false;
|
| 38 |
+
/**
|
| 39 |
+
* Checks if the given type is `any`.
|
| 40 |
+
*/
|
| 41 |
+
export type IsAny<T> = [T] extends [Secret] ? Not<IsNever<T>> : false;
|
| 42 |
+
/**
|
| 43 |
+
* Determines if the given type is `unknown`.
|
| 44 |
+
*/
|
| 45 |
+
export type IsUnknown<T> = [unknown] extends [T] ? Not<IsAny<T>> : false;
|
| 46 |
+
/**
|
| 47 |
+
* Determines if a type is either `never` or `any`.
|
| 48 |
+
*/
|
| 49 |
+
export type IsNeverOrAny<T> = Or<[IsNever<T>, IsAny<T>]>;
|
| 50 |
+
/**
|
| 51 |
+
* Subjective "useful" keys from a type. For objects it's just `keyof` but for
|
| 52 |
+
* tuples/arrays it's the number keys.
|
| 53 |
+
*
|
| 54 |
+
* @example
|
| 55 |
+
* ```ts
|
| 56 |
+
* UsefulKeys<{ a: 1; b: 2 }> // 'a' | 'b'
|
| 57 |
+
*
|
| 58 |
+
* UsefulKeys<['a', 'b']> // '0' | '1'
|
| 59 |
+
*
|
| 60 |
+
* UsefulKeys<string[]> // number
|
| 61 |
+
* ```
|
| 62 |
+
*/
|
| 63 |
+
export type UsefulKeys<T> = T extends any[] ? {
|
| 64 |
+
[K in keyof T]: K;
|
| 65 |
+
}[number] : keyof T;
|
| 66 |
+
/**
|
| 67 |
+
* Extracts the keys from a type that are required (not optional).
|
| 68 |
+
*/
|
| 69 |
+
export type RequiredKeys<T> = Extract<{
|
| 70 |
+
[K in keyof T]-?: {} extends Pick<T, K> ? never : K;
|
| 71 |
+
}[keyof T], keyof T>;
|
| 72 |
+
/**
|
| 73 |
+
* Gets the keys of an object type that are optional.
|
| 74 |
+
*/
|
| 75 |
+
export type OptionalKeys<T> = Exclude<keyof T, RequiredKeys<T>>;
|
| 76 |
+
/**
|
| 77 |
+
* Extracts the keys from a type that are not `readonly`.
|
| 78 |
+
*/
|
| 79 |
+
export type ReadonlyKeys<T> = Extract<{
|
| 80 |
+
[K in keyof T]-?: ReadonlyEquivalent<{
|
| 81 |
+
[_K in K]: T[K];
|
| 82 |
+
}, {
|
| 83 |
+
-readonly [_K in K]: T[K];
|
| 84 |
+
}> extends true ? never : K;
|
| 85 |
+
}[keyof T], keyof T>;
|
| 86 |
+
/**
|
| 87 |
+
* Determines if two types, are equivalent in a `readonly` manner.
|
| 88 |
+
*
|
| 89 |
+
* @internal
|
| 90 |
+
*/
|
| 91 |
+
type ReadonlyEquivalent<X, Y> = Extends<(<T>() => T extends X ? true : false), (<T>() => T extends Y ? true : false)>;
|
| 92 |
+
/**
|
| 93 |
+
* Checks if one type extends another. Note: this is not quite the same as `Left extends Right` because:
|
| 94 |
+
* 1. If either type is `never`, the result is `true` iff the other type is also `never`.
|
| 95 |
+
* 2. Types are wrapped in a 1-tuple so that union types are not distributed - instead we consider `string | number` to _not_ extend `number`. If we used `Left extends Right` directly you would get `Extends<string | number, number>` => `false | true` => `boolean`.
|
| 96 |
+
*/
|
| 97 |
+
export type Extends<Left, Right> = IsNever<Left> extends true ? IsNever<Right> : [Left] extends [Right] ? true : false;
|
| 98 |
+
/**
|
| 99 |
+
* Checks if the {@linkcode Left} type extends the {@linkcode Right} type,
|
| 100 |
+
* excluding `any` or `never`.
|
| 101 |
+
*/
|
| 102 |
+
export type ExtendsExcludingAnyOrNever<Left, Right> = IsAny<Left> extends true ? IsAny<Right> : Extends<Left, Right>;
|
| 103 |
+
/**
|
| 104 |
+
* Checks if two types are strictly equal using
|
| 105 |
+
* the TypeScript internal identical-to operator.
|
| 106 |
+
*
|
| 107 |
+
* @see {@link https://github.com/microsoft/TypeScript/issues/55188#issuecomment-1656328122 | much history}
|
| 108 |
+
*/
|
| 109 |
+
export type StrictEqualUsingTSInternalIdenticalToOperator<L, R> = (<T>() => T extends (L & T) | T ? true : false) extends <T>() => T extends (R & T) | T ? true : false ? IsNever<L> extends IsNever<R> ? true : false : false;
|
| 110 |
+
/**
|
| 111 |
+
* Checks that {@linkcode Left} and {@linkcode Right} extend each other.
|
| 112 |
+
* Not quite the same as an equality check since `any` can make it resolve
|
| 113 |
+
* to `true`. So should only be used when {@linkcode Left} and
|
| 114 |
+
* {@linkcode Right} are known to avoid `any`.
|
| 115 |
+
*/
|
| 116 |
+
export type MutuallyExtends<Left, Right> = And<[Extends<Left, Right>, Extends<Right, Left>]>;
|
| 117 |
+
/**
|
| 118 |
+
* @internal
|
| 119 |
+
*/
|
| 120 |
+
declare const mismatch: unique symbol;
|
| 121 |
+
/**
|
| 122 |
+
* @internal
|
| 123 |
+
*/
|
| 124 |
+
type Mismatch = {
|
| 125 |
+
[mismatch]: 'mismatch';
|
| 126 |
+
};
|
| 127 |
+
/**
|
| 128 |
+
* A type which should match anything passed as a value but *doesn't*
|
| 129 |
+
* match {@linkcode Mismatch}. It helps TypeScript select the right overload
|
| 130 |
+
* for {@linkcode PositiveExpectTypeOf.toEqualTypeOf | .toEqualTypeOf()} and
|
| 131 |
+
* {@linkcode PositiveExpectTypeOf.toMatchTypeOf | .toMatchTypeOf()}.
|
| 132 |
+
*
|
| 133 |
+
* @internal
|
| 134 |
+
*/
|
| 135 |
+
declare const avalue: unique symbol;
|
| 136 |
+
/**
|
| 137 |
+
* Represents a value that can be of various types.
|
| 138 |
+
*/
|
| 139 |
+
export type AValue = {
|
| 140 |
+
[avalue]?: undefined;
|
| 141 |
+
} | string | number | boolean | symbol | bigint | null | undefined | void;
|
| 142 |
+
/**
|
| 143 |
+
* Represents the type of mismatched arguments between
|
| 144 |
+
* the actual result and the expected result.
|
| 145 |
+
*
|
| 146 |
+
* If {@linkcode ActualResult} and {@linkcode ExpectedResult} are equivalent,
|
| 147 |
+
* the type resolves to an empty tuple `[]`, indicating no mismatch.
|
| 148 |
+
* If they are not equivalent, it resolves to a tuple containing the element
|
| 149 |
+
* {@linkcode Mismatch}, signifying a discrepancy between
|
| 150 |
+
* the expected and actual results.
|
| 151 |
+
*/
|
| 152 |
+
export type MismatchArgs<ActualResult extends boolean, ExpectedResult extends boolean> = Eq<ActualResult, ExpectedResult> extends true ? [] : [Mismatch];
|
| 153 |
+
/**
|
| 154 |
+
* Represents the options for the {@linkcode ExpectTypeOf} function.
|
| 155 |
+
*/
|
| 156 |
+
export interface ExpectTypeOfOptions {
|
| 157 |
+
positive: boolean;
|
| 158 |
+
branded: boolean;
|
| 159 |
+
}
|
| 160 |
+
/**
|
| 161 |
+
* Convert a union to an intersection.
|
| 162 |
+
* `A | B | C` -\> `A & B & C`
|
| 163 |
+
*/
|
| 164 |
+
export type UnionToIntersection<Union> = (Union extends any ? (distributedUnion: Union) => void : never) extends (mergedIntersection: infer Intersection) => void ? Intersection : never;
|
| 165 |
+
/**
|
| 166 |
+
* Get the last element of a union.
|
| 167 |
+
* First, converts to a union of `() => T` functions,
|
| 168 |
+
* then uses {@linkcode UnionToIntersection} to get the last one.
|
| 169 |
+
*/
|
| 170 |
+
export type LastOf<Union> = UnionToIntersection<Union extends any ? () => Union : never> extends () => infer R ? R : never;
|
| 171 |
+
/**
|
| 172 |
+
* Intermediate type for {@linkcode UnionToTuple} which pushes the
|
| 173 |
+
* "last" union member to the end of a tuple, and recursively prepends
|
| 174 |
+
* the remainder of the union.
|
| 175 |
+
*/
|
| 176 |
+
export type TuplifyUnion<Union, LastElement = LastOf<Union>> = IsNever<Union> extends true ? [] : [...TuplifyUnion<Exclude<Union, LastElement>>, LastElement];
|
| 177 |
+
/**
|
| 178 |
+
* Convert a union like `1 | 2 | 3` to a tuple like `[1, 2, 3]`.
|
| 179 |
+
*/
|
| 180 |
+
export type UnionToTuple<Union> = TuplifyUnion<Union>;
|
| 181 |
+
export type IsTuple<T> = Or<[Extends<T, []>, Extends<T, [any, ...any[]]>]>;
|
| 182 |
+
export type IsUnion<T> = Not<Extends<UnionToTuple<T>['length'], 1>>;
|
| 183 |
+
/**
|
| 184 |
+
* A recursive version of `Pick` that selects properties from the left type that are present in the right type.
|
| 185 |
+
* The "leaf" types from `Left` are used - only the keys of `Right` are considered.
|
| 186 |
+
*
|
| 187 |
+
* @example
|
| 188 |
+
* ```ts
|
| 189 |
+
* const user = {email: 'a@b.com', name: 'John Doe', address: {street: '123 2nd St', city: 'New York', zip: '10001', state: 'NY', country: 'USA'}}
|
| 190 |
+
*
|
| 191 |
+
* type Result = DeepPickMatchingProps<typeof user, {name: unknown; address: {city: unknown}}> // {name: string, address: {city: string}}
|
| 192 |
+
* ```
|
| 193 |
+
*/
|
| 194 |
+
export type DeepPickMatchingProps<Left, Right> = Left extends Record<string, unknown> ? Pick<{
|
| 195 |
+
[K in keyof Left]: K extends keyof Right ? DeepPickMatchingProps<Left[K], Right[K]> : never;
|
| 196 |
+
}, Extract<keyof Left, keyof Right>> : Left;
|
| 197 |
+
export {};
|
tools/ui/node_modules/expect-type/dist/utils.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
Object.defineProperty(exports, "__esModule", { value: true });
|
| 3 |
+
/**
|
| 4 |
+
* @internal
|
| 5 |
+
*/
|
| 6 |
+
const secret = Symbol('secret');
|
| 7 |
+
/**
|
| 8 |
+
* @internal
|
| 9 |
+
*/
|
| 10 |
+
const mismatch = Symbol('mismatch');
|
| 11 |
+
/**
|
| 12 |
+
* A type which should match anything passed as a value but *doesn't*
|
| 13 |
+
* match {@linkcode Mismatch}. It helps TypeScript select the right overload
|
| 14 |
+
* for {@linkcode PositiveExpectTypeOf.toEqualTypeOf | .toEqualTypeOf()} and
|
| 15 |
+
* {@linkcode PositiveExpectTypeOf.toMatchTypeOf | .toMatchTypeOf()}.
|
| 16 |
+
*
|
| 17 |
+
* @internal
|
| 18 |
+
*/
|
| 19 |
+
const avalue = Symbol('avalue');
|
tools/ui/node_modules/expect-type/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "expect-type",
|
| 3 |
+
"version": "1.3.0",
|
| 4 |
+
"engines": {
|
| 5 |
+
"node": ">=12.0.0"
|
| 6 |
+
},
|
| 7 |
+
"keywords": [
|
| 8 |
+
"typescript",
|
| 9 |
+
"type-check",
|
| 10 |
+
"assert",
|
| 11 |
+
"types",
|
| 12 |
+
"typings",
|
| 13 |
+
"test",
|
| 14 |
+
"testing"
|
| 15 |
+
],
|
| 16 |
+
"homepage": "https://github.com/mmkal/expect-type#readme",
|
| 17 |
+
"repository": {
|
| 18 |
+
"type": "git",
|
| 19 |
+
"url": "https://github.com/mmkal/expect-type.git"
|
| 20 |
+
},
|
| 21 |
+
"license": "Apache-2.0",
|
| 22 |
+
"main": "dist/index.js",
|
| 23 |
+
"types": "dist/index.d.ts",
|
| 24 |
+
"files": [
|
| 25 |
+
"dist",
|
| 26 |
+
"*.md"
|
| 27 |
+
],
|
| 28 |
+
"devDependencies": {
|
| 29 |
+
"@arethetypeswrong/cli": "0.17.3",
|
| 30 |
+
"@types/node": "^22.0.0",
|
| 31 |
+
"@typescript/native-preview": "7.0.0-dev.20250527.1",
|
| 32 |
+
"@vitest/ui": "^3.0.0",
|
| 33 |
+
"eslint": "^8.57.0",
|
| 34 |
+
"eslint-plugin-mmkal": "0.9.0",
|
| 35 |
+
"np": "^10.2.0",
|
| 36 |
+
"pkg-pr-new": "0.0.39",
|
| 37 |
+
"strip-ansi": "7.1.0",
|
| 38 |
+
"ts-morph": "23.0.0",
|
| 39 |
+
"typescript": "5.9.2",
|
| 40 |
+
"vitest": "^3.0.0"
|
| 41 |
+
},
|
| 42 |
+
"scripts": {
|
| 43 |
+
"eslint": "eslint --max-warnings 0",
|
| 44 |
+
"lint": "tsc && pnpm eslint .",
|
| 45 |
+
"type-check": "tsc",
|
| 46 |
+
"build": "tsc -p tsconfig.lib.json",
|
| 47 |
+
"arethetypeswrong": "attw --pack",
|
| 48 |
+
"test": "vitest run"
|
| 49 |
+
}
|
| 50 |
+
}
|
tools/ui/node_modules/express-rate-limit/dist/index.cjs
ADDED
|
@@ -0,0 +1,1016 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
var __defProp = Object.defineProperty;
|
| 3 |
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
| 4 |
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
| 5 |
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
| 6 |
+
var __export = (target, all) => {
|
| 7 |
+
for (var name in all)
|
| 8 |
+
__defProp(target, name, { get: all[name], enumerable: true });
|
| 9 |
+
};
|
| 10 |
+
var __copyProps = (to, from, except, desc) => {
|
| 11 |
+
if (from && typeof from === "object" || typeof from === "function") {
|
| 12 |
+
for (let key of __getOwnPropNames(from))
|
| 13 |
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
| 14 |
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
| 15 |
+
}
|
| 16 |
+
return to;
|
| 17 |
+
};
|
| 18 |
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
| 19 |
+
|
| 20 |
+
// source/index.ts
|
| 21 |
+
var index_exports = {};
|
| 22 |
+
__export(index_exports, {
|
| 23 |
+
MemoryStore: () => MemoryStore,
|
| 24 |
+
default: () => rate_limit_default,
|
| 25 |
+
ipKeyGenerator: () => ipKeyGenerator,
|
| 26 |
+
rateLimit: () => rate_limit_default
|
| 27 |
+
});
|
| 28 |
+
module.exports = __toCommonJS(index_exports);
|
| 29 |
+
|
| 30 |
+
// source/ip-key-generator.ts
|
| 31 |
+
var import_node_net = require("node:net");
|
| 32 |
+
var import_ip_address = require("ip-address");
|
| 33 |
+
function ipKeyGenerator(ip, ipv6Subnet = 56) {
|
| 34 |
+
if ((0, import_node_net.isIPv6)(ip)) {
|
| 35 |
+
const address = new import_ip_address.Address6(ip);
|
| 36 |
+
if (address.is4()) return address.to4().correctForm();
|
| 37 |
+
if (ipv6Subnet) {
|
| 38 |
+
const subnet = new import_ip_address.Address6(`${ip}/${ipv6Subnet}`);
|
| 39 |
+
return subnet.networkForm();
|
| 40 |
+
}
|
| 41 |
+
}
|
| 42 |
+
return ip;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
// source/memory-store.ts
|
| 46 |
+
var MemoryStore = class {
|
| 47 |
+
constructor(validations2) {
|
| 48 |
+
this.validations = validations2;
|
| 49 |
+
/**
|
| 50 |
+
* These two maps store usage (requests) and reset time by key (for example, IP
|
| 51 |
+
* addresses or API keys).
|
| 52 |
+
*
|
| 53 |
+
* They are split into two to avoid having to iterate through the entire set to
|
| 54 |
+
* determine which ones need reset. Instead, `Client`s are moved from `previous`
|
| 55 |
+
* to `current` as they hit the endpoint. Once `windowMs` has elapsed, all clients
|
| 56 |
+
* left in `previous`, i.e., those that have not made any recent requests, are
|
| 57 |
+
* known to be expired and can be deleted in bulk.
|
| 58 |
+
*/
|
| 59 |
+
this.previous = /* @__PURE__ */ new Map();
|
| 60 |
+
this.current = /* @__PURE__ */ new Map();
|
| 61 |
+
/**
|
| 62 |
+
* Confirmation that the keys incremented in once instance of MemoryStore
|
| 63 |
+
* cannot affect other instances.
|
| 64 |
+
*/
|
| 65 |
+
this.localKeys = true;
|
| 66 |
+
}
|
| 67 |
+
/**
|
| 68 |
+
* Method that initializes the store.
|
| 69 |
+
*
|
| 70 |
+
* @param options {Options} - The options used to setup the middleware.
|
| 71 |
+
*/
|
| 72 |
+
init(options) {
|
| 73 |
+
this.windowMs = options.windowMs;
|
| 74 |
+
this.validations?.windowMs(this.windowMs);
|
| 75 |
+
if (this.interval) clearInterval(this.interval);
|
| 76 |
+
this.interval = setInterval(() => {
|
| 77 |
+
this.clearExpired();
|
| 78 |
+
}, this.windowMs);
|
| 79 |
+
this.interval.unref?.();
|
| 80 |
+
}
|
| 81 |
+
/**
|
| 82 |
+
* Method to fetch a client's hit count and reset time.
|
| 83 |
+
*
|
| 84 |
+
* @param key {string} - The identifier for a client.
|
| 85 |
+
*
|
| 86 |
+
* @returns {ClientRateLimitInfo | undefined} - The number of hits and reset time for that client.
|
| 87 |
+
*
|
| 88 |
+
* @public
|
| 89 |
+
*/
|
| 90 |
+
async get(key) {
|
| 91 |
+
return this.current.get(key) ?? this.previous.get(key);
|
| 92 |
+
}
|
| 93 |
+
/**
|
| 94 |
+
* Method to increment a client's hit counter.
|
| 95 |
+
*
|
| 96 |
+
* @param key {string} - The identifier for a client.
|
| 97 |
+
*
|
| 98 |
+
* @returns {ClientRateLimitInfo} - The number of hits and reset time for that client.
|
| 99 |
+
*
|
| 100 |
+
* @public
|
| 101 |
+
*/
|
| 102 |
+
async increment(key) {
|
| 103 |
+
const client = this.getClient(key);
|
| 104 |
+
const now = Date.now();
|
| 105 |
+
if (client.resetTime.getTime() <= now) {
|
| 106 |
+
this.resetClient(client, now);
|
| 107 |
+
}
|
| 108 |
+
client.totalHits++;
|
| 109 |
+
return client;
|
| 110 |
+
}
|
| 111 |
+
/**
|
| 112 |
+
* Method to decrement a client's hit counter.
|
| 113 |
+
*
|
| 114 |
+
* @param key {string} - The identifier for a client.
|
| 115 |
+
*
|
| 116 |
+
* @public
|
| 117 |
+
*/
|
| 118 |
+
async decrement(key) {
|
| 119 |
+
const client = this.getClient(key);
|
| 120 |
+
if (client.totalHits > 0) client.totalHits--;
|
| 121 |
+
}
|
| 122 |
+
/**
|
| 123 |
+
* Method to reset a client's hit counter.
|
| 124 |
+
*
|
| 125 |
+
* @param key {string} - The identifier for a client.
|
| 126 |
+
*
|
| 127 |
+
* @public
|
| 128 |
+
*/
|
| 129 |
+
async resetKey(key) {
|
| 130 |
+
this.current.delete(key);
|
| 131 |
+
this.previous.delete(key);
|
| 132 |
+
}
|
| 133 |
+
/**
|
| 134 |
+
* Method to reset everyone's hit counter.
|
| 135 |
+
*
|
| 136 |
+
* @public
|
| 137 |
+
*/
|
| 138 |
+
async resetAll() {
|
| 139 |
+
this.current.clear();
|
| 140 |
+
this.previous.clear();
|
| 141 |
+
}
|
| 142 |
+
/**
|
| 143 |
+
* Method to stop the timer (if currently running) and prevent any memory
|
| 144 |
+
* leaks.
|
| 145 |
+
*
|
| 146 |
+
* @public
|
| 147 |
+
*/
|
| 148 |
+
shutdown() {
|
| 149 |
+
clearInterval(this.interval);
|
| 150 |
+
void this.resetAll();
|
| 151 |
+
}
|
| 152 |
+
/**
|
| 153 |
+
* Recycles a client by setting its hit count to zero, and reset time to
|
| 154 |
+
* `windowMs` milliseconds from now.
|
| 155 |
+
*
|
| 156 |
+
* NOT to be confused with `#resetKey()`, which removes a client from both the
|
| 157 |
+
* `current` and `previous` maps.
|
| 158 |
+
*
|
| 159 |
+
* @param client {Client} - The client to recycle.
|
| 160 |
+
* @param now {number} - The current time, to which the `windowMs` is added to get the `resetTime` for the client.
|
| 161 |
+
*
|
| 162 |
+
* @return {Client} - The modified client that was passed in, to allow for chaining.
|
| 163 |
+
*/
|
| 164 |
+
resetClient(client, now = Date.now()) {
|
| 165 |
+
client.totalHits = 0;
|
| 166 |
+
client.resetTime.setTime(now + this.windowMs);
|
| 167 |
+
return client;
|
| 168 |
+
}
|
| 169 |
+
/**
|
| 170 |
+
* Retrieves or creates a client, given a key. Also ensures that the client being
|
| 171 |
+
* returned is in the `current` map.
|
| 172 |
+
*
|
| 173 |
+
* @param key {string} - The key under which the client is (or is to be) stored.
|
| 174 |
+
*
|
| 175 |
+
* @returns {Client} - The requested client.
|
| 176 |
+
*/
|
| 177 |
+
getClient(key) {
|
| 178 |
+
if (this.current.has(key)) return this.current.get(key);
|
| 179 |
+
let client;
|
| 180 |
+
if (this.previous.has(key)) {
|
| 181 |
+
client = this.previous.get(key);
|
| 182 |
+
this.previous.delete(key);
|
| 183 |
+
} else {
|
| 184 |
+
client = { totalHits: 0, resetTime: /* @__PURE__ */ new Date() };
|
| 185 |
+
this.resetClient(client);
|
| 186 |
+
}
|
| 187 |
+
this.current.set(key, client);
|
| 188 |
+
return client;
|
| 189 |
+
}
|
| 190 |
+
/**
|
| 191 |
+
* Move current clients to previous, create a new map for current.
|
| 192 |
+
*
|
| 193 |
+
* This function is called every `windowMs`.
|
| 194 |
+
*/
|
| 195 |
+
clearExpired() {
|
| 196 |
+
this.previous = this.current;
|
| 197 |
+
this.current = /* @__PURE__ */ new Map();
|
| 198 |
+
}
|
| 199 |
+
};
|
| 200 |
+
|
| 201 |
+
// source/rate-limit.ts
|
| 202 |
+
var import_node_net3 = require("node:net");
|
| 203 |
+
|
| 204 |
+
// source/console-logger.ts
|
| 205 |
+
var ConsoleLogger = {
|
| 206 |
+
warn(...args) {
|
| 207 |
+
console.warn(...args.reverse());
|
| 208 |
+
},
|
| 209 |
+
error(...args) {
|
| 210 |
+
console.error(...args.reverse());
|
| 211 |
+
}
|
| 212 |
+
};
|
| 213 |
+
|
| 214 |
+
// source/headers.ts
|
| 215 |
+
var import_node_buffer = require("node:buffer");
|
| 216 |
+
var import_node_crypto = require("node:crypto");
|
| 217 |
+
var SUPPORTED_DRAFT_VERSIONS = [
|
| 218 |
+
"draft-6",
|
| 219 |
+
"draft-7",
|
| 220 |
+
"draft-8"
|
| 221 |
+
];
|
| 222 |
+
var getResetSeconds = (windowMs, resetTime) => {
|
| 223 |
+
let resetSeconds;
|
| 224 |
+
if (resetTime) {
|
| 225 |
+
const deltaSeconds = Math.ceil((resetTime.getTime() - Date.now()) / 1e3);
|
| 226 |
+
resetSeconds = Math.max(0, deltaSeconds);
|
| 227 |
+
} else {
|
| 228 |
+
resetSeconds = Math.ceil(windowMs / 1e3);
|
| 229 |
+
}
|
| 230 |
+
return resetSeconds;
|
| 231 |
+
};
|
| 232 |
+
var getPartitionKey = (key) => {
|
| 233 |
+
const hash = (0, import_node_crypto.createHash)("sha256");
|
| 234 |
+
hash.update(key);
|
| 235 |
+
const partitionKey = hash.digest("hex").slice(0, 12);
|
| 236 |
+
return import_node_buffer.Buffer.from(partitionKey).toString("base64");
|
| 237 |
+
};
|
| 238 |
+
var setLegacyHeaders = (response, info) => {
|
| 239 |
+
if (response.headersSent) return;
|
| 240 |
+
response.setHeader("X-RateLimit-Limit", info.limit.toString());
|
| 241 |
+
response.setHeader("X-RateLimit-Remaining", info.remaining.toString());
|
| 242 |
+
if (info.resetTime instanceof Date) {
|
| 243 |
+
response.setHeader("Date", (/* @__PURE__ */ new Date()).toUTCString());
|
| 244 |
+
response.setHeader(
|
| 245 |
+
"X-RateLimit-Reset",
|
| 246 |
+
Math.ceil(info.resetTime.getTime() / 1e3).toString()
|
| 247 |
+
);
|
| 248 |
+
}
|
| 249 |
+
};
|
| 250 |
+
var setDraft6Headers = (response, info, windowMs) => {
|
| 251 |
+
if (response.headersSent) return;
|
| 252 |
+
const windowSeconds = Math.ceil(windowMs / 1e3);
|
| 253 |
+
const resetSeconds = getResetSeconds(windowMs, info.resetTime);
|
| 254 |
+
response.setHeader("RateLimit-Policy", `${info.limit};w=${windowSeconds}`);
|
| 255 |
+
response.setHeader("RateLimit-Limit", info.limit.toString());
|
| 256 |
+
response.setHeader("RateLimit-Remaining", info.remaining.toString());
|
| 257 |
+
if (typeof resetSeconds === "number")
|
| 258 |
+
response.setHeader("RateLimit-Reset", resetSeconds.toString());
|
| 259 |
+
};
|
| 260 |
+
var setDraft7Headers = (response, info, windowMs) => {
|
| 261 |
+
if (response.headersSent) return;
|
| 262 |
+
const windowSeconds = Math.ceil(windowMs / 1e3);
|
| 263 |
+
const resetSeconds = getResetSeconds(windowMs, info.resetTime);
|
| 264 |
+
response.setHeader("RateLimit-Policy", `${info.limit};w=${windowSeconds}`);
|
| 265 |
+
response.setHeader(
|
| 266 |
+
"RateLimit",
|
| 267 |
+
`limit=${info.limit}, remaining=${info.remaining}, reset=${resetSeconds}`
|
| 268 |
+
);
|
| 269 |
+
};
|
| 270 |
+
var setDraft8Headers = (response, info, windowMs, name, key) => {
|
| 271 |
+
if (response.headersSent) return;
|
| 272 |
+
const windowSeconds = Math.ceil(windowMs / 1e3);
|
| 273 |
+
const resetSeconds = getResetSeconds(windowMs, info.resetTime);
|
| 274 |
+
const partitionKey = getPartitionKey(key);
|
| 275 |
+
const header = `r=${info.remaining}; t=${resetSeconds}`;
|
| 276 |
+
const policy = `q=${info.limit}; w=${windowSeconds}; pk=:${partitionKey}:`;
|
| 277 |
+
response.append("RateLimit", `"${name}"; ${header}`);
|
| 278 |
+
response.append("RateLimit-Policy", `"${name}"; ${policy}`);
|
| 279 |
+
};
|
| 280 |
+
var setRetryAfterHeader = (response, info, windowMs) => {
|
| 281 |
+
if (response.headersSent) return;
|
| 282 |
+
const resetSeconds = getResetSeconds(windowMs, info.resetTime);
|
| 283 |
+
response.setHeader("Retry-After", resetSeconds.toString());
|
| 284 |
+
};
|
| 285 |
+
|
| 286 |
+
// source/utils.ts
|
| 287 |
+
var omitUndefinedProperties = (passedOptions) => {
|
| 288 |
+
const omittedOptions = {};
|
| 289 |
+
for (const k of Object.keys(passedOptions)) {
|
| 290 |
+
const key = k;
|
| 291 |
+
if (passedOptions[key] !== void 0) {
|
| 292 |
+
omittedOptions[key] = passedOptions[key];
|
| 293 |
+
}
|
| 294 |
+
}
|
| 295 |
+
return omittedOptions;
|
| 296 |
+
};
|
| 297 |
+
|
| 298 |
+
// source/validations.ts
|
| 299 |
+
var import_node_net2 = require("node:net");
|
| 300 |
+
var ValidationError = class extends Error {
|
| 301 |
+
/**
|
| 302 |
+
* The code must be a string, in snake case and all capital, that starts with
|
| 303 |
+
* the substring `ERR_ERL_`.
|
| 304 |
+
*
|
| 305 |
+
* The message must be a string, starting with an uppercase character,
|
| 306 |
+
* describing the issue in detail.
|
| 307 |
+
*/
|
| 308 |
+
constructor(code, message) {
|
| 309 |
+
const url = `https://express-rate-limit.github.io/${code}/`;
|
| 310 |
+
super(`${message} See ${url} for more information.`);
|
| 311 |
+
this.name = this.constructor.name;
|
| 312 |
+
this.code = code;
|
| 313 |
+
this.help = url;
|
| 314 |
+
}
|
| 315 |
+
};
|
| 316 |
+
var ChangeWarning = class extends ValidationError {
|
| 317 |
+
};
|
| 318 |
+
var usedStores = /* @__PURE__ */ new Set();
|
| 319 |
+
var singleCountKeys = /* @__PURE__ */ new WeakMap();
|
| 320 |
+
var validations = {
|
| 321 |
+
enabled: {
|
| 322 |
+
default: true
|
| 323 |
+
},
|
| 324 |
+
// Should be EnabledValidations type, but that's a circular reference
|
| 325 |
+
disable() {
|
| 326 |
+
for (const k of Object.keys(this.enabled)) this.enabled[k] = false;
|
| 327 |
+
},
|
| 328 |
+
/**
|
| 329 |
+
* Checks whether the IP address is valid, and that it does not have a port
|
| 330 |
+
* number in it.
|
| 331 |
+
*
|
| 332 |
+
* See https://github.com/express-rate-limit/express-rate-limit/wiki/Error-Codes#err_erl_invalid_ip_address.
|
| 333 |
+
*
|
| 334 |
+
* @param ip {string | undefined} - The IP address provided by Express as request.ip.
|
| 335 |
+
*
|
| 336 |
+
* @returns {void}
|
| 337 |
+
*/
|
| 338 |
+
ip(ip) {
|
| 339 |
+
if (ip === void 0) {
|
| 340 |
+
throw new ValidationError(
|
| 341 |
+
"ERR_ERL_UNDEFINED_IP_ADDRESS",
|
| 342 |
+
`An undefined 'request.ip' was detected. This might indicate a misconfiguration or the connection being destroyed prematurely.`
|
| 343 |
+
);
|
| 344 |
+
}
|
| 345 |
+
if (!(0, import_node_net2.isIP)(ip)) {
|
| 346 |
+
throw new ValidationError(
|
| 347 |
+
"ERR_ERL_INVALID_IP_ADDRESS",
|
| 348 |
+
`An invalid 'request.ip' (${ip}) was detected. Consider passing a custom 'keyGenerator' function to the rate limiter.`
|
| 349 |
+
);
|
| 350 |
+
}
|
| 351 |
+
},
|
| 352 |
+
/**
|
| 353 |
+
* Makes sure the trust proxy setting is not set to `true`.
|
| 354 |
+
*
|
| 355 |
+
* See https://github.com/express-rate-limit/express-rate-limit/wiki/Error-Codes#err_erl_permissive_trust_proxy.
|
| 356 |
+
*
|
| 357 |
+
* @param request {Request} - The Express request object.
|
| 358 |
+
*
|
| 359 |
+
* @returns {void}
|
| 360 |
+
*/
|
| 361 |
+
trustProxy(request) {
|
| 362 |
+
if (request.app.get("trust proxy") === true) {
|
| 363 |
+
throw new ValidationError(
|
| 364 |
+
"ERR_ERL_PERMISSIVE_TRUST_PROXY",
|
| 365 |
+
`The Express 'trust proxy' setting is true, which allows anyone to trivially bypass IP-based rate limiting.`
|
| 366 |
+
);
|
| 367 |
+
}
|
| 368 |
+
},
|
| 369 |
+
/**
|
| 370 |
+
* Makes sure the trust proxy setting is set in case the `X-Forwarded-For`
|
| 371 |
+
* header is present.
|
| 372 |
+
*
|
| 373 |
+
* See https://github.com/express-rate-limit/express-rate-limit/wiki/Error-Codes#err_erl_unset_trust_proxy.
|
| 374 |
+
*
|
| 375 |
+
* @param request {Request} - The Express request object.
|
| 376 |
+
*
|
| 377 |
+
* @returns {void}
|
| 378 |
+
*/
|
| 379 |
+
xForwardedForHeader(request) {
|
| 380 |
+
if (request.headers["x-forwarded-for"] && request.app.get("trust proxy") === false) {
|
| 381 |
+
throw new ValidationError(
|
| 382 |
+
"ERR_ERL_UNEXPECTED_X_FORWARDED_FOR",
|
| 383 |
+
`The 'X-Forwarded-For' header is set but the Express 'trust proxy' setting is false (default). This could indicate a misconfiguration which would prevent express-rate-limit from accurately identifying users.`
|
| 384 |
+
);
|
| 385 |
+
}
|
| 386 |
+
},
|
| 387 |
+
/**
|
| 388 |
+
* Alert the user if the Forwarded header is set (standardized version of X-Forwarded-For - not supported by express as of version 5.1.0)
|
| 389 |
+
*
|
| 390 |
+
* @param request {Request} - The Express request object.
|
| 391 |
+
*
|
| 392 |
+
* @returns {void}
|
| 393 |
+
*/
|
| 394 |
+
forwardedHeader(request) {
|
| 395 |
+
if (request.headers.forwarded && request.ip === request.socket?.remoteAddress) {
|
| 396 |
+
throw new ValidationError(
|
| 397 |
+
"ERR_ERL_FORWARDED_HEADER",
|
| 398 |
+
`The 'Forwarded' header (standardized X-Forwarded-For) is set but currently being ignored. Add a custom keyGenerator to use a value from this header.`
|
| 399 |
+
);
|
| 400 |
+
}
|
| 401 |
+
},
|
| 402 |
+
/**
|
| 403 |
+
* Ensures totalHits value from store is a positive integer.
|
| 404 |
+
*
|
| 405 |
+
* @param hits {any} - The `totalHits` returned by the store.
|
| 406 |
+
*/
|
| 407 |
+
positiveHits(hits) {
|
| 408 |
+
if (typeof hits !== "number" || hits < 1 || hits !== Math.round(hits)) {
|
| 409 |
+
throw new ValidationError(
|
| 410 |
+
"ERR_ERL_INVALID_HITS",
|
| 411 |
+
`The totalHits value returned from the store must be a positive integer, got ${hits}`
|
| 412 |
+
);
|
| 413 |
+
}
|
| 414 |
+
},
|
| 415 |
+
/**
|
| 416 |
+
* Ensures a single store instance is not used with multiple express-rate-limit instances
|
| 417 |
+
*/
|
| 418 |
+
unsharedStore(store) {
|
| 419 |
+
if (usedStores.has(store)) {
|
| 420 |
+
const maybeUniquePrefix = store?.localKeys ? "" : " (with a unique prefix)";
|
| 421 |
+
throw new ValidationError(
|
| 422 |
+
"ERR_ERL_STORE_REUSE",
|
| 423 |
+
`A Store instance must not be shared across multiple rate limiters. Create a new instance of ${store.constructor.name}${maybeUniquePrefix} for each limiter instead.`
|
| 424 |
+
);
|
| 425 |
+
}
|
| 426 |
+
usedStores.add(store);
|
| 427 |
+
},
|
| 428 |
+
/**
|
| 429 |
+
* Ensures a given key is incremented only once per request.
|
| 430 |
+
*
|
| 431 |
+
* @param request {Request} - The Express request object.
|
| 432 |
+
* @param store {Store} - The store class.
|
| 433 |
+
* @param key {string} - The key used to store the client's hit count.
|
| 434 |
+
*
|
| 435 |
+
* @returns {void}
|
| 436 |
+
*/
|
| 437 |
+
singleCount(request, store, key) {
|
| 438 |
+
let storeKeys = singleCountKeys.get(request);
|
| 439 |
+
if (!storeKeys) {
|
| 440 |
+
storeKeys = /* @__PURE__ */ new Map();
|
| 441 |
+
singleCountKeys.set(request, storeKeys);
|
| 442 |
+
}
|
| 443 |
+
const storeKey = store.localKeys ? store : store.constructor.name;
|
| 444 |
+
let keys = storeKeys.get(storeKey);
|
| 445 |
+
if (!keys) {
|
| 446 |
+
keys = [];
|
| 447 |
+
storeKeys.set(storeKey, keys);
|
| 448 |
+
}
|
| 449 |
+
const prefixedKey = `${store.prefix ?? ""}${key}`;
|
| 450 |
+
if (keys.includes(prefixedKey)) {
|
| 451 |
+
throw new ValidationError(
|
| 452 |
+
"ERR_ERL_DOUBLE_COUNT",
|
| 453 |
+
`The hit count for ${key} was incremented more than once for a single request.`
|
| 454 |
+
);
|
| 455 |
+
}
|
| 456 |
+
keys.push(prefixedKey);
|
| 457 |
+
},
|
| 458 |
+
/**
|
| 459 |
+
* Warns the user that the behaviour for `max: 0` / `limit: 0` is
|
| 460 |
+
* changing in the next major release.
|
| 461 |
+
*
|
| 462 |
+
* @param limit {number} - The maximum number of hits per client.
|
| 463 |
+
*
|
| 464 |
+
* @returns {void}
|
| 465 |
+
*/
|
| 466 |
+
limit(limit) {
|
| 467 |
+
if (limit === 0) {
|
| 468 |
+
throw new ChangeWarning(
|
| 469 |
+
"WRN_ERL_MAX_ZERO",
|
| 470 |
+
"Setting limit or max to 0 disables rate limiting in express-rate-limit v6 and older, but will cause all requests to be blocked in v7"
|
| 471 |
+
);
|
| 472 |
+
}
|
| 473 |
+
},
|
| 474 |
+
/**
|
| 475 |
+
* Warns the user that the `draft_polli_ratelimit_headers` option is deprecated
|
| 476 |
+
* and will be removed in the next major release.
|
| 477 |
+
*
|
| 478 |
+
* @param draft_polli_ratelimit_headers {any | undefined} - The now-deprecated setting that was used to enable standard headers.
|
| 479 |
+
*
|
| 480 |
+
* @returns {void}
|
| 481 |
+
*/
|
| 482 |
+
draftPolliHeaders(draft_polli_ratelimit_headers) {
|
| 483 |
+
if (draft_polli_ratelimit_headers) {
|
| 484 |
+
throw new ChangeWarning(
|
| 485 |
+
"WRN_ERL_DEPRECATED_DRAFT_POLLI_HEADERS",
|
| 486 |
+
`The draft_polli_ratelimit_headers configuration option is deprecated and has been removed in express-rate-limit v7, please set standardHeaders: 'draft-6' instead.`
|
| 487 |
+
);
|
| 488 |
+
}
|
| 489 |
+
},
|
| 490 |
+
/**
|
| 491 |
+
* Warns the user that the `onLimitReached` option is deprecated and
|
| 492 |
+
* will be removed in the next major release.
|
| 493 |
+
*
|
| 494 |
+
* @param onLimitReached {any | undefined} - The maximum number of hits per client.
|
| 495 |
+
*
|
| 496 |
+
* @returns {void}
|
| 497 |
+
*/
|
| 498 |
+
onLimitReached(onLimitReached) {
|
| 499 |
+
if (onLimitReached) {
|
| 500 |
+
throw new ChangeWarning(
|
| 501 |
+
"WRN_ERL_DEPRECATED_ON_LIMIT_REACHED",
|
| 502 |
+
"The onLimitReached configuration option is deprecated and has been removed in express-rate-limit v7."
|
| 503 |
+
);
|
| 504 |
+
}
|
| 505 |
+
},
|
| 506 |
+
/**
|
| 507 |
+
* Warns the user when an invalid/unsupported version of the draft spec is passed.
|
| 508 |
+
*
|
| 509 |
+
* @param version {any | undefined} - The version passed by the user.
|
| 510 |
+
*
|
| 511 |
+
* @returns {void}
|
| 512 |
+
*/
|
| 513 |
+
headersDraftVersion(version) {
|
| 514 |
+
if (typeof version !== "string" || // @ts-expect-error This is fine. If version is not in the array, it will just return false.
|
| 515 |
+
!SUPPORTED_DRAFT_VERSIONS.includes(version)) {
|
| 516 |
+
const versionString = SUPPORTED_DRAFT_VERSIONS.join(", ");
|
| 517 |
+
throw new ValidationError(
|
| 518 |
+
"ERR_ERL_HEADERS_UNSUPPORTED_DRAFT_VERSION",
|
| 519 |
+
`standardHeaders: only the following versions of the IETF draft specification are supported: ${versionString}.`
|
| 520 |
+
);
|
| 521 |
+
}
|
| 522 |
+
},
|
| 523 |
+
/**
|
| 524 |
+
* Warns the user when the selected headers option requires a reset time but
|
| 525 |
+
* the store does not provide one.
|
| 526 |
+
*
|
| 527 |
+
* @param resetTime {Date | undefined} - The timestamp when the client's hit count will be reset.
|
| 528 |
+
*
|
| 529 |
+
* @returns {void}
|
| 530 |
+
*/
|
| 531 |
+
headersResetTime(resetTime) {
|
| 532 |
+
if (!resetTime) {
|
| 533 |
+
throw new ValidationError(
|
| 534 |
+
"ERR_ERL_HEADERS_NO_RESET",
|
| 535 |
+
`standardHeaders: 'draft-7' requires a 'resetTime', but the store did not provide one. The 'windowMs' value will be used instead, which may cause clients to wait longer than necessary.`
|
| 536 |
+
);
|
| 537 |
+
}
|
| 538 |
+
},
|
| 539 |
+
knownOptions(passedOptions) {
|
| 540 |
+
if (!passedOptions) return;
|
| 541 |
+
const optionsMap = {
|
| 542 |
+
windowMs: true,
|
| 543 |
+
limit: true,
|
| 544 |
+
message: true,
|
| 545 |
+
statusCode: true,
|
| 546 |
+
legacyHeaders: true,
|
| 547 |
+
standardHeaders: true,
|
| 548 |
+
identifier: true,
|
| 549 |
+
requestPropertyName: true,
|
| 550 |
+
skipFailedRequests: true,
|
| 551 |
+
skipSuccessfulRequests: true,
|
| 552 |
+
keyGenerator: true,
|
| 553 |
+
ipv6Subnet: true,
|
| 554 |
+
handler: true,
|
| 555 |
+
skip: true,
|
| 556 |
+
requestWasSuccessful: true,
|
| 557 |
+
store: true,
|
| 558 |
+
validate: true,
|
| 559 |
+
headers: true,
|
| 560 |
+
max: true,
|
| 561 |
+
passOnStoreError: true,
|
| 562 |
+
logger: true
|
| 563 |
+
};
|
| 564 |
+
const validOptions = Object.keys(optionsMap).concat(
|
| 565 |
+
"draft_polli_ratelimit_headers",
|
| 566 |
+
// not a valid option anymore, but we have a more specific check for this one, so don't warn for it here
|
| 567 |
+
// from express-slow-down - https://github.com/express-rate-limit/express-slow-down/blob/main/source/types.ts#L65
|
| 568 |
+
"delayAfter",
|
| 569 |
+
"delayMs",
|
| 570 |
+
"maxDelayMs"
|
| 571 |
+
);
|
| 572 |
+
for (const key of Object.keys(passedOptions)) {
|
| 573 |
+
if (!validOptions.includes(key)) {
|
| 574 |
+
throw new ValidationError(
|
| 575 |
+
"ERR_ERL_UNKNOWN_OPTION",
|
| 576 |
+
`Unexpected configuration option: ${key}`
|
| 577 |
+
// todo: suggest a valid option with a short levenstein distance?
|
| 578 |
+
);
|
| 579 |
+
}
|
| 580 |
+
}
|
| 581 |
+
},
|
| 582 |
+
/**
|
| 583 |
+
* Checks the options.validate setting to ensure that only recognized
|
| 584 |
+
* validations are enabled or disabled.
|
| 585 |
+
*
|
| 586 |
+
* If any unrecognized values are found, an error is logged that
|
| 587 |
+
* includes the list of supported validations.
|
| 588 |
+
*/
|
| 589 |
+
validationsConfig() {
|
| 590 |
+
const supportedValidations = Object.keys(this).filter(
|
| 591 |
+
(k) => !["enabled", "disable"].includes(k)
|
| 592 |
+
);
|
| 593 |
+
supportedValidations.push("default");
|
| 594 |
+
for (const key of Object.keys(this.enabled)) {
|
| 595 |
+
if (!supportedValidations.includes(key)) {
|
| 596 |
+
throw new ValidationError(
|
| 597 |
+
"ERR_ERL_UNKNOWN_VALIDATION",
|
| 598 |
+
`options.validate.${key} is not recognized. Supported validate options are: ${supportedValidations.join(
|
| 599 |
+
", "
|
| 600 |
+
)}.`
|
| 601 |
+
);
|
| 602 |
+
}
|
| 603 |
+
}
|
| 604 |
+
},
|
| 605 |
+
/**
|
| 606 |
+
* Checks to see if the instance was created inside of a request handler,
|
| 607 |
+
* which would prevent it from working correctly, with the default memory
|
| 608 |
+
* store (or any other store with localKeys.)
|
| 609 |
+
*/
|
| 610 |
+
creationStack(store) {
|
| 611 |
+
const { stack } = new Error(
|
| 612 |
+
"express-rate-limit validation check (set options.validate.creationStack=false to disable)"
|
| 613 |
+
);
|
| 614 |
+
if (stack?.includes("Layer.handle [as handle_request]") || // express v4
|
| 615 |
+
stack?.includes("Layer.handleRequest")) {
|
| 616 |
+
if (!store.localKeys) {
|
| 617 |
+
throw new ValidationError(
|
| 618 |
+
"ERR_ERL_CREATED_IN_REQUEST_HANDLER",
|
| 619 |
+
"express-rate-limit instance should *usually* be created at app initialization, not when responding to a request."
|
| 620 |
+
);
|
| 621 |
+
}
|
| 622 |
+
throw new ValidationError(
|
| 623 |
+
"ERR_ERL_CREATED_IN_REQUEST_HANDLER",
|
| 624 |
+
"express-rate-limit instance should be created at app initialization, not when responding to a request."
|
| 625 |
+
);
|
| 626 |
+
}
|
| 627 |
+
},
|
| 628 |
+
ipv6Subnet(ipv6Subnet) {
|
| 629 |
+
if (ipv6Subnet === false) {
|
| 630 |
+
return;
|
| 631 |
+
}
|
| 632 |
+
if (!Number.isInteger(ipv6Subnet) || ipv6Subnet < 32 || ipv6Subnet > 64) {
|
| 633 |
+
throw new ValidationError(
|
| 634 |
+
"ERR_ERL_IPV6_SUBNET",
|
| 635 |
+
`Unexpected ipv6Subnet value: ${ipv6Subnet}. Expected an integer between 32 and 64 (usually 48-64).`
|
| 636 |
+
);
|
| 637 |
+
}
|
| 638 |
+
},
|
| 639 |
+
ipv6SubnetOrKeyGenerator(options) {
|
| 640 |
+
if (options.ipv6Subnet !== void 0 && options.keyGenerator) {
|
| 641 |
+
throw new ValidationError(
|
| 642 |
+
"ERR_ERL_IPV6SUBNET_OR_KEYGENERATOR",
|
| 643 |
+
`Incompatible options: the 'ipv6Subnet' option is ignored when a custom 'keyGenerator' function is also set.`
|
| 644 |
+
);
|
| 645 |
+
}
|
| 646 |
+
},
|
| 647 |
+
keyGeneratorIpFallback(keyGenerator) {
|
| 648 |
+
if (!keyGenerator) {
|
| 649 |
+
return;
|
| 650 |
+
}
|
| 651 |
+
const src = keyGenerator.toString();
|
| 652 |
+
if ((src.includes("req.ip") || src.includes("request.ip")) && !src.includes("ipKeyGenerator")) {
|
| 653 |
+
throw new ValidationError(
|
| 654 |
+
"ERR_ERL_KEY_GEN_IPV6",
|
| 655 |
+
"Custom keyGenerator appears to use request IP without calling the ipKeyGenerator helper function for IPv6 addresses. This could allow IPv6 users to bypass limits."
|
| 656 |
+
);
|
| 657 |
+
}
|
| 658 |
+
},
|
| 659 |
+
/**
|
| 660 |
+
* Checks to see if the window duration is greater than 2^32 - 1. This is only
|
| 661 |
+
* called by the default MemoryStore, since it uses Node's setInterval method.
|
| 662 |
+
*
|
| 663 |
+
* See https://nodejs.org/api/timers.html#setintervalcallback-delay-args.
|
| 664 |
+
*/
|
| 665 |
+
windowMs(windowMs) {
|
| 666 |
+
const SET_TIMEOUT_MAX = 2 ** 31 - 1;
|
| 667 |
+
if (typeof windowMs !== "number" || Number.isNaN(windowMs) || windowMs < 1 || windowMs > SET_TIMEOUT_MAX) {
|
| 668 |
+
throw new ValidationError(
|
| 669 |
+
"ERR_ERL_WINDOW_MS",
|
| 670 |
+
`Invalid windowMs value: ${windowMs}${typeof windowMs !== "number" ? ` (${typeof windowMs})` : ""}, must be a number between 1 and ${SET_TIMEOUT_MAX} when using the default MemoryStore`
|
| 671 |
+
);
|
| 672 |
+
}
|
| 673 |
+
}
|
| 674 |
+
};
|
| 675 |
+
function validateLogger(logger) {
|
| 676 |
+
if (typeof logger !== "object" || typeof logger.error !== "function" || typeof logger.warn !== "function") {
|
| 677 |
+
throw new TypeError(
|
| 678 |
+
"Provided logger does not implement the Logger interface"
|
| 679 |
+
);
|
| 680 |
+
}
|
| 681 |
+
}
|
| 682 |
+
var getValidations = (_enabled, logger) => {
|
| 683 |
+
validateLogger(logger);
|
| 684 |
+
let enabled;
|
| 685 |
+
if (typeof _enabled === "boolean") {
|
| 686 |
+
enabled = {
|
| 687 |
+
default: _enabled
|
| 688 |
+
};
|
| 689 |
+
} else {
|
| 690 |
+
enabled = {
|
| 691 |
+
default: true,
|
| 692 |
+
..._enabled
|
| 693 |
+
};
|
| 694 |
+
}
|
| 695 |
+
const wrappedValidations = { enabled };
|
| 696 |
+
for (const [name, validation] of Object.entries(validations)) {
|
| 697 |
+
if (typeof validation === "function")
|
| 698 |
+
wrappedValidations[name] = (...args) => {
|
| 699 |
+
if (!(enabled[name] ?? enabled.default)) {
|
| 700 |
+
return;
|
| 701 |
+
}
|
| 702 |
+
try {
|
| 703 |
+
;
|
| 704 |
+
validation.apply(
|
| 705 |
+
wrappedValidations,
|
| 706 |
+
args
|
| 707 |
+
);
|
| 708 |
+
} catch (error) {
|
| 709 |
+
if (error instanceof ChangeWarning) logger.warn(error);
|
| 710 |
+
else logger.error(error);
|
| 711 |
+
}
|
| 712 |
+
};
|
| 713 |
+
}
|
| 714 |
+
return wrappedValidations;
|
| 715 |
+
};
|
| 716 |
+
|
| 717 |
+
// source/rate-limit.ts
|
| 718 |
+
var isLegacyStore = (store) => (
|
| 719 |
+
// Check that `incr` exists but `increment` does not - store authors might want
|
| 720 |
+
// to keep both around for backwards compatibility.
|
| 721 |
+
typeof store.incr === "function" && typeof store.increment !== "function"
|
| 722 |
+
);
|
| 723 |
+
var promisifyStore = (passedStore) => {
|
| 724 |
+
if (!isLegacyStore(passedStore)) {
|
| 725 |
+
return passedStore;
|
| 726 |
+
}
|
| 727 |
+
const legacyStore = passedStore;
|
| 728 |
+
class PromisifiedStore {
|
| 729 |
+
async increment(key) {
|
| 730 |
+
return new Promise((resolve, reject) => {
|
| 731 |
+
legacyStore.incr(
|
| 732 |
+
key,
|
| 733 |
+
(error, totalHits, resetTime) => {
|
| 734 |
+
if (error) reject(error);
|
| 735 |
+
resolve({ totalHits, resetTime });
|
| 736 |
+
}
|
| 737 |
+
);
|
| 738 |
+
});
|
| 739 |
+
}
|
| 740 |
+
async decrement(key) {
|
| 741 |
+
return legacyStore.decrement(key);
|
| 742 |
+
}
|
| 743 |
+
async resetKey(key) {
|
| 744 |
+
return legacyStore.resetKey(key);
|
| 745 |
+
}
|
| 746 |
+
/* istanbul ignore next */
|
| 747 |
+
async resetAll() {
|
| 748 |
+
if (typeof legacyStore.resetAll === "function")
|
| 749 |
+
return legacyStore.resetAll();
|
| 750 |
+
}
|
| 751 |
+
}
|
| 752 |
+
return new PromisifiedStore();
|
| 753 |
+
};
|
| 754 |
+
var getOptionsFromConfig = (config) => {
|
| 755 |
+
const { validations: validations2, ...directlyPassableEntries } = config;
|
| 756 |
+
return {
|
| 757 |
+
...directlyPassableEntries,
|
| 758 |
+
validate: validations2.enabled
|
| 759 |
+
};
|
| 760 |
+
};
|
| 761 |
+
var parseOptions = (passedOptions) => {
|
| 762 |
+
const notUndefinedOptions = omitUndefinedProperties(passedOptions);
|
| 763 |
+
const logger = passedOptions.logger ?? ConsoleLogger;
|
| 764 |
+
const validations2 = getValidations(
|
| 765 |
+
notUndefinedOptions?.validate ?? true,
|
| 766 |
+
logger
|
| 767 |
+
);
|
| 768 |
+
validations2.validationsConfig();
|
| 769 |
+
validations2.knownOptions(passedOptions);
|
| 770 |
+
validations2.draftPolliHeaders(
|
| 771 |
+
// @ts-expect-error see the note above.
|
| 772 |
+
notUndefinedOptions.draft_polli_ratelimit_headers
|
| 773 |
+
);
|
| 774 |
+
validations2.onLimitReached(notUndefinedOptions.onLimitReached);
|
| 775 |
+
if (notUndefinedOptions.ipv6Subnet !== void 0 && typeof notUndefinedOptions.ipv6Subnet !== "function") {
|
| 776 |
+
validations2.ipv6Subnet(notUndefinedOptions.ipv6Subnet);
|
| 777 |
+
}
|
| 778 |
+
validations2.keyGeneratorIpFallback(notUndefinedOptions.keyGenerator);
|
| 779 |
+
validations2.ipv6SubnetOrKeyGenerator(notUndefinedOptions);
|
| 780 |
+
let standardHeaders = notUndefinedOptions.standardHeaders ?? false;
|
| 781 |
+
if (standardHeaders === true) standardHeaders = "draft-6";
|
| 782 |
+
const config = {
|
| 783 |
+
windowMs: 60 * 1e3,
|
| 784 |
+
limit: passedOptions.max ?? 5,
|
| 785 |
+
// `max` is deprecated, but support it anyways.
|
| 786 |
+
message: "Too many requests, please try again later.",
|
| 787 |
+
statusCode: 429,
|
| 788 |
+
legacyHeaders: passedOptions.headers ?? true,
|
| 789 |
+
identifier(request, _response) {
|
| 790 |
+
let duration = "";
|
| 791 |
+
const property = config.requestPropertyName;
|
| 792 |
+
const { limit } = request[property];
|
| 793 |
+
const seconds = config.windowMs / 1e3;
|
| 794 |
+
const minutes = config.windowMs / (1e3 * 60);
|
| 795 |
+
const hours = config.windowMs / (1e3 * 60 * 60);
|
| 796 |
+
const days = config.windowMs / (1e3 * 60 * 60 * 24);
|
| 797 |
+
if (seconds < 60) duration = `${seconds}sec`;
|
| 798 |
+
else if (minutes < 60) duration = `${minutes}min`;
|
| 799 |
+
else if (hours < 24) duration = `${hours}hr${hours > 1 ? "s" : ""}`;
|
| 800 |
+
else duration = `${days}day${days > 1 ? "s" : ""}`;
|
| 801 |
+
return `${limit}-in-${duration}`;
|
| 802 |
+
},
|
| 803 |
+
requestPropertyName: "rateLimit",
|
| 804 |
+
skipFailedRequests: false,
|
| 805 |
+
skipSuccessfulRequests: false,
|
| 806 |
+
requestWasSuccessful: (_request, response) => response.statusCode < 400,
|
| 807 |
+
skip: (_request, _response) => false,
|
| 808 |
+
async keyGenerator(request, response) {
|
| 809 |
+
validations2.ip(request.ip);
|
| 810 |
+
validations2.trustProxy(request);
|
| 811 |
+
validations2.xForwardedForHeader(request);
|
| 812 |
+
validations2.forwardedHeader(request);
|
| 813 |
+
const ip = request.ip;
|
| 814 |
+
let subnet = 56;
|
| 815 |
+
if ((0, import_node_net3.isIPv6)(ip)) {
|
| 816 |
+
subnet = typeof config.ipv6Subnet === "function" ? await config.ipv6Subnet(request, response) : config.ipv6Subnet;
|
| 817 |
+
if (typeof config.ipv6Subnet === "function")
|
| 818 |
+
validations2.ipv6Subnet(subnet);
|
| 819 |
+
}
|
| 820 |
+
return ipKeyGenerator(ip, subnet);
|
| 821 |
+
},
|
| 822 |
+
ipv6Subnet: 56,
|
| 823 |
+
async handler(request, response, _next, _optionsUsed) {
|
| 824 |
+
response.status(config.statusCode);
|
| 825 |
+
const message = typeof config.message === "function" ? await config.message(
|
| 826 |
+
request,
|
| 827 |
+
response
|
| 828 |
+
) : config.message;
|
| 829 |
+
if (!response.writableEnded) response.send(message);
|
| 830 |
+
},
|
| 831 |
+
passOnStoreError: false,
|
| 832 |
+
// Allow the default options to be overridden by the passed options.
|
| 833 |
+
...notUndefinedOptions,
|
| 834 |
+
// `standardHeaders` is resolved into a draft version above, use that.
|
| 835 |
+
standardHeaders,
|
| 836 |
+
// Note that this field is declared after the user's options are spread in,
|
| 837 |
+
// so that this field doesn't get overridden with an un-promisified store!
|
| 838 |
+
store: promisifyStore(
|
| 839 |
+
notUndefinedOptions.store ?? new MemoryStore(validations2)
|
| 840 |
+
),
|
| 841 |
+
// Print an error to the console if a few known misconfigurations are detected.
|
| 842 |
+
validations: validations2,
|
| 843 |
+
logger
|
| 844 |
+
};
|
| 845 |
+
if (typeof config.store.increment !== "function" || typeof config.store.decrement !== "function" || typeof config.store.resetKey !== "function" || config.store.resetAll !== void 0 && typeof config.store.resetAll !== "function" || config.store.init !== void 0 && typeof config.store.init !== "function") {
|
| 846 |
+
throw new TypeError(
|
| 847 |
+
"An invalid store was passed. Please ensure that the store is a class that implements the `Store` interface."
|
| 848 |
+
);
|
| 849 |
+
}
|
| 850 |
+
return config;
|
| 851 |
+
};
|
| 852 |
+
var handleAsyncErrors = (fn) => async (request, response, next) => {
|
| 853 |
+
try {
|
| 854 |
+
await Promise.resolve(fn(request, response, next)).catch(next);
|
| 855 |
+
} catch (error) {
|
| 856 |
+
next(error);
|
| 857 |
+
}
|
| 858 |
+
};
|
| 859 |
+
var rateLimit = (passedOptions) => {
|
| 860 |
+
const config = parseOptions(passedOptions ?? {});
|
| 861 |
+
const options = getOptionsFromConfig(config);
|
| 862 |
+
config.validations.creationStack(config.store);
|
| 863 |
+
config.validations.unsharedStore(config.store);
|
| 864 |
+
if (typeof config.store.init === "function") {
|
| 865 |
+
try {
|
| 866 |
+
const storeInit = config.store.init(options);
|
| 867 |
+
if (storeInit instanceof Promise) {
|
| 868 |
+
storeInit.catch(
|
| 869 |
+
(error) => config.logger.error(
|
| 870 |
+
error,
|
| 871 |
+
"express-rate-limit: async error during store initialization."
|
| 872 |
+
)
|
| 873 |
+
);
|
| 874 |
+
}
|
| 875 |
+
} catch (error) {
|
| 876 |
+
config.logger.error(
|
| 877 |
+
error,
|
| 878 |
+
"express-rate-limit: error during store initialization."
|
| 879 |
+
);
|
| 880 |
+
}
|
| 881 |
+
}
|
| 882 |
+
const middleware = handleAsyncErrors(
|
| 883 |
+
async (request, response, next) => {
|
| 884 |
+
const closePromise = config.skipFailedRequests && new Promise((resolve) => response.once("close", resolve));
|
| 885 |
+
const finishPromise = (config.skipFailedRequests || config.skipSuccessfulRequests) && new Promise((resolve) => response.once("finish", resolve));
|
| 886 |
+
const errorPromise = config.skipFailedRequests && new Promise((resolve) => response.once("error", resolve));
|
| 887 |
+
const skip = await config.skip(request, response);
|
| 888 |
+
if (skip) {
|
| 889 |
+
next();
|
| 890 |
+
return;
|
| 891 |
+
}
|
| 892 |
+
const augmentedRequest = request;
|
| 893 |
+
const key = await config.keyGenerator(request, response);
|
| 894 |
+
let totalHits = 0;
|
| 895 |
+
let resetTime;
|
| 896 |
+
try {
|
| 897 |
+
const incrementResult = await config.store.increment(key);
|
| 898 |
+
totalHits = incrementResult.totalHits;
|
| 899 |
+
resetTime = incrementResult.resetTime;
|
| 900 |
+
} catch (error) {
|
| 901 |
+
if (config.passOnStoreError) {
|
| 902 |
+
config.logger.error(
|
| 903 |
+
error,
|
| 904 |
+
"express-rate-limit: error from store, allowing request without rate-limiting."
|
| 905 |
+
);
|
| 906 |
+
next();
|
| 907 |
+
return;
|
| 908 |
+
}
|
| 909 |
+
throw error;
|
| 910 |
+
}
|
| 911 |
+
config.validations.positiveHits(totalHits);
|
| 912 |
+
config.validations.singleCount(request, config.store, key);
|
| 913 |
+
const retrieveLimit = typeof config.limit === "function" ? config.limit(request, response) : config.limit;
|
| 914 |
+
const limit = await retrieveLimit;
|
| 915 |
+
config.validations.limit(limit);
|
| 916 |
+
const info = {
|
| 917 |
+
limit,
|
| 918 |
+
used: totalHits,
|
| 919 |
+
remaining: Math.max(limit - totalHits, 0),
|
| 920 |
+
resetTime,
|
| 921 |
+
key
|
| 922 |
+
};
|
| 923 |
+
Object.defineProperty(info, "current", {
|
| 924 |
+
configurable: false,
|
| 925 |
+
enumerable: false,
|
| 926 |
+
value: totalHits
|
| 927 |
+
});
|
| 928 |
+
augmentedRequest[config.requestPropertyName] = info;
|
| 929 |
+
if (config.legacyHeaders && !response.headersSent) {
|
| 930 |
+
setLegacyHeaders(response, info);
|
| 931 |
+
}
|
| 932 |
+
if (config.standardHeaders && !response.headersSent) {
|
| 933 |
+
switch (config.standardHeaders) {
|
| 934 |
+
case "draft-6": {
|
| 935 |
+
setDraft6Headers(response, info, config.windowMs);
|
| 936 |
+
break;
|
| 937 |
+
}
|
| 938 |
+
case "draft-7": {
|
| 939 |
+
config.validations.headersResetTime(info.resetTime);
|
| 940 |
+
setDraft7Headers(response, info, config.windowMs);
|
| 941 |
+
break;
|
| 942 |
+
}
|
| 943 |
+
case "draft-8": {
|
| 944 |
+
const retrieveName = typeof config.identifier === "function" ? config.identifier(request, response) : config.identifier;
|
| 945 |
+
const name = await retrieveName;
|
| 946 |
+
config.validations.headersResetTime(info.resetTime);
|
| 947 |
+
setDraft8Headers(response, info, config.windowMs, name, key);
|
| 948 |
+
break;
|
| 949 |
+
}
|
| 950 |
+
default: {
|
| 951 |
+
config.validations.headersDraftVersion(config.standardHeaders);
|
| 952 |
+
break;
|
| 953 |
+
}
|
| 954 |
+
}
|
| 955 |
+
}
|
| 956 |
+
if (config.skipFailedRequests || config.skipSuccessfulRequests) {
|
| 957 |
+
let decremented = false;
|
| 958 |
+
const decrementKey = async () => {
|
| 959 |
+
if (!decremented) {
|
| 960 |
+
await config.store.decrement(key);
|
| 961 |
+
decremented = true;
|
| 962 |
+
}
|
| 963 |
+
};
|
| 964 |
+
if (config.skipFailedRequests) {
|
| 965 |
+
if (finishPromise) {
|
| 966 |
+
void finishPromise.then(async () => {
|
| 967 |
+
if (!await config.requestWasSuccessful(request, response))
|
| 968 |
+
await decrementKey();
|
| 969 |
+
});
|
| 970 |
+
}
|
| 971 |
+
if (closePromise) {
|
| 972 |
+
void closePromise.then(async () => {
|
| 973 |
+
if (!response.writableEnded) await decrementKey();
|
| 974 |
+
});
|
| 975 |
+
}
|
| 976 |
+
if (errorPromise) {
|
| 977 |
+
void errorPromise.then(async () => {
|
| 978 |
+
await decrementKey();
|
| 979 |
+
});
|
| 980 |
+
}
|
| 981 |
+
}
|
| 982 |
+
if (config.skipSuccessfulRequests) {
|
| 983 |
+
if (finishPromise) {
|
| 984 |
+
void finishPromise.then(async () => {
|
| 985 |
+
if (await config.requestWasSuccessful(request, response))
|
| 986 |
+
await decrementKey();
|
| 987 |
+
});
|
| 988 |
+
}
|
| 989 |
+
}
|
| 990 |
+
}
|
| 991 |
+
config.validations.disable();
|
| 992 |
+
if (totalHits > limit) {
|
| 993 |
+
if (config.legacyHeaders || config.standardHeaders) {
|
| 994 |
+
setRetryAfterHeader(response, info, config.windowMs);
|
| 995 |
+
}
|
| 996 |
+
config.handler(request, response, next, options);
|
| 997 |
+
return;
|
| 998 |
+
}
|
| 999 |
+
next();
|
| 1000 |
+
}
|
| 1001 |
+
);
|
| 1002 |
+
const getThrowFn = () => {
|
| 1003 |
+
throw new Error("The current store does not support the get/getKey method");
|
| 1004 |
+
};
|
| 1005 |
+
middleware.resetKey = config.store.resetKey.bind(config.store);
|
| 1006 |
+
middleware.getKey = typeof config.store.get === "function" ? config.store.get.bind(config.store) : getThrowFn;
|
| 1007 |
+
return middleware;
|
| 1008 |
+
};
|
| 1009 |
+
var rate_limit_default = rateLimit;
|
| 1010 |
+
// Annotate the CommonJS export names for ESM import in node:
|
| 1011 |
+
0 && (module.exports = {
|
| 1012 |
+
MemoryStore,
|
| 1013 |
+
ipKeyGenerator,
|
| 1014 |
+
rateLimit
|
| 1015 |
+
});
|
| 1016 |
+
module.exports = Object.assign(rateLimit, module.exports);
|
tools/ui/node_modules/express-rate-limit/dist/index.d.cts
ADDED
|
@@ -0,0 +1,672 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Generated by dts-bundle-generator v8.1.2
|
| 2 |
+
|
| 3 |
+
import { NextFunction, Request, RequestHandler, Response } from 'express';
|
| 4 |
+
|
| 5 |
+
/**
|
| 6 |
+
* Returns the IP address itself for IPv4, or a CIDR-notation subnet for IPv6.
|
| 7 |
+
*
|
| 8 |
+
* If you write a custom keyGenerator that allows a fallback to IP address for
|
| 9 |
+
* unauthenticated users, return ipKeyGenerator(req.ip) rather than just req.ip.
|
| 10 |
+
*
|
| 11 |
+
* For more information, {@see Options.ipv6Subnet}.
|
| 12 |
+
*
|
| 13 |
+
* @param ip {string} - The IP address to process, usually request.ip.
|
| 14 |
+
* @param ipv6Subnet {number | false} - The subnet mask for IPv6 addresses.
|
| 15 |
+
*
|
| 16 |
+
* @returns {string} - The key generated from the IP address
|
| 17 |
+
*
|
| 18 |
+
* @public
|
| 19 |
+
*/
|
| 20 |
+
export declare function ipKeyGenerator(ip: string, ipv6Subnet?: number | false): string;
|
| 21 |
+
declare const SUPPORTED_DRAFT_VERSIONS: readonly [
|
| 22 |
+
"draft-6",
|
| 23 |
+
"draft-7",
|
| 24 |
+
"draft-8"
|
| 25 |
+
];
|
| 26 |
+
declare const validations: {
|
| 27 |
+
enabled: {
|
| 28 |
+
[key: string]: boolean;
|
| 29 |
+
};
|
| 30 |
+
disable(): void;
|
| 31 |
+
/**
|
| 32 |
+
* Checks whether the IP address is valid, and that it does not have a port
|
| 33 |
+
* number in it.
|
| 34 |
+
*
|
| 35 |
+
* See https://github.com/express-rate-limit/express-rate-limit/wiki/Error-Codes#err_erl_invalid_ip_address.
|
| 36 |
+
*
|
| 37 |
+
* @param ip {string | undefined} - The IP address provided by Express as request.ip.
|
| 38 |
+
*
|
| 39 |
+
* @returns {void}
|
| 40 |
+
*/
|
| 41 |
+
ip(ip: string | undefined): void;
|
| 42 |
+
/**
|
| 43 |
+
* Makes sure the trust proxy setting is not set to `true`.
|
| 44 |
+
*
|
| 45 |
+
* See https://github.com/express-rate-limit/express-rate-limit/wiki/Error-Codes#err_erl_permissive_trust_proxy.
|
| 46 |
+
*
|
| 47 |
+
* @param request {Request} - The Express request object.
|
| 48 |
+
*
|
| 49 |
+
* @returns {void}
|
| 50 |
+
*/
|
| 51 |
+
trustProxy(request: Request): void;
|
| 52 |
+
/**
|
| 53 |
+
* Makes sure the trust proxy setting is set in case the `X-Forwarded-For`
|
| 54 |
+
* header is present.
|
| 55 |
+
*
|
| 56 |
+
* See https://github.com/express-rate-limit/express-rate-limit/wiki/Error-Codes#err_erl_unset_trust_proxy.
|
| 57 |
+
*
|
| 58 |
+
* @param request {Request} - The Express request object.
|
| 59 |
+
*
|
| 60 |
+
* @returns {void}
|
| 61 |
+
*/
|
| 62 |
+
xForwardedForHeader(request: Request): void;
|
| 63 |
+
/**
|
| 64 |
+
* Alert the user if the Forwarded header is set (standardized version of X-Forwarded-For - not supported by express as of version 5.1.0)
|
| 65 |
+
*
|
| 66 |
+
* @param request {Request} - The Express request object.
|
| 67 |
+
*
|
| 68 |
+
* @returns {void}
|
| 69 |
+
*/
|
| 70 |
+
forwardedHeader(request: Request): void;
|
| 71 |
+
/**
|
| 72 |
+
* Ensures totalHits value from store is a positive integer.
|
| 73 |
+
*
|
| 74 |
+
* @param hits {any} - The `totalHits` returned by the store.
|
| 75 |
+
*/
|
| 76 |
+
positiveHits(hits: any): void;
|
| 77 |
+
/**
|
| 78 |
+
* Ensures a single store instance is not used with multiple express-rate-limit instances
|
| 79 |
+
*/
|
| 80 |
+
unsharedStore(store: Store): void;
|
| 81 |
+
/**
|
| 82 |
+
* Ensures a given key is incremented only once per request.
|
| 83 |
+
*
|
| 84 |
+
* @param request {Request} - The Express request object.
|
| 85 |
+
* @param store {Store} - The store class.
|
| 86 |
+
* @param key {string} - The key used to store the client's hit count.
|
| 87 |
+
*
|
| 88 |
+
* @returns {void}
|
| 89 |
+
*/
|
| 90 |
+
singleCount(request: Request, store: Store, key: string): void;
|
| 91 |
+
/**
|
| 92 |
+
* Warns the user that the behaviour for `max: 0` / `limit: 0` is
|
| 93 |
+
* changing in the next major release.
|
| 94 |
+
*
|
| 95 |
+
* @param limit {number} - The maximum number of hits per client.
|
| 96 |
+
*
|
| 97 |
+
* @returns {void}
|
| 98 |
+
*/
|
| 99 |
+
limit(limit: number): void;
|
| 100 |
+
/**
|
| 101 |
+
* Warns the user that the `draft_polli_ratelimit_headers` option is deprecated
|
| 102 |
+
* and will be removed in the next major release.
|
| 103 |
+
*
|
| 104 |
+
* @param draft_polli_ratelimit_headers {any | undefined} - The now-deprecated setting that was used to enable standard headers.
|
| 105 |
+
*
|
| 106 |
+
* @returns {void}
|
| 107 |
+
*/
|
| 108 |
+
draftPolliHeaders(draft_polli_ratelimit_headers?: any): void;
|
| 109 |
+
/**
|
| 110 |
+
* Warns the user that the `onLimitReached` option is deprecated and
|
| 111 |
+
* will be removed in the next major release.
|
| 112 |
+
*
|
| 113 |
+
* @param onLimitReached {any | undefined} - The maximum number of hits per client.
|
| 114 |
+
*
|
| 115 |
+
* @returns {void}
|
| 116 |
+
*/
|
| 117 |
+
onLimitReached(onLimitReached?: any): void;
|
| 118 |
+
/**
|
| 119 |
+
* Warns the user when an invalid/unsupported version of the draft spec is passed.
|
| 120 |
+
*
|
| 121 |
+
* @param version {any | undefined} - The version passed by the user.
|
| 122 |
+
*
|
| 123 |
+
* @returns {void}
|
| 124 |
+
*/
|
| 125 |
+
headersDraftVersion(version?: any): void;
|
| 126 |
+
/**
|
| 127 |
+
* Warns the user when the selected headers option requires a reset time but
|
| 128 |
+
* the store does not provide one.
|
| 129 |
+
*
|
| 130 |
+
* @param resetTime {Date | undefined} - The timestamp when the client's hit count will be reset.
|
| 131 |
+
*
|
| 132 |
+
* @returns {void}
|
| 133 |
+
*/
|
| 134 |
+
headersResetTime(resetTime?: Date): void;
|
| 135 |
+
knownOptions(passedOptions?: Partial<Options>): void;
|
| 136 |
+
/**
|
| 137 |
+
* Checks the options.validate setting to ensure that only recognized
|
| 138 |
+
* validations are enabled or disabled.
|
| 139 |
+
*
|
| 140 |
+
* If any unrecognized values are found, an error is logged that
|
| 141 |
+
* includes the list of supported validations.
|
| 142 |
+
*/
|
| 143 |
+
validationsConfig(): void;
|
| 144 |
+
/**
|
| 145 |
+
* Checks to see if the instance was created inside of a request handler,
|
| 146 |
+
* which would prevent it from working correctly, with the default memory
|
| 147 |
+
* store (or any other store with localKeys.)
|
| 148 |
+
*/
|
| 149 |
+
creationStack(store: Store): void;
|
| 150 |
+
ipv6Subnet(ipv6Subnet?: any): void;
|
| 151 |
+
ipv6SubnetOrKeyGenerator(options: Partial<Options>): void;
|
| 152 |
+
keyGeneratorIpFallback(keyGenerator?: ValueDeterminingMiddleware<string>): void;
|
| 153 |
+
/**
|
| 154 |
+
* Checks to see if the window duration is greater than 2^32 - 1. This is only
|
| 155 |
+
* called by the default MemoryStore, since it uses Node's setInterval method.
|
| 156 |
+
*
|
| 157 |
+
* See https://nodejs.org/api/timers.html#setintervalcallback-delay-args.
|
| 158 |
+
*/
|
| 159 |
+
windowMs(windowMs: number): void;
|
| 160 |
+
};
|
| 161 |
+
export type Validations = typeof validations;
|
| 162 |
+
/**
|
| 163 |
+
* Basic logging function
|
| 164 |
+
*
|
| 165 |
+
* @param error {unknown} - The error to log
|
| 166 |
+
* @param message {string | undefined} - Additional details about the error
|
| 167 |
+
*/
|
| 168 |
+
export type LoggerFn = (error: unknown, message?: string) => void;
|
| 169 |
+
/**
|
| 170 |
+
* Minimal interface for logging warnings and errors
|
| 171 |
+
*/
|
| 172 |
+
export type Logger = {
|
| 173 |
+
/**
|
| 174 |
+
* Function to log an error
|
| 175 |
+
*/
|
| 176 |
+
error: LoggerFn;
|
| 177 |
+
/**
|
| 178 |
+
* Function to log a warning
|
| 179 |
+
*/
|
| 180 |
+
warn: LoggerFn;
|
| 181 |
+
};
|
| 182 |
+
/**
|
| 183 |
+
* Callback that fires when a client's hit counter is incremented.
|
| 184 |
+
*
|
| 185 |
+
* @param error {Error | undefined} - The error that occurred, if any.
|
| 186 |
+
* @param totalHits {number} - The number of hits for that client so far.
|
| 187 |
+
* @param resetTime {Date | undefined} - The time when the counter resets.
|
| 188 |
+
*/
|
| 189 |
+
export type IncrementCallback = (error: Error | undefined, totalHits: number, resetTime: Date | undefined) => void;
|
| 190 |
+
/**
|
| 191 |
+
* Method (in the form of middleware) to generate/retrieve a value based on the
|
| 192 |
+
* incoming request.
|
| 193 |
+
*
|
| 194 |
+
* @param request {Request} - The Express request object.
|
| 195 |
+
* @param response {Response} - The Express response object.
|
| 196 |
+
*
|
| 197 |
+
* @returns {T} - The value needed.
|
| 198 |
+
*/
|
| 199 |
+
export type ValueDeterminingMiddleware<T> = (request: Request, response: Response) => T | Promise<T>;
|
| 200 |
+
/**
|
| 201 |
+
* Express request handler that sends back a response when a client is
|
| 202 |
+
* rate-limited.
|
| 203 |
+
*
|
| 204 |
+
* @param request {Request} - The Express request object.
|
| 205 |
+
* @param response {Response} - The Express response object.
|
| 206 |
+
* @param next {NextFunction} - The Express `next` function, can be called to skip responding.
|
| 207 |
+
* @param optionsUsed {Options} - The options used to set up the middleware.
|
| 208 |
+
*/
|
| 209 |
+
export type RateLimitExceededEventHandler = (request: Request, response: Response, next: NextFunction, optionsUsed: Options) => void;
|
| 210 |
+
/**
|
| 211 |
+
* Event callback that is triggered on a client's first request that exceeds the limit
|
| 212 |
+
* but not for subsequent requests. May be used for logging, etc. Should *not*
|
| 213 |
+
* send a response.
|
| 214 |
+
*
|
| 215 |
+
* @param request {Request} - The Express request object.
|
| 216 |
+
* @param response {Response} - The Express response object.
|
| 217 |
+
* @param optionsUsed {Options} - The options used to set up the middleware.
|
| 218 |
+
*/
|
| 219 |
+
export type RateLimitReachedEventHandler = (request: Request, response: Response, optionsUsed: Options) => void;
|
| 220 |
+
/**
|
| 221 |
+
* Data returned from the `Store` when a client's hit counter is incremented.
|
| 222 |
+
*
|
| 223 |
+
* @property totalHits {number} - The number of hits for that client so far.
|
| 224 |
+
* @property resetTime {Date | undefined} - The time when the counter resets.
|
| 225 |
+
*/
|
| 226 |
+
export type ClientRateLimitInfo = {
|
| 227 |
+
totalHits: number;
|
| 228 |
+
resetTime: Date | undefined;
|
| 229 |
+
};
|
| 230 |
+
export type IncrementResponse = ClientRateLimitInfo;
|
| 231 |
+
/**
|
| 232 |
+
* A modified Express request handler with the rate limit functions.
|
| 233 |
+
*/
|
| 234 |
+
export type RateLimitRequestHandler = RequestHandler & {
|
| 235 |
+
/**
|
| 236 |
+
* Method to reset a client's hit counter.
|
| 237 |
+
*
|
| 238 |
+
* @param key {string} - The identifier for a client.
|
| 239 |
+
*/
|
| 240 |
+
resetKey: (key: string) => void;
|
| 241 |
+
/**
|
| 242 |
+
* Method to fetch a client's hit count and reset time.
|
| 243 |
+
*
|
| 244 |
+
* @param key {string} - The identifier for a client.
|
| 245 |
+
*
|
| 246 |
+
* @returns {ClientRateLimitInfo} - The number of hits and reset time for that client.
|
| 247 |
+
*/
|
| 248 |
+
getKey: (key: string) => Promise<ClientRateLimitInfo | undefined> | ClientRateLimitInfo | undefined;
|
| 249 |
+
};
|
| 250 |
+
/**
|
| 251 |
+
* An interface that all hit counter stores must implement.
|
| 252 |
+
*
|
| 253 |
+
* @deprecated 6.x - Implement the `Store` interface instead.
|
| 254 |
+
*/
|
| 255 |
+
export type LegacyStore = {
|
| 256 |
+
/**
|
| 257 |
+
* Method to increment a client's hit counter.
|
| 258 |
+
*
|
| 259 |
+
* @param key {string} - The identifier for a client.
|
| 260 |
+
* @param callback {IncrementCallback} - The callback to call once the counter is incremented.
|
| 261 |
+
*/
|
| 262 |
+
incr: (key: string, callback: IncrementCallback) => void;
|
| 263 |
+
/**
|
| 264 |
+
* Method to decrement a client's hit counter.
|
| 265 |
+
*
|
| 266 |
+
* @param key {string} - The identifier for a client.
|
| 267 |
+
*/
|
| 268 |
+
decrement: (key: string) => void;
|
| 269 |
+
/**
|
| 270 |
+
* Method to reset a client's hit counter.
|
| 271 |
+
*
|
| 272 |
+
* @param key {string} - The identifier for a client.
|
| 273 |
+
*/
|
| 274 |
+
resetKey: (key: string) => void;
|
| 275 |
+
/**
|
| 276 |
+
* Method to reset everyone's hit counter.
|
| 277 |
+
*/
|
| 278 |
+
resetAll?: () => void;
|
| 279 |
+
};
|
| 280 |
+
/**
|
| 281 |
+
* An interface that all hit counter stores must implement.
|
| 282 |
+
*/
|
| 283 |
+
export type Store = {
|
| 284 |
+
/**
|
| 285 |
+
* Method that initializes the store, and has access to the options passed to
|
| 286 |
+
* the middleware too.
|
| 287 |
+
*
|
| 288 |
+
* Called once during initialization.
|
| 289 |
+
*
|
| 290 |
+
* Errors / promise rejections will be caught and logged.
|
| 291 |
+
*
|
| 292 |
+
* Note that the result is not awaited - other store methods (such as increment) may be called before init returns and/or after it throws/rejects.
|
| 293 |
+
*
|
| 294 |
+
* @param options {Options} - The options used to setup the middleware.
|
| 295 |
+
*/
|
| 296 |
+
init?: (options: Options) => void | Promise<void>;
|
| 297 |
+
/**
|
| 298 |
+
* Method to fetch a client's hit count and reset time.
|
| 299 |
+
*
|
| 300 |
+
* @param key {string} - The identifier for a client.
|
| 301 |
+
*
|
| 302 |
+
* @returns {ClientRateLimitInfo} - The number of hits and reset time for that client.
|
| 303 |
+
*/
|
| 304 |
+
get?: (key: string) => Promise<ClientRateLimitInfo | undefined> | ClientRateLimitInfo | undefined;
|
| 305 |
+
/**
|
| 306 |
+
* Method to increment a client's hit counter.
|
| 307 |
+
*
|
| 308 |
+
* @param key {string} - The identifier for a client.
|
| 309 |
+
*
|
| 310 |
+
* @returns {IncrementResponse | undefined} - The number of hits and reset time for that client.
|
| 311 |
+
*/
|
| 312 |
+
increment: (key: string) => Promise<IncrementResponse> | IncrementResponse;
|
| 313 |
+
/**
|
| 314 |
+
* Method to decrement a client's hit counter.
|
| 315 |
+
*
|
| 316 |
+
* @param key {string} - The identifier for a client.
|
| 317 |
+
*/
|
| 318 |
+
decrement: (key: string) => Promise<void> | void;
|
| 319 |
+
/**
|
| 320 |
+
* Method to reset a client's hit counter.
|
| 321 |
+
*
|
| 322 |
+
* @param key {string} - The identifier for a client.
|
| 323 |
+
*/
|
| 324 |
+
resetKey: (key: string) => Promise<void> | void;
|
| 325 |
+
/**
|
| 326 |
+
* Method to reset everyone's hit counter.
|
| 327 |
+
*/
|
| 328 |
+
resetAll?: () => Promise<void> | void;
|
| 329 |
+
/**
|
| 330 |
+
* Method to shutdown the store, stop timers, and release all resources.
|
| 331 |
+
*/
|
| 332 |
+
shutdown?: () => Promise<void> | void;
|
| 333 |
+
/**
|
| 334 |
+
* Flag to indicate that keys incremented in one instance of this store can
|
| 335 |
+
* not affect other instances. Typically false if a database is used, true for
|
| 336 |
+
* MemoryStore.
|
| 337 |
+
*
|
| 338 |
+
* Used to help detect double-counting misconfigurations.
|
| 339 |
+
*/
|
| 340 |
+
localKeys?: boolean;
|
| 341 |
+
/**
|
| 342 |
+
* Optional value that the store prepends to keys
|
| 343 |
+
*
|
| 344 |
+
* Used by the double-count check to avoid false-positives when a key is counted
|
| 345 |
+
* twice, but with different prefixes.
|
| 346 |
+
*/
|
| 347 |
+
prefix?: string;
|
| 348 |
+
};
|
| 349 |
+
export type DraftHeadersVersion = (typeof SUPPORTED_DRAFT_VERSIONS)[number];
|
| 350 |
+
/**
|
| 351 |
+
* Validate configuration object for enabling or disabling specific validations.
|
| 352 |
+
*
|
| 353 |
+
* The keys must also be keys in the validations object, except `enable`, `disable`,
|
| 354 |
+
* and `default`.
|
| 355 |
+
*/
|
| 356 |
+
export type EnabledValidations = {
|
| 357 |
+
[key in keyof Omit<Validations, "enabled" | "disable"> | "default"]?: boolean;
|
| 358 |
+
};
|
| 359 |
+
/**
|
| 360 |
+
* The configuration options for the rate limiter.
|
| 361 |
+
*/
|
| 362 |
+
export type Options = {
|
| 363 |
+
/**
|
| 364 |
+
* How long we should remember the requests.
|
| 365 |
+
*
|
| 366 |
+
* Defaults to `60000` ms (= 1 minute).
|
| 367 |
+
*/
|
| 368 |
+
windowMs: number;
|
| 369 |
+
/**
|
| 370 |
+
* The maximum number of connections to allow during the `window` before
|
| 371 |
+
* rate limiting the client.
|
| 372 |
+
*
|
| 373 |
+
* Can be the limit itself as a number or express middleware that parses
|
| 374 |
+
* the request and then figures out the limit.
|
| 375 |
+
*
|
| 376 |
+
* Defaults to `5`.
|
| 377 |
+
*/
|
| 378 |
+
limit: number | ValueDeterminingMiddleware<number>;
|
| 379 |
+
/**
|
| 380 |
+
* The response body to send back when a client is rate limited.
|
| 381 |
+
*
|
| 382 |
+
* Defaults to `'Too many requests, please try again later.'`
|
| 383 |
+
*/
|
| 384 |
+
message: any | ValueDeterminingMiddleware<any>;
|
| 385 |
+
/**
|
| 386 |
+
* The HTTP status code to send back when a client is rate limited.
|
| 387 |
+
*
|
| 388 |
+
* Defaults to `HTTP 429 Too Many Requests` (RFC 6585).
|
| 389 |
+
*/
|
| 390 |
+
statusCode: number;
|
| 391 |
+
/**
|
| 392 |
+
* Whether to send `X-RateLimit-*` headers with the rate limit and the number
|
| 393 |
+
* of requests.
|
| 394 |
+
*
|
| 395 |
+
* Defaults to `true` (for backward compatibility).
|
| 396 |
+
*/
|
| 397 |
+
legacyHeaders: boolean;
|
| 398 |
+
/**
|
| 399 |
+
* Whether to enable support for the standardized rate limit headers (`RateLimit-*`).
|
| 400 |
+
*
|
| 401 |
+
* Defaults to `false` (for backward compatibility, but its use is recommended).
|
| 402 |
+
*/
|
| 403 |
+
standardHeaders: boolean | DraftHeadersVersion;
|
| 404 |
+
/**
|
| 405 |
+
* The name used to identify the quota policy in the `RateLimit` headers as per
|
| 406 |
+
* the 8th draft of the IETF specification.
|
| 407 |
+
*
|
| 408 |
+
* Defaults to `{limit}-in-{window}`.
|
| 409 |
+
*/
|
| 410 |
+
identifier: string | ValueDeterminingMiddleware<string>;
|
| 411 |
+
/**
|
| 412 |
+
* The name of the property on the request object to store the rate limit info.
|
| 413 |
+
*
|
| 414 |
+
* Defaults to `rateLimit`.
|
| 415 |
+
*/
|
| 416 |
+
requestPropertyName: string;
|
| 417 |
+
/**
|
| 418 |
+
* If `true`, the library will (by default) skip all requests that have a 4XX
|
| 419 |
+
* or 5XX status.
|
| 420 |
+
*
|
| 421 |
+
* Defaults to `false`.
|
| 422 |
+
*/
|
| 423 |
+
skipFailedRequests: boolean;
|
| 424 |
+
/**
|
| 425 |
+
* If `true`, the library will (by default) skip all requests that have a
|
| 426 |
+
* status code less than 400.
|
| 427 |
+
*
|
| 428 |
+
* Defaults to `false`.
|
| 429 |
+
*/
|
| 430 |
+
skipSuccessfulRequests: boolean;
|
| 431 |
+
/**
|
| 432 |
+
* Method to generate custom identifiers for clients.
|
| 433 |
+
*
|
| 434 |
+
* By default, the client's IP address is used.
|
| 435 |
+
*/
|
| 436 |
+
keyGenerator: ValueDeterminingMiddleware<string>;
|
| 437 |
+
/**
|
| 438 |
+
* IPv6 subnet mask applied to IPv6 addresses in the default keyGenerator.
|
| 439 |
+
*
|
| 440 |
+
* Default is 56. The valid range is technically 1-128 but the value should
|
| 441 |
+
* generally be in the 32-64 range.
|
| 442 |
+
*
|
| 443 |
+
* Smaller numbers are more aggressive, larger numbers are more lenient. Try
|
| 444 |
+
* bumping to 60 or 64 if you see evidence of users being blocked incorrectly.
|
| 445 |
+
*
|
| 446 |
+
* May also be set to a function that returns a number based on the request.
|
| 447 |
+
*
|
| 448 |
+
* See the documentation for more info:
|
| 449 |
+
* https://express-rate-limit.mintlify.app/reference/configuration#ipv6subnet.
|
| 450 |
+
*/
|
| 451 |
+
ipv6Subnet: 64 | 60 | 56 | 52 | 50 | 48 | 32 | number | ValueDeterminingMiddleware<number> | false;
|
| 452 |
+
/**
|
| 453 |
+
* Express request handler that sends back a response when a client is
|
| 454 |
+
* rate-limited.
|
| 455 |
+
*
|
| 456 |
+
* By default, sends back the `statusCode` and `message` set via the options.
|
| 457 |
+
*/
|
| 458 |
+
handler: RateLimitExceededEventHandler;
|
| 459 |
+
/**
|
| 460 |
+
* Method (in the form of middleware) to determine whether or not this request
|
| 461 |
+
* counts towards a client's quota.
|
| 462 |
+
*
|
| 463 |
+
* By default, skips no requests.
|
| 464 |
+
*/
|
| 465 |
+
skip: ValueDeterminingMiddleware<boolean>;
|
| 466 |
+
/**
|
| 467 |
+
* Method to determine whether or not the request counts as 'successful'. Used
|
| 468 |
+
* when either `skipSuccessfulRequests` or `skipFailedRequests` is set to true.
|
| 469 |
+
*
|
| 470 |
+
* By default, requests with a response status code less than 400 are considered
|
| 471 |
+
* successful.
|
| 472 |
+
*/
|
| 473 |
+
requestWasSuccessful: ValueDeterminingMiddleware<boolean>;
|
| 474 |
+
/**
|
| 475 |
+
* The `Store` to use to store the hit count for each client.
|
| 476 |
+
*
|
| 477 |
+
* By default, the built-in `MemoryStore` will be used.
|
| 478 |
+
*/
|
| 479 |
+
store: Store | LegacyStore;
|
| 480 |
+
/**
|
| 481 |
+
* The list of validation checks that should run.
|
| 482 |
+
*/
|
| 483 |
+
validate: boolean | EnabledValidations;
|
| 484 |
+
/**
|
| 485 |
+
* Whether to send `X-RateLimit-*` headers with the rate limit and the number
|
| 486 |
+
* of requests.
|
| 487 |
+
*
|
| 488 |
+
* @deprecated 6.x - This option was renamed to `legacyHeaders`.
|
| 489 |
+
*/
|
| 490 |
+
headers?: boolean;
|
| 491 |
+
/**
|
| 492 |
+
* The maximum number of connections to allow during the `window` before
|
| 493 |
+
* rate limiting the client.
|
| 494 |
+
*
|
| 495 |
+
* Can be the limit itself as a number or express middleware that parses
|
| 496 |
+
* the request and then figures out the limit.
|
| 497 |
+
*
|
| 498 |
+
* @deprecated 7.x - This option was renamed to `limit`. However, it will not
|
| 499 |
+
* be removed from the library in the foreseeable future.
|
| 500 |
+
*/
|
| 501 |
+
max?: number | ValueDeterminingMiddleware<number>;
|
| 502 |
+
/**
|
| 503 |
+
* If the Store generates an error, allow the request to pass.
|
| 504 |
+
*/
|
| 505 |
+
passOnStoreError: boolean;
|
| 506 |
+
/**
|
| 507 |
+
* The logger to use to log errors. If absent, logs to the console.
|
| 508 |
+
*/
|
| 509 |
+
logger: Logger;
|
| 510 |
+
};
|
| 511 |
+
/**
|
| 512 |
+
* The extended request object that includes information about the client's
|
| 513 |
+
* rate limit.
|
| 514 |
+
*/
|
| 515 |
+
export type AugmentedRequest = Request & {
|
| 516 |
+
[key: string]: RateLimitInfo;
|
| 517 |
+
};
|
| 518 |
+
/**
|
| 519 |
+
* The rate limit related information for each client included in the
|
| 520 |
+
* Express request object.
|
| 521 |
+
*/
|
| 522 |
+
export type RateLimitInfo = {
|
| 523 |
+
limit: number;
|
| 524 |
+
used: number;
|
| 525 |
+
remaining: number;
|
| 526 |
+
resetTime: Date | undefined;
|
| 527 |
+
key: string;
|
| 528 |
+
};
|
| 529 |
+
/**
|
| 530 |
+
* The record that stores information about a client - namely, how many times
|
| 531 |
+
* they have hit the endpoint, and when their hit count resets.
|
| 532 |
+
*
|
| 533 |
+
* Similar to `ClientRateLimitInfo`, except `resetTime` is a compulsory field.
|
| 534 |
+
*/
|
| 535 |
+
export type Client = {
|
| 536 |
+
totalHits: number;
|
| 537 |
+
resetTime: Date;
|
| 538 |
+
};
|
| 539 |
+
/**
|
| 540 |
+
* A `Store` that stores the hit count for each client in memory.
|
| 541 |
+
*
|
| 542 |
+
* @public
|
| 543 |
+
*/
|
| 544 |
+
export declare class MemoryStore implements Store {
|
| 545 |
+
private validations?;
|
| 546 |
+
/**
|
| 547 |
+
* The duration of time before which all hit counts are reset (in milliseconds).
|
| 548 |
+
*/
|
| 549 |
+
windowMs: number;
|
| 550 |
+
/**
|
| 551 |
+
* These two maps store usage (requests) and reset time by key (for example, IP
|
| 552 |
+
* addresses or API keys).
|
| 553 |
+
*
|
| 554 |
+
* They are split into two to avoid having to iterate through the entire set to
|
| 555 |
+
* determine which ones need reset. Instead, `Client`s are moved from `previous`
|
| 556 |
+
* to `current` as they hit the endpoint. Once `windowMs` has elapsed, all clients
|
| 557 |
+
* left in `previous`, i.e., those that have not made any recent requests, are
|
| 558 |
+
* known to be expired and can be deleted in bulk.
|
| 559 |
+
*/
|
| 560 |
+
previous: Map<string, Client>;
|
| 561 |
+
current: Map<string, Client>;
|
| 562 |
+
/**
|
| 563 |
+
* A reference to the active timer.
|
| 564 |
+
*/
|
| 565 |
+
interval?: NodeJS.Timeout;
|
| 566 |
+
/**
|
| 567 |
+
* Confirmation that the keys incremented in once instance of MemoryStore
|
| 568 |
+
* cannot affect other instances.
|
| 569 |
+
*/
|
| 570 |
+
localKeys: boolean;
|
| 571 |
+
constructor(validations?: Validations | undefined);
|
| 572 |
+
/**
|
| 573 |
+
* Method that initializes the store.
|
| 574 |
+
*
|
| 575 |
+
* @param options {Options} - The options used to setup the middleware.
|
| 576 |
+
*/
|
| 577 |
+
init(options: Options): void;
|
| 578 |
+
/**
|
| 579 |
+
* Method to fetch a client's hit count and reset time.
|
| 580 |
+
*
|
| 581 |
+
* @param key {string} - The identifier for a client.
|
| 582 |
+
*
|
| 583 |
+
* @returns {ClientRateLimitInfo | undefined} - The number of hits and reset time for that client.
|
| 584 |
+
*
|
| 585 |
+
* @public
|
| 586 |
+
*/
|
| 587 |
+
get(key: string): Promise<ClientRateLimitInfo | undefined>;
|
| 588 |
+
/**
|
| 589 |
+
* Method to increment a client's hit counter.
|
| 590 |
+
*
|
| 591 |
+
* @param key {string} - The identifier for a client.
|
| 592 |
+
*
|
| 593 |
+
* @returns {ClientRateLimitInfo} - The number of hits and reset time for that client.
|
| 594 |
+
*
|
| 595 |
+
* @public
|
| 596 |
+
*/
|
| 597 |
+
increment(key: string): Promise<ClientRateLimitInfo>;
|
| 598 |
+
/**
|
| 599 |
+
* Method to decrement a client's hit counter.
|
| 600 |
+
*
|
| 601 |
+
* @param key {string} - The identifier for a client.
|
| 602 |
+
*
|
| 603 |
+
* @public
|
| 604 |
+
*/
|
| 605 |
+
decrement(key: string): Promise<void>;
|
| 606 |
+
/**
|
| 607 |
+
* Method to reset a client's hit counter.
|
| 608 |
+
*
|
| 609 |
+
* @param key {string} - The identifier for a client.
|
| 610 |
+
*
|
| 611 |
+
* @public
|
| 612 |
+
*/
|
| 613 |
+
resetKey(key: string): Promise<void>;
|
| 614 |
+
/**
|
| 615 |
+
* Method to reset everyone's hit counter.
|
| 616 |
+
*
|
| 617 |
+
* @public
|
| 618 |
+
*/
|
| 619 |
+
resetAll(): Promise<void>;
|
| 620 |
+
/**
|
| 621 |
+
* Method to stop the timer (if currently running) and prevent any memory
|
| 622 |
+
* leaks.
|
| 623 |
+
*
|
| 624 |
+
* @public
|
| 625 |
+
*/
|
| 626 |
+
shutdown(): void;
|
| 627 |
+
/**
|
| 628 |
+
* Recycles a client by setting its hit count to zero, and reset time to
|
| 629 |
+
* `windowMs` milliseconds from now.
|
| 630 |
+
*
|
| 631 |
+
* NOT to be confused with `#resetKey()`, which removes a client from both the
|
| 632 |
+
* `current` and `previous` maps.
|
| 633 |
+
*
|
| 634 |
+
* @param client {Client} - The client to recycle.
|
| 635 |
+
* @param now {number} - The current time, to which the `windowMs` is added to get the `resetTime` for the client.
|
| 636 |
+
*
|
| 637 |
+
* @return {Client} - The modified client that was passed in, to allow for chaining.
|
| 638 |
+
*/
|
| 639 |
+
private resetClient;
|
| 640 |
+
/**
|
| 641 |
+
* Retrieves or creates a client, given a key. Also ensures that the client being
|
| 642 |
+
* returned is in the `current` map.
|
| 643 |
+
*
|
| 644 |
+
* @param key {string} - The key under which the client is (or is to be) stored.
|
| 645 |
+
*
|
| 646 |
+
* @returns {Client} - The requested client.
|
| 647 |
+
*/
|
| 648 |
+
private getClient;
|
| 649 |
+
/**
|
| 650 |
+
* Move current clients to previous, create a new map for current.
|
| 651 |
+
*
|
| 652 |
+
* This function is called every `windowMs`.
|
| 653 |
+
*/
|
| 654 |
+
private clearExpired;
|
| 655 |
+
}
|
| 656 |
+
/**
|
| 657 |
+
*
|
| 658 |
+
* Create an instance of IP rate-limiting middleware for Express.
|
| 659 |
+
*
|
| 660 |
+
* @param passedOptions {Options} - Options to configure the rate limiter.
|
| 661 |
+
*
|
| 662 |
+
* @returns {RateLimitRequestHandler} - The middleware that rate-limits clients based on your configuration.
|
| 663 |
+
*
|
| 664 |
+
* @public
|
| 665 |
+
*/
|
| 666 |
+
export declare const rateLimit: (passedOptions?: Partial<Options>) => RateLimitRequestHandler;
|
| 667 |
+
|
| 668 |
+
export {
|
| 669 |
+
rateLimit as default,
|
| 670 |
+
};
|
| 671 |
+
|
| 672 |
+
export {};
|
tools/ui/node_modules/express-rate-limit/dist/index.d.mts
ADDED
|
@@ -0,0 +1,672 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Generated by dts-bundle-generator v8.1.2
|
| 2 |
+
|
| 3 |
+
import { NextFunction, Request, RequestHandler, Response } from 'express';
|
| 4 |
+
|
| 5 |
+
/**
|
| 6 |
+
* Returns the IP address itself for IPv4, or a CIDR-notation subnet for IPv6.
|
| 7 |
+
*
|
| 8 |
+
* If you write a custom keyGenerator that allows a fallback to IP address for
|
| 9 |
+
* unauthenticated users, return ipKeyGenerator(req.ip) rather than just req.ip.
|
| 10 |
+
*
|
| 11 |
+
* For more information, {@see Options.ipv6Subnet}.
|
| 12 |
+
*
|
| 13 |
+
* @param ip {string} - The IP address to process, usually request.ip.
|
| 14 |
+
* @param ipv6Subnet {number | false} - The subnet mask for IPv6 addresses.
|
| 15 |
+
*
|
| 16 |
+
* @returns {string} - The key generated from the IP address
|
| 17 |
+
*
|
| 18 |
+
* @public
|
| 19 |
+
*/
|
| 20 |
+
export declare function ipKeyGenerator(ip: string, ipv6Subnet?: number | false): string;
|
| 21 |
+
declare const SUPPORTED_DRAFT_VERSIONS: readonly [
|
| 22 |
+
"draft-6",
|
| 23 |
+
"draft-7",
|
| 24 |
+
"draft-8"
|
| 25 |
+
];
|
| 26 |
+
declare const validations: {
|
| 27 |
+
enabled: {
|
| 28 |
+
[key: string]: boolean;
|
| 29 |
+
};
|
| 30 |
+
disable(): void;
|
| 31 |
+
/**
|
| 32 |
+
* Checks whether the IP address is valid, and that it does not have a port
|
| 33 |
+
* number in it.
|
| 34 |
+
*
|
| 35 |
+
* See https://github.com/express-rate-limit/express-rate-limit/wiki/Error-Codes#err_erl_invalid_ip_address.
|
| 36 |
+
*
|
| 37 |
+
* @param ip {string | undefined} - The IP address provided by Express as request.ip.
|
| 38 |
+
*
|
| 39 |
+
* @returns {void}
|
| 40 |
+
*/
|
| 41 |
+
ip(ip: string | undefined): void;
|
| 42 |
+
/**
|
| 43 |
+
* Makes sure the trust proxy setting is not set to `true`.
|
| 44 |
+
*
|
| 45 |
+
* See https://github.com/express-rate-limit/express-rate-limit/wiki/Error-Codes#err_erl_permissive_trust_proxy.
|
| 46 |
+
*
|
| 47 |
+
* @param request {Request} - The Express request object.
|
| 48 |
+
*
|
| 49 |
+
* @returns {void}
|
| 50 |
+
*/
|
| 51 |
+
trustProxy(request: Request): void;
|
| 52 |
+
/**
|
| 53 |
+
* Makes sure the trust proxy setting is set in case the `X-Forwarded-For`
|
| 54 |
+
* header is present.
|
| 55 |
+
*
|
| 56 |
+
* See https://github.com/express-rate-limit/express-rate-limit/wiki/Error-Codes#err_erl_unset_trust_proxy.
|
| 57 |
+
*
|
| 58 |
+
* @param request {Request} - The Express request object.
|
| 59 |
+
*
|
| 60 |
+
* @returns {void}
|
| 61 |
+
*/
|
| 62 |
+
xForwardedForHeader(request: Request): void;
|
| 63 |
+
/**
|
| 64 |
+
* Alert the user if the Forwarded header is set (standardized version of X-Forwarded-For - not supported by express as of version 5.1.0)
|
| 65 |
+
*
|
| 66 |
+
* @param request {Request} - The Express request object.
|
| 67 |
+
*
|
| 68 |
+
* @returns {void}
|
| 69 |
+
*/
|
| 70 |
+
forwardedHeader(request: Request): void;
|
| 71 |
+
/**
|
| 72 |
+
* Ensures totalHits value from store is a positive integer.
|
| 73 |
+
*
|
| 74 |
+
* @param hits {any} - The `totalHits` returned by the store.
|
| 75 |
+
*/
|
| 76 |
+
positiveHits(hits: any): void;
|
| 77 |
+
/**
|
| 78 |
+
* Ensures a single store instance is not used with multiple express-rate-limit instances
|
| 79 |
+
*/
|
| 80 |
+
unsharedStore(store: Store): void;
|
| 81 |
+
/**
|
| 82 |
+
* Ensures a given key is incremented only once per request.
|
| 83 |
+
*
|
| 84 |
+
* @param request {Request} - The Express request object.
|
| 85 |
+
* @param store {Store} - The store class.
|
| 86 |
+
* @param key {string} - The key used to store the client's hit count.
|
| 87 |
+
*
|
| 88 |
+
* @returns {void}
|
| 89 |
+
*/
|
| 90 |
+
singleCount(request: Request, store: Store, key: string): void;
|
| 91 |
+
/**
|
| 92 |
+
* Warns the user that the behaviour for `max: 0` / `limit: 0` is
|
| 93 |
+
* changing in the next major release.
|
| 94 |
+
*
|
| 95 |
+
* @param limit {number} - The maximum number of hits per client.
|
| 96 |
+
*
|
| 97 |
+
* @returns {void}
|
| 98 |
+
*/
|
| 99 |
+
limit(limit: number): void;
|
| 100 |
+
/**
|
| 101 |
+
* Warns the user that the `draft_polli_ratelimit_headers` option is deprecated
|
| 102 |
+
* and will be removed in the next major release.
|
| 103 |
+
*
|
| 104 |
+
* @param draft_polli_ratelimit_headers {any | undefined} - The now-deprecated setting that was used to enable standard headers.
|
| 105 |
+
*
|
| 106 |
+
* @returns {void}
|
| 107 |
+
*/
|
| 108 |
+
draftPolliHeaders(draft_polli_ratelimit_headers?: any): void;
|
| 109 |
+
/**
|
| 110 |
+
* Warns the user that the `onLimitReached` option is deprecated and
|
| 111 |
+
* will be removed in the next major release.
|
| 112 |
+
*
|
| 113 |
+
* @param onLimitReached {any | undefined} - The maximum number of hits per client.
|
| 114 |
+
*
|
| 115 |
+
* @returns {void}
|
| 116 |
+
*/
|
| 117 |
+
onLimitReached(onLimitReached?: any): void;
|
| 118 |
+
/**
|
| 119 |
+
* Warns the user when an invalid/unsupported version of the draft spec is passed.
|
| 120 |
+
*
|
| 121 |
+
* @param version {any | undefined} - The version passed by the user.
|
| 122 |
+
*
|
| 123 |
+
* @returns {void}
|
| 124 |
+
*/
|
| 125 |
+
headersDraftVersion(version?: any): void;
|
| 126 |
+
/**
|
| 127 |
+
* Warns the user when the selected headers option requires a reset time but
|
| 128 |
+
* the store does not provide one.
|
| 129 |
+
*
|
| 130 |
+
* @param resetTime {Date | undefined} - The timestamp when the client's hit count will be reset.
|
| 131 |
+
*
|
| 132 |
+
* @returns {void}
|
| 133 |
+
*/
|
| 134 |
+
headersResetTime(resetTime?: Date): void;
|
| 135 |
+
knownOptions(passedOptions?: Partial<Options>): void;
|
| 136 |
+
/**
|
| 137 |
+
* Checks the options.validate setting to ensure that only recognized
|
| 138 |
+
* validations are enabled or disabled.
|
| 139 |
+
*
|
| 140 |
+
* If any unrecognized values are found, an error is logged that
|
| 141 |
+
* includes the list of supported validations.
|
| 142 |
+
*/
|
| 143 |
+
validationsConfig(): void;
|
| 144 |
+
/**
|
| 145 |
+
* Checks to see if the instance was created inside of a request handler,
|
| 146 |
+
* which would prevent it from working correctly, with the default memory
|
| 147 |
+
* store (or any other store with localKeys.)
|
| 148 |
+
*/
|
| 149 |
+
creationStack(store: Store): void;
|
| 150 |
+
ipv6Subnet(ipv6Subnet?: any): void;
|
| 151 |
+
ipv6SubnetOrKeyGenerator(options: Partial<Options>): void;
|
| 152 |
+
keyGeneratorIpFallback(keyGenerator?: ValueDeterminingMiddleware<string>): void;
|
| 153 |
+
/**
|
| 154 |
+
* Checks to see if the window duration is greater than 2^32 - 1. This is only
|
| 155 |
+
* called by the default MemoryStore, since it uses Node's setInterval method.
|
| 156 |
+
*
|
| 157 |
+
* See https://nodejs.org/api/timers.html#setintervalcallback-delay-args.
|
| 158 |
+
*/
|
| 159 |
+
windowMs(windowMs: number): void;
|
| 160 |
+
};
|
| 161 |
+
export type Validations = typeof validations;
|
| 162 |
+
/**
|
| 163 |
+
* Basic logging function
|
| 164 |
+
*
|
| 165 |
+
* @param error {unknown} - The error to log
|
| 166 |
+
* @param message {string | undefined} - Additional details about the error
|
| 167 |
+
*/
|
| 168 |
+
export type LoggerFn = (error: unknown, message?: string) => void;
|
| 169 |
+
/**
|
| 170 |
+
* Minimal interface for logging warnings and errors
|
| 171 |
+
*/
|
| 172 |
+
export type Logger = {
|
| 173 |
+
/**
|
| 174 |
+
* Function to log an error
|
| 175 |
+
*/
|
| 176 |
+
error: LoggerFn;
|
| 177 |
+
/**
|
| 178 |
+
* Function to log a warning
|
| 179 |
+
*/
|
| 180 |
+
warn: LoggerFn;
|
| 181 |
+
};
|
| 182 |
+
/**
|
| 183 |
+
* Callback that fires when a client's hit counter is incremented.
|
| 184 |
+
*
|
| 185 |
+
* @param error {Error | undefined} - The error that occurred, if any.
|
| 186 |
+
* @param totalHits {number} - The number of hits for that client so far.
|
| 187 |
+
* @param resetTime {Date | undefined} - The time when the counter resets.
|
| 188 |
+
*/
|
| 189 |
+
export type IncrementCallback = (error: Error | undefined, totalHits: number, resetTime: Date | undefined) => void;
|
| 190 |
+
/**
|
| 191 |
+
* Method (in the form of middleware) to generate/retrieve a value based on the
|
| 192 |
+
* incoming request.
|
| 193 |
+
*
|
| 194 |
+
* @param request {Request} - The Express request object.
|
| 195 |
+
* @param response {Response} - The Express response object.
|
| 196 |
+
*
|
| 197 |
+
* @returns {T} - The value needed.
|
| 198 |
+
*/
|
| 199 |
+
export type ValueDeterminingMiddleware<T> = (request: Request, response: Response) => T | Promise<T>;
|
| 200 |
+
/**
|
| 201 |
+
* Express request handler that sends back a response when a client is
|
| 202 |
+
* rate-limited.
|
| 203 |
+
*
|
| 204 |
+
* @param request {Request} - The Express request object.
|
| 205 |
+
* @param response {Response} - The Express response object.
|
| 206 |
+
* @param next {NextFunction} - The Express `next` function, can be called to skip responding.
|
| 207 |
+
* @param optionsUsed {Options} - The options used to set up the middleware.
|
| 208 |
+
*/
|
| 209 |
+
export type RateLimitExceededEventHandler = (request: Request, response: Response, next: NextFunction, optionsUsed: Options) => void;
|
| 210 |
+
/**
|
| 211 |
+
* Event callback that is triggered on a client's first request that exceeds the limit
|
| 212 |
+
* but not for subsequent requests. May be used for logging, etc. Should *not*
|
| 213 |
+
* send a response.
|
| 214 |
+
*
|
| 215 |
+
* @param request {Request} - The Express request object.
|
| 216 |
+
* @param response {Response} - The Express response object.
|
| 217 |
+
* @param optionsUsed {Options} - The options used to set up the middleware.
|
| 218 |
+
*/
|
| 219 |
+
export type RateLimitReachedEventHandler = (request: Request, response: Response, optionsUsed: Options) => void;
|
| 220 |
+
/**
|
| 221 |
+
* Data returned from the `Store` when a client's hit counter is incremented.
|
| 222 |
+
*
|
| 223 |
+
* @property totalHits {number} - The number of hits for that client so far.
|
| 224 |
+
* @property resetTime {Date | undefined} - The time when the counter resets.
|
| 225 |
+
*/
|
| 226 |
+
export type ClientRateLimitInfo = {
|
| 227 |
+
totalHits: number;
|
| 228 |
+
resetTime: Date | undefined;
|
| 229 |
+
};
|
| 230 |
+
export type IncrementResponse = ClientRateLimitInfo;
|
| 231 |
+
/**
|
| 232 |
+
* A modified Express request handler with the rate limit functions.
|
| 233 |
+
*/
|
| 234 |
+
export type RateLimitRequestHandler = RequestHandler & {
|
| 235 |
+
/**
|
| 236 |
+
* Method to reset a client's hit counter.
|
| 237 |
+
*
|
| 238 |
+
* @param key {string} - The identifier for a client.
|
| 239 |
+
*/
|
| 240 |
+
resetKey: (key: string) => void;
|
| 241 |
+
/**
|
| 242 |
+
* Method to fetch a client's hit count and reset time.
|
| 243 |
+
*
|
| 244 |
+
* @param key {string} - The identifier for a client.
|
| 245 |
+
*
|
| 246 |
+
* @returns {ClientRateLimitInfo} - The number of hits and reset time for that client.
|
| 247 |
+
*/
|
| 248 |
+
getKey: (key: string) => Promise<ClientRateLimitInfo | undefined> | ClientRateLimitInfo | undefined;
|
| 249 |
+
};
|
| 250 |
+
/**
|
| 251 |
+
* An interface that all hit counter stores must implement.
|
| 252 |
+
*
|
| 253 |
+
* @deprecated 6.x - Implement the `Store` interface instead.
|
| 254 |
+
*/
|
| 255 |
+
export type LegacyStore = {
|
| 256 |
+
/**
|
| 257 |
+
* Method to increment a client's hit counter.
|
| 258 |
+
*
|
| 259 |
+
* @param key {string} - The identifier for a client.
|
| 260 |
+
* @param callback {IncrementCallback} - The callback to call once the counter is incremented.
|
| 261 |
+
*/
|
| 262 |
+
incr: (key: string, callback: IncrementCallback) => void;
|
| 263 |
+
/**
|
| 264 |
+
* Method to decrement a client's hit counter.
|
| 265 |
+
*
|
| 266 |
+
* @param key {string} - The identifier for a client.
|
| 267 |
+
*/
|
| 268 |
+
decrement: (key: string) => void;
|
| 269 |
+
/**
|
| 270 |
+
* Method to reset a client's hit counter.
|
| 271 |
+
*
|
| 272 |
+
* @param key {string} - The identifier for a client.
|
| 273 |
+
*/
|
| 274 |
+
resetKey: (key: string) => void;
|
| 275 |
+
/**
|
| 276 |
+
* Method to reset everyone's hit counter.
|
| 277 |
+
*/
|
| 278 |
+
resetAll?: () => void;
|
| 279 |
+
};
|
| 280 |
+
/**
|
| 281 |
+
* An interface that all hit counter stores must implement.
|
| 282 |
+
*/
|
| 283 |
+
export type Store = {
|
| 284 |
+
/**
|
| 285 |
+
* Method that initializes the store, and has access to the options passed to
|
| 286 |
+
* the middleware too.
|
| 287 |
+
*
|
| 288 |
+
* Called once during initialization.
|
| 289 |
+
*
|
| 290 |
+
* Errors / promise rejections will be caught and logged.
|
| 291 |
+
*
|
| 292 |
+
* Note that the result is not awaited - other store methods (such as increment) may be called before init returns and/or after it throws/rejects.
|
| 293 |
+
*
|
| 294 |
+
* @param options {Options} - The options used to setup the middleware.
|
| 295 |
+
*/
|
| 296 |
+
init?: (options: Options) => void | Promise<void>;
|
| 297 |
+
/**
|
| 298 |
+
* Method to fetch a client's hit count and reset time.
|
| 299 |
+
*
|
| 300 |
+
* @param key {string} - The identifier for a client.
|
| 301 |
+
*
|
| 302 |
+
* @returns {ClientRateLimitInfo} - The number of hits and reset time for that client.
|
| 303 |
+
*/
|
| 304 |
+
get?: (key: string) => Promise<ClientRateLimitInfo | undefined> | ClientRateLimitInfo | undefined;
|
| 305 |
+
/**
|
| 306 |
+
* Method to increment a client's hit counter.
|
| 307 |
+
*
|
| 308 |
+
* @param key {string} - The identifier for a client.
|
| 309 |
+
*
|
| 310 |
+
* @returns {IncrementResponse | undefined} - The number of hits and reset time for that client.
|
| 311 |
+
*/
|
| 312 |
+
increment: (key: string) => Promise<IncrementResponse> | IncrementResponse;
|
| 313 |
+
/**
|
| 314 |
+
* Method to decrement a client's hit counter.
|
| 315 |
+
*
|
| 316 |
+
* @param key {string} - The identifier for a client.
|
| 317 |
+
*/
|
| 318 |
+
decrement: (key: string) => Promise<void> | void;
|
| 319 |
+
/**
|
| 320 |
+
* Method to reset a client's hit counter.
|
| 321 |
+
*
|
| 322 |
+
* @param key {string} - The identifier for a client.
|
| 323 |
+
*/
|
| 324 |
+
resetKey: (key: string) => Promise<void> | void;
|
| 325 |
+
/**
|
| 326 |
+
* Method to reset everyone's hit counter.
|
| 327 |
+
*/
|
| 328 |
+
resetAll?: () => Promise<void> | void;
|
| 329 |
+
/**
|
| 330 |
+
* Method to shutdown the store, stop timers, and release all resources.
|
| 331 |
+
*/
|
| 332 |
+
shutdown?: () => Promise<void> | void;
|
| 333 |
+
/**
|
| 334 |
+
* Flag to indicate that keys incremented in one instance of this store can
|
| 335 |
+
* not affect other instances. Typically false if a database is used, true for
|
| 336 |
+
* MemoryStore.
|
| 337 |
+
*
|
| 338 |
+
* Used to help detect double-counting misconfigurations.
|
| 339 |
+
*/
|
| 340 |
+
localKeys?: boolean;
|
| 341 |
+
/**
|
| 342 |
+
* Optional value that the store prepends to keys
|
| 343 |
+
*
|
| 344 |
+
* Used by the double-count check to avoid false-positives when a key is counted
|
| 345 |
+
* twice, but with different prefixes.
|
| 346 |
+
*/
|
| 347 |
+
prefix?: string;
|
| 348 |
+
};
|
| 349 |
+
export type DraftHeadersVersion = (typeof SUPPORTED_DRAFT_VERSIONS)[number];
|
| 350 |
+
/**
|
| 351 |
+
* Validate configuration object for enabling or disabling specific validations.
|
| 352 |
+
*
|
| 353 |
+
* The keys must also be keys in the validations object, except `enable`, `disable`,
|
| 354 |
+
* and `default`.
|
| 355 |
+
*/
|
| 356 |
+
export type EnabledValidations = {
|
| 357 |
+
[key in keyof Omit<Validations, "enabled" | "disable"> | "default"]?: boolean;
|
| 358 |
+
};
|
| 359 |
+
/**
|
| 360 |
+
* The configuration options for the rate limiter.
|
| 361 |
+
*/
|
| 362 |
+
export type Options = {
|
| 363 |
+
/**
|
| 364 |
+
* How long we should remember the requests.
|
| 365 |
+
*
|
| 366 |
+
* Defaults to `60000` ms (= 1 minute).
|
| 367 |
+
*/
|
| 368 |
+
windowMs: number;
|
| 369 |
+
/**
|
| 370 |
+
* The maximum number of connections to allow during the `window` before
|
| 371 |
+
* rate limiting the client.
|
| 372 |
+
*
|
| 373 |
+
* Can be the limit itself as a number or express middleware that parses
|
| 374 |
+
* the request and then figures out the limit.
|
| 375 |
+
*
|
| 376 |
+
* Defaults to `5`.
|
| 377 |
+
*/
|
| 378 |
+
limit: number | ValueDeterminingMiddleware<number>;
|
| 379 |
+
/**
|
| 380 |
+
* The response body to send back when a client is rate limited.
|
| 381 |
+
*
|
| 382 |
+
* Defaults to `'Too many requests, please try again later.'`
|
| 383 |
+
*/
|
| 384 |
+
message: any | ValueDeterminingMiddleware<any>;
|
| 385 |
+
/**
|
| 386 |
+
* The HTTP status code to send back when a client is rate limited.
|
| 387 |
+
*
|
| 388 |
+
* Defaults to `HTTP 429 Too Many Requests` (RFC 6585).
|
| 389 |
+
*/
|
| 390 |
+
statusCode: number;
|
| 391 |
+
/**
|
| 392 |
+
* Whether to send `X-RateLimit-*` headers with the rate limit and the number
|
| 393 |
+
* of requests.
|
| 394 |
+
*
|
| 395 |
+
* Defaults to `true` (for backward compatibility).
|
| 396 |
+
*/
|
| 397 |
+
legacyHeaders: boolean;
|
| 398 |
+
/**
|
| 399 |
+
* Whether to enable support for the standardized rate limit headers (`RateLimit-*`).
|
| 400 |
+
*
|
| 401 |
+
* Defaults to `false` (for backward compatibility, but its use is recommended).
|
| 402 |
+
*/
|
| 403 |
+
standardHeaders: boolean | DraftHeadersVersion;
|
| 404 |
+
/**
|
| 405 |
+
* The name used to identify the quota policy in the `RateLimit` headers as per
|
| 406 |
+
* the 8th draft of the IETF specification.
|
| 407 |
+
*
|
| 408 |
+
* Defaults to `{limit}-in-{window}`.
|
| 409 |
+
*/
|
| 410 |
+
identifier: string | ValueDeterminingMiddleware<string>;
|
| 411 |
+
/**
|
| 412 |
+
* The name of the property on the request object to store the rate limit info.
|
| 413 |
+
*
|
| 414 |
+
* Defaults to `rateLimit`.
|
| 415 |
+
*/
|
| 416 |
+
requestPropertyName: string;
|
| 417 |
+
/**
|
| 418 |
+
* If `true`, the library will (by default) skip all requests that have a 4XX
|
| 419 |
+
* or 5XX status.
|
| 420 |
+
*
|
| 421 |
+
* Defaults to `false`.
|
| 422 |
+
*/
|
| 423 |
+
skipFailedRequests: boolean;
|
| 424 |
+
/**
|
| 425 |
+
* If `true`, the library will (by default) skip all requests that have a
|
| 426 |
+
* status code less than 400.
|
| 427 |
+
*
|
| 428 |
+
* Defaults to `false`.
|
| 429 |
+
*/
|
| 430 |
+
skipSuccessfulRequests: boolean;
|
| 431 |
+
/**
|
| 432 |
+
* Method to generate custom identifiers for clients.
|
| 433 |
+
*
|
| 434 |
+
* By default, the client's IP address is used.
|
| 435 |
+
*/
|
| 436 |
+
keyGenerator: ValueDeterminingMiddleware<string>;
|
| 437 |
+
/**
|
| 438 |
+
* IPv6 subnet mask applied to IPv6 addresses in the default keyGenerator.
|
| 439 |
+
*
|
| 440 |
+
* Default is 56. The valid range is technically 1-128 but the value should
|
| 441 |
+
* generally be in the 32-64 range.
|
| 442 |
+
*
|
| 443 |
+
* Smaller numbers are more aggressive, larger numbers are more lenient. Try
|
| 444 |
+
* bumping to 60 or 64 if you see evidence of users being blocked incorrectly.
|
| 445 |
+
*
|
| 446 |
+
* May also be set to a function that returns a number based on the request.
|
| 447 |
+
*
|
| 448 |
+
* See the documentation for more info:
|
| 449 |
+
* https://express-rate-limit.mintlify.app/reference/configuration#ipv6subnet.
|
| 450 |
+
*/
|
| 451 |
+
ipv6Subnet: 64 | 60 | 56 | 52 | 50 | 48 | 32 | number | ValueDeterminingMiddleware<number> | false;
|
| 452 |
+
/**
|
| 453 |
+
* Express request handler that sends back a response when a client is
|
| 454 |
+
* rate-limited.
|
| 455 |
+
*
|
| 456 |
+
* By default, sends back the `statusCode` and `message` set via the options.
|
| 457 |
+
*/
|
| 458 |
+
handler: RateLimitExceededEventHandler;
|
| 459 |
+
/**
|
| 460 |
+
* Method (in the form of middleware) to determine whether or not this request
|
| 461 |
+
* counts towards a client's quota.
|
| 462 |
+
*
|
| 463 |
+
* By default, skips no requests.
|
| 464 |
+
*/
|
| 465 |
+
skip: ValueDeterminingMiddleware<boolean>;
|
| 466 |
+
/**
|
| 467 |
+
* Method to determine whether or not the request counts as 'successful'. Used
|
| 468 |
+
* when either `skipSuccessfulRequests` or `skipFailedRequests` is set to true.
|
| 469 |
+
*
|
| 470 |
+
* By default, requests with a response status code less than 400 are considered
|
| 471 |
+
* successful.
|
| 472 |
+
*/
|
| 473 |
+
requestWasSuccessful: ValueDeterminingMiddleware<boolean>;
|
| 474 |
+
/**
|
| 475 |
+
* The `Store` to use to store the hit count for each client.
|
| 476 |
+
*
|
| 477 |
+
* By default, the built-in `MemoryStore` will be used.
|
| 478 |
+
*/
|
| 479 |
+
store: Store | LegacyStore;
|
| 480 |
+
/**
|
| 481 |
+
* The list of validation checks that should run.
|
| 482 |
+
*/
|
| 483 |
+
validate: boolean | EnabledValidations;
|
| 484 |
+
/**
|
| 485 |
+
* Whether to send `X-RateLimit-*` headers with the rate limit and the number
|
| 486 |
+
* of requests.
|
| 487 |
+
*
|
| 488 |
+
* @deprecated 6.x - This option was renamed to `legacyHeaders`.
|
| 489 |
+
*/
|
| 490 |
+
headers?: boolean;
|
| 491 |
+
/**
|
| 492 |
+
* The maximum number of connections to allow during the `window` before
|
| 493 |
+
* rate limiting the client.
|
| 494 |
+
*
|
| 495 |
+
* Can be the limit itself as a number or express middleware that parses
|
| 496 |
+
* the request and then figures out the limit.
|
| 497 |
+
*
|
| 498 |
+
* @deprecated 7.x - This option was renamed to `limit`. However, it will not
|
| 499 |
+
* be removed from the library in the foreseeable future.
|
| 500 |
+
*/
|
| 501 |
+
max?: number | ValueDeterminingMiddleware<number>;
|
| 502 |
+
/**
|
| 503 |
+
* If the Store generates an error, allow the request to pass.
|
| 504 |
+
*/
|
| 505 |
+
passOnStoreError: boolean;
|
| 506 |
+
/**
|
| 507 |
+
* The logger to use to log errors. If absent, logs to the console.
|
| 508 |
+
*/
|
| 509 |
+
logger: Logger;
|
| 510 |
+
};
|
| 511 |
+
/**
|
| 512 |
+
* The extended request object that includes information about the client's
|
| 513 |
+
* rate limit.
|
| 514 |
+
*/
|
| 515 |
+
export type AugmentedRequest = Request & {
|
| 516 |
+
[key: string]: RateLimitInfo;
|
| 517 |
+
};
|
| 518 |
+
/**
|
| 519 |
+
* The rate limit related information for each client included in the
|
| 520 |
+
* Express request object.
|
| 521 |
+
*/
|
| 522 |
+
export type RateLimitInfo = {
|
| 523 |
+
limit: number;
|
| 524 |
+
used: number;
|
| 525 |
+
remaining: number;
|
| 526 |
+
resetTime: Date | undefined;
|
| 527 |
+
key: string;
|
| 528 |
+
};
|
| 529 |
+
/**
|
| 530 |
+
* The record that stores information about a client - namely, how many times
|
| 531 |
+
* they have hit the endpoint, and when their hit count resets.
|
| 532 |
+
*
|
| 533 |
+
* Similar to `ClientRateLimitInfo`, except `resetTime` is a compulsory field.
|
| 534 |
+
*/
|
| 535 |
+
export type Client = {
|
| 536 |
+
totalHits: number;
|
| 537 |
+
resetTime: Date;
|
| 538 |
+
};
|
| 539 |
+
/**
|
| 540 |
+
* A `Store` that stores the hit count for each client in memory.
|
| 541 |
+
*
|
| 542 |
+
* @public
|
| 543 |
+
*/
|
| 544 |
+
export declare class MemoryStore implements Store {
|
| 545 |
+
private validations?;
|
| 546 |
+
/**
|
| 547 |
+
* The duration of time before which all hit counts are reset (in milliseconds).
|
| 548 |
+
*/
|
| 549 |
+
windowMs: number;
|
| 550 |
+
/**
|
| 551 |
+
* These two maps store usage (requests) and reset time by key (for example, IP
|
| 552 |
+
* addresses or API keys).
|
| 553 |
+
*
|
| 554 |
+
* They are split into two to avoid having to iterate through the entire set to
|
| 555 |
+
* determine which ones need reset. Instead, `Client`s are moved from `previous`
|
| 556 |
+
* to `current` as they hit the endpoint. Once `windowMs` has elapsed, all clients
|
| 557 |
+
* left in `previous`, i.e., those that have not made any recent requests, are
|
| 558 |
+
* known to be expired and can be deleted in bulk.
|
| 559 |
+
*/
|
| 560 |
+
previous: Map<string, Client>;
|
| 561 |
+
current: Map<string, Client>;
|
| 562 |
+
/**
|
| 563 |
+
* A reference to the active timer.
|
| 564 |
+
*/
|
| 565 |
+
interval?: NodeJS.Timeout;
|
| 566 |
+
/**
|
| 567 |
+
* Confirmation that the keys incremented in once instance of MemoryStore
|
| 568 |
+
* cannot affect other instances.
|
| 569 |
+
*/
|
| 570 |
+
localKeys: boolean;
|
| 571 |
+
constructor(validations?: Validations | undefined);
|
| 572 |
+
/**
|
| 573 |
+
* Method that initializes the store.
|
| 574 |
+
*
|
| 575 |
+
* @param options {Options} - The options used to setup the middleware.
|
| 576 |
+
*/
|
| 577 |
+
init(options: Options): void;
|
| 578 |
+
/**
|
| 579 |
+
* Method to fetch a client's hit count and reset time.
|
| 580 |
+
*
|
| 581 |
+
* @param key {string} - The identifier for a client.
|
| 582 |
+
*
|
| 583 |
+
* @returns {ClientRateLimitInfo | undefined} - The number of hits and reset time for that client.
|
| 584 |
+
*
|
| 585 |
+
* @public
|
| 586 |
+
*/
|
| 587 |
+
get(key: string): Promise<ClientRateLimitInfo | undefined>;
|
| 588 |
+
/**
|
| 589 |
+
* Method to increment a client's hit counter.
|
| 590 |
+
*
|
| 591 |
+
* @param key {string} - The identifier for a client.
|
| 592 |
+
*
|
| 593 |
+
* @returns {ClientRateLimitInfo} - The number of hits and reset time for that client.
|
| 594 |
+
*
|
| 595 |
+
* @public
|
| 596 |
+
*/
|
| 597 |
+
increment(key: string): Promise<ClientRateLimitInfo>;
|
| 598 |
+
/**
|
| 599 |
+
* Method to decrement a client's hit counter.
|
| 600 |
+
*
|
| 601 |
+
* @param key {string} - The identifier for a client.
|
| 602 |
+
*
|
| 603 |
+
* @public
|
| 604 |
+
*/
|
| 605 |
+
decrement(key: string): Promise<void>;
|
| 606 |
+
/**
|
| 607 |
+
* Method to reset a client's hit counter.
|
| 608 |
+
*
|
| 609 |
+
* @param key {string} - The identifier for a client.
|
| 610 |
+
*
|
| 611 |
+
* @public
|
| 612 |
+
*/
|
| 613 |
+
resetKey(key: string): Promise<void>;
|
| 614 |
+
/**
|
| 615 |
+
* Method to reset everyone's hit counter.
|
| 616 |
+
*
|
| 617 |
+
* @public
|
| 618 |
+
*/
|
| 619 |
+
resetAll(): Promise<void>;
|
| 620 |
+
/**
|
| 621 |
+
* Method to stop the timer (if currently running) and prevent any memory
|
| 622 |
+
* leaks.
|
| 623 |
+
*
|
| 624 |
+
* @public
|
| 625 |
+
*/
|
| 626 |
+
shutdown(): void;
|
| 627 |
+
/**
|
| 628 |
+
* Recycles a client by setting its hit count to zero, and reset time to
|
| 629 |
+
* `windowMs` milliseconds from now.
|
| 630 |
+
*
|
| 631 |
+
* NOT to be confused with `#resetKey()`, which removes a client from both the
|
| 632 |
+
* `current` and `previous` maps.
|
| 633 |
+
*
|
| 634 |
+
* @param client {Client} - The client to recycle.
|
| 635 |
+
* @param now {number} - The current time, to which the `windowMs` is added to get the `resetTime` for the client.
|
| 636 |
+
*
|
| 637 |
+
* @return {Client} - The modified client that was passed in, to allow for chaining.
|
| 638 |
+
*/
|
| 639 |
+
private resetClient;
|
| 640 |
+
/**
|
| 641 |
+
* Retrieves or creates a client, given a key. Also ensures that the client being
|
| 642 |
+
* returned is in the `current` map.
|
| 643 |
+
*
|
| 644 |
+
* @param key {string} - The key under which the client is (or is to be) stored.
|
| 645 |
+
*
|
| 646 |
+
* @returns {Client} - The requested client.
|
| 647 |
+
*/
|
| 648 |
+
private getClient;
|
| 649 |
+
/**
|
| 650 |
+
* Move current clients to previous, create a new map for current.
|
| 651 |
+
*
|
| 652 |
+
* This function is called every `windowMs`.
|
| 653 |
+
*/
|
| 654 |
+
private clearExpired;
|
| 655 |
+
}
|
| 656 |
+
/**
|
| 657 |
+
*
|
| 658 |
+
* Create an instance of IP rate-limiting middleware for Express.
|
| 659 |
+
*
|
| 660 |
+
* @param passedOptions {Options} - Options to configure the rate limiter.
|
| 661 |
+
*
|
| 662 |
+
* @returns {RateLimitRequestHandler} - The middleware that rate-limits clients based on your configuration.
|
| 663 |
+
*
|
| 664 |
+
* @public
|
| 665 |
+
*/
|
| 666 |
+
export declare const rateLimit: (passedOptions?: Partial<Options>) => RateLimitRequestHandler;
|
| 667 |
+
|
| 668 |
+
export {
|
| 669 |
+
rateLimit as default,
|
| 670 |
+
};
|
| 671 |
+
|
| 672 |
+
export {};
|
tools/ui/node_modules/express-rate-limit/dist/index.d.ts
ADDED
|
@@ -0,0 +1,672 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Generated by dts-bundle-generator v8.1.2
|
| 2 |
+
|
| 3 |
+
import { NextFunction, Request, RequestHandler, Response } from 'express';
|
| 4 |
+
|
| 5 |
+
/**
|
| 6 |
+
* Returns the IP address itself for IPv4, or a CIDR-notation subnet for IPv6.
|
| 7 |
+
*
|
| 8 |
+
* If you write a custom keyGenerator that allows a fallback to IP address for
|
| 9 |
+
* unauthenticated users, return ipKeyGenerator(req.ip) rather than just req.ip.
|
| 10 |
+
*
|
| 11 |
+
* For more information, {@see Options.ipv6Subnet}.
|
| 12 |
+
*
|
| 13 |
+
* @param ip {string} - The IP address to process, usually request.ip.
|
| 14 |
+
* @param ipv6Subnet {number | false} - The subnet mask for IPv6 addresses.
|
| 15 |
+
*
|
| 16 |
+
* @returns {string} - The key generated from the IP address
|
| 17 |
+
*
|
| 18 |
+
* @public
|
| 19 |
+
*/
|
| 20 |
+
export declare function ipKeyGenerator(ip: string, ipv6Subnet?: number | false): string;
|
| 21 |
+
declare const SUPPORTED_DRAFT_VERSIONS: readonly [
|
| 22 |
+
"draft-6",
|
| 23 |
+
"draft-7",
|
| 24 |
+
"draft-8"
|
| 25 |
+
];
|
| 26 |
+
declare const validations: {
|
| 27 |
+
enabled: {
|
| 28 |
+
[key: string]: boolean;
|
| 29 |
+
};
|
| 30 |
+
disable(): void;
|
| 31 |
+
/**
|
| 32 |
+
* Checks whether the IP address is valid, and that it does not have a port
|
| 33 |
+
* number in it.
|
| 34 |
+
*
|
| 35 |
+
* See https://github.com/express-rate-limit/express-rate-limit/wiki/Error-Codes#err_erl_invalid_ip_address.
|
| 36 |
+
*
|
| 37 |
+
* @param ip {string | undefined} - The IP address provided by Express as request.ip.
|
| 38 |
+
*
|
| 39 |
+
* @returns {void}
|
| 40 |
+
*/
|
| 41 |
+
ip(ip: string | undefined): void;
|
| 42 |
+
/**
|
| 43 |
+
* Makes sure the trust proxy setting is not set to `true`.
|
| 44 |
+
*
|
| 45 |
+
* See https://github.com/express-rate-limit/express-rate-limit/wiki/Error-Codes#err_erl_permissive_trust_proxy.
|
| 46 |
+
*
|
| 47 |
+
* @param request {Request} - The Express request object.
|
| 48 |
+
*
|
| 49 |
+
* @returns {void}
|
| 50 |
+
*/
|
| 51 |
+
trustProxy(request: Request): void;
|
| 52 |
+
/**
|
| 53 |
+
* Makes sure the trust proxy setting is set in case the `X-Forwarded-For`
|
| 54 |
+
* header is present.
|
| 55 |
+
*
|
| 56 |
+
* See https://github.com/express-rate-limit/express-rate-limit/wiki/Error-Codes#err_erl_unset_trust_proxy.
|
| 57 |
+
*
|
| 58 |
+
* @param request {Request} - The Express request object.
|
| 59 |
+
*
|
| 60 |
+
* @returns {void}
|
| 61 |
+
*/
|
| 62 |
+
xForwardedForHeader(request: Request): void;
|
| 63 |
+
/**
|
| 64 |
+
* Alert the user if the Forwarded header is set (standardized version of X-Forwarded-For - not supported by express as of version 5.1.0)
|
| 65 |
+
*
|
| 66 |
+
* @param request {Request} - The Express request object.
|
| 67 |
+
*
|
| 68 |
+
* @returns {void}
|
| 69 |
+
*/
|
| 70 |
+
forwardedHeader(request: Request): void;
|
| 71 |
+
/**
|
| 72 |
+
* Ensures totalHits value from store is a positive integer.
|
| 73 |
+
*
|
| 74 |
+
* @param hits {any} - The `totalHits` returned by the store.
|
| 75 |
+
*/
|
| 76 |
+
positiveHits(hits: any): void;
|
| 77 |
+
/**
|
| 78 |
+
* Ensures a single store instance is not used with multiple express-rate-limit instances
|
| 79 |
+
*/
|
| 80 |
+
unsharedStore(store: Store): void;
|
| 81 |
+
/**
|
| 82 |
+
* Ensures a given key is incremented only once per request.
|
| 83 |
+
*
|
| 84 |
+
* @param request {Request} - The Express request object.
|
| 85 |
+
* @param store {Store} - The store class.
|
| 86 |
+
* @param key {string} - The key used to store the client's hit count.
|
| 87 |
+
*
|
| 88 |
+
* @returns {void}
|
| 89 |
+
*/
|
| 90 |
+
singleCount(request: Request, store: Store, key: string): void;
|
| 91 |
+
/**
|
| 92 |
+
* Warns the user that the behaviour for `max: 0` / `limit: 0` is
|
| 93 |
+
* changing in the next major release.
|
| 94 |
+
*
|
| 95 |
+
* @param limit {number} - The maximum number of hits per client.
|
| 96 |
+
*
|
| 97 |
+
* @returns {void}
|
| 98 |
+
*/
|
| 99 |
+
limit(limit: number): void;
|
| 100 |
+
/**
|
| 101 |
+
* Warns the user that the `draft_polli_ratelimit_headers` option is deprecated
|
| 102 |
+
* and will be removed in the next major release.
|
| 103 |
+
*
|
| 104 |
+
* @param draft_polli_ratelimit_headers {any | undefined} - The now-deprecated setting that was used to enable standard headers.
|
| 105 |
+
*
|
| 106 |
+
* @returns {void}
|
| 107 |
+
*/
|
| 108 |
+
draftPolliHeaders(draft_polli_ratelimit_headers?: any): void;
|
| 109 |
+
/**
|
| 110 |
+
* Warns the user that the `onLimitReached` option is deprecated and
|
| 111 |
+
* will be removed in the next major release.
|
| 112 |
+
*
|
| 113 |
+
* @param onLimitReached {any | undefined} - The maximum number of hits per client.
|
| 114 |
+
*
|
| 115 |
+
* @returns {void}
|
| 116 |
+
*/
|
| 117 |
+
onLimitReached(onLimitReached?: any): void;
|
| 118 |
+
/**
|
| 119 |
+
* Warns the user when an invalid/unsupported version of the draft spec is passed.
|
| 120 |
+
*
|
| 121 |
+
* @param version {any | undefined} - The version passed by the user.
|
| 122 |
+
*
|
| 123 |
+
* @returns {void}
|
| 124 |
+
*/
|
| 125 |
+
headersDraftVersion(version?: any): void;
|
| 126 |
+
/**
|
| 127 |
+
* Warns the user when the selected headers option requires a reset time but
|
| 128 |
+
* the store does not provide one.
|
| 129 |
+
*
|
| 130 |
+
* @param resetTime {Date | undefined} - The timestamp when the client's hit count will be reset.
|
| 131 |
+
*
|
| 132 |
+
* @returns {void}
|
| 133 |
+
*/
|
| 134 |
+
headersResetTime(resetTime?: Date): void;
|
| 135 |
+
knownOptions(passedOptions?: Partial<Options>): void;
|
| 136 |
+
/**
|
| 137 |
+
* Checks the options.validate setting to ensure that only recognized
|
| 138 |
+
* validations are enabled or disabled.
|
| 139 |
+
*
|
| 140 |
+
* If any unrecognized values are found, an error is logged that
|
| 141 |
+
* includes the list of supported validations.
|
| 142 |
+
*/
|
| 143 |
+
validationsConfig(): void;
|
| 144 |
+
/**
|
| 145 |
+
* Checks to see if the instance was created inside of a request handler,
|
| 146 |
+
* which would prevent it from working correctly, with the default memory
|
| 147 |
+
* store (or any other store with localKeys.)
|
| 148 |
+
*/
|
| 149 |
+
creationStack(store: Store): void;
|
| 150 |
+
ipv6Subnet(ipv6Subnet?: any): void;
|
| 151 |
+
ipv6SubnetOrKeyGenerator(options: Partial<Options>): void;
|
| 152 |
+
keyGeneratorIpFallback(keyGenerator?: ValueDeterminingMiddleware<string>): void;
|
| 153 |
+
/**
|
| 154 |
+
* Checks to see if the window duration is greater than 2^32 - 1. This is only
|
| 155 |
+
* called by the default MemoryStore, since it uses Node's setInterval method.
|
| 156 |
+
*
|
| 157 |
+
* See https://nodejs.org/api/timers.html#setintervalcallback-delay-args.
|
| 158 |
+
*/
|
| 159 |
+
windowMs(windowMs: number): void;
|
| 160 |
+
};
|
| 161 |
+
export type Validations = typeof validations;
|
| 162 |
+
/**
|
| 163 |
+
* Basic logging function
|
| 164 |
+
*
|
| 165 |
+
* @param error {unknown} - The error to log
|
| 166 |
+
* @param message {string | undefined} - Additional details about the error
|
| 167 |
+
*/
|
| 168 |
+
export type LoggerFn = (error: unknown, message?: string) => void;
|
| 169 |
+
/**
|
| 170 |
+
* Minimal interface for logging warnings and errors
|
| 171 |
+
*/
|
| 172 |
+
export type Logger = {
|
| 173 |
+
/**
|
| 174 |
+
* Function to log an error
|
| 175 |
+
*/
|
| 176 |
+
error: LoggerFn;
|
| 177 |
+
/**
|
| 178 |
+
* Function to log a warning
|
| 179 |
+
*/
|
| 180 |
+
warn: LoggerFn;
|
| 181 |
+
};
|
| 182 |
+
/**
|
| 183 |
+
* Callback that fires when a client's hit counter is incremented.
|
| 184 |
+
*
|
| 185 |
+
* @param error {Error | undefined} - The error that occurred, if any.
|
| 186 |
+
* @param totalHits {number} - The number of hits for that client so far.
|
| 187 |
+
* @param resetTime {Date | undefined} - The time when the counter resets.
|
| 188 |
+
*/
|
| 189 |
+
export type IncrementCallback = (error: Error | undefined, totalHits: number, resetTime: Date | undefined) => void;
|
| 190 |
+
/**
|
| 191 |
+
* Method (in the form of middleware) to generate/retrieve a value based on the
|
| 192 |
+
* incoming request.
|
| 193 |
+
*
|
| 194 |
+
* @param request {Request} - The Express request object.
|
| 195 |
+
* @param response {Response} - The Express response object.
|
| 196 |
+
*
|
| 197 |
+
* @returns {T} - The value needed.
|
| 198 |
+
*/
|
| 199 |
+
export type ValueDeterminingMiddleware<T> = (request: Request, response: Response) => T | Promise<T>;
|
| 200 |
+
/**
|
| 201 |
+
* Express request handler that sends back a response when a client is
|
| 202 |
+
* rate-limited.
|
| 203 |
+
*
|
| 204 |
+
* @param request {Request} - The Express request object.
|
| 205 |
+
* @param response {Response} - The Express response object.
|
| 206 |
+
* @param next {NextFunction} - The Express `next` function, can be called to skip responding.
|
| 207 |
+
* @param optionsUsed {Options} - The options used to set up the middleware.
|
| 208 |
+
*/
|
| 209 |
+
export type RateLimitExceededEventHandler = (request: Request, response: Response, next: NextFunction, optionsUsed: Options) => void;
|
| 210 |
+
/**
|
| 211 |
+
* Event callback that is triggered on a client's first request that exceeds the limit
|
| 212 |
+
* but not for subsequent requests. May be used for logging, etc. Should *not*
|
| 213 |
+
* send a response.
|
| 214 |
+
*
|
| 215 |
+
* @param request {Request} - The Express request object.
|
| 216 |
+
* @param response {Response} - The Express response object.
|
| 217 |
+
* @param optionsUsed {Options} - The options used to set up the middleware.
|
| 218 |
+
*/
|
| 219 |
+
export type RateLimitReachedEventHandler = (request: Request, response: Response, optionsUsed: Options) => void;
|
| 220 |
+
/**
|
| 221 |
+
* Data returned from the `Store` when a client's hit counter is incremented.
|
| 222 |
+
*
|
| 223 |
+
* @property totalHits {number} - The number of hits for that client so far.
|
| 224 |
+
* @property resetTime {Date | undefined} - The time when the counter resets.
|
| 225 |
+
*/
|
| 226 |
+
export type ClientRateLimitInfo = {
|
| 227 |
+
totalHits: number;
|
| 228 |
+
resetTime: Date | undefined;
|
| 229 |
+
};
|
| 230 |
+
export type IncrementResponse = ClientRateLimitInfo;
|
| 231 |
+
/**
|
| 232 |
+
* A modified Express request handler with the rate limit functions.
|
| 233 |
+
*/
|
| 234 |
+
export type RateLimitRequestHandler = RequestHandler & {
|
| 235 |
+
/**
|
| 236 |
+
* Method to reset a client's hit counter.
|
| 237 |
+
*
|
| 238 |
+
* @param key {string} - The identifier for a client.
|
| 239 |
+
*/
|
| 240 |
+
resetKey: (key: string) => void;
|
| 241 |
+
/**
|
| 242 |
+
* Method to fetch a client's hit count and reset time.
|
| 243 |
+
*
|
| 244 |
+
* @param key {string} - The identifier for a client.
|
| 245 |
+
*
|
| 246 |
+
* @returns {ClientRateLimitInfo} - The number of hits and reset time for that client.
|
| 247 |
+
*/
|
| 248 |
+
getKey: (key: string) => Promise<ClientRateLimitInfo | undefined> | ClientRateLimitInfo | undefined;
|
| 249 |
+
};
|
| 250 |
+
/**
|
| 251 |
+
* An interface that all hit counter stores must implement.
|
| 252 |
+
*
|
| 253 |
+
* @deprecated 6.x - Implement the `Store` interface instead.
|
| 254 |
+
*/
|
| 255 |
+
export type LegacyStore = {
|
| 256 |
+
/**
|
| 257 |
+
* Method to increment a client's hit counter.
|
| 258 |
+
*
|
| 259 |
+
* @param key {string} - The identifier for a client.
|
| 260 |
+
* @param callback {IncrementCallback} - The callback to call once the counter is incremented.
|
| 261 |
+
*/
|
| 262 |
+
incr: (key: string, callback: IncrementCallback) => void;
|
| 263 |
+
/**
|
| 264 |
+
* Method to decrement a client's hit counter.
|
| 265 |
+
*
|
| 266 |
+
* @param key {string} - The identifier for a client.
|
| 267 |
+
*/
|
| 268 |
+
decrement: (key: string) => void;
|
| 269 |
+
/**
|
| 270 |
+
* Method to reset a client's hit counter.
|
| 271 |
+
*
|
| 272 |
+
* @param key {string} - The identifier for a client.
|
| 273 |
+
*/
|
| 274 |
+
resetKey: (key: string) => void;
|
| 275 |
+
/**
|
| 276 |
+
* Method to reset everyone's hit counter.
|
| 277 |
+
*/
|
| 278 |
+
resetAll?: () => void;
|
| 279 |
+
};
|
| 280 |
+
/**
|
| 281 |
+
* An interface that all hit counter stores must implement.
|
| 282 |
+
*/
|
| 283 |
+
export type Store = {
|
| 284 |
+
/**
|
| 285 |
+
* Method that initializes the store, and has access to the options passed to
|
| 286 |
+
* the middleware too.
|
| 287 |
+
*
|
| 288 |
+
* Called once during initialization.
|
| 289 |
+
*
|
| 290 |
+
* Errors / promise rejections will be caught and logged.
|
| 291 |
+
*
|
| 292 |
+
* Note that the result is not awaited - other store methods (such as increment) may be called before init returns and/or after it throws/rejects.
|
| 293 |
+
*
|
| 294 |
+
* @param options {Options} - The options used to setup the middleware.
|
| 295 |
+
*/
|
| 296 |
+
init?: (options: Options) => void | Promise<void>;
|
| 297 |
+
/**
|
| 298 |
+
* Method to fetch a client's hit count and reset time.
|
| 299 |
+
*
|
| 300 |
+
* @param key {string} - The identifier for a client.
|
| 301 |
+
*
|
| 302 |
+
* @returns {ClientRateLimitInfo} - The number of hits and reset time for that client.
|
| 303 |
+
*/
|
| 304 |
+
get?: (key: string) => Promise<ClientRateLimitInfo | undefined> | ClientRateLimitInfo | undefined;
|
| 305 |
+
/**
|
| 306 |
+
* Method to increment a client's hit counter.
|
| 307 |
+
*
|
| 308 |
+
* @param key {string} - The identifier for a client.
|
| 309 |
+
*
|
| 310 |
+
* @returns {IncrementResponse | undefined} - The number of hits and reset time for that client.
|
| 311 |
+
*/
|
| 312 |
+
increment: (key: string) => Promise<IncrementResponse> | IncrementResponse;
|
| 313 |
+
/**
|
| 314 |
+
* Method to decrement a client's hit counter.
|
| 315 |
+
*
|
| 316 |
+
* @param key {string} - The identifier for a client.
|
| 317 |
+
*/
|
| 318 |
+
decrement: (key: string) => Promise<void> | void;
|
| 319 |
+
/**
|
| 320 |
+
* Method to reset a client's hit counter.
|
| 321 |
+
*
|
| 322 |
+
* @param key {string} - The identifier for a client.
|
| 323 |
+
*/
|
| 324 |
+
resetKey: (key: string) => Promise<void> | void;
|
| 325 |
+
/**
|
| 326 |
+
* Method to reset everyone's hit counter.
|
| 327 |
+
*/
|
| 328 |
+
resetAll?: () => Promise<void> | void;
|
| 329 |
+
/**
|
| 330 |
+
* Method to shutdown the store, stop timers, and release all resources.
|
| 331 |
+
*/
|
| 332 |
+
shutdown?: () => Promise<void> | void;
|
| 333 |
+
/**
|
| 334 |
+
* Flag to indicate that keys incremented in one instance of this store can
|
| 335 |
+
* not affect other instances. Typically false if a database is used, true for
|
| 336 |
+
* MemoryStore.
|
| 337 |
+
*
|
| 338 |
+
* Used to help detect double-counting misconfigurations.
|
| 339 |
+
*/
|
| 340 |
+
localKeys?: boolean;
|
| 341 |
+
/**
|
| 342 |
+
* Optional value that the store prepends to keys
|
| 343 |
+
*
|
| 344 |
+
* Used by the double-count check to avoid false-positives when a key is counted
|
| 345 |
+
* twice, but with different prefixes.
|
| 346 |
+
*/
|
| 347 |
+
prefix?: string;
|
| 348 |
+
};
|
| 349 |
+
export type DraftHeadersVersion = (typeof SUPPORTED_DRAFT_VERSIONS)[number];
|
| 350 |
+
/**
|
| 351 |
+
* Validate configuration object for enabling or disabling specific validations.
|
| 352 |
+
*
|
| 353 |
+
* The keys must also be keys in the validations object, except `enable`, `disable`,
|
| 354 |
+
* and `default`.
|
| 355 |
+
*/
|
| 356 |
+
export type EnabledValidations = {
|
| 357 |
+
[key in keyof Omit<Validations, "enabled" | "disable"> | "default"]?: boolean;
|
| 358 |
+
};
|
| 359 |
+
/**
|
| 360 |
+
* The configuration options for the rate limiter.
|
| 361 |
+
*/
|
| 362 |
+
export type Options = {
|
| 363 |
+
/**
|
| 364 |
+
* How long we should remember the requests.
|
| 365 |
+
*
|
| 366 |
+
* Defaults to `60000` ms (= 1 minute).
|
| 367 |
+
*/
|
| 368 |
+
windowMs: number;
|
| 369 |
+
/**
|
| 370 |
+
* The maximum number of connections to allow during the `window` before
|
| 371 |
+
* rate limiting the client.
|
| 372 |
+
*
|
| 373 |
+
* Can be the limit itself as a number or express middleware that parses
|
| 374 |
+
* the request and then figures out the limit.
|
| 375 |
+
*
|
| 376 |
+
* Defaults to `5`.
|
| 377 |
+
*/
|
| 378 |
+
limit: number | ValueDeterminingMiddleware<number>;
|
| 379 |
+
/**
|
| 380 |
+
* The response body to send back when a client is rate limited.
|
| 381 |
+
*
|
| 382 |
+
* Defaults to `'Too many requests, please try again later.'`
|
| 383 |
+
*/
|
| 384 |
+
message: any | ValueDeterminingMiddleware<any>;
|
| 385 |
+
/**
|
| 386 |
+
* The HTTP status code to send back when a client is rate limited.
|
| 387 |
+
*
|
| 388 |
+
* Defaults to `HTTP 429 Too Many Requests` (RFC 6585).
|
| 389 |
+
*/
|
| 390 |
+
statusCode: number;
|
| 391 |
+
/**
|
| 392 |
+
* Whether to send `X-RateLimit-*` headers with the rate limit and the number
|
| 393 |
+
* of requests.
|
| 394 |
+
*
|
| 395 |
+
* Defaults to `true` (for backward compatibility).
|
| 396 |
+
*/
|
| 397 |
+
legacyHeaders: boolean;
|
| 398 |
+
/**
|
| 399 |
+
* Whether to enable support for the standardized rate limit headers (`RateLimit-*`).
|
| 400 |
+
*
|
| 401 |
+
* Defaults to `false` (for backward compatibility, but its use is recommended).
|
| 402 |
+
*/
|
| 403 |
+
standardHeaders: boolean | DraftHeadersVersion;
|
| 404 |
+
/**
|
| 405 |
+
* The name used to identify the quota policy in the `RateLimit` headers as per
|
| 406 |
+
* the 8th draft of the IETF specification.
|
| 407 |
+
*
|
| 408 |
+
* Defaults to `{limit}-in-{window}`.
|
| 409 |
+
*/
|
| 410 |
+
identifier: string | ValueDeterminingMiddleware<string>;
|
| 411 |
+
/**
|
| 412 |
+
* The name of the property on the request object to store the rate limit info.
|
| 413 |
+
*
|
| 414 |
+
* Defaults to `rateLimit`.
|
| 415 |
+
*/
|
| 416 |
+
requestPropertyName: string;
|
| 417 |
+
/**
|
| 418 |
+
* If `true`, the library will (by default) skip all requests that have a 4XX
|
| 419 |
+
* or 5XX status.
|
| 420 |
+
*
|
| 421 |
+
* Defaults to `false`.
|
| 422 |
+
*/
|
| 423 |
+
skipFailedRequests: boolean;
|
| 424 |
+
/**
|
| 425 |
+
* If `true`, the library will (by default) skip all requests that have a
|
| 426 |
+
* status code less than 400.
|
| 427 |
+
*
|
| 428 |
+
* Defaults to `false`.
|
| 429 |
+
*/
|
| 430 |
+
skipSuccessfulRequests: boolean;
|
| 431 |
+
/**
|
| 432 |
+
* Method to generate custom identifiers for clients.
|
| 433 |
+
*
|
| 434 |
+
* By default, the client's IP address is used.
|
| 435 |
+
*/
|
| 436 |
+
keyGenerator: ValueDeterminingMiddleware<string>;
|
| 437 |
+
/**
|
| 438 |
+
* IPv6 subnet mask applied to IPv6 addresses in the default keyGenerator.
|
| 439 |
+
*
|
| 440 |
+
* Default is 56. The valid range is technically 1-128 but the value should
|
| 441 |
+
* generally be in the 32-64 range.
|
| 442 |
+
*
|
| 443 |
+
* Smaller numbers are more aggressive, larger numbers are more lenient. Try
|
| 444 |
+
* bumping to 60 or 64 if you see evidence of users being blocked incorrectly.
|
| 445 |
+
*
|
| 446 |
+
* May also be set to a function that returns a number based on the request.
|
| 447 |
+
*
|
| 448 |
+
* See the documentation for more info:
|
| 449 |
+
* https://express-rate-limit.mintlify.app/reference/configuration#ipv6subnet.
|
| 450 |
+
*/
|
| 451 |
+
ipv6Subnet: 64 | 60 | 56 | 52 | 50 | 48 | 32 | number | ValueDeterminingMiddleware<number> | false;
|
| 452 |
+
/**
|
| 453 |
+
* Express request handler that sends back a response when a client is
|
| 454 |
+
* rate-limited.
|
| 455 |
+
*
|
| 456 |
+
* By default, sends back the `statusCode` and `message` set via the options.
|
| 457 |
+
*/
|
| 458 |
+
handler: RateLimitExceededEventHandler;
|
| 459 |
+
/**
|
| 460 |
+
* Method (in the form of middleware) to determine whether or not this request
|
| 461 |
+
* counts towards a client's quota.
|
| 462 |
+
*
|
| 463 |
+
* By default, skips no requests.
|
| 464 |
+
*/
|
| 465 |
+
skip: ValueDeterminingMiddleware<boolean>;
|
| 466 |
+
/**
|
| 467 |
+
* Method to determine whether or not the request counts as 'successful'. Used
|
| 468 |
+
* when either `skipSuccessfulRequests` or `skipFailedRequests` is set to true.
|
| 469 |
+
*
|
| 470 |
+
* By default, requests with a response status code less than 400 are considered
|
| 471 |
+
* successful.
|
| 472 |
+
*/
|
| 473 |
+
requestWasSuccessful: ValueDeterminingMiddleware<boolean>;
|
| 474 |
+
/**
|
| 475 |
+
* The `Store` to use to store the hit count for each client.
|
| 476 |
+
*
|
| 477 |
+
* By default, the built-in `MemoryStore` will be used.
|
| 478 |
+
*/
|
| 479 |
+
store: Store | LegacyStore;
|
| 480 |
+
/**
|
| 481 |
+
* The list of validation checks that should run.
|
| 482 |
+
*/
|
| 483 |
+
validate: boolean | EnabledValidations;
|
| 484 |
+
/**
|
| 485 |
+
* Whether to send `X-RateLimit-*` headers with the rate limit and the number
|
| 486 |
+
* of requests.
|
| 487 |
+
*
|
| 488 |
+
* @deprecated 6.x - This option was renamed to `legacyHeaders`.
|
| 489 |
+
*/
|
| 490 |
+
headers?: boolean;
|
| 491 |
+
/**
|
| 492 |
+
* The maximum number of connections to allow during the `window` before
|
| 493 |
+
* rate limiting the client.
|
| 494 |
+
*
|
| 495 |
+
* Can be the limit itself as a number or express middleware that parses
|
| 496 |
+
* the request and then figures out the limit.
|
| 497 |
+
*
|
| 498 |
+
* @deprecated 7.x - This option was renamed to `limit`. However, it will not
|
| 499 |
+
* be removed from the library in the foreseeable future.
|
| 500 |
+
*/
|
| 501 |
+
max?: number | ValueDeterminingMiddleware<number>;
|
| 502 |
+
/**
|
| 503 |
+
* If the Store generates an error, allow the request to pass.
|
| 504 |
+
*/
|
| 505 |
+
passOnStoreError: boolean;
|
| 506 |
+
/**
|
| 507 |
+
* The logger to use to log errors. If absent, logs to the console.
|
| 508 |
+
*/
|
| 509 |
+
logger: Logger;
|
| 510 |
+
};
|
| 511 |
+
/**
|
| 512 |
+
* The extended request object that includes information about the client's
|
| 513 |
+
* rate limit.
|
| 514 |
+
*/
|
| 515 |
+
export type AugmentedRequest = Request & {
|
| 516 |
+
[key: string]: RateLimitInfo;
|
| 517 |
+
};
|
| 518 |
+
/**
|
| 519 |
+
* The rate limit related information for each client included in the
|
| 520 |
+
* Express request object.
|
| 521 |
+
*/
|
| 522 |
+
export type RateLimitInfo = {
|
| 523 |
+
limit: number;
|
| 524 |
+
used: number;
|
| 525 |
+
remaining: number;
|
| 526 |
+
resetTime: Date | undefined;
|
| 527 |
+
key: string;
|
| 528 |
+
};
|
| 529 |
+
/**
|
| 530 |
+
* The record that stores information about a client - namely, how many times
|
| 531 |
+
* they have hit the endpoint, and when their hit count resets.
|
| 532 |
+
*
|
| 533 |
+
* Similar to `ClientRateLimitInfo`, except `resetTime` is a compulsory field.
|
| 534 |
+
*/
|
| 535 |
+
export type Client = {
|
| 536 |
+
totalHits: number;
|
| 537 |
+
resetTime: Date;
|
| 538 |
+
};
|
| 539 |
+
/**
|
| 540 |
+
* A `Store` that stores the hit count for each client in memory.
|
| 541 |
+
*
|
| 542 |
+
* @public
|
| 543 |
+
*/
|
| 544 |
+
export declare class MemoryStore implements Store {
|
| 545 |
+
private validations?;
|
| 546 |
+
/**
|
| 547 |
+
* The duration of time before which all hit counts are reset (in milliseconds).
|
| 548 |
+
*/
|
| 549 |
+
windowMs: number;
|
| 550 |
+
/**
|
| 551 |
+
* These two maps store usage (requests) and reset time by key (for example, IP
|
| 552 |
+
* addresses or API keys).
|
| 553 |
+
*
|
| 554 |
+
* They are split into two to avoid having to iterate through the entire set to
|
| 555 |
+
* determine which ones need reset. Instead, `Client`s are moved from `previous`
|
| 556 |
+
* to `current` as they hit the endpoint. Once `windowMs` has elapsed, all clients
|
| 557 |
+
* left in `previous`, i.e., those that have not made any recent requests, are
|
| 558 |
+
* known to be expired and can be deleted in bulk.
|
| 559 |
+
*/
|
| 560 |
+
previous: Map<string, Client>;
|
| 561 |
+
current: Map<string, Client>;
|
| 562 |
+
/**
|
| 563 |
+
* A reference to the active timer.
|
| 564 |
+
*/
|
| 565 |
+
interval?: NodeJS.Timeout;
|
| 566 |
+
/**
|
| 567 |
+
* Confirmation that the keys incremented in once instance of MemoryStore
|
| 568 |
+
* cannot affect other instances.
|
| 569 |
+
*/
|
| 570 |
+
localKeys: boolean;
|
| 571 |
+
constructor(validations?: Validations | undefined);
|
| 572 |
+
/**
|
| 573 |
+
* Method that initializes the store.
|
| 574 |
+
*
|
| 575 |
+
* @param options {Options} - The options used to setup the middleware.
|
| 576 |
+
*/
|
| 577 |
+
init(options: Options): void;
|
| 578 |
+
/**
|
| 579 |
+
* Method to fetch a client's hit count and reset time.
|
| 580 |
+
*
|
| 581 |
+
* @param key {string} - The identifier for a client.
|
| 582 |
+
*
|
| 583 |
+
* @returns {ClientRateLimitInfo | undefined} - The number of hits and reset time for that client.
|
| 584 |
+
*
|
| 585 |
+
* @public
|
| 586 |
+
*/
|
| 587 |
+
get(key: string): Promise<ClientRateLimitInfo | undefined>;
|
| 588 |
+
/**
|
| 589 |
+
* Method to increment a client's hit counter.
|
| 590 |
+
*
|
| 591 |
+
* @param key {string} - The identifier for a client.
|
| 592 |
+
*
|
| 593 |
+
* @returns {ClientRateLimitInfo} - The number of hits and reset time for that client.
|
| 594 |
+
*
|
| 595 |
+
* @public
|
| 596 |
+
*/
|
| 597 |
+
increment(key: string): Promise<ClientRateLimitInfo>;
|
| 598 |
+
/**
|
| 599 |
+
* Method to decrement a client's hit counter.
|
| 600 |
+
*
|
| 601 |
+
* @param key {string} - The identifier for a client.
|
| 602 |
+
*
|
| 603 |
+
* @public
|
| 604 |
+
*/
|
| 605 |
+
decrement(key: string): Promise<void>;
|
| 606 |
+
/**
|
| 607 |
+
* Method to reset a client's hit counter.
|
| 608 |
+
*
|
| 609 |
+
* @param key {string} - The identifier for a client.
|
| 610 |
+
*
|
| 611 |
+
* @public
|
| 612 |
+
*/
|
| 613 |
+
resetKey(key: string): Promise<void>;
|
| 614 |
+
/**
|
| 615 |
+
* Method to reset everyone's hit counter.
|
| 616 |
+
*
|
| 617 |
+
* @public
|
| 618 |
+
*/
|
| 619 |
+
resetAll(): Promise<void>;
|
| 620 |
+
/**
|
| 621 |
+
* Method to stop the timer (if currently running) and prevent any memory
|
| 622 |
+
* leaks.
|
| 623 |
+
*
|
| 624 |
+
* @public
|
| 625 |
+
*/
|
| 626 |
+
shutdown(): void;
|
| 627 |
+
/**
|
| 628 |
+
* Recycles a client by setting its hit count to zero, and reset time to
|
| 629 |
+
* `windowMs` milliseconds from now.
|
| 630 |
+
*
|
| 631 |
+
* NOT to be confused with `#resetKey()`, which removes a client from both the
|
| 632 |
+
* `current` and `previous` maps.
|
| 633 |
+
*
|
| 634 |
+
* @param client {Client} - The client to recycle.
|
| 635 |
+
* @param now {number} - The current time, to which the `windowMs` is added to get the `resetTime` for the client.
|
| 636 |
+
*
|
| 637 |
+
* @return {Client} - The modified client that was passed in, to allow for chaining.
|
| 638 |
+
*/
|
| 639 |
+
private resetClient;
|
| 640 |
+
/**
|
| 641 |
+
* Retrieves or creates a client, given a key. Also ensures that the client being
|
| 642 |
+
* returned is in the `current` map.
|
| 643 |
+
*
|
| 644 |
+
* @param key {string} - The key under which the client is (or is to be) stored.
|
| 645 |
+
*
|
| 646 |
+
* @returns {Client} - The requested client.
|
| 647 |
+
*/
|
| 648 |
+
private getClient;
|
| 649 |
+
/**
|
| 650 |
+
* Move current clients to previous, create a new map for current.
|
| 651 |
+
*
|
| 652 |
+
* This function is called every `windowMs`.
|
| 653 |
+
*/
|
| 654 |
+
private clearExpired;
|
| 655 |
+
}
|
| 656 |
+
/**
|
| 657 |
+
*
|
| 658 |
+
* Create an instance of IP rate-limiting middleware for Express.
|
| 659 |
+
*
|
| 660 |
+
* @param passedOptions {Options} - Options to configure the rate limiter.
|
| 661 |
+
*
|
| 662 |
+
* @returns {RateLimitRequestHandler} - The middleware that rate-limits clients based on your configuration.
|
| 663 |
+
*
|
| 664 |
+
* @public
|
| 665 |
+
*/
|
| 666 |
+
export declare const rateLimit: (passedOptions?: Partial<Options>) => RateLimitRequestHandler;
|
| 667 |
+
|
| 668 |
+
export {
|
| 669 |
+
rateLimit as default,
|
| 670 |
+
};
|
| 671 |
+
|
| 672 |
+
export {};
|
tools/ui/node_modules/express-rate-limit/dist/index.mjs
ADDED
|
@@ -0,0 +1,986 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// source/ip-key-generator.ts
|
| 2 |
+
import { isIPv6 } from "node:net";
|
| 3 |
+
import { Address6 } from "ip-address";
|
| 4 |
+
function ipKeyGenerator(ip, ipv6Subnet = 56) {
|
| 5 |
+
if (isIPv6(ip)) {
|
| 6 |
+
const address = new Address6(ip);
|
| 7 |
+
if (address.is4()) return address.to4().correctForm();
|
| 8 |
+
if (ipv6Subnet) {
|
| 9 |
+
const subnet = new Address6(`${ip}/${ipv6Subnet}`);
|
| 10 |
+
return subnet.networkForm();
|
| 11 |
+
}
|
| 12 |
+
}
|
| 13 |
+
return ip;
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
// source/memory-store.ts
|
| 17 |
+
var MemoryStore = class {
|
| 18 |
+
constructor(validations2) {
|
| 19 |
+
this.validations = validations2;
|
| 20 |
+
/**
|
| 21 |
+
* These two maps store usage (requests) and reset time by key (for example, IP
|
| 22 |
+
* addresses or API keys).
|
| 23 |
+
*
|
| 24 |
+
* They are split into two to avoid having to iterate through the entire set to
|
| 25 |
+
* determine which ones need reset. Instead, `Client`s are moved from `previous`
|
| 26 |
+
* to `current` as they hit the endpoint. Once `windowMs` has elapsed, all clients
|
| 27 |
+
* left in `previous`, i.e., those that have not made any recent requests, are
|
| 28 |
+
* known to be expired and can be deleted in bulk.
|
| 29 |
+
*/
|
| 30 |
+
this.previous = /* @__PURE__ */ new Map();
|
| 31 |
+
this.current = /* @__PURE__ */ new Map();
|
| 32 |
+
/**
|
| 33 |
+
* Confirmation that the keys incremented in once instance of MemoryStore
|
| 34 |
+
* cannot affect other instances.
|
| 35 |
+
*/
|
| 36 |
+
this.localKeys = true;
|
| 37 |
+
}
|
| 38 |
+
/**
|
| 39 |
+
* Method that initializes the store.
|
| 40 |
+
*
|
| 41 |
+
* @param options {Options} - The options used to setup the middleware.
|
| 42 |
+
*/
|
| 43 |
+
init(options) {
|
| 44 |
+
this.windowMs = options.windowMs;
|
| 45 |
+
this.validations?.windowMs(this.windowMs);
|
| 46 |
+
if (this.interval) clearInterval(this.interval);
|
| 47 |
+
this.interval = setInterval(() => {
|
| 48 |
+
this.clearExpired();
|
| 49 |
+
}, this.windowMs);
|
| 50 |
+
this.interval.unref?.();
|
| 51 |
+
}
|
| 52 |
+
/**
|
| 53 |
+
* Method to fetch a client's hit count and reset time.
|
| 54 |
+
*
|
| 55 |
+
* @param key {string} - The identifier for a client.
|
| 56 |
+
*
|
| 57 |
+
* @returns {ClientRateLimitInfo | undefined} - The number of hits and reset time for that client.
|
| 58 |
+
*
|
| 59 |
+
* @public
|
| 60 |
+
*/
|
| 61 |
+
async get(key) {
|
| 62 |
+
return this.current.get(key) ?? this.previous.get(key);
|
| 63 |
+
}
|
| 64 |
+
/**
|
| 65 |
+
* Method to increment a client's hit counter.
|
| 66 |
+
*
|
| 67 |
+
* @param key {string} - The identifier for a client.
|
| 68 |
+
*
|
| 69 |
+
* @returns {ClientRateLimitInfo} - The number of hits and reset time for that client.
|
| 70 |
+
*
|
| 71 |
+
* @public
|
| 72 |
+
*/
|
| 73 |
+
async increment(key) {
|
| 74 |
+
const client = this.getClient(key);
|
| 75 |
+
const now = Date.now();
|
| 76 |
+
if (client.resetTime.getTime() <= now) {
|
| 77 |
+
this.resetClient(client, now);
|
| 78 |
+
}
|
| 79 |
+
client.totalHits++;
|
| 80 |
+
return client;
|
| 81 |
+
}
|
| 82 |
+
/**
|
| 83 |
+
* Method to decrement a client's hit counter.
|
| 84 |
+
*
|
| 85 |
+
* @param key {string} - The identifier for a client.
|
| 86 |
+
*
|
| 87 |
+
* @public
|
| 88 |
+
*/
|
| 89 |
+
async decrement(key) {
|
| 90 |
+
const client = this.getClient(key);
|
| 91 |
+
if (client.totalHits > 0) client.totalHits--;
|
| 92 |
+
}
|
| 93 |
+
/**
|
| 94 |
+
* Method to reset a client's hit counter.
|
| 95 |
+
*
|
| 96 |
+
* @param key {string} - The identifier for a client.
|
| 97 |
+
*
|
| 98 |
+
* @public
|
| 99 |
+
*/
|
| 100 |
+
async resetKey(key) {
|
| 101 |
+
this.current.delete(key);
|
| 102 |
+
this.previous.delete(key);
|
| 103 |
+
}
|
| 104 |
+
/**
|
| 105 |
+
* Method to reset everyone's hit counter.
|
| 106 |
+
*
|
| 107 |
+
* @public
|
| 108 |
+
*/
|
| 109 |
+
async resetAll() {
|
| 110 |
+
this.current.clear();
|
| 111 |
+
this.previous.clear();
|
| 112 |
+
}
|
| 113 |
+
/**
|
| 114 |
+
* Method to stop the timer (if currently running) and prevent any memory
|
| 115 |
+
* leaks.
|
| 116 |
+
*
|
| 117 |
+
* @public
|
| 118 |
+
*/
|
| 119 |
+
shutdown() {
|
| 120 |
+
clearInterval(this.interval);
|
| 121 |
+
void this.resetAll();
|
| 122 |
+
}
|
| 123 |
+
/**
|
| 124 |
+
* Recycles a client by setting its hit count to zero, and reset time to
|
| 125 |
+
* `windowMs` milliseconds from now.
|
| 126 |
+
*
|
| 127 |
+
* NOT to be confused with `#resetKey()`, which removes a client from both the
|
| 128 |
+
* `current` and `previous` maps.
|
| 129 |
+
*
|
| 130 |
+
* @param client {Client} - The client to recycle.
|
| 131 |
+
* @param now {number} - The current time, to which the `windowMs` is added to get the `resetTime` for the client.
|
| 132 |
+
*
|
| 133 |
+
* @return {Client} - The modified client that was passed in, to allow for chaining.
|
| 134 |
+
*/
|
| 135 |
+
resetClient(client, now = Date.now()) {
|
| 136 |
+
client.totalHits = 0;
|
| 137 |
+
client.resetTime.setTime(now + this.windowMs);
|
| 138 |
+
return client;
|
| 139 |
+
}
|
| 140 |
+
/**
|
| 141 |
+
* Retrieves or creates a client, given a key. Also ensures that the client being
|
| 142 |
+
* returned is in the `current` map.
|
| 143 |
+
*
|
| 144 |
+
* @param key {string} - The key under which the client is (or is to be) stored.
|
| 145 |
+
*
|
| 146 |
+
* @returns {Client} - The requested client.
|
| 147 |
+
*/
|
| 148 |
+
getClient(key) {
|
| 149 |
+
if (this.current.has(key)) return this.current.get(key);
|
| 150 |
+
let client;
|
| 151 |
+
if (this.previous.has(key)) {
|
| 152 |
+
client = this.previous.get(key);
|
| 153 |
+
this.previous.delete(key);
|
| 154 |
+
} else {
|
| 155 |
+
client = { totalHits: 0, resetTime: /* @__PURE__ */ new Date() };
|
| 156 |
+
this.resetClient(client);
|
| 157 |
+
}
|
| 158 |
+
this.current.set(key, client);
|
| 159 |
+
return client;
|
| 160 |
+
}
|
| 161 |
+
/**
|
| 162 |
+
* Move current clients to previous, create a new map for current.
|
| 163 |
+
*
|
| 164 |
+
* This function is called every `windowMs`.
|
| 165 |
+
*/
|
| 166 |
+
clearExpired() {
|
| 167 |
+
this.previous = this.current;
|
| 168 |
+
this.current = /* @__PURE__ */ new Map();
|
| 169 |
+
}
|
| 170 |
+
};
|
| 171 |
+
|
| 172 |
+
// source/rate-limit.ts
|
| 173 |
+
import { isIPv6 as isIPv62 } from "node:net";
|
| 174 |
+
|
| 175 |
+
// source/console-logger.ts
|
| 176 |
+
var ConsoleLogger = {
|
| 177 |
+
warn(...args) {
|
| 178 |
+
console.warn(...args.reverse());
|
| 179 |
+
},
|
| 180 |
+
error(...args) {
|
| 181 |
+
console.error(...args.reverse());
|
| 182 |
+
}
|
| 183 |
+
};
|
| 184 |
+
|
| 185 |
+
// source/headers.ts
|
| 186 |
+
import { Buffer } from "node:buffer";
|
| 187 |
+
import { createHash } from "node:crypto";
|
| 188 |
+
var SUPPORTED_DRAFT_VERSIONS = [
|
| 189 |
+
"draft-6",
|
| 190 |
+
"draft-7",
|
| 191 |
+
"draft-8"
|
| 192 |
+
];
|
| 193 |
+
var getResetSeconds = (windowMs, resetTime) => {
|
| 194 |
+
let resetSeconds;
|
| 195 |
+
if (resetTime) {
|
| 196 |
+
const deltaSeconds = Math.ceil((resetTime.getTime() - Date.now()) / 1e3);
|
| 197 |
+
resetSeconds = Math.max(0, deltaSeconds);
|
| 198 |
+
} else {
|
| 199 |
+
resetSeconds = Math.ceil(windowMs / 1e3);
|
| 200 |
+
}
|
| 201 |
+
return resetSeconds;
|
| 202 |
+
};
|
| 203 |
+
var getPartitionKey = (key) => {
|
| 204 |
+
const hash = createHash("sha256");
|
| 205 |
+
hash.update(key);
|
| 206 |
+
const partitionKey = hash.digest("hex").slice(0, 12);
|
| 207 |
+
return Buffer.from(partitionKey).toString("base64");
|
| 208 |
+
};
|
| 209 |
+
var setLegacyHeaders = (response, info) => {
|
| 210 |
+
if (response.headersSent) return;
|
| 211 |
+
response.setHeader("X-RateLimit-Limit", info.limit.toString());
|
| 212 |
+
response.setHeader("X-RateLimit-Remaining", info.remaining.toString());
|
| 213 |
+
if (info.resetTime instanceof Date) {
|
| 214 |
+
response.setHeader("Date", (/* @__PURE__ */ new Date()).toUTCString());
|
| 215 |
+
response.setHeader(
|
| 216 |
+
"X-RateLimit-Reset",
|
| 217 |
+
Math.ceil(info.resetTime.getTime() / 1e3).toString()
|
| 218 |
+
);
|
| 219 |
+
}
|
| 220 |
+
};
|
| 221 |
+
var setDraft6Headers = (response, info, windowMs) => {
|
| 222 |
+
if (response.headersSent) return;
|
| 223 |
+
const windowSeconds = Math.ceil(windowMs / 1e3);
|
| 224 |
+
const resetSeconds = getResetSeconds(windowMs, info.resetTime);
|
| 225 |
+
response.setHeader("RateLimit-Policy", `${info.limit};w=${windowSeconds}`);
|
| 226 |
+
response.setHeader("RateLimit-Limit", info.limit.toString());
|
| 227 |
+
response.setHeader("RateLimit-Remaining", info.remaining.toString());
|
| 228 |
+
if (typeof resetSeconds === "number")
|
| 229 |
+
response.setHeader("RateLimit-Reset", resetSeconds.toString());
|
| 230 |
+
};
|
| 231 |
+
var setDraft7Headers = (response, info, windowMs) => {
|
| 232 |
+
if (response.headersSent) return;
|
| 233 |
+
const windowSeconds = Math.ceil(windowMs / 1e3);
|
| 234 |
+
const resetSeconds = getResetSeconds(windowMs, info.resetTime);
|
| 235 |
+
response.setHeader("RateLimit-Policy", `${info.limit};w=${windowSeconds}`);
|
| 236 |
+
response.setHeader(
|
| 237 |
+
"RateLimit",
|
| 238 |
+
`limit=${info.limit}, remaining=${info.remaining}, reset=${resetSeconds}`
|
| 239 |
+
);
|
| 240 |
+
};
|
| 241 |
+
var setDraft8Headers = (response, info, windowMs, name, key) => {
|
| 242 |
+
if (response.headersSent) return;
|
| 243 |
+
const windowSeconds = Math.ceil(windowMs / 1e3);
|
| 244 |
+
const resetSeconds = getResetSeconds(windowMs, info.resetTime);
|
| 245 |
+
const partitionKey = getPartitionKey(key);
|
| 246 |
+
const header = `r=${info.remaining}; t=${resetSeconds}`;
|
| 247 |
+
const policy = `q=${info.limit}; w=${windowSeconds}; pk=:${partitionKey}:`;
|
| 248 |
+
response.append("RateLimit", `"${name}"; ${header}`);
|
| 249 |
+
response.append("RateLimit-Policy", `"${name}"; ${policy}`);
|
| 250 |
+
};
|
| 251 |
+
var setRetryAfterHeader = (response, info, windowMs) => {
|
| 252 |
+
if (response.headersSent) return;
|
| 253 |
+
const resetSeconds = getResetSeconds(windowMs, info.resetTime);
|
| 254 |
+
response.setHeader("Retry-After", resetSeconds.toString());
|
| 255 |
+
};
|
| 256 |
+
|
| 257 |
+
// source/utils.ts
|
| 258 |
+
var omitUndefinedProperties = (passedOptions) => {
|
| 259 |
+
const omittedOptions = {};
|
| 260 |
+
for (const k of Object.keys(passedOptions)) {
|
| 261 |
+
const key = k;
|
| 262 |
+
if (passedOptions[key] !== void 0) {
|
| 263 |
+
omittedOptions[key] = passedOptions[key];
|
| 264 |
+
}
|
| 265 |
+
}
|
| 266 |
+
return omittedOptions;
|
| 267 |
+
};
|
| 268 |
+
|
| 269 |
+
// source/validations.ts
|
| 270 |
+
import { isIP } from "node:net";
|
| 271 |
+
var ValidationError = class extends Error {
|
| 272 |
+
/**
|
| 273 |
+
* The code must be a string, in snake case and all capital, that starts with
|
| 274 |
+
* the substring `ERR_ERL_`.
|
| 275 |
+
*
|
| 276 |
+
* The message must be a string, starting with an uppercase character,
|
| 277 |
+
* describing the issue in detail.
|
| 278 |
+
*/
|
| 279 |
+
constructor(code, message) {
|
| 280 |
+
const url = `https://express-rate-limit.github.io/${code}/`;
|
| 281 |
+
super(`${message} See ${url} for more information.`);
|
| 282 |
+
this.name = this.constructor.name;
|
| 283 |
+
this.code = code;
|
| 284 |
+
this.help = url;
|
| 285 |
+
}
|
| 286 |
+
};
|
| 287 |
+
var ChangeWarning = class extends ValidationError {
|
| 288 |
+
};
|
| 289 |
+
var usedStores = /* @__PURE__ */ new Set();
|
| 290 |
+
var singleCountKeys = /* @__PURE__ */ new WeakMap();
|
| 291 |
+
var validations = {
|
| 292 |
+
enabled: {
|
| 293 |
+
default: true
|
| 294 |
+
},
|
| 295 |
+
// Should be EnabledValidations type, but that's a circular reference
|
| 296 |
+
disable() {
|
| 297 |
+
for (const k of Object.keys(this.enabled)) this.enabled[k] = false;
|
| 298 |
+
},
|
| 299 |
+
/**
|
| 300 |
+
* Checks whether the IP address is valid, and that it does not have a port
|
| 301 |
+
* number in it.
|
| 302 |
+
*
|
| 303 |
+
* See https://github.com/express-rate-limit/express-rate-limit/wiki/Error-Codes#err_erl_invalid_ip_address.
|
| 304 |
+
*
|
| 305 |
+
* @param ip {string | undefined} - The IP address provided by Express as request.ip.
|
| 306 |
+
*
|
| 307 |
+
* @returns {void}
|
| 308 |
+
*/
|
| 309 |
+
ip(ip) {
|
| 310 |
+
if (ip === void 0) {
|
| 311 |
+
throw new ValidationError(
|
| 312 |
+
"ERR_ERL_UNDEFINED_IP_ADDRESS",
|
| 313 |
+
`An undefined 'request.ip' was detected. This might indicate a misconfiguration or the connection being destroyed prematurely.`
|
| 314 |
+
);
|
| 315 |
+
}
|
| 316 |
+
if (!isIP(ip)) {
|
| 317 |
+
throw new ValidationError(
|
| 318 |
+
"ERR_ERL_INVALID_IP_ADDRESS",
|
| 319 |
+
`An invalid 'request.ip' (${ip}) was detected. Consider passing a custom 'keyGenerator' function to the rate limiter.`
|
| 320 |
+
);
|
| 321 |
+
}
|
| 322 |
+
},
|
| 323 |
+
/**
|
| 324 |
+
* Makes sure the trust proxy setting is not set to `true`.
|
| 325 |
+
*
|
| 326 |
+
* See https://github.com/express-rate-limit/express-rate-limit/wiki/Error-Codes#err_erl_permissive_trust_proxy.
|
| 327 |
+
*
|
| 328 |
+
* @param request {Request} - The Express request object.
|
| 329 |
+
*
|
| 330 |
+
* @returns {void}
|
| 331 |
+
*/
|
| 332 |
+
trustProxy(request) {
|
| 333 |
+
if (request.app.get("trust proxy") === true) {
|
| 334 |
+
throw new ValidationError(
|
| 335 |
+
"ERR_ERL_PERMISSIVE_TRUST_PROXY",
|
| 336 |
+
`The Express 'trust proxy' setting is true, which allows anyone to trivially bypass IP-based rate limiting.`
|
| 337 |
+
);
|
| 338 |
+
}
|
| 339 |
+
},
|
| 340 |
+
/**
|
| 341 |
+
* Makes sure the trust proxy setting is set in case the `X-Forwarded-For`
|
| 342 |
+
* header is present.
|
| 343 |
+
*
|
| 344 |
+
* See https://github.com/express-rate-limit/express-rate-limit/wiki/Error-Codes#err_erl_unset_trust_proxy.
|
| 345 |
+
*
|
| 346 |
+
* @param request {Request} - The Express request object.
|
| 347 |
+
*
|
| 348 |
+
* @returns {void}
|
| 349 |
+
*/
|
| 350 |
+
xForwardedForHeader(request) {
|
| 351 |
+
if (request.headers["x-forwarded-for"] && request.app.get("trust proxy") === false) {
|
| 352 |
+
throw new ValidationError(
|
| 353 |
+
"ERR_ERL_UNEXPECTED_X_FORWARDED_FOR",
|
| 354 |
+
`The 'X-Forwarded-For' header is set but the Express 'trust proxy' setting is false (default). This could indicate a misconfiguration which would prevent express-rate-limit from accurately identifying users.`
|
| 355 |
+
);
|
| 356 |
+
}
|
| 357 |
+
},
|
| 358 |
+
/**
|
| 359 |
+
* Alert the user if the Forwarded header is set (standardized version of X-Forwarded-For - not supported by express as of version 5.1.0)
|
| 360 |
+
*
|
| 361 |
+
* @param request {Request} - The Express request object.
|
| 362 |
+
*
|
| 363 |
+
* @returns {void}
|
| 364 |
+
*/
|
| 365 |
+
forwardedHeader(request) {
|
| 366 |
+
if (request.headers.forwarded && request.ip === request.socket?.remoteAddress) {
|
| 367 |
+
throw new ValidationError(
|
| 368 |
+
"ERR_ERL_FORWARDED_HEADER",
|
| 369 |
+
`The 'Forwarded' header (standardized X-Forwarded-For) is set but currently being ignored. Add a custom keyGenerator to use a value from this header.`
|
| 370 |
+
);
|
| 371 |
+
}
|
| 372 |
+
},
|
| 373 |
+
/**
|
| 374 |
+
* Ensures totalHits value from store is a positive integer.
|
| 375 |
+
*
|
| 376 |
+
* @param hits {any} - The `totalHits` returned by the store.
|
| 377 |
+
*/
|
| 378 |
+
positiveHits(hits) {
|
| 379 |
+
if (typeof hits !== "number" || hits < 1 || hits !== Math.round(hits)) {
|
| 380 |
+
throw new ValidationError(
|
| 381 |
+
"ERR_ERL_INVALID_HITS",
|
| 382 |
+
`The totalHits value returned from the store must be a positive integer, got ${hits}`
|
| 383 |
+
);
|
| 384 |
+
}
|
| 385 |
+
},
|
| 386 |
+
/**
|
| 387 |
+
* Ensures a single store instance is not used with multiple express-rate-limit instances
|
| 388 |
+
*/
|
| 389 |
+
unsharedStore(store) {
|
| 390 |
+
if (usedStores.has(store)) {
|
| 391 |
+
const maybeUniquePrefix = store?.localKeys ? "" : " (with a unique prefix)";
|
| 392 |
+
throw new ValidationError(
|
| 393 |
+
"ERR_ERL_STORE_REUSE",
|
| 394 |
+
`A Store instance must not be shared across multiple rate limiters. Create a new instance of ${store.constructor.name}${maybeUniquePrefix} for each limiter instead.`
|
| 395 |
+
);
|
| 396 |
+
}
|
| 397 |
+
usedStores.add(store);
|
| 398 |
+
},
|
| 399 |
+
/**
|
| 400 |
+
* Ensures a given key is incremented only once per request.
|
| 401 |
+
*
|
| 402 |
+
* @param request {Request} - The Express request object.
|
| 403 |
+
* @param store {Store} - The store class.
|
| 404 |
+
* @param key {string} - The key used to store the client's hit count.
|
| 405 |
+
*
|
| 406 |
+
* @returns {void}
|
| 407 |
+
*/
|
| 408 |
+
singleCount(request, store, key) {
|
| 409 |
+
let storeKeys = singleCountKeys.get(request);
|
| 410 |
+
if (!storeKeys) {
|
| 411 |
+
storeKeys = /* @__PURE__ */ new Map();
|
| 412 |
+
singleCountKeys.set(request, storeKeys);
|
| 413 |
+
}
|
| 414 |
+
const storeKey = store.localKeys ? store : store.constructor.name;
|
| 415 |
+
let keys = storeKeys.get(storeKey);
|
| 416 |
+
if (!keys) {
|
| 417 |
+
keys = [];
|
| 418 |
+
storeKeys.set(storeKey, keys);
|
| 419 |
+
}
|
| 420 |
+
const prefixedKey = `${store.prefix ?? ""}${key}`;
|
| 421 |
+
if (keys.includes(prefixedKey)) {
|
| 422 |
+
throw new ValidationError(
|
| 423 |
+
"ERR_ERL_DOUBLE_COUNT",
|
| 424 |
+
`The hit count for ${key} was incremented more than once for a single request.`
|
| 425 |
+
);
|
| 426 |
+
}
|
| 427 |
+
keys.push(prefixedKey);
|
| 428 |
+
},
|
| 429 |
+
/**
|
| 430 |
+
* Warns the user that the behaviour for `max: 0` / `limit: 0` is
|
| 431 |
+
* changing in the next major release.
|
| 432 |
+
*
|
| 433 |
+
* @param limit {number} - The maximum number of hits per client.
|
| 434 |
+
*
|
| 435 |
+
* @returns {void}
|
| 436 |
+
*/
|
| 437 |
+
limit(limit) {
|
| 438 |
+
if (limit === 0) {
|
| 439 |
+
throw new ChangeWarning(
|
| 440 |
+
"WRN_ERL_MAX_ZERO",
|
| 441 |
+
"Setting limit or max to 0 disables rate limiting in express-rate-limit v6 and older, but will cause all requests to be blocked in v7"
|
| 442 |
+
);
|
| 443 |
+
}
|
| 444 |
+
},
|
| 445 |
+
/**
|
| 446 |
+
* Warns the user that the `draft_polli_ratelimit_headers` option is deprecated
|
| 447 |
+
* and will be removed in the next major release.
|
| 448 |
+
*
|
| 449 |
+
* @param draft_polli_ratelimit_headers {any | undefined} - The now-deprecated setting that was used to enable standard headers.
|
| 450 |
+
*
|
| 451 |
+
* @returns {void}
|
| 452 |
+
*/
|
| 453 |
+
draftPolliHeaders(draft_polli_ratelimit_headers) {
|
| 454 |
+
if (draft_polli_ratelimit_headers) {
|
| 455 |
+
throw new ChangeWarning(
|
| 456 |
+
"WRN_ERL_DEPRECATED_DRAFT_POLLI_HEADERS",
|
| 457 |
+
`The draft_polli_ratelimit_headers configuration option is deprecated and has been removed in express-rate-limit v7, please set standardHeaders: 'draft-6' instead.`
|
| 458 |
+
);
|
| 459 |
+
}
|
| 460 |
+
},
|
| 461 |
+
/**
|
| 462 |
+
* Warns the user that the `onLimitReached` option is deprecated and
|
| 463 |
+
* will be removed in the next major release.
|
| 464 |
+
*
|
| 465 |
+
* @param onLimitReached {any | undefined} - The maximum number of hits per client.
|
| 466 |
+
*
|
| 467 |
+
* @returns {void}
|
| 468 |
+
*/
|
| 469 |
+
onLimitReached(onLimitReached) {
|
| 470 |
+
if (onLimitReached) {
|
| 471 |
+
throw new ChangeWarning(
|
| 472 |
+
"WRN_ERL_DEPRECATED_ON_LIMIT_REACHED",
|
| 473 |
+
"The onLimitReached configuration option is deprecated and has been removed in express-rate-limit v7."
|
| 474 |
+
);
|
| 475 |
+
}
|
| 476 |
+
},
|
| 477 |
+
/**
|
| 478 |
+
* Warns the user when an invalid/unsupported version of the draft spec is passed.
|
| 479 |
+
*
|
| 480 |
+
* @param version {any | undefined} - The version passed by the user.
|
| 481 |
+
*
|
| 482 |
+
* @returns {void}
|
| 483 |
+
*/
|
| 484 |
+
headersDraftVersion(version) {
|
| 485 |
+
if (typeof version !== "string" || // @ts-expect-error This is fine. If version is not in the array, it will just return false.
|
| 486 |
+
!SUPPORTED_DRAFT_VERSIONS.includes(version)) {
|
| 487 |
+
const versionString = SUPPORTED_DRAFT_VERSIONS.join(", ");
|
| 488 |
+
throw new ValidationError(
|
| 489 |
+
"ERR_ERL_HEADERS_UNSUPPORTED_DRAFT_VERSION",
|
| 490 |
+
`standardHeaders: only the following versions of the IETF draft specification are supported: ${versionString}.`
|
| 491 |
+
);
|
| 492 |
+
}
|
| 493 |
+
},
|
| 494 |
+
/**
|
| 495 |
+
* Warns the user when the selected headers option requires a reset time but
|
| 496 |
+
* the store does not provide one.
|
| 497 |
+
*
|
| 498 |
+
* @param resetTime {Date | undefined} - The timestamp when the client's hit count will be reset.
|
| 499 |
+
*
|
| 500 |
+
* @returns {void}
|
| 501 |
+
*/
|
| 502 |
+
headersResetTime(resetTime) {
|
| 503 |
+
if (!resetTime) {
|
| 504 |
+
throw new ValidationError(
|
| 505 |
+
"ERR_ERL_HEADERS_NO_RESET",
|
| 506 |
+
`standardHeaders: 'draft-7' requires a 'resetTime', but the store did not provide one. The 'windowMs' value will be used instead, which may cause clients to wait longer than necessary.`
|
| 507 |
+
);
|
| 508 |
+
}
|
| 509 |
+
},
|
| 510 |
+
knownOptions(passedOptions) {
|
| 511 |
+
if (!passedOptions) return;
|
| 512 |
+
const optionsMap = {
|
| 513 |
+
windowMs: true,
|
| 514 |
+
limit: true,
|
| 515 |
+
message: true,
|
| 516 |
+
statusCode: true,
|
| 517 |
+
legacyHeaders: true,
|
| 518 |
+
standardHeaders: true,
|
| 519 |
+
identifier: true,
|
| 520 |
+
requestPropertyName: true,
|
| 521 |
+
skipFailedRequests: true,
|
| 522 |
+
skipSuccessfulRequests: true,
|
| 523 |
+
keyGenerator: true,
|
| 524 |
+
ipv6Subnet: true,
|
| 525 |
+
handler: true,
|
| 526 |
+
skip: true,
|
| 527 |
+
requestWasSuccessful: true,
|
| 528 |
+
store: true,
|
| 529 |
+
validate: true,
|
| 530 |
+
headers: true,
|
| 531 |
+
max: true,
|
| 532 |
+
passOnStoreError: true,
|
| 533 |
+
logger: true
|
| 534 |
+
};
|
| 535 |
+
const validOptions = Object.keys(optionsMap).concat(
|
| 536 |
+
"draft_polli_ratelimit_headers",
|
| 537 |
+
// not a valid option anymore, but we have a more specific check for this one, so don't warn for it here
|
| 538 |
+
// from express-slow-down - https://github.com/express-rate-limit/express-slow-down/blob/main/source/types.ts#L65
|
| 539 |
+
"delayAfter",
|
| 540 |
+
"delayMs",
|
| 541 |
+
"maxDelayMs"
|
| 542 |
+
);
|
| 543 |
+
for (const key of Object.keys(passedOptions)) {
|
| 544 |
+
if (!validOptions.includes(key)) {
|
| 545 |
+
throw new ValidationError(
|
| 546 |
+
"ERR_ERL_UNKNOWN_OPTION",
|
| 547 |
+
`Unexpected configuration option: ${key}`
|
| 548 |
+
// todo: suggest a valid option with a short levenstein distance?
|
| 549 |
+
);
|
| 550 |
+
}
|
| 551 |
+
}
|
| 552 |
+
},
|
| 553 |
+
/**
|
| 554 |
+
* Checks the options.validate setting to ensure that only recognized
|
| 555 |
+
* validations are enabled or disabled.
|
| 556 |
+
*
|
| 557 |
+
* If any unrecognized values are found, an error is logged that
|
| 558 |
+
* includes the list of supported validations.
|
| 559 |
+
*/
|
| 560 |
+
validationsConfig() {
|
| 561 |
+
const supportedValidations = Object.keys(this).filter(
|
| 562 |
+
(k) => !["enabled", "disable"].includes(k)
|
| 563 |
+
);
|
| 564 |
+
supportedValidations.push("default");
|
| 565 |
+
for (const key of Object.keys(this.enabled)) {
|
| 566 |
+
if (!supportedValidations.includes(key)) {
|
| 567 |
+
throw new ValidationError(
|
| 568 |
+
"ERR_ERL_UNKNOWN_VALIDATION",
|
| 569 |
+
`options.validate.${key} is not recognized. Supported validate options are: ${supportedValidations.join(
|
| 570 |
+
", "
|
| 571 |
+
)}.`
|
| 572 |
+
);
|
| 573 |
+
}
|
| 574 |
+
}
|
| 575 |
+
},
|
| 576 |
+
/**
|
| 577 |
+
* Checks to see if the instance was created inside of a request handler,
|
| 578 |
+
* which would prevent it from working correctly, with the default memory
|
| 579 |
+
* store (or any other store with localKeys.)
|
| 580 |
+
*/
|
| 581 |
+
creationStack(store) {
|
| 582 |
+
const { stack } = new Error(
|
| 583 |
+
"express-rate-limit validation check (set options.validate.creationStack=false to disable)"
|
| 584 |
+
);
|
| 585 |
+
if (stack?.includes("Layer.handle [as handle_request]") || // express v4
|
| 586 |
+
stack?.includes("Layer.handleRequest")) {
|
| 587 |
+
if (!store.localKeys) {
|
| 588 |
+
throw new ValidationError(
|
| 589 |
+
"ERR_ERL_CREATED_IN_REQUEST_HANDLER",
|
| 590 |
+
"express-rate-limit instance should *usually* be created at app initialization, not when responding to a request."
|
| 591 |
+
);
|
| 592 |
+
}
|
| 593 |
+
throw new ValidationError(
|
| 594 |
+
"ERR_ERL_CREATED_IN_REQUEST_HANDLER",
|
| 595 |
+
"express-rate-limit instance should be created at app initialization, not when responding to a request."
|
| 596 |
+
);
|
| 597 |
+
}
|
| 598 |
+
},
|
| 599 |
+
ipv6Subnet(ipv6Subnet) {
|
| 600 |
+
if (ipv6Subnet === false) {
|
| 601 |
+
return;
|
| 602 |
+
}
|
| 603 |
+
if (!Number.isInteger(ipv6Subnet) || ipv6Subnet < 32 || ipv6Subnet > 64) {
|
| 604 |
+
throw new ValidationError(
|
| 605 |
+
"ERR_ERL_IPV6_SUBNET",
|
| 606 |
+
`Unexpected ipv6Subnet value: ${ipv6Subnet}. Expected an integer between 32 and 64 (usually 48-64).`
|
| 607 |
+
);
|
| 608 |
+
}
|
| 609 |
+
},
|
| 610 |
+
ipv6SubnetOrKeyGenerator(options) {
|
| 611 |
+
if (options.ipv6Subnet !== void 0 && options.keyGenerator) {
|
| 612 |
+
throw new ValidationError(
|
| 613 |
+
"ERR_ERL_IPV6SUBNET_OR_KEYGENERATOR",
|
| 614 |
+
`Incompatible options: the 'ipv6Subnet' option is ignored when a custom 'keyGenerator' function is also set.`
|
| 615 |
+
);
|
| 616 |
+
}
|
| 617 |
+
},
|
| 618 |
+
keyGeneratorIpFallback(keyGenerator) {
|
| 619 |
+
if (!keyGenerator) {
|
| 620 |
+
return;
|
| 621 |
+
}
|
| 622 |
+
const src = keyGenerator.toString();
|
| 623 |
+
if ((src.includes("req.ip") || src.includes("request.ip")) && !src.includes("ipKeyGenerator")) {
|
| 624 |
+
throw new ValidationError(
|
| 625 |
+
"ERR_ERL_KEY_GEN_IPV6",
|
| 626 |
+
"Custom keyGenerator appears to use request IP without calling the ipKeyGenerator helper function for IPv6 addresses. This could allow IPv6 users to bypass limits."
|
| 627 |
+
);
|
| 628 |
+
}
|
| 629 |
+
},
|
| 630 |
+
/**
|
| 631 |
+
* Checks to see if the window duration is greater than 2^32 - 1. This is only
|
| 632 |
+
* called by the default MemoryStore, since it uses Node's setInterval method.
|
| 633 |
+
*
|
| 634 |
+
* See https://nodejs.org/api/timers.html#setintervalcallback-delay-args.
|
| 635 |
+
*/
|
| 636 |
+
windowMs(windowMs) {
|
| 637 |
+
const SET_TIMEOUT_MAX = 2 ** 31 - 1;
|
| 638 |
+
if (typeof windowMs !== "number" || Number.isNaN(windowMs) || windowMs < 1 || windowMs > SET_TIMEOUT_MAX) {
|
| 639 |
+
throw new ValidationError(
|
| 640 |
+
"ERR_ERL_WINDOW_MS",
|
| 641 |
+
`Invalid windowMs value: ${windowMs}${typeof windowMs !== "number" ? ` (${typeof windowMs})` : ""}, must be a number between 1 and ${SET_TIMEOUT_MAX} when using the default MemoryStore`
|
| 642 |
+
);
|
| 643 |
+
}
|
| 644 |
+
}
|
| 645 |
+
};
|
| 646 |
+
function validateLogger(logger) {
|
| 647 |
+
if (typeof logger !== "object" || typeof logger.error !== "function" || typeof logger.warn !== "function") {
|
| 648 |
+
throw new TypeError(
|
| 649 |
+
"Provided logger does not implement the Logger interface"
|
| 650 |
+
);
|
| 651 |
+
}
|
| 652 |
+
}
|
| 653 |
+
var getValidations = (_enabled, logger) => {
|
| 654 |
+
validateLogger(logger);
|
| 655 |
+
let enabled;
|
| 656 |
+
if (typeof _enabled === "boolean") {
|
| 657 |
+
enabled = {
|
| 658 |
+
default: _enabled
|
| 659 |
+
};
|
| 660 |
+
} else {
|
| 661 |
+
enabled = {
|
| 662 |
+
default: true,
|
| 663 |
+
..._enabled
|
| 664 |
+
};
|
| 665 |
+
}
|
| 666 |
+
const wrappedValidations = { enabled };
|
| 667 |
+
for (const [name, validation] of Object.entries(validations)) {
|
| 668 |
+
if (typeof validation === "function")
|
| 669 |
+
wrappedValidations[name] = (...args) => {
|
| 670 |
+
if (!(enabled[name] ?? enabled.default)) {
|
| 671 |
+
return;
|
| 672 |
+
}
|
| 673 |
+
try {
|
| 674 |
+
;
|
| 675 |
+
validation.apply(
|
| 676 |
+
wrappedValidations,
|
| 677 |
+
args
|
| 678 |
+
);
|
| 679 |
+
} catch (error) {
|
| 680 |
+
if (error instanceof ChangeWarning) logger.warn(error);
|
| 681 |
+
else logger.error(error);
|
| 682 |
+
}
|
| 683 |
+
};
|
| 684 |
+
}
|
| 685 |
+
return wrappedValidations;
|
| 686 |
+
};
|
| 687 |
+
|
| 688 |
+
// source/rate-limit.ts
|
| 689 |
+
var isLegacyStore = (store) => (
|
| 690 |
+
// Check that `incr` exists but `increment` does not - store authors might want
|
| 691 |
+
// to keep both around for backwards compatibility.
|
| 692 |
+
typeof store.incr === "function" && typeof store.increment !== "function"
|
| 693 |
+
);
|
| 694 |
+
var promisifyStore = (passedStore) => {
|
| 695 |
+
if (!isLegacyStore(passedStore)) {
|
| 696 |
+
return passedStore;
|
| 697 |
+
}
|
| 698 |
+
const legacyStore = passedStore;
|
| 699 |
+
class PromisifiedStore {
|
| 700 |
+
async increment(key) {
|
| 701 |
+
return new Promise((resolve, reject) => {
|
| 702 |
+
legacyStore.incr(
|
| 703 |
+
key,
|
| 704 |
+
(error, totalHits, resetTime) => {
|
| 705 |
+
if (error) reject(error);
|
| 706 |
+
resolve({ totalHits, resetTime });
|
| 707 |
+
}
|
| 708 |
+
);
|
| 709 |
+
});
|
| 710 |
+
}
|
| 711 |
+
async decrement(key) {
|
| 712 |
+
return legacyStore.decrement(key);
|
| 713 |
+
}
|
| 714 |
+
async resetKey(key) {
|
| 715 |
+
return legacyStore.resetKey(key);
|
| 716 |
+
}
|
| 717 |
+
/* istanbul ignore next */
|
| 718 |
+
async resetAll() {
|
| 719 |
+
if (typeof legacyStore.resetAll === "function")
|
| 720 |
+
return legacyStore.resetAll();
|
| 721 |
+
}
|
| 722 |
+
}
|
| 723 |
+
return new PromisifiedStore();
|
| 724 |
+
};
|
| 725 |
+
var getOptionsFromConfig = (config) => {
|
| 726 |
+
const { validations: validations2, ...directlyPassableEntries } = config;
|
| 727 |
+
return {
|
| 728 |
+
...directlyPassableEntries,
|
| 729 |
+
validate: validations2.enabled
|
| 730 |
+
};
|
| 731 |
+
};
|
| 732 |
+
var parseOptions = (passedOptions) => {
|
| 733 |
+
const notUndefinedOptions = omitUndefinedProperties(passedOptions);
|
| 734 |
+
const logger = passedOptions.logger ?? ConsoleLogger;
|
| 735 |
+
const validations2 = getValidations(
|
| 736 |
+
notUndefinedOptions?.validate ?? true,
|
| 737 |
+
logger
|
| 738 |
+
);
|
| 739 |
+
validations2.validationsConfig();
|
| 740 |
+
validations2.knownOptions(passedOptions);
|
| 741 |
+
validations2.draftPolliHeaders(
|
| 742 |
+
// @ts-expect-error see the note above.
|
| 743 |
+
notUndefinedOptions.draft_polli_ratelimit_headers
|
| 744 |
+
);
|
| 745 |
+
validations2.onLimitReached(notUndefinedOptions.onLimitReached);
|
| 746 |
+
if (notUndefinedOptions.ipv6Subnet !== void 0 && typeof notUndefinedOptions.ipv6Subnet !== "function") {
|
| 747 |
+
validations2.ipv6Subnet(notUndefinedOptions.ipv6Subnet);
|
| 748 |
+
}
|
| 749 |
+
validations2.keyGeneratorIpFallback(notUndefinedOptions.keyGenerator);
|
| 750 |
+
validations2.ipv6SubnetOrKeyGenerator(notUndefinedOptions);
|
| 751 |
+
let standardHeaders = notUndefinedOptions.standardHeaders ?? false;
|
| 752 |
+
if (standardHeaders === true) standardHeaders = "draft-6";
|
| 753 |
+
const config = {
|
| 754 |
+
windowMs: 60 * 1e3,
|
| 755 |
+
limit: passedOptions.max ?? 5,
|
| 756 |
+
// `max` is deprecated, but support it anyways.
|
| 757 |
+
message: "Too many requests, please try again later.",
|
| 758 |
+
statusCode: 429,
|
| 759 |
+
legacyHeaders: passedOptions.headers ?? true,
|
| 760 |
+
identifier(request, _response) {
|
| 761 |
+
let duration = "";
|
| 762 |
+
const property = config.requestPropertyName;
|
| 763 |
+
const { limit } = request[property];
|
| 764 |
+
const seconds = config.windowMs / 1e3;
|
| 765 |
+
const minutes = config.windowMs / (1e3 * 60);
|
| 766 |
+
const hours = config.windowMs / (1e3 * 60 * 60);
|
| 767 |
+
const days = config.windowMs / (1e3 * 60 * 60 * 24);
|
| 768 |
+
if (seconds < 60) duration = `${seconds}sec`;
|
| 769 |
+
else if (minutes < 60) duration = `${minutes}min`;
|
| 770 |
+
else if (hours < 24) duration = `${hours}hr${hours > 1 ? "s" : ""}`;
|
| 771 |
+
else duration = `${days}day${days > 1 ? "s" : ""}`;
|
| 772 |
+
return `${limit}-in-${duration}`;
|
| 773 |
+
},
|
| 774 |
+
requestPropertyName: "rateLimit",
|
| 775 |
+
skipFailedRequests: false,
|
| 776 |
+
skipSuccessfulRequests: false,
|
| 777 |
+
requestWasSuccessful: (_request, response) => response.statusCode < 400,
|
| 778 |
+
skip: (_request, _response) => false,
|
| 779 |
+
async keyGenerator(request, response) {
|
| 780 |
+
validations2.ip(request.ip);
|
| 781 |
+
validations2.trustProxy(request);
|
| 782 |
+
validations2.xForwardedForHeader(request);
|
| 783 |
+
validations2.forwardedHeader(request);
|
| 784 |
+
const ip = request.ip;
|
| 785 |
+
let subnet = 56;
|
| 786 |
+
if (isIPv62(ip)) {
|
| 787 |
+
subnet = typeof config.ipv6Subnet === "function" ? await config.ipv6Subnet(request, response) : config.ipv6Subnet;
|
| 788 |
+
if (typeof config.ipv6Subnet === "function")
|
| 789 |
+
validations2.ipv6Subnet(subnet);
|
| 790 |
+
}
|
| 791 |
+
return ipKeyGenerator(ip, subnet);
|
| 792 |
+
},
|
| 793 |
+
ipv6Subnet: 56,
|
| 794 |
+
async handler(request, response, _next, _optionsUsed) {
|
| 795 |
+
response.status(config.statusCode);
|
| 796 |
+
const message = typeof config.message === "function" ? await config.message(
|
| 797 |
+
request,
|
| 798 |
+
response
|
| 799 |
+
) : config.message;
|
| 800 |
+
if (!response.writableEnded) response.send(message);
|
| 801 |
+
},
|
| 802 |
+
passOnStoreError: false,
|
| 803 |
+
// Allow the default options to be overridden by the passed options.
|
| 804 |
+
...notUndefinedOptions,
|
| 805 |
+
// `standardHeaders` is resolved into a draft version above, use that.
|
| 806 |
+
standardHeaders,
|
| 807 |
+
// Note that this field is declared after the user's options are spread in,
|
| 808 |
+
// so that this field doesn't get overridden with an un-promisified store!
|
| 809 |
+
store: promisifyStore(
|
| 810 |
+
notUndefinedOptions.store ?? new MemoryStore(validations2)
|
| 811 |
+
),
|
| 812 |
+
// Print an error to the console if a few known misconfigurations are detected.
|
| 813 |
+
validations: validations2,
|
| 814 |
+
logger
|
| 815 |
+
};
|
| 816 |
+
if (typeof config.store.increment !== "function" || typeof config.store.decrement !== "function" || typeof config.store.resetKey !== "function" || config.store.resetAll !== void 0 && typeof config.store.resetAll !== "function" || config.store.init !== void 0 && typeof config.store.init !== "function") {
|
| 817 |
+
throw new TypeError(
|
| 818 |
+
"An invalid store was passed. Please ensure that the store is a class that implements the `Store` interface."
|
| 819 |
+
);
|
| 820 |
+
}
|
| 821 |
+
return config;
|
| 822 |
+
};
|
| 823 |
+
var handleAsyncErrors = (fn) => async (request, response, next) => {
|
| 824 |
+
try {
|
| 825 |
+
await Promise.resolve(fn(request, response, next)).catch(next);
|
| 826 |
+
} catch (error) {
|
| 827 |
+
next(error);
|
| 828 |
+
}
|
| 829 |
+
};
|
| 830 |
+
var rateLimit = (passedOptions) => {
|
| 831 |
+
const config = parseOptions(passedOptions ?? {});
|
| 832 |
+
const options = getOptionsFromConfig(config);
|
| 833 |
+
config.validations.creationStack(config.store);
|
| 834 |
+
config.validations.unsharedStore(config.store);
|
| 835 |
+
if (typeof config.store.init === "function") {
|
| 836 |
+
try {
|
| 837 |
+
const storeInit = config.store.init(options);
|
| 838 |
+
if (storeInit instanceof Promise) {
|
| 839 |
+
storeInit.catch(
|
| 840 |
+
(error) => config.logger.error(
|
| 841 |
+
error,
|
| 842 |
+
"express-rate-limit: async error during store initialization."
|
| 843 |
+
)
|
| 844 |
+
);
|
| 845 |
+
}
|
| 846 |
+
} catch (error) {
|
| 847 |
+
config.logger.error(
|
| 848 |
+
error,
|
| 849 |
+
"express-rate-limit: error during store initialization."
|
| 850 |
+
);
|
| 851 |
+
}
|
| 852 |
+
}
|
| 853 |
+
const middleware = handleAsyncErrors(
|
| 854 |
+
async (request, response, next) => {
|
| 855 |
+
const closePromise = config.skipFailedRequests && new Promise((resolve) => response.once("close", resolve));
|
| 856 |
+
const finishPromise = (config.skipFailedRequests || config.skipSuccessfulRequests) && new Promise((resolve) => response.once("finish", resolve));
|
| 857 |
+
const errorPromise = config.skipFailedRequests && new Promise((resolve) => response.once("error", resolve));
|
| 858 |
+
const skip = await config.skip(request, response);
|
| 859 |
+
if (skip) {
|
| 860 |
+
next();
|
| 861 |
+
return;
|
| 862 |
+
}
|
| 863 |
+
const augmentedRequest = request;
|
| 864 |
+
const key = await config.keyGenerator(request, response);
|
| 865 |
+
let totalHits = 0;
|
| 866 |
+
let resetTime;
|
| 867 |
+
try {
|
| 868 |
+
const incrementResult = await config.store.increment(key);
|
| 869 |
+
totalHits = incrementResult.totalHits;
|
| 870 |
+
resetTime = incrementResult.resetTime;
|
| 871 |
+
} catch (error) {
|
| 872 |
+
if (config.passOnStoreError) {
|
| 873 |
+
config.logger.error(
|
| 874 |
+
error,
|
| 875 |
+
"express-rate-limit: error from store, allowing request without rate-limiting."
|
| 876 |
+
);
|
| 877 |
+
next();
|
| 878 |
+
return;
|
| 879 |
+
}
|
| 880 |
+
throw error;
|
| 881 |
+
}
|
| 882 |
+
config.validations.positiveHits(totalHits);
|
| 883 |
+
config.validations.singleCount(request, config.store, key);
|
| 884 |
+
const retrieveLimit = typeof config.limit === "function" ? config.limit(request, response) : config.limit;
|
| 885 |
+
const limit = await retrieveLimit;
|
| 886 |
+
config.validations.limit(limit);
|
| 887 |
+
const info = {
|
| 888 |
+
limit,
|
| 889 |
+
used: totalHits,
|
| 890 |
+
remaining: Math.max(limit - totalHits, 0),
|
| 891 |
+
resetTime,
|
| 892 |
+
key
|
| 893 |
+
};
|
| 894 |
+
Object.defineProperty(info, "current", {
|
| 895 |
+
configurable: false,
|
| 896 |
+
enumerable: false,
|
| 897 |
+
value: totalHits
|
| 898 |
+
});
|
| 899 |
+
augmentedRequest[config.requestPropertyName] = info;
|
| 900 |
+
if (config.legacyHeaders && !response.headersSent) {
|
| 901 |
+
setLegacyHeaders(response, info);
|
| 902 |
+
}
|
| 903 |
+
if (config.standardHeaders && !response.headersSent) {
|
| 904 |
+
switch (config.standardHeaders) {
|
| 905 |
+
case "draft-6": {
|
| 906 |
+
setDraft6Headers(response, info, config.windowMs);
|
| 907 |
+
break;
|
| 908 |
+
}
|
| 909 |
+
case "draft-7": {
|
| 910 |
+
config.validations.headersResetTime(info.resetTime);
|
| 911 |
+
setDraft7Headers(response, info, config.windowMs);
|
| 912 |
+
break;
|
| 913 |
+
}
|
| 914 |
+
case "draft-8": {
|
| 915 |
+
const retrieveName = typeof config.identifier === "function" ? config.identifier(request, response) : config.identifier;
|
| 916 |
+
const name = await retrieveName;
|
| 917 |
+
config.validations.headersResetTime(info.resetTime);
|
| 918 |
+
setDraft8Headers(response, info, config.windowMs, name, key);
|
| 919 |
+
break;
|
| 920 |
+
}
|
| 921 |
+
default: {
|
| 922 |
+
config.validations.headersDraftVersion(config.standardHeaders);
|
| 923 |
+
break;
|
| 924 |
+
}
|
| 925 |
+
}
|
| 926 |
+
}
|
| 927 |
+
if (config.skipFailedRequests || config.skipSuccessfulRequests) {
|
| 928 |
+
let decremented = false;
|
| 929 |
+
const decrementKey = async () => {
|
| 930 |
+
if (!decremented) {
|
| 931 |
+
await config.store.decrement(key);
|
| 932 |
+
decremented = true;
|
| 933 |
+
}
|
| 934 |
+
};
|
| 935 |
+
if (config.skipFailedRequests) {
|
| 936 |
+
if (finishPromise) {
|
| 937 |
+
void finishPromise.then(async () => {
|
| 938 |
+
if (!await config.requestWasSuccessful(request, response))
|
| 939 |
+
await decrementKey();
|
| 940 |
+
});
|
| 941 |
+
}
|
| 942 |
+
if (closePromise) {
|
| 943 |
+
void closePromise.then(async () => {
|
| 944 |
+
if (!response.writableEnded) await decrementKey();
|
| 945 |
+
});
|
| 946 |
+
}
|
| 947 |
+
if (errorPromise) {
|
| 948 |
+
void errorPromise.then(async () => {
|
| 949 |
+
await decrementKey();
|
| 950 |
+
});
|
| 951 |
+
}
|
| 952 |
+
}
|
| 953 |
+
if (config.skipSuccessfulRequests) {
|
| 954 |
+
if (finishPromise) {
|
| 955 |
+
void finishPromise.then(async () => {
|
| 956 |
+
if (await config.requestWasSuccessful(request, response))
|
| 957 |
+
await decrementKey();
|
| 958 |
+
});
|
| 959 |
+
}
|
| 960 |
+
}
|
| 961 |
+
}
|
| 962 |
+
config.validations.disable();
|
| 963 |
+
if (totalHits > limit) {
|
| 964 |
+
if (config.legacyHeaders || config.standardHeaders) {
|
| 965 |
+
setRetryAfterHeader(response, info, config.windowMs);
|
| 966 |
+
}
|
| 967 |
+
config.handler(request, response, next, options);
|
| 968 |
+
return;
|
| 969 |
+
}
|
| 970 |
+
next();
|
| 971 |
+
}
|
| 972 |
+
);
|
| 973 |
+
const getThrowFn = () => {
|
| 974 |
+
throw new Error("The current store does not support the get/getKey method");
|
| 975 |
+
};
|
| 976 |
+
middleware.resetKey = config.store.resetKey.bind(config.store);
|
| 977 |
+
middleware.getKey = typeof config.store.get === "function" ? config.store.get.bind(config.store) : getThrowFn;
|
| 978 |
+
return middleware;
|
| 979 |
+
};
|
| 980 |
+
var rate_limit_default = rateLimit;
|
| 981 |
+
export {
|
| 982 |
+
MemoryStore,
|
| 983 |
+
rate_limit_default as default,
|
| 984 |
+
ipKeyGenerator,
|
| 985 |
+
rate_limit_default as rateLimit
|
| 986 |
+
};
|
tools/ui/node_modules/express-rate-limit/license.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# MIT License
|
| 2 |
+
|
| 3 |
+
Copyright 2023 Nathan Friedly, Vedant K
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
| 6 |
+
this software and associated documentation files (the "Software"), to deal in
|
| 7 |
+
the Software without restriction, including without limitation the rights to
|
| 8 |
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
| 9 |
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
| 10 |
+
subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
| 17 |
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
| 18 |
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
| 19 |
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
| 20 |
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
tools/ui/node_modules/express-rate-limit/package.json
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "express-rate-limit",
|
| 3 |
+
"version": "8.5.2",
|
| 4 |
+
"description": "Basic IP rate-limiting middleware for Express. Use to limit repeated requests to public APIs and/or endpoints such as password reset.",
|
| 5 |
+
"author": {
|
| 6 |
+
"name": "Nathan Friedly",
|
| 7 |
+
"url": "http://nfriedly.com/"
|
| 8 |
+
},
|
| 9 |
+
"license": "MIT",
|
| 10 |
+
"homepage": "https://github.com/express-rate-limit/express-rate-limit",
|
| 11 |
+
"repository": {
|
| 12 |
+
"type": "git",
|
| 13 |
+
"url": "git+https://github.com/express-rate-limit/express-rate-limit.git"
|
| 14 |
+
},
|
| 15 |
+
"funding": "https://github.com/sponsors/express-rate-limit",
|
| 16 |
+
"keywords": [
|
| 17 |
+
"express-rate-limit",
|
| 18 |
+
"express",
|
| 19 |
+
"rate",
|
| 20 |
+
"limit",
|
| 21 |
+
"ratelimit",
|
| 22 |
+
"rate-limit",
|
| 23 |
+
"middleware",
|
| 24 |
+
"ip",
|
| 25 |
+
"auth",
|
| 26 |
+
"authorization",
|
| 27 |
+
"security",
|
| 28 |
+
"brute",
|
| 29 |
+
"force",
|
| 30 |
+
"bruteforce",
|
| 31 |
+
"brute-force",
|
| 32 |
+
"attack"
|
| 33 |
+
],
|
| 34 |
+
"type": "module",
|
| 35 |
+
"exports": {
|
| 36 |
+
".": {
|
| 37 |
+
"import": {
|
| 38 |
+
"types": "./dist/index.d.mts",
|
| 39 |
+
"default": "./dist/index.mjs"
|
| 40 |
+
},
|
| 41 |
+
"require": {
|
| 42 |
+
"types": "./dist/index.d.cts",
|
| 43 |
+
"default": "./dist/index.cjs"
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
},
|
| 47 |
+
"main": "./dist/index.cjs",
|
| 48 |
+
"module": "./dist/index.mjs",
|
| 49 |
+
"types": "./dist/index.d.ts",
|
| 50 |
+
"files": [
|
| 51 |
+
"dist/",
|
| 52 |
+
"tsconfig.json"
|
| 53 |
+
],
|
| 54 |
+
"engines": {
|
| 55 |
+
"node": ">= 16"
|
| 56 |
+
},
|
| 57 |
+
"scripts": {
|
| 58 |
+
"clean": "del-cli dist/ coverage/ *.log *.tmp *.bak *.tgz",
|
| 59 |
+
"build:cjs": "esbuild --packages=external --platform=node --bundle --target=es2022 --format=cjs --outfile=dist/index.cjs --footer:js=\"module.exports = Object.assign(rateLimit, module.exports);\" source/index.ts",
|
| 60 |
+
"build:esm": "esbuild --packages=external --platform=node --bundle --target=es2022 --format=esm --outfile=dist/index.mjs source/index.ts",
|
| 61 |
+
"build:types": "dts-bundle-generator --out-file=dist/index.d.ts source/index.ts && cp dist/index.d.ts dist/index.d.cts && cp dist/index.d.ts dist/index.d.mts",
|
| 62 |
+
"compile": "run-s clean build:*",
|
| 63 |
+
"docs": "cd docs && mintlify dev",
|
| 64 |
+
"lint:code": "biome check",
|
| 65 |
+
"lint:docs": "prettier --check docs/ *.md",
|
| 66 |
+
"lint": "run-s lint:*",
|
| 67 |
+
"format:code": "biome check --write",
|
| 68 |
+
"format:docs": "prettier --write docs/ *.md",
|
| 69 |
+
"format": "run-s format:*",
|
| 70 |
+
"test:lib": "jest",
|
| 71 |
+
"test:ext": "cd test/external/ && bash run-all-tests",
|
| 72 |
+
"test": "run-s lint test:lib",
|
| 73 |
+
"format-test": "run-s format test:lib",
|
| 74 |
+
"pre-commit": "lint-staged",
|
| 75 |
+
"prepare": "run-s compile && husky"
|
| 76 |
+
},
|
| 77 |
+
"dependencies": {
|
| 78 |
+
"ip-address": "^10.2.0"
|
| 79 |
+
},
|
| 80 |
+
"peerDependencies": {
|
| 81 |
+
"express": ">= 4.11"
|
| 82 |
+
},
|
| 83 |
+
"devDependencies": {
|
| 84 |
+
"@biomejs/biome": "2.4.6",
|
| 85 |
+
"@express-rate-limit/prettier": "1.1.1",
|
| 86 |
+
"@express-rate-limit/tsconfig": "1.0.2",
|
| 87 |
+
"@jest/globals": "30.4.1",
|
| 88 |
+
"@types/express": "5.0.6",
|
| 89 |
+
"@types/jest": "30.0.0",
|
| 90 |
+
"@types/node": "25.7.0",
|
| 91 |
+
"@types/supertest": "7.2.0",
|
| 92 |
+
"del-cli": "7.0.0",
|
| 93 |
+
"dts-bundle-generator": "8.1.2",
|
| 94 |
+
"esbuild": "0.28.0",
|
| 95 |
+
"express": "5.2.1",
|
| 96 |
+
"husky": "9.1.7",
|
| 97 |
+
"jest": "30.4.2",
|
| 98 |
+
"lint-staged": "17.0.4",
|
| 99 |
+
"mintlify": "4.2.559",
|
| 100 |
+
"npm-run-all": "4.1.5",
|
| 101 |
+
"prettier": "3.8.3",
|
| 102 |
+
"ratelimit-header-parser": "0.1.0",
|
| 103 |
+
"supertest": "7.2.2",
|
| 104 |
+
"ts-jest": "29.4.9",
|
| 105 |
+
"ts-node": "10.9.2",
|
| 106 |
+
"typescript": "5.9.3"
|
| 107 |
+
},
|
| 108 |
+
"prettier": "@express-rate-limit/prettier",
|
| 109 |
+
"lint-staged": {
|
| 110 |
+
"*.{js,ts,json}": "biome check --write",
|
| 111 |
+
"*.{md,yaml}": "prettier --write"
|
| 112 |
+
}
|
| 113 |
+
}
|
tools/ui/node_modules/express-rate-limit/readme.md
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<h1 align="center"> <code>express-rate-limit</code> </h1>
|
| 2 |
+
|
| 3 |
+
<div align="center">
|
| 4 |
+
|
| 5 |
+
[](https://github.com/express-rate-limit/express-rate-limit/actions/workflows/ci.yaml)
|
| 6 |
+
[](https://npmjs.org/package/express-rate-limit 'View this project on NPM')
|
| 7 |
+
[](https://www.npmjs.com/package/express-rate-limit)
|
| 8 |
+
[](license.md)
|
| 9 |
+
|
| 10 |
+
</div>
|
| 11 |
+
|
| 12 |
+
Basic rate-limiting middleware for [Express](http://expressjs.com/). Use to
|
| 13 |
+
limit repeated requests to public APIs and/or endpoints such as password reset.
|
| 14 |
+
Plays nice with
|
| 15 |
+
[express-slow-down](https://www.npmjs.com/package/express-slow-down) and
|
| 16 |
+
[ratelimit-header-parser](https://www.npmjs.com/package/ratelimit-header-parser).
|
| 17 |
+
|
| 18 |
+
## Usage
|
| 19 |
+
|
| 20 |
+
The [full documentation](https://express-rate-limit.mintlify.app/overview) is
|
| 21 |
+
available on-line.
|
| 22 |
+
|
| 23 |
+
```ts
|
| 24 |
+
import { rateLimit } from 'express-rate-limit'
|
| 25 |
+
|
| 26 |
+
const limiter = rateLimit({
|
| 27 |
+
windowMs: 15 * 60 * 1000, // 15 minutes
|
| 28 |
+
limit: 100, // Limit each IP to 100 requests per `window` (here, per 15 minutes).
|
| 29 |
+
standardHeaders: 'draft-8', // draft-6: `RateLimit-*` headers; draft-7 & draft-8: combined `RateLimit` header
|
| 30 |
+
legacyHeaders: false, // Disable the `X-RateLimit-*` headers.
|
| 31 |
+
ipv6Subnet: 56, // Set to 60 or 64 to be less aggressive, or 52 or 48 to be more aggressive
|
| 32 |
+
// store: ... , // Redis, Memcached, etc. See below.
|
| 33 |
+
})
|
| 34 |
+
|
| 35 |
+
// Apply the rate limiting middleware to all requests.
|
| 36 |
+
app.use(limiter)
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
+
### Data Stores
|
| 40 |
+
|
| 41 |
+
The rate limiter comes with a built-in memory store, and supports a variety of
|
| 42 |
+
[external data stores](https://express-rate-limit.mintlify.app/reference/stores).
|
| 43 |
+
|
| 44 |
+
### Configuration
|
| 45 |
+
|
| 46 |
+
All function options may be async. Click the name for additional info and
|
| 47 |
+
default values.
|
| 48 |
+
|
| 49 |
+
| Option | Type | Remarks |
|
| 50 |
+
| -------------------------- | ----------------------------------------- | ----------------------------------------------------------------------------------------------- |
|
| 51 |
+
| [`windowMs`] | `number` | How long to remember requests for, in milliseconds. |
|
| 52 |
+
| [`limit`] | `number` \| `function` | How many requests to allow. |
|
| 53 |
+
| [`message`] | `string` \| `json` \| `function` | Response to return after limit is reached. |
|
| 54 |
+
| [`statusCode`] | `number` | HTTP status code after limit is reached (default is 429). |
|
| 55 |
+
| [`handler`] | `function` | Function to run after limit is reached (overrides `message` and `statusCode` settings, if set). |
|
| 56 |
+
| [`legacyHeaders`] | `boolean` | Enable the `X-Rate-Limit` header. |
|
| 57 |
+
| [`standardHeaders`] | `'draft-6'` \| `'draft-7'` \| `'draft-8'` | Enable the `Ratelimit` header. |
|
| 58 |
+
| [`identifier`] | `string` \| `function` | Name associated with the quota policy enforced by this rate limiter. |
|
| 59 |
+
| [`store`] | `Store` | Use a custom store to share hit counts across multiple nodes. |
|
| 60 |
+
| [`passOnStoreError`] | `boolean` | Allow (`true`) or block (`false`, default) traffic if the store becomes unavailable. |
|
| 61 |
+
| [`keyGenerator`] | `function` | Identify users (defaults to IP address). |
|
| 62 |
+
| [`ipv6Subnet`] | `number` (32-64) \| `function` \| `false` | How many bits of IPv6 addresses to use in default `keyGenerator` |
|
| 63 |
+
| [`requestPropertyName`] | `string` | Add rate limit info to the `req` object. |
|
| 64 |
+
| [`skip`] | `function` | Return `true` to bypass the limiter for the given request. |
|
| 65 |
+
| [`skipSuccessfulRequests`] | `boolean` | Uncount 1xx/2xx/3xx responses. |
|
| 66 |
+
| [`skipFailedRequests`] | `boolean` | Uncount 4xx/5xx responses. |
|
| 67 |
+
| [`requestWasSuccessful`] | `function` | Used by `skipSuccessfulRequests` and `skipFailedRequests`. |
|
| 68 |
+
| [`validate`] | `boolean` \| `object` | Enable or disable built-in validation checks. |
|
| 69 |
+
| [`logger`] | `Logger` | Custom logger |
|
| 70 |
+
|
| 71 |
+
## Thank You
|
| 72 |
+
|
| 73 |
+
---
|
| 74 |
+
|
| 75 |
+
Thanks to Mintlify for hosting the documentation at
|
| 76 |
+
[express-rate-limit.mintlify.app](https://express-rate-limit.mintlify.app)
|
| 77 |
+
|
| 78 |
+
<p align="center">
|
| 79 |
+
<a href="https://mintlify.com/?utm_campaign=devmark&utm_medium=readme&utm_source=express-rate-limit">
|
| 80 |
+
<img height="75" src="https://devmark-public-assets.s3.us-west-2.amazonaws.com/sponsorships/mintlify.svg" alt="Create your docs today">
|
| 81 |
+
</a>
|
| 82 |
+
</p>
|
| 83 |
+
|
| 84 |
+
---
|
| 85 |
+
|
| 86 |
+
And thank you to everyone who's contributed to this project in any way! 🫶
|
| 87 |
+
|
| 88 |
+
## Issues and Contributing
|
| 89 |
+
|
| 90 |
+
If you encounter a bug or want to see something added/changed, please go ahead
|
| 91 |
+
and
|
| 92 |
+
[open an issue](https://github.com/express-rate-limit/express-rate-limit/issues/new)!
|
| 93 |
+
If you need help with something, feel free to
|
| 94 |
+
[start a discussion](https://github.com/express-rate-limit/express-rate-limit/discussions/new)!
|
| 95 |
+
|
| 96 |
+
If you wish to contribute to the library, thanks! First, please read
|
| 97 |
+
[the contributing guide](https://express-rate-limit.mintlify.app/guides/contributing).
|
| 98 |
+
Then you can pick up any issue and fix/implement it!
|
| 99 |
+
|
| 100 |
+
## License
|
| 101 |
+
|
| 102 |
+
MIT © [Nathan Friedly](http://nfriedly.com/),
|
| 103 |
+
[Vedant K](https://github.com/gamemaker1)
|
| 104 |
+
|
| 105 |
+
[`windowMs`]:
|
| 106 |
+
https://express-rate-limit.mintlify.app/reference/configuration#windowms
|
| 107 |
+
[`limit`]: https://express-rate-limit.mintlify.app/reference/configuration#limit
|
| 108 |
+
[`message`]:
|
| 109 |
+
https://express-rate-limit.mintlify.app/reference/configuration#message
|
| 110 |
+
[`statusCode`]:
|
| 111 |
+
https://express-rate-limit.mintlify.app/reference/configuration#statuscode
|
| 112 |
+
[`handler`]:
|
| 113 |
+
https://express-rate-limit.mintlify.app/reference/configuration#handler
|
| 114 |
+
[`legacyHeaders`]:
|
| 115 |
+
https://express-rate-limit.mintlify.app/reference/configuration#legacyheaders
|
| 116 |
+
[`standardHeaders`]:
|
| 117 |
+
https://express-rate-limit.mintlify.app/reference/configuration#standardheaders
|
| 118 |
+
[`identifier`]:
|
| 119 |
+
https://express-rate-limit.mintlify.app/reference/configuration#identifier
|
| 120 |
+
[`store`]: https://express-rate-limit.mintlify.app/reference/configuration#store
|
| 121 |
+
[`passOnStoreError`]:
|
| 122 |
+
https://express-rate-limit.mintlify.app/reference/configuration#passonstoreerror
|
| 123 |
+
[`keyGenerator`]:
|
| 124 |
+
https://express-rate-limit.mintlify.app/reference/configuration#keygenerator
|
| 125 |
+
[`ipv6Subnet`]:
|
| 126 |
+
https://express-rate-limit.mintlify.app/reference/configuration#ipv6subnet
|
| 127 |
+
[`requestPropertyName`]:
|
| 128 |
+
https://express-rate-limit.mintlify.app/reference/configuration#requestpropertyname
|
| 129 |
+
[`skip`]: https://express-rate-limit.mintlify.app/reference/configuration#skip
|
| 130 |
+
[`skipSuccessfulRequests`]:
|
| 131 |
+
https://express-rate-limit.mintlify.app/reference/configuration#skipsuccessfulrequests
|
| 132 |
+
[`skipFailedRequests`]:
|
| 133 |
+
https://express-rate-limit.mintlify.app/reference/configuration#skipfailedrequests
|
| 134 |
+
[`requestWasSuccessful`]:
|
| 135 |
+
https://express-rate-limit.mintlify.app/reference/configuration#requestwassuccessful
|
| 136 |
+
[`validate`]:
|
| 137 |
+
https://express-rate-limit.mintlify.app/reference/configuration#validate
|
| 138 |
+
[`logger`]:
|
| 139 |
+
https://express-rate-limit.mintlify.app/reference/configuration#logger
|
tools/ui/node_modules/express-rate-limit/tsconfig.json
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"include": ["source/"],
|
| 3 |
+
"exclude": ["node_modules/"],
|
| 4 |
+
"extends": "@express-rate-limit/tsconfig",
|
| 5 |
+
"compilerOptions": {
|
| 6 |
+
"target": "ES2020"
|
| 7 |
+
}
|
| 8 |
+
}
|
tools/ui/node_modules/express/LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
(The MIT License)
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2009-2014 TJ Holowaychuk <tj@vision-media.ca>
|
| 4 |
+
Copyright (c) 2013-2014 Roman Shtylman <shtylman+expressjs@gmail.com>
|
| 5 |
+
Copyright (c) 2014-2015 Douglas Christopher Wilson <doug@somethingdoug.com>
|
| 6 |
+
|
| 7 |
+
Permission is hereby granted, free of charge, to any person obtaining
|
| 8 |
+
a copy of this software and associated documentation files (the
|
| 9 |
+
'Software'), to deal in the Software without restriction, including
|
| 10 |
+
without limitation the rights to use, copy, modify, merge, publish,
|
| 11 |
+
distribute, sublicense, and/or sell copies of the Software, and to
|
| 12 |
+
permit persons to whom the Software is furnished to do so, subject to
|
| 13 |
+
the following conditions:
|
| 14 |
+
|
| 15 |
+
The above copyright notice and this permission notice shall be
|
| 16 |
+
included in all copies or substantial portions of the Software.
|
| 17 |
+
|
| 18 |
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
| 19 |
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
| 20 |
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
| 21 |
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
| 22 |
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
| 23 |
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
| 24 |
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
tools/ui/node_modules/express/Readme.md
ADDED
|
@@ -0,0 +1,276 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[](https://expressjs.com/)
|
| 2 |
+
|
| 3 |
+
**Fast, unopinionated, minimalist web framework for [Node.js](https://nodejs.org).**
|
| 4 |
+
|
| 5 |
+
**This project has a [Code of Conduct].**
|
| 6 |
+
|
| 7 |
+
## Table of contents
|
| 8 |
+
|
| 9 |
+
- [Table of contents](#table-of-contents)
|
| 10 |
+
- [Installation](#installation)
|
| 11 |
+
- [Features](#features)
|
| 12 |
+
- [Docs \& Community](#docs--community)
|
| 13 |
+
- [Quick Start](#quick-start)
|
| 14 |
+
- [Philosophy](#philosophy)
|
| 15 |
+
- [Examples](#examples)
|
| 16 |
+
- [Contributing](#contributing)
|
| 17 |
+
- [Security Issues](#security-issues)
|
| 18 |
+
- [Running Tests](#running-tests)
|
| 19 |
+
- [Current project team members](#current-project-team-members)
|
| 20 |
+
- [TC (Technical Committee)](#tc-technical-committee)
|
| 21 |
+
- [TC emeriti members](#tc-emeriti-members)
|
| 22 |
+
- [Triagers](#triagers)
|
| 23 |
+
- [Emeritus Triagers](#emeritus-triagers)
|
| 24 |
+
- [License](#license)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
[![NPM Version][npm-version-image]][npm-url]
|
| 28 |
+
[![NPM Downloads][npm-downloads-image]][npm-downloads-url]
|
| 29 |
+
[![Linux Build][github-actions-ci-image]][github-actions-ci-url]
|
| 30 |
+
[![Test Coverage][coveralls-image]][coveralls-url]
|
| 31 |
+
[![OpenSSF Scorecard Badge][ossf-scorecard-badge]][ossf-scorecard-visualizer]
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
```js
|
| 35 |
+
import express from 'express'
|
| 36 |
+
|
| 37 |
+
const app = express()
|
| 38 |
+
|
| 39 |
+
app.get('/', (req, res) => {
|
| 40 |
+
res.send('Hello World')
|
| 41 |
+
})
|
| 42 |
+
|
| 43 |
+
app.listen(3000, () => {
|
| 44 |
+
console.log('Server is running on http://localhost:3000')
|
| 45 |
+
})
|
| 46 |
+
```
|
| 47 |
+
|
| 48 |
+
## Installation
|
| 49 |
+
|
| 50 |
+
This is a [Node.js](https://nodejs.org/en/) module available through the
|
| 51 |
+
[npm registry](https://www.npmjs.com/).
|
| 52 |
+
|
| 53 |
+
Before installing, [download and install Node.js](https://nodejs.org/en/download/).
|
| 54 |
+
Node.js 18 or higher is required.
|
| 55 |
+
|
| 56 |
+
If this is a brand new project, make sure to create a `package.json` first with
|
| 57 |
+
the [`npm init` command](https://docs.npmjs.com/creating-a-package-json-file).
|
| 58 |
+
|
| 59 |
+
Installation is done using the
|
| 60 |
+
[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):
|
| 61 |
+
|
| 62 |
+
```bash
|
| 63 |
+
npm install express
|
| 64 |
+
```
|
| 65 |
+
|
| 66 |
+
Follow [our installing guide](https://expressjs.com/en/starter/installing.html)
|
| 67 |
+
for more information.
|
| 68 |
+
|
| 69 |
+
## Features
|
| 70 |
+
|
| 71 |
+
* Robust routing
|
| 72 |
+
* Focus on high performance
|
| 73 |
+
* Super-high test coverage
|
| 74 |
+
* HTTP helpers (redirection, caching, etc)
|
| 75 |
+
* View system supporting 14+ template engines
|
| 76 |
+
* Content negotiation
|
| 77 |
+
* Executable for generating applications quickly
|
| 78 |
+
|
| 79 |
+
## Docs & Community
|
| 80 |
+
|
| 81 |
+
* [Website and Documentation](https://expressjs.com/) - [[website repo](https://github.com/expressjs/expressjs.com)]
|
| 82 |
+
* [GitHub Organization](https://github.com/expressjs) for Official Middleware & Modules
|
| 83 |
+
* [Github Discussions](https://github.com/expressjs/discussions) for discussion on the development and usage of Express
|
| 84 |
+
|
| 85 |
+
**PROTIP** Be sure to read the [migration guide to v5](https://expressjs.com/en/guide/migrating-5)
|
| 86 |
+
|
| 87 |
+
## Quick Start
|
| 88 |
+
|
| 89 |
+
The quickest way to get started with express is to utilize the executable [`express(1)`](https://github.com/expressjs/generator) to generate an application as shown below:
|
| 90 |
+
|
| 91 |
+
Install the executable. The executable's major version will match Express's:
|
| 92 |
+
|
| 93 |
+
```bash
|
| 94 |
+
npm install -g express-generator@4
|
| 95 |
+
```
|
| 96 |
+
|
| 97 |
+
Create the app:
|
| 98 |
+
|
| 99 |
+
```bash
|
| 100 |
+
express /tmp/foo && cd /tmp/foo
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
Install dependencies:
|
| 104 |
+
|
| 105 |
+
```bash
|
| 106 |
+
npm install
|
| 107 |
+
```
|
| 108 |
+
|
| 109 |
+
Start the server:
|
| 110 |
+
|
| 111 |
+
```bash
|
| 112 |
+
npm start
|
| 113 |
+
```
|
| 114 |
+
|
| 115 |
+
View the website at: http://localhost:3000
|
| 116 |
+
|
| 117 |
+
## Philosophy
|
| 118 |
+
|
| 119 |
+
The Express philosophy is to provide small, robust tooling for HTTP servers, making
|
| 120 |
+
it a great solution for single page applications, websites, hybrids, or public
|
| 121 |
+
HTTP APIs.
|
| 122 |
+
|
| 123 |
+
Express does not force you to use any specific ORM or template engine. With support for over
|
| 124 |
+
14 template engines via [@ladjs/consolidate](https://github.com/ladjs/consolidate),
|
| 125 |
+
you can quickly craft your perfect framework.
|
| 126 |
+
|
| 127 |
+
## Examples
|
| 128 |
+
|
| 129 |
+
To view the examples, clone the Express repository:
|
| 130 |
+
|
| 131 |
+
```bash
|
| 132 |
+
git clone https://github.com/expressjs/express.git --depth 1 && cd express
|
| 133 |
+
```
|
| 134 |
+
|
| 135 |
+
Then install the dependencies:
|
| 136 |
+
|
| 137 |
+
```bash
|
| 138 |
+
npm install
|
| 139 |
+
```
|
| 140 |
+
|
| 141 |
+
Then run whichever example you want:
|
| 142 |
+
|
| 143 |
+
```bash
|
| 144 |
+
node examples/content-negotiation
|
| 145 |
+
```
|
| 146 |
+
|
| 147 |
+
## Contributing
|
| 148 |
+
|
| 149 |
+
The Express.js project welcomes all constructive contributions. Contributions take many forms,
|
| 150 |
+
from code for bug fixes and enhancements, to additions and fixes to documentation, additional
|
| 151 |
+
tests, triaging incoming pull requests and issues, and more!
|
| 152 |
+
|
| 153 |
+
See the [Contributing Guide] for more technical details on contributing.
|
| 154 |
+
|
| 155 |
+
### Security Issues
|
| 156 |
+
|
| 157 |
+
If you discover a security vulnerability in Express, please see [Security Policies and Procedures](SECURITY.md).
|
| 158 |
+
|
| 159 |
+
### Running Tests
|
| 160 |
+
|
| 161 |
+
To run the test suite, first install the dependencies:
|
| 162 |
+
|
| 163 |
+
```bash
|
| 164 |
+
npm install
|
| 165 |
+
```
|
| 166 |
+
|
| 167 |
+
Then run `npm test`:
|
| 168 |
+
|
| 169 |
+
```bash
|
| 170 |
+
npm test
|
| 171 |
+
```
|
| 172 |
+
|
| 173 |
+
## Current project team members
|
| 174 |
+
|
| 175 |
+
For information about the governance of the express.js project, see [GOVERNANCE.md](https://github.com/expressjs/discussions/blob/HEAD/docs/GOVERNANCE.md).
|
| 176 |
+
|
| 177 |
+
The original author of Express is [TJ Holowaychuk](https://github.com/tj)
|
| 178 |
+
|
| 179 |
+
[List of all contributors](https://github.com/expressjs/express/graphs/contributors)
|
| 180 |
+
|
| 181 |
+
### TC (Technical Committee)
|
| 182 |
+
|
| 183 |
+
* [UlisesGascon](https://github.com/UlisesGascon) - **Ulises Gascón** (he/him)
|
| 184 |
+
* [jonchurch](https://github.com/jonchurch) - **Jon Church**
|
| 185 |
+
* [wesleytodd](https://github.com/wesleytodd) - **Wes Todd**
|
| 186 |
+
* [LinusU](https://github.com/LinusU) - **Linus Unnebäck**
|
| 187 |
+
* [blakeembrey](https://github.com/blakeembrey) - **Blake Embrey**
|
| 188 |
+
* [sheplu](https://github.com/sheplu) - **Jean Burellier**
|
| 189 |
+
* [crandmck](https://github.com/crandmck) - **Rand McKinney**
|
| 190 |
+
* [ctcpip](https://github.com/ctcpip) - **Chris de Almeida**
|
| 191 |
+
|
| 192 |
+
<details>
|
| 193 |
+
<summary>TC emeriti members</summary>
|
| 194 |
+
|
| 195 |
+
#### TC emeriti members
|
| 196 |
+
|
| 197 |
+
* [dougwilson](https://github.com/dougwilson) - **Douglas Wilson**
|
| 198 |
+
* [hacksparrow](https://github.com/hacksparrow) - **Hage Yaapa**
|
| 199 |
+
* [jonathanong](https://github.com/jonathanong) - **jongleberry**
|
| 200 |
+
* [niftylettuce](https://github.com/niftylettuce) - **niftylettuce**
|
| 201 |
+
* [troygoode](https://github.com/troygoode) - **Troy Goode**
|
| 202 |
+
</details>
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
### Triagers
|
| 206 |
+
|
| 207 |
+
* [aravindvnair99](https://github.com/aravindvnair99) - **Aravind Nair**
|
| 208 |
+
* [bjohansebas](https://github.com/bjohansebas) - **Sebastian Beltran**
|
| 209 |
+
* [carpasse](https://github.com/carpasse) - **Carlos Serrano**
|
| 210 |
+
* [CBID2](https://github.com/CBID2) - **Christine Belzie**
|
| 211 |
+
* [UlisesGascon](https://github.com/UlisesGascon) - **Ulises Gascón** (he/him)
|
| 212 |
+
* [IamLizu](https://github.com/IamLizu) - **S M Mahmudul Hasan** (he/him)
|
| 213 |
+
* [Phillip9587](https://github.com/Phillip9587) - **Phillip Barta**
|
| 214 |
+
* [efekrskl](https://github.com/efekrskl) - **Efe Karasakal**
|
| 215 |
+
|
| 216 |
+
|
| 217 |
+
<details>
|
| 218 |
+
<summary>Triagers emeriti members</summary>
|
| 219 |
+
|
| 220 |
+
#### Emeritus Triagers
|
| 221 |
+
|
| 222 |
+
* [AuggieH](https://github.com/AuggieH) - **Auggie Hudak**
|
| 223 |
+
* [G-Rath](https://github.com/G-Rath) - **Gareth Jones**
|
| 224 |
+
* [MohammadXroid](https://github.com/MohammadXroid) - **Mohammad Ayashi**
|
| 225 |
+
* [NawafSwe](https://github.com/NawafSwe) - **Nawaf Alsharqi**
|
| 226 |
+
* [NotMoni](https://github.com/NotMoni) - **Moni**
|
| 227 |
+
* [VigneshMurugan](https://github.com/VigneshMurugan) - **Vignesh Murugan**
|
| 228 |
+
* [davidmashe](https://github.com/davidmashe) - **David Ashe**
|
| 229 |
+
* [digitaIfabric](https://github.com/digitaIfabric) - **David**
|
| 230 |
+
* [e-l-i-s-e](https://github.com/e-l-i-s-e) - **Elise Bonner**
|
| 231 |
+
* [fed135](https://github.com/fed135) - **Frederic Charette**
|
| 232 |
+
* [firmanJS](https://github.com/firmanJS) - **Firman Abdul Hakim**
|
| 233 |
+
* [getspooky](https://github.com/getspooky) - **Yasser Ameur**
|
| 234 |
+
* [ghinks](https://github.com/ghinks) - **Glenn**
|
| 235 |
+
* [ghousemohamed](https://github.com/ghousemohamed) - **Ghouse Mohamed**
|
| 236 |
+
* [gireeshpunathil](https://github.com/gireeshpunathil) - **Gireesh Punathil**
|
| 237 |
+
* [jake32321](https://github.com/jake32321) - **Jake Reed**
|
| 238 |
+
* [jonchurch](https://github.com/jonchurch) - **Jon Church**
|
| 239 |
+
* [lekanikotun](https://github.com/lekanikotun) - **Troy Goode**
|
| 240 |
+
* [marsonya](https://github.com/marsonya) - **Lekan Ikotun**
|
| 241 |
+
* [mastermatt](https://github.com/mastermatt) - **Matt R. Wilson**
|
| 242 |
+
* [maxakuru](https://github.com/maxakuru) - **Max Edell**
|
| 243 |
+
* [mlrawlings](https://github.com/mlrawlings) - **Michael Rawlings**
|
| 244 |
+
* [rodion-arr](https://github.com/rodion-arr) - **Rodion Abdurakhimov**
|
| 245 |
+
* [sheplu](https://github.com/sheplu) - **Jean Burellier**
|
| 246 |
+
* [tarunyadav1](https://github.com/tarunyadav1) - **Tarun yadav**
|
| 247 |
+
* [tunniclm](https://github.com/tunniclm) - **Mike Tunnicliffe**
|
| 248 |
+
* [enyoghasim](https://github.com/enyoghasim) - **David Enyoghasim**
|
| 249 |
+
* [0ss](https://github.com/0ss) - **Salah**
|
| 250 |
+
* [import-brain](https://github.com/import-brain) - **Eric Cheng** (he/him)
|
| 251 |
+
* [dakshkhetan](https://github.com/dakshkhetan) - **Daksh Khetan** (he/him)
|
| 252 |
+
* [lucasraziel](https://github.com/lucasraziel) - **Lucas Soares Do Rego**
|
| 253 |
+
* [mertcanaltin](https://github.com/mertcanaltin) - **Mert Can Altin**
|
| 254 |
+
* [dpopp07](https://github.com/dpopp07) - **Dustin Popp**
|
| 255 |
+
* [Sushmeet](https://github.com/Sushmeet) - **Sushmeet Sunger**
|
| 256 |
+
* [3imed-jaberi](https://github.com/3imed-jaberi) - **Imed Jaberi**
|
| 257 |
+
|
| 258 |
+
</details>
|
| 259 |
+
|
| 260 |
+
|
| 261 |
+
## License
|
| 262 |
+
|
| 263 |
+
[MIT](LICENSE)
|
| 264 |
+
|
| 265 |
+
[coveralls-image]: https://img.shields.io/coverallsCoverage/github/expressjs/express?branch=master
|
| 266 |
+
[coveralls-url]: https://coveralls.io/r/expressjs/express?branch=master
|
| 267 |
+
[github-actions-ci-image]: https://img.shields.io/github/actions/workflow/status/expressjs/express/ci.yml?branch=master&label=ci
|
| 268 |
+
[github-actions-ci-url]: https://github.com/expressjs/express/actions/workflows/ci.yml
|
| 269 |
+
[npm-downloads-image]: https://img.shields.io/npm/dm/express
|
| 270 |
+
[npm-downloads-url]: https://npmcharts.com/compare/express?minimal=true
|
| 271 |
+
[npm-url]: https://npmjs.org/package/express
|
| 272 |
+
[npm-version-image]: https://img.shields.io/npm/v/express
|
| 273 |
+
[ossf-scorecard-badge]: https://api.scorecard.dev/projects/github.com/expressjs/express/badge
|
| 274 |
+
[ossf-scorecard-visualizer]: https://ossf.github.io/scorecard-visualizer/#/projects/github.com/expressjs/express
|
| 275 |
+
[Code of Conduct]: https://github.com/expressjs/.github/blob/HEAD/CODE_OF_CONDUCT.md
|
| 276 |
+
[Contributing Guide]: https://github.com/expressjs/.github/blob/HEAD/CONTRIBUTING.md
|
tools/ui/node_modules/express/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*!
|
| 2 |
+
* express
|
| 3 |
+
* Copyright(c) 2009-2013 TJ Holowaychuk
|
| 4 |
+
* Copyright(c) 2013 Roman Shtylman
|
| 5 |
+
* Copyright(c) 2014-2015 Douglas Christopher Wilson
|
| 6 |
+
* MIT Licensed
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
'use strict';
|
| 10 |
+
|
| 11 |
+
module.exports = require('./lib/express');
|
tools/ui/node_modules/express/lib/application.js
ADDED
|
@@ -0,0 +1,631 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*!
|
| 2 |
+
* express
|
| 3 |
+
* Copyright(c) 2009-2013 TJ Holowaychuk
|
| 4 |
+
* Copyright(c) 2013 Roman Shtylman
|
| 5 |
+
* Copyright(c) 2014-2015 Douglas Christopher Wilson
|
| 6 |
+
* MIT Licensed
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
'use strict';
|
| 10 |
+
|
| 11 |
+
/**
|
| 12 |
+
* Module dependencies.
|
| 13 |
+
* @private
|
| 14 |
+
*/
|
| 15 |
+
|
| 16 |
+
var finalhandler = require('finalhandler');
|
| 17 |
+
var debug = require('debug')('express:application');
|
| 18 |
+
var View = require('./view');
|
| 19 |
+
var http = require('node:http');
|
| 20 |
+
var methods = require('./utils').methods;
|
| 21 |
+
var compileETag = require('./utils').compileETag;
|
| 22 |
+
var compileQueryParser = require('./utils').compileQueryParser;
|
| 23 |
+
var compileTrust = require('./utils').compileTrust;
|
| 24 |
+
var resolve = require('node:path').resolve;
|
| 25 |
+
var once = require('once')
|
| 26 |
+
var Router = require('router');
|
| 27 |
+
|
| 28 |
+
/**
|
| 29 |
+
* Module variables.
|
| 30 |
+
* @private
|
| 31 |
+
*/
|
| 32 |
+
|
| 33 |
+
var slice = Array.prototype.slice;
|
| 34 |
+
var flatten = Array.prototype.flat;
|
| 35 |
+
|
| 36 |
+
/**
|
| 37 |
+
* Application prototype.
|
| 38 |
+
*/
|
| 39 |
+
|
| 40 |
+
var app = exports = module.exports = {};
|
| 41 |
+
|
| 42 |
+
/**
|
| 43 |
+
* Variable for trust proxy inheritance back-compat
|
| 44 |
+
* @private
|
| 45 |
+
*/
|
| 46 |
+
|
| 47 |
+
var trustProxyDefaultSymbol = '@@symbol:trust_proxy_default';
|
| 48 |
+
|
| 49 |
+
/**
|
| 50 |
+
* Initialize the server.
|
| 51 |
+
*
|
| 52 |
+
* - setup default configuration
|
| 53 |
+
* - setup default middleware
|
| 54 |
+
* - setup route reflection methods
|
| 55 |
+
*
|
| 56 |
+
* @private
|
| 57 |
+
*/
|
| 58 |
+
|
| 59 |
+
app.init = function init() {
|
| 60 |
+
var router = null;
|
| 61 |
+
|
| 62 |
+
this.cache = Object.create(null);
|
| 63 |
+
this.engines = Object.create(null);
|
| 64 |
+
this.settings = Object.create(null);
|
| 65 |
+
|
| 66 |
+
this.defaultConfiguration();
|
| 67 |
+
|
| 68 |
+
// Setup getting to lazily add base router
|
| 69 |
+
Object.defineProperty(this, 'router', {
|
| 70 |
+
configurable: true,
|
| 71 |
+
enumerable: true,
|
| 72 |
+
get: function getrouter() {
|
| 73 |
+
if (router === null) {
|
| 74 |
+
router = new Router({
|
| 75 |
+
caseSensitive: this.enabled('case sensitive routing'),
|
| 76 |
+
strict: this.enabled('strict routing')
|
| 77 |
+
});
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
return router;
|
| 81 |
+
}
|
| 82 |
+
});
|
| 83 |
+
};
|
| 84 |
+
|
| 85 |
+
/**
|
| 86 |
+
* Initialize application configuration.
|
| 87 |
+
* @private
|
| 88 |
+
*/
|
| 89 |
+
|
| 90 |
+
app.defaultConfiguration = function defaultConfiguration() {
|
| 91 |
+
var env = process.env.NODE_ENV || 'development';
|
| 92 |
+
|
| 93 |
+
// default settings
|
| 94 |
+
this.enable('x-powered-by');
|
| 95 |
+
this.set('etag', 'weak');
|
| 96 |
+
this.set('env', env);
|
| 97 |
+
this.set('query parser', 'simple')
|
| 98 |
+
this.set('subdomain offset', 2);
|
| 99 |
+
this.set('trust proxy', false);
|
| 100 |
+
|
| 101 |
+
// trust proxy inherit back-compat
|
| 102 |
+
Object.defineProperty(this.settings, trustProxyDefaultSymbol, {
|
| 103 |
+
configurable: true,
|
| 104 |
+
value: true
|
| 105 |
+
});
|
| 106 |
+
|
| 107 |
+
debug('booting in %s mode', env);
|
| 108 |
+
|
| 109 |
+
this.on('mount', function onmount(parent) {
|
| 110 |
+
// inherit trust proxy
|
| 111 |
+
if (this.settings[trustProxyDefaultSymbol] === true
|
| 112 |
+
&& typeof parent.settings['trust proxy fn'] === 'function') {
|
| 113 |
+
delete this.settings['trust proxy'];
|
| 114 |
+
delete this.settings['trust proxy fn'];
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
// inherit protos
|
| 118 |
+
Object.setPrototypeOf(this.request, parent.request)
|
| 119 |
+
Object.setPrototypeOf(this.response, parent.response)
|
| 120 |
+
Object.setPrototypeOf(this.engines, parent.engines)
|
| 121 |
+
Object.setPrototypeOf(this.settings, parent.settings)
|
| 122 |
+
});
|
| 123 |
+
|
| 124 |
+
// setup locals
|
| 125 |
+
this.locals = Object.create(null);
|
| 126 |
+
|
| 127 |
+
// top-most app is mounted at /
|
| 128 |
+
this.mountpath = '/';
|
| 129 |
+
|
| 130 |
+
// default locals
|
| 131 |
+
this.locals.settings = this.settings;
|
| 132 |
+
|
| 133 |
+
// default configuration
|
| 134 |
+
this.set('view', View);
|
| 135 |
+
this.set('views', resolve('views'));
|
| 136 |
+
this.set('jsonp callback name', 'callback');
|
| 137 |
+
|
| 138 |
+
if (env === 'production') {
|
| 139 |
+
this.enable('view cache');
|
| 140 |
+
}
|
| 141 |
+
};
|
| 142 |
+
|
| 143 |
+
/**
|
| 144 |
+
* Dispatch a req, res pair into the application. Starts pipeline processing.
|
| 145 |
+
*
|
| 146 |
+
* If no callback is provided, then default error handlers will respond
|
| 147 |
+
* in the event of an error bubbling through the stack.
|
| 148 |
+
*
|
| 149 |
+
* @private
|
| 150 |
+
*/
|
| 151 |
+
|
| 152 |
+
app.handle = function handle(req, res, callback) {
|
| 153 |
+
// final handler
|
| 154 |
+
var done = callback || finalhandler(req, res, {
|
| 155 |
+
env: this.get('env'),
|
| 156 |
+
onerror: logerror.bind(this)
|
| 157 |
+
});
|
| 158 |
+
|
| 159 |
+
// set powered by header
|
| 160 |
+
if (this.enabled('x-powered-by')) {
|
| 161 |
+
res.setHeader('X-Powered-By', 'Express');
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
// set circular references
|
| 165 |
+
req.res = res;
|
| 166 |
+
res.req = req;
|
| 167 |
+
|
| 168 |
+
// alter the prototypes
|
| 169 |
+
Object.setPrototypeOf(req, this.request)
|
| 170 |
+
Object.setPrototypeOf(res, this.response)
|
| 171 |
+
|
| 172 |
+
// setup locals
|
| 173 |
+
if (!res.locals) {
|
| 174 |
+
res.locals = Object.create(null);
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
this.router.handle(req, res, done);
|
| 178 |
+
};
|
| 179 |
+
|
| 180 |
+
/**
|
| 181 |
+
* Proxy `Router#use()` to add middleware to the app router.
|
| 182 |
+
* See Router#use() documentation for details.
|
| 183 |
+
*
|
| 184 |
+
* If the _fn_ parameter is an express app, then it will be
|
| 185 |
+
* mounted at the _route_ specified.
|
| 186 |
+
*
|
| 187 |
+
* @public
|
| 188 |
+
*/
|
| 189 |
+
|
| 190 |
+
app.use = function use(fn) {
|
| 191 |
+
var offset = 0;
|
| 192 |
+
var path = '/';
|
| 193 |
+
|
| 194 |
+
// default path to '/'
|
| 195 |
+
// disambiguate app.use([fn])
|
| 196 |
+
if (typeof fn !== 'function') {
|
| 197 |
+
var arg = fn;
|
| 198 |
+
|
| 199 |
+
while (Array.isArray(arg) && arg.length !== 0) {
|
| 200 |
+
arg = arg[0];
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
// first arg is the path
|
| 204 |
+
if (typeof arg !== 'function') {
|
| 205 |
+
offset = 1;
|
| 206 |
+
path = fn;
|
| 207 |
+
}
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
var fns = flatten.call(slice.call(arguments, offset), Infinity);
|
| 211 |
+
|
| 212 |
+
if (fns.length === 0) {
|
| 213 |
+
throw new TypeError('app.use() requires a middleware function')
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
// get router
|
| 217 |
+
var router = this.router;
|
| 218 |
+
|
| 219 |
+
fns.forEach(function (fn) {
|
| 220 |
+
// non-express app
|
| 221 |
+
if (!fn || !fn.handle || !fn.set) {
|
| 222 |
+
return router.use(path, fn);
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
debug('.use app under %s', path);
|
| 226 |
+
fn.mountpath = path;
|
| 227 |
+
fn.parent = this;
|
| 228 |
+
|
| 229 |
+
// restore .app property on req and res
|
| 230 |
+
router.use(path, function mounted_app(req, res, next) {
|
| 231 |
+
var orig = req.app;
|
| 232 |
+
fn.handle(req, res, function (err) {
|
| 233 |
+
Object.setPrototypeOf(req, orig.request)
|
| 234 |
+
Object.setPrototypeOf(res, orig.response)
|
| 235 |
+
next(err);
|
| 236 |
+
});
|
| 237 |
+
});
|
| 238 |
+
|
| 239 |
+
// mounted an app
|
| 240 |
+
fn.emit('mount', this);
|
| 241 |
+
}, this);
|
| 242 |
+
|
| 243 |
+
return this;
|
| 244 |
+
};
|
| 245 |
+
|
| 246 |
+
/**
|
| 247 |
+
* Proxy to the app `Router#route()`
|
| 248 |
+
* Returns a new `Route` instance for the _path_.
|
| 249 |
+
*
|
| 250 |
+
* Routes are isolated middleware stacks for specific paths.
|
| 251 |
+
* See the Route api docs for details.
|
| 252 |
+
*
|
| 253 |
+
* @public
|
| 254 |
+
*/
|
| 255 |
+
|
| 256 |
+
app.route = function route(path) {
|
| 257 |
+
return this.router.route(path);
|
| 258 |
+
};
|
| 259 |
+
|
| 260 |
+
/**
|
| 261 |
+
* Register the given template engine callback `fn`
|
| 262 |
+
* as `ext`.
|
| 263 |
+
*
|
| 264 |
+
* By default will `require()` the engine based on the
|
| 265 |
+
* file extension. For example if you try to render
|
| 266 |
+
* a "foo.ejs" file Express will invoke the following internally:
|
| 267 |
+
*
|
| 268 |
+
* app.engine('ejs', require('ejs').__express);
|
| 269 |
+
*
|
| 270 |
+
* For engines that do not provide `.__express` out of the box,
|
| 271 |
+
* or if you wish to "map" a different extension to the template engine
|
| 272 |
+
* you may use this method. For example mapping the EJS template engine to
|
| 273 |
+
* ".html" files:
|
| 274 |
+
*
|
| 275 |
+
* app.engine('html', require('ejs').renderFile);
|
| 276 |
+
*
|
| 277 |
+
* In this case EJS provides a `.renderFile()` method with
|
| 278 |
+
* the same signature that Express expects: `(path, options, callback)`,
|
| 279 |
+
* though note that it aliases this method as `ejs.__express` internally
|
| 280 |
+
* so if you're using ".ejs" extensions you don't need to do anything.
|
| 281 |
+
*
|
| 282 |
+
* Some template engines do not follow this convention, the
|
| 283 |
+
* [Consolidate.js](https://github.com/tj/consolidate.js)
|
| 284 |
+
* library was created to map all of node's popular template
|
| 285 |
+
* engines to follow this convention, thus allowing them to
|
| 286 |
+
* work seamlessly within Express.
|
| 287 |
+
*
|
| 288 |
+
* @param {String} ext
|
| 289 |
+
* @param {Function} fn
|
| 290 |
+
* @return {app} for chaining
|
| 291 |
+
* @public
|
| 292 |
+
*/
|
| 293 |
+
|
| 294 |
+
app.engine = function engine(ext, fn) {
|
| 295 |
+
if (typeof fn !== 'function') {
|
| 296 |
+
throw new Error('callback function required');
|
| 297 |
+
}
|
| 298 |
+
|
| 299 |
+
// get file extension
|
| 300 |
+
var extension = ext[0] !== '.'
|
| 301 |
+
? '.' + ext
|
| 302 |
+
: ext;
|
| 303 |
+
|
| 304 |
+
// store engine
|
| 305 |
+
this.engines[extension] = fn;
|
| 306 |
+
|
| 307 |
+
return this;
|
| 308 |
+
};
|
| 309 |
+
|
| 310 |
+
/**
|
| 311 |
+
* Proxy to `Router#param()` with one added api feature. The _name_ parameter
|
| 312 |
+
* can be an array of names.
|
| 313 |
+
*
|
| 314 |
+
* See the Router#param() docs for more details.
|
| 315 |
+
*
|
| 316 |
+
* @param {String|Array} name
|
| 317 |
+
* @param {Function} fn
|
| 318 |
+
* @return {app} for chaining
|
| 319 |
+
* @public
|
| 320 |
+
*/
|
| 321 |
+
|
| 322 |
+
app.param = function param(name, fn) {
|
| 323 |
+
if (Array.isArray(name)) {
|
| 324 |
+
for (var i = 0; i < name.length; i++) {
|
| 325 |
+
this.param(name[i], fn);
|
| 326 |
+
}
|
| 327 |
+
|
| 328 |
+
return this;
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
this.router.param(name, fn);
|
| 332 |
+
|
| 333 |
+
return this;
|
| 334 |
+
};
|
| 335 |
+
|
| 336 |
+
/**
|
| 337 |
+
* Assign `setting` to `val`, or return `setting`'s value.
|
| 338 |
+
*
|
| 339 |
+
* app.set('foo', 'bar');
|
| 340 |
+
* app.set('foo');
|
| 341 |
+
* // => "bar"
|
| 342 |
+
*
|
| 343 |
+
* Mounted servers inherit their parent server's settings.
|
| 344 |
+
*
|
| 345 |
+
* @param {String} setting
|
| 346 |
+
* @param {*} [val]
|
| 347 |
+
* @return {Server} for chaining
|
| 348 |
+
* @public
|
| 349 |
+
*/
|
| 350 |
+
|
| 351 |
+
app.set = function set(setting, val) {
|
| 352 |
+
if (arguments.length === 1) {
|
| 353 |
+
// app.get(setting)
|
| 354 |
+
return this.settings[setting];
|
| 355 |
+
}
|
| 356 |
+
|
| 357 |
+
debug('set "%s" to %o', setting, val);
|
| 358 |
+
|
| 359 |
+
// set value
|
| 360 |
+
this.settings[setting] = val;
|
| 361 |
+
|
| 362 |
+
// trigger matched settings
|
| 363 |
+
switch (setting) {
|
| 364 |
+
case 'etag':
|
| 365 |
+
this.set('etag fn', compileETag(val));
|
| 366 |
+
break;
|
| 367 |
+
case 'query parser':
|
| 368 |
+
this.set('query parser fn', compileQueryParser(val));
|
| 369 |
+
break;
|
| 370 |
+
case 'trust proxy':
|
| 371 |
+
this.set('trust proxy fn', compileTrust(val));
|
| 372 |
+
|
| 373 |
+
// trust proxy inherit back-compat
|
| 374 |
+
Object.defineProperty(this.settings, trustProxyDefaultSymbol, {
|
| 375 |
+
configurable: true,
|
| 376 |
+
value: false
|
| 377 |
+
});
|
| 378 |
+
|
| 379 |
+
break;
|
| 380 |
+
}
|
| 381 |
+
|
| 382 |
+
return this;
|
| 383 |
+
};
|
| 384 |
+
|
| 385 |
+
/**
|
| 386 |
+
* Return the app's absolute pathname
|
| 387 |
+
* based on the parent(s) that have
|
| 388 |
+
* mounted it.
|
| 389 |
+
*
|
| 390 |
+
* For example if the application was
|
| 391 |
+
* mounted as "/admin", which itself
|
| 392 |
+
* was mounted as "/blog" then the
|
| 393 |
+
* return value would be "/blog/admin".
|
| 394 |
+
*
|
| 395 |
+
* @return {String}
|
| 396 |
+
* @private
|
| 397 |
+
*/
|
| 398 |
+
|
| 399 |
+
app.path = function path() {
|
| 400 |
+
return this.parent
|
| 401 |
+
? this.parent.path() + this.mountpath
|
| 402 |
+
: '';
|
| 403 |
+
};
|
| 404 |
+
|
| 405 |
+
/**
|
| 406 |
+
* Check if `setting` is enabled (truthy).
|
| 407 |
+
*
|
| 408 |
+
* app.enabled('foo')
|
| 409 |
+
* // => false
|
| 410 |
+
*
|
| 411 |
+
* app.enable('foo')
|
| 412 |
+
* app.enabled('foo')
|
| 413 |
+
* // => true
|
| 414 |
+
*
|
| 415 |
+
* @param {String} setting
|
| 416 |
+
* @return {Boolean}
|
| 417 |
+
* @public
|
| 418 |
+
*/
|
| 419 |
+
|
| 420 |
+
app.enabled = function enabled(setting) {
|
| 421 |
+
return Boolean(this.set(setting));
|
| 422 |
+
};
|
| 423 |
+
|
| 424 |
+
/**
|
| 425 |
+
* Check if `setting` is disabled.
|
| 426 |
+
*
|
| 427 |
+
* app.disabled('foo')
|
| 428 |
+
* // => true
|
| 429 |
+
*
|
| 430 |
+
* app.enable('foo')
|
| 431 |
+
* app.disabled('foo')
|
| 432 |
+
* // => false
|
| 433 |
+
*
|
| 434 |
+
* @param {String} setting
|
| 435 |
+
* @return {Boolean}
|
| 436 |
+
* @public
|
| 437 |
+
*/
|
| 438 |
+
|
| 439 |
+
app.disabled = function disabled(setting) {
|
| 440 |
+
return !this.set(setting);
|
| 441 |
+
};
|
| 442 |
+
|
| 443 |
+
/**
|
| 444 |
+
* Enable `setting`.
|
| 445 |
+
*
|
| 446 |
+
* @param {String} setting
|
| 447 |
+
* @return {app} for chaining
|
| 448 |
+
* @public
|
| 449 |
+
*/
|
| 450 |
+
|
| 451 |
+
app.enable = function enable(setting) {
|
| 452 |
+
return this.set(setting, true);
|
| 453 |
+
};
|
| 454 |
+
|
| 455 |
+
/**
|
| 456 |
+
* Disable `setting`.
|
| 457 |
+
*
|
| 458 |
+
* @param {String} setting
|
| 459 |
+
* @return {app} for chaining
|
| 460 |
+
* @public
|
| 461 |
+
*/
|
| 462 |
+
|
| 463 |
+
app.disable = function disable(setting) {
|
| 464 |
+
return this.set(setting, false);
|
| 465 |
+
};
|
| 466 |
+
|
| 467 |
+
/**
|
| 468 |
+
* Delegate `.VERB(...)` calls to `router.VERB(...)`.
|
| 469 |
+
*/
|
| 470 |
+
|
| 471 |
+
methods.forEach(function (method) {
|
| 472 |
+
app[method] = function (path) {
|
| 473 |
+
if (method === 'get' && arguments.length === 1) {
|
| 474 |
+
// app.get(setting)
|
| 475 |
+
return this.set(path);
|
| 476 |
+
}
|
| 477 |
+
|
| 478 |
+
var route = this.route(path);
|
| 479 |
+
route[method].apply(route, slice.call(arguments, 1));
|
| 480 |
+
return this;
|
| 481 |
+
};
|
| 482 |
+
});
|
| 483 |
+
|
| 484 |
+
/**
|
| 485 |
+
* Special-cased "all" method, applying the given route `path`,
|
| 486 |
+
* middleware, and callback to _every_ HTTP method.
|
| 487 |
+
*
|
| 488 |
+
* @param {String} path
|
| 489 |
+
* @param {Function} ...
|
| 490 |
+
* @return {app} for chaining
|
| 491 |
+
* @public
|
| 492 |
+
*/
|
| 493 |
+
|
| 494 |
+
app.all = function all(path) {
|
| 495 |
+
var route = this.route(path);
|
| 496 |
+
var args = slice.call(arguments, 1);
|
| 497 |
+
|
| 498 |
+
for (var i = 0; i < methods.length; i++) {
|
| 499 |
+
route[methods[i]].apply(route, args);
|
| 500 |
+
}
|
| 501 |
+
|
| 502 |
+
return this;
|
| 503 |
+
};
|
| 504 |
+
|
| 505 |
+
/**
|
| 506 |
+
* Render the given view `name` name with `options`
|
| 507 |
+
* and a callback accepting an error and the
|
| 508 |
+
* rendered template string.
|
| 509 |
+
*
|
| 510 |
+
* Example:
|
| 511 |
+
*
|
| 512 |
+
* app.render('email', { name: 'Tobi' }, function(err, html){
|
| 513 |
+
* // ...
|
| 514 |
+
* })
|
| 515 |
+
*
|
| 516 |
+
* @param {String} name
|
| 517 |
+
* @param {Object|Function} options or fn
|
| 518 |
+
* @param {Function} callback
|
| 519 |
+
* @public
|
| 520 |
+
*/
|
| 521 |
+
|
| 522 |
+
app.render = function render(name, options, callback) {
|
| 523 |
+
var cache = this.cache;
|
| 524 |
+
var done = callback;
|
| 525 |
+
var engines = this.engines;
|
| 526 |
+
var opts = options;
|
| 527 |
+
var view;
|
| 528 |
+
|
| 529 |
+
// support callback function as second arg
|
| 530 |
+
if (typeof options === 'function') {
|
| 531 |
+
done = options;
|
| 532 |
+
opts = {};
|
| 533 |
+
}
|
| 534 |
+
|
| 535 |
+
// merge options
|
| 536 |
+
var renderOptions = { ...this.locals, ...opts._locals, ...opts };
|
| 537 |
+
|
| 538 |
+
// set .cache unless explicitly provided
|
| 539 |
+
if (renderOptions.cache == null) {
|
| 540 |
+
renderOptions.cache = this.enabled('view cache');
|
| 541 |
+
}
|
| 542 |
+
|
| 543 |
+
// primed cache
|
| 544 |
+
if (renderOptions.cache) {
|
| 545 |
+
view = cache[name];
|
| 546 |
+
}
|
| 547 |
+
|
| 548 |
+
// view
|
| 549 |
+
if (!view) {
|
| 550 |
+
var View = this.get('view');
|
| 551 |
+
|
| 552 |
+
view = new View(name, {
|
| 553 |
+
defaultEngine: this.get('view engine'),
|
| 554 |
+
root: this.get('views'),
|
| 555 |
+
engines: engines
|
| 556 |
+
});
|
| 557 |
+
|
| 558 |
+
if (!view.path) {
|
| 559 |
+
var dirs = Array.isArray(view.root) && view.root.length > 1
|
| 560 |
+
? 'directories "' + view.root.slice(0, -1).join('", "') + '" or "' + view.root[view.root.length - 1] + '"'
|
| 561 |
+
: 'directory "' + view.root + '"'
|
| 562 |
+
var err = new Error('Failed to lookup view "' + name + '" in views ' + dirs);
|
| 563 |
+
err.view = view;
|
| 564 |
+
return done(err);
|
| 565 |
+
}
|
| 566 |
+
|
| 567 |
+
// prime the cache
|
| 568 |
+
if (renderOptions.cache) {
|
| 569 |
+
cache[name] = view;
|
| 570 |
+
}
|
| 571 |
+
}
|
| 572 |
+
|
| 573 |
+
// render
|
| 574 |
+
tryRender(view, renderOptions, done);
|
| 575 |
+
};
|
| 576 |
+
|
| 577 |
+
/**
|
| 578 |
+
* Listen for connections.
|
| 579 |
+
*
|
| 580 |
+
* A node `http.Server` is returned, with this
|
| 581 |
+
* application (which is a `Function`) as its
|
| 582 |
+
* callback. If you wish to create both an HTTP
|
| 583 |
+
* and HTTPS server you may do so with the "http"
|
| 584 |
+
* and "https" modules as shown here:
|
| 585 |
+
*
|
| 586 |
+
* var http = require('node:http')
|
| 587 |
+
* , https = require('node:https')
|
| 588 |
+
* , express = require('express')
|
| 589 |
+
* , app = express();
|
| 590 |
+
*
|
| 591 |
+
* http.createServer(app).listen(80);
|
| 592 |
+
* https.createServer({ ... }, app).listen(443);
|
| 593 |
+
*
|
| 594 |
+
* @return {http.Server}
|
| 595 |
+
* @public
|
| 596 |
+
*/
|
| 597 |
+
|
| 598 |
+
app.listen = function listen() {
|
| 599 |
+
var server = http.createServer(this)
|
| 600 |
+
var args = slice.call(arguments)
|
| 601 |
+
if (typeof args[args.length - 1] === 'function') {
|
| 602 |
+
var done = args[args.length - 1] = once(args[args.length - 1])
|
| 603 |
+
server.once('error', done)
|
| 604 |
+
}
|
| 605 |
+
return server.listen.apply(server, args)
|
| 606 |
+
}
|
| 607 |
+
|
| 608 |
+
/**
|
| 609 |
+
* Log error using console.error.
|
| 610 |
+
*
|
| 611 |
+
* @param {Error} err
|
| 612 |
+
* @private
|
| 613 |
+
*/
|
| 614 |
+
|
| 615 |
+
function logerror(err) {
|
| 616 |
+
/* istanbul ignore next */
|
| 617 |
+
if (this.get('env') !== 'test') console.error(err.stack || err.toString());
|
| 618 |
+
}
|
| 619 |
+
|
| 620 |
+
/**
|
| 621 |
+
* Try rendering a view.
|
| 622 |
+
* @private
|
| 623 |
+
*/
|
| 624 |
+
|
| 625 |
+
function tryRender(view, options, callback) {
|
| 626 |
+
try {
|
| 627 |
+
view.render(options, callback);
|
| 628 |
+
} catch (err) {
|
| 629 |
+
callback(err);
|
| 630 |
+
}
|
| 631 |
+
}
|
tools/ui/node_modules/express/lib/express.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*!
|
| 2 |
+
* express
|
| 3 |
+
* Copyright(c) 2009-2013 TJ Holowaychuk
|
| 4 |
+
* Copyright(c) 2013 Roman Shtylman
|
| 5 |
+
* Copyright(c) 2014-2015 Douglas Christopher Wilson
|
| 6 |
+
* MIT Licensed
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
'use strict';
|
| 10 |
+
|
| 11 |
+
/**
|
| 12 |
+
* Module dependencies.
|
| 13 |
+
*/
|
| 14 |
+
|
| 15 |
+
var bodyParser = require('body-parser')
|
| 16 |
+
var EventEmitter = require('node:events').EventEmitter;
|
| 17 |
+
var mixin = require('merge-descriptors');
|
| 18 |
+
var proto = require('./application');
|
| 19 |
+
var Router = require('router');
|
| 20 |
+
var req = require('./request');
|
| 21 |
+
var res = require('./response');
|
| 22 |
+
|
| 23 |
+
/**
|
| 24 |
+
* Expose `createApplication()`.
|
| 25 |
+
*/
|
| 26 |
+
|
| 27 |
+
exports = module.exports = createApplication;
|
| 28 |
+
|
| 29 |
+
/**
|
| 30 |
+
* Create an express application.
|
| 31 |
+
*
|
| 32 |
+
* @return {Function}
|
| 33 |
+
* @api public
|
| 34 |
+
*/
|
| 35 |
+
|
| 36 |
+
function createApplication() {
|
| 37 |
+
var app = function(req, res, next) {
|
| 38 |
+
app.handle(req, res, next);
|
| 39 |
+
};
|
| 40 |
+
|
| 41 |
+
mixin(app, EventEmitter.prototype, false);
|
| 42 |
+
mixin(app, proto, false);
|
| 43 |
+
|
| 44 |
+
// expose the prototype that will get set on requests
|
| 45 |
+
app.request = Object.create(req, {
|
| 46 |
+
app: { configurable: true, enumerable: true, writable: true, value: app }
|
| 47 |
+
})
|
| 48 |
+
|
| 49 |
+
// expose the prototype that will get set on responses
|
| 50 |
+
app.response = Object.create(res, {
|
| 51 |
+
app: { configurable: true, enumerable: true, writable: true, value: app }
|
| 52 |
+
})
|
| 53 |
+
|
| 54 |
+
app.init();
|
| 55 |
+
return app;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
/**
|
| 59 |
+
* Expose the prototypes.
|
| 60 |
+
*/
|
| 61 |
+
|
| 62 |
+
exports.application = proto;
|
| 63 |
+
exports.request = req;
|
| 64 |
+
exports.response = res;
|
| 65 |
+
|
| 66 |
+
/**
|
| 67 |
+
* Expose constructors.
|
| 68 |
+
*/
|
| 69 |
+
|
| 70 |
+
exports.Route = Router.Route;
|
| 71 |
+
exports.Router = Router;
|
| 72 |
+
|
| 73 |
+
/**
|
| 74 |
+
* Expose middleware
|
| 75 |
+
*/
|
| 76 |
+
|
| 77 |
+
exports.json = bodyParser.json
|
| 78 |
+
exports.raw = bodyParser.raw
|
| 79 |
+
exports.static = require('serve-static');
|
| 80 |
+
exports.text = bodyParser.text
|
| 81 |
+
exports.urlencoded = bodyParser.urlencoded
|
tools/ui/node_modules/express/lib/request.js
ADDED
|
@@ -0,0 +1,514 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*!
|
| 2 |
+
* express
|
| 3 |
+
* Copyright(c) 2009-2013 TJ Holowaychuk
|
| 4 |
+
* Copyright(c) 2013 Roman Shtylman
|
| 5 |
+
* Copyright(c) 2014-2015 Douglas Christopher Wilson
|
| 6 |
+
* MIT Licensed
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
'use strict';
|
| 10 |
+
|
| 11 |
+
/**
|
| 12 |
+
* Module dependencies.
|
| 13 |
+
* @private
|
| 14 |
+
*/
|
| 15 |
+
|
| 16 |
+
var accepts = require('accepts');
|
| 17 |
+
var isIP = require('node:net').isIP;
|
| 18 |
+
var typeis = require('type-is');
|
| 19 |
+
var http = require('node:http');
|
| 20 |
+
var fresh = require('fresh');
|
| 21 |
+
var parseRange = require('range-parser');
|
| 22 |
+
var parse = require('parseurl');
|
| 23 |
+
var proxyaddr = require('proxy-addr');
|
| 24 |
+
|
| 25 |
+
/**
|
| 26 |
+
* Request prototype.
|
| 27 |
+
* @public
|
| 28 |
+
*/
|
| 29 |
+
|
| 30 |
+
var req = Object.create(http.IncomingMessage.prototype)
|
| 31 |
+
|
| 32 |
+
/**
|
| 33 |
+
* Module exports.
|
| 34 |
+
* @public
|
| 35 |
+
*/
|
| 36 |
+
|
| 37 |
+
module.exports = req
|
| 38 |
+
|
| 39 |
+
/**
|
| 40 |
+
* Return request header.
|
| 41 |
+
*
|
| 42 |
+
* The `Referrer` header field is special-cased,
|
| 43 |
+
* both `Referrer` and `Referer` are interchangeable.
|
| 44 |
+
*
|
| 45 |
+
* Examples:
|
| 46 |
+
*
|
| 47 |
+
* req.get('Content-Type');
|
| 48 |
+
* // => "text/plain"
|
| 49 |
+
*
|
| 50 |
+
* req.get('content-type');
|
| 51 |
+
* // => "text/plain"
|
| 52 |
+
*
|
| 53 |
+
* req.get('Something');
|
| 54 |
+
* // => undefined
|
| 55 |
+
*
|
| 56 |
+
* Aliased as `req.header()`.
|
| 57 |
+
*
|
| 58 |
+
* @param {String} name
|
| 59 |
+
* @return {String}
|
| 60 |
+
* @public
|
| 61 |
+
*/
|
| 62 |
+
|
| 63 |
+
req.get =
|
| 64 |
+
req.header = function header(name) {
|
| 65 |
+
if (!name) {
|
| 66 |
+
throw new TypeError('name argument is required to req.get');
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
if (typeof name !== 'string') {
|
| 70 |
+
throw new TypeError('name must be a string to req.get');
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
var lc = name.toLowerCase();
|
| 74 |
+
|
| 75 |
+
switch (lc) {
|
| 76 |
+
case 'referer':
|
| 77 |
+
case 'referrer':
|
| 78 |
+
return this.headers.referrer
|
| 79 |
+
|| this.headers.referer;
|
| 80 |
+
default:
|
| 81 |
+
return this.headers[lc];
|
| 82 |
+
}
|
| 83 |
+
};
|
| 84 |
+
|
| 85 |
+
/**
|
| 86 |
+
* To do: update docs.
|
| 87 |
+
*
|
| 88 |
+
* Check if the given `type(s)` is acceptable, returning
|
| 89 |
+
* the best match when true, otherwise `undefined`, in which
|
| 90 |
+
* case you should respond with 406 "Not Acceptable".
|
| 91 |
+
*
|
| 92 |
+
* The `type` value may be a single MIME type string
|
| 93 |
+
* such as "application/json", an extension name
|
| 94 |
+
* such as "json", a comma-delimited list such as "json, html, text/plain",
|
| 95 |
+
* an argument list such as `"json", "html", "text/plain"`,
|
| 96 |
+
* or an array `["json", "html", "text/plain"]`. When a list
|
| 97 |
+
* or array is given, the _best_ match, if any is returned.
|
| 98 |
+
*
|
| 99 |
+
* Examples:
|
| 100 |
+
*
|
| 101 |
+
* // Accept: text/html
|
| 102 |
+
* req.accepts('html');
|
| 103 |
+
* // => "html"
|
| 104 |
+
*
|
| 105 |
+
* // Accept: text/*, application/json
|
| 106 |
+
* req.accepts('html');
|
| 107 |
+
* // => "html"
|
| 108 |
+
* req.accepts('text/html');
|
| 109 |
+
* // => "text/html"
|
| 110 |
+
* req.accepts('json, text');
|
| 111 |
+
* // => "json"
|
| 112 |
+
* req.accepts('application/json');
|
| 113 |
+
* // => "application/json"
|
| 114 |
+
*
|
| 115 |
+
* // Accept: text/*, application/json
|
| 116 |
+
* req.accepts('image/png');
|
| 117 |
+
* req.accepts('png');
|
| 118 |
+
* // => undefined
|
| 119 |
+
*
|
| 120 |
+
* // Accept: text/*;q=.5, application/json
|
| 121 |
+
* req.accepts(['html', 'json']);
|
| 122 |
+
* req.accepts('html', 'json');
|
| 123 |
+
* req.accepts('html, json');
|
| 124 |
+
* // => "json"
|
| 125 |
+
*
|
| 126 |
+
* @param {String|Array} type(s)
|
| 127 |
+
* @return {String|Array|Boolean}
|
| 128 |
+
* @public
|
| 129 |
+
*/
|
| 130 |
+
|
| 131 |
+
req.accepts = function(){
|
| 132 |
+
var accept = accepts(this);
|
| 133 |
+
return accept.types.apply(accept, arguments);
|
| 134 |
+
};
|
| 135 |
+
|
| 136 |
+
/**
|
| 137 |
+
* Check if the given `encoding`s are accepted.
|
| 138 |
+
*
|
| 139 |
+
* @param {String} ...encoding
|
| 140 |
+
* @return {String|Array}
|
| 141 |
+
* @public
|
| 142 |
+
*/
|
| 143 |
+
|
| 144 |
+
req.acceptsEncodings = function(){
|
| 145 |
+
var accept = accepts(this);
|
| 146 |
+
return accept.encodings.apply(accept, arguments);
|
| 147 |
+
};
|
| 148 |
+
|
| 149 |
+
/**
|
| 150 |
+
* Check if the given `charset`s are acceptable,
|
| 151 |
+
* otherwise you should respond with 406 "Not Acceptable".
|
| 152 |
+
*
|
| 153 |
+
* @param {String} ...charset
|
| 154 |
+
* @return {String|Array}
|
| 155 |
+
* @public
|
| 156 |
+
*/
|
| 157 |
+
|
| 158 |
+
req.acceptsCharsets = function(){
|
| 159 |
+
var accept = accepts(this);
|
| 160 |
+
return accept.charsets.apply(accept, arguments);
|
| 161 |
+
};
|
| 162 |
+
|
| 163 |
+
/**
|
| 164 |
+
* Check if the given `lang`s are acceptable,
|
| 165 |
+
* otherwise you should respond with 406 "Not Acceptable".
|
| 166 |
+
*
|
| 167 |
+
* @param {String} ...lang
|
| 168 |
+
* @return {String|Array}
|
| 169 |
+
* @public
|
| 170 |
+
*/
|
| 171 |
+
|
| 172 |
+
req.acceptsLanguages = function(...languages) {
|
| 173 |
+
return accepts(this).languages(...languages);
|
| 174 |
+
};
|
| 175 |
+
|
| 176 |
+
/**
|
| 177 |
+
* Parse Range header field, capping to the given `size`.
|
| 178 |
+
*
|
| 179 |
+
* Unspecified ranges such as "0-" require knowledge of your resource length. In
|
| 180 |
+
* the case of a byte range this is of course the total number of bytes. If the
|
| 181 |
+
* Range header field is not given `undefined` is returned, `-1` when unsatisfiable,
|
| 182 |
+
* and `-2` when syntactically invalid.
|
| 183 |
+
*
|
| 184 |
+
* When ranges are returned, the array has a "type" property which is the type of
|
| 185 |
+
* range that is required (most commonly, "bytes"). Each array element is an object
|
| 186 |
+
* with a "start" and "end" property for the portion of the range.
|
| 187 |
+
*
|
| 188 |
+
* The "combine" option can be set to `true` and overlapping & adjacent ranges
|
| 189 |
+
* will be combined into a single range.
|
| 190 |
+
*
|
| 191 |
+
* NOTE: remember that ranges are inclusive, so for example "Range: users=0-3"
|
| 192 |
+
* should respond with 4 users when available, not 3.
|
| 193 |
+
*
|
| 194 |
+
* @param {number} size
|
| 195 |
+
* @param {object} [options]
|
| 196 |
+
* @param {boolean} [options.combine=false]
|
| 197 |
+
* @return {number|array}
|
| 198 |
+
* @public
|
| 199 |
+
*/
|
| 200 |
+
|
| 201 |
+
req.range = function range(size, options) {
|
| 202 |
+
var range = this.get('Range');
|
| 203 |
+
if (!range) return;
|
| 204 |
+
return parseRange(size, range, options);
|
| 205 |
+
};
|
| 206 |
+
|
| 207 |
+
/**
|
| 208 |
+
* Parse the query string of `req.url`.
|
| 209 |
+
*
|
| 210 |
+
* This uses the "query parser" setting to parse the raw
|
| 211 |
+
* string into an object.
|
| 212 |
+
*
|
| 213 |
+
* @return {String}
|
| 214 |
+
* @api public
|
| 215 |
+
*/
|
| 216 |
+
|
| 217 |
+
defineGetter(req, 'query', function query(){
|
| 218 |
+
var queryparse = this.app.get('query parser fn');
|
| 219 |
+
|
| 220 |
+
if (!queryparse) {
|
| 221 |
+
// parsing is disabled
|
| 222 |
+
return Object.create(null);
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
var querystring = parse(this).query;
|
| 226 |
+
|
| 227 |
+
return queryparse(querystring);
|
| 228 |
+
});
|
| 229 |
+
|
| 230 |
+
/**
|
| 231 |
+
* Check if the incoming request contains the "Content-Type"
|
| 232 |
+
* header field, and it contains the given mime `type`.
|
| 233 |
+
*
|
| 234 |
+
* Examples:
|
| 235 |
+
*
|
| 236 |
+
* // With Content-Type: text/html; charset=utf-8
|
| 237 |
+
* req.is('html');
|
| 238 |
+
* req.is('text/html');
|
| 239 |
+
* req.is('text/*');
|
| 240 |
+
* // => true
|
| 241 |
+
*
|
| 242 |
+
* // When Content-Type is application/json
|
| 243 |
+
* req.is('json');
|
| 244 |
+
* req.is('application/json');
|
| 245 |
+
* req.is('application/*');
|
| 246 |
+
* // => true
|
| 247 |
+
*
|
| 248 |
+
* req.is('html');
|
| 249 |
+
* // => false
|
| 250 |
+
*
|
| 251 |
+
* @param {String|Array} types...
|
| 252 |
+
* @return {String|false|null}
|
| 253 |
+
* @public
|
| 254 |
+
*/
|
| 255 |
+
|
| 256 |
+
req.is = function is(types) {
|
| 257 |
+
var arr = types;
|
| 258 |
+
|
| 259 |
+
// support flattened arguments
|
| 260 |
+
if (!Array.isArray(types)) {
|
| 261 |
+
arr = new Array(arguments.length);
|
| 262 |
+
for (var i = 0; i < arr.length; i++) {
|
| 263 |
+
arr[i] = arguments[i];
|
| 264 |
+
}
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
return typeis(this, arr);
|
| 268 |
+
};
|
| 269 |
+
|
| 270 |
+
/**
|
| 271 |
+
* Return the protocol string "http" or "https"
|
| 272 |
+
* when requested with TLS. When the "trust proxy"
|
| 273 |
+
* setting trusts the socket address, the
|
| 274 |
+
* "X-Forwarded-Proto" header field will be trusted
|
| 275 |
+
* and used if present.
|
| 276 |
+
*
|
| 277 |
+
* If you're running behind a reverse proxy that
|
| 278 |
+
* supplies https for you this may be enabled.
|
| 279 |
+
*
|
| 280 |
+
* @return {String}
|
| 281 |
+
* @public
|
| 282 |
+
*/
|
| 283 |
+
|
| 284 |
+
defineGetter(req, 'protocol', function protocol(){
|
| 285 |
+
var proto = this.socket.encrypted
|
| 286 |
+
? 'https'
|
| 287 |
+
: 'http';
|
| 288 |
+
var trust = this.app.get('trust proxy fn');
|
| 289 |
+
|
| 290 |
+
if (!trust(this.socket.remoteAddress, 0)) {
|
| 291 |
+
return proto;
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
// Note: X-Forwarded-Proto is normally only ever a
|
| 295 |
+
// single value, but this is to be safe.
|
| 296 |
+
var header = this.get('X-Forwarded-Proto') || proto
|
| 297 |
+
var index = header.indexOf(',')
|
| 298 |
+
|
| 299 |
+
return index !== -1
|
| 300 |
+
? header.substring(0, index).trim()
|
| 301 |
+
: header.trim()
|
| 302 |
+
});
|
| 303 |
+
|
| 304 |
+
/**
|
| 305 |
+
* Short-hand for:
|
| 306 |
+
*
|
| 307 |
+
* req.protocol === 'https'
|
| 308 |
+
*
|
| 309 |
+
* @return {Boolean}
|
| 310 |
+
* @public
|
| 311 |
+
*/
|
| 312 |
+
|
| 313 |
+
defineGetter(req, 'secure', function secure(){
|
| 314 |
+
return this.protocol === 'https';
|
| 315 |
+
});
|
| 316 |
+
|
| 317 |
+
/**
|
| 318 |
+
* Return the remote address from the trusted proxy.
|
| 319 |
+
*
|
| 320 |
+
* The is the remote address on the socket unless
|
| 321 |
+
* "trust proxy" is set.
|
| 322 |
+
*
|
| 323 |
+
* @return {String}
|
| 324 |
+
* @public
|
| 325 |
+
*/
|
| 326 |
+
|
| 327 |
+
defineGetter(req, 'ip', function ip(){
|
| 328 |
+
var trust = this.app.get('trust proxy fn');
|
| 329 |
+
return proxyaddr(this, trust);
|
| 330 |
+
});
|
| 331 |
+
|
| 332 |
+
/**
|
| 333 |
+
* When "trust proxy" is set, trusted proxy addresses + client.
|
| 334 |
+
*
|
| 335 |
+
* For example if the value were "client, proxy1, proxy2"
|
| 336 |
+
* you would receive the array `["client", "proxy1", "proxy2"]`
|
| 337 |
+
* where "proxy2" is the furthest down-stream and "proxy1" and
|
| 338 |
+
* "proxy2" were trusted.
|
| 339 |
+
*
|
| 340 |
+
* @return {Array}
|
| 341 |
+
* @public
|
| 342 |
+
*/
|
| 343 |
+
|
| 344 |
+
defineGetter(req, 'ips', function ips() {
|
| 345 |
+
var trust = this.app.get('trust proxy fn');
|
| 346 |
+
var addrs = proxyaddr.all(this, trust);
|
| 347 |
+
|
| 348 |
+
// reverse the order (to farthest -> closest)
|
| 349 |
+
// and remove socket address
|
| 350 |
+
addrs.reverse().pop()
|
| 351 |
+
|
| 352 |
+
return addrs
|
| 353 |
+
});
|
| 354 |
+
|
| 355 |
+
/**
|
| 356 |
+
* Return subdomains as an array.
|
| 357 |
+
*
|
| 358 |
+
* Subdomains are the dot-separated parts of the host before the main domain of
|
| 359 |
+
* the app. By default, the domain of the app is assumed to be the last two
|
| 360 |
+
* parts of the host. This can be changed by setting "subdomain offset".
|
| 361 |
+
*
|
| 362 |
+
* For example, if the domain is "tobi.ferrets.example.com":
|
| 363 |
+
* If "subdomain offset" is not set, req.subdomains is `["ferrets", "tobi"]`.
|
| 364 |
+
* If "subdomain offset" is 3, req.subdomains is `["tobi"]`.
|
| 365 |
+
*
|
| 366 |
+
* @return {Array}
|
| 367 |
+
* @public
|
| 368 |
+
*/
|
| 369 |
+
|
| 370 |
+
defineGetter(req, 'subdomains', function subdomains() {
|
| 371 |
+
var hostname = this.hostname;
|
| 372 |
+
|
| 373 |
+
if (!hostname) return [];
|
| 374 |
+
|
| 375 |
+
var offset = this.app.get('subdomain offset');
|
| 376 |
+
var subdomains = !isIP(hostname)
|
| 377 |
+
? hostname.split('.').reverse()
|
| 378 |
+
: [hostname];
|
| 379 |
+
|
| 380 |
+
return subdomains.slice(offset);
|
| 381 |
+
});
|
| 382 |
+
|
| 383 |
+
/**
|
| 384 |
+
* Short-hand for `url.parse(req.url).pathname`.
|
| 385 |
+
*
|
| 386 |
+
* @return {String}
|
| 387 |
+
* @public
|
| 388 |
+
*/
|
| 389 |
+
|
| 390 |
+
defineGetter(req, 'path', function path() {
|
| 391 |
+
return parse(this).pathname;
|
| 392 |
+
});
|
| 393 |
+
|
| 394 |
+
/**
|
| 395 |
+
* Parse the "Host" header field to a host.
|
| 396 |
+
*
|
| 397 |
+
* When the "trust proxy" setting trusts the socket
|
| 398 |
+
* address, the "X-Forwarded-Host" header field will
|
| 399 |
+
* be trusted.
|
| 400 |
+
*
|
| 401 |
+
* @return {String}
|
| 402 |
+
* @public
|
| 403 |
+
*/
|
| 404 |
+
|
| 405 |
+
defineGetter(req, 'host', function host(){
|
| 406 |
+
var trust = this.app.get('trust proxy fn');
|
| 407 |
+
var val = this.get('X-Forwarded-Host');
|
| 408 |
+
|
| 409 |
+
if (!val || !trust(this.socket.remoteAddress, 0)) {
|
| 410 |
+
val = this.get('Host');
|
| 411 |
+
} else if (val.indexOf(',') !== -1) {
|
| 412 |
+
// Note: X-Forwarded-Host is normally only ever a
|
| 413 |
+
// single value, but this is to be safe.
|
| 414 |
+
val = val.substring(0, val.indexOf(',')).trimRight()
|
| 415 |
+
}
|
| 416 |
+
|
| 417 |
+
return val || undefined;
|
| 418 |
+
});
|
| 419 |
+
|
| 420 |
+
/**
|
| 421 |
+
* Parse the "Host" header field to a hostname.
|
| 422 |
+
*
|
| 423 |
+
* When the "trust proxy" setting trusts the socket
|
| 424 |
+
* address, the "X-Forwarded-Host" header field will
|
| 425 |
+
* be trusted.
|
| 426 |
+
*
|
| 427 |
+
* @return {String}
|
| 428 |
+
* @api public
|
| 429 |
+
*/
|
| 430 |
+
|
| 431 |
+
defineGetter(req, 'hostname', function hostname(){
|
| 432 |
+
var host = this.host;
|
| 433 |
+
|
| 434 |
+
if (!host) return;
|
| 435 |
+
|
| 436 |
+
// IPv6 literal support
|
| 437 |
+
var offset = host[0] === '['
|
| 438 |
+
? host.indexOf(']') + 1
|
| 439 |
+
: 0;
|
| 440 |
+
var index = host.indexOf(':', offset);
|
| 441 |
+
|
| 442 |
+
return index !== -1
|
| 443 |
+
? host.substring(0, index)
|
| 444 |
+
: host;
|
| 445 |
+
});
|
| 446 |
+
|
| 447 |
+
/**
|
| 448 |
+
* Check if the request is fresh, aka
|
| 449 |
+
* Last-Modified or the ETag
|
| 450 |
+
* still match.
|
| 451 |
+
*
|
| 452 |
+
* @return {Boolean}
|
| 453 |
+
* @public
|
| 454 |
+
*/
|
| 455 |
+
|
| 456 |
+
defineGetter(req, 'fresh', function(){
|
| 457 |
+
var method = this.method;
|
| 458 |
+
var res = this.res
|
| 459 |
+
var status = res.statusCode
|
| 460 |
+
|
| 461 |
+
// GET or HEAD for weak freshness validation only
|
| 462 |
+
if ('GET' !== method && 'HEAD' !== method) return false;
|
| 463 |
+
|
| 464 |
+
// 2xx or 304 as per rfc2616 14.26
|
| 465 |
+
if ((status >= 200 && status < 300) || 304 === status) {
|
| 466 |
+
return fresh(this.headers, {
|
| 467 |
+
'etag': res.get('ETag'),
|
| 468 |
+
'last-modified': res.get('Last-Modified')
|
| 469 |
+
})
|
| 470 |
+
}
|
| 471 |
+
|
| 472 |
+
return false;
|
| 473 |
+
});
|
| 474 |
+
|
| 475 |
+
/**
|
| 476 |
+
* Check if the request is stale, aka
|
| 477 |
+
* "Last-Modified" and / or the "ETag" for the
|
| 478 |
+
* resource has changed.
|
| 479 |
+
*
|
| 480 |
+
* @return {Boolean}
|
| 481 |
+
* @public
|
| 482 |
+
*/
|
| 483 |
+
|
| 484 |
+
defineGetter(req, 'stale', function stale(){
|
| 485 |
+
return !this.fresh;
|
| 486 |
+
});
|
| 487 |
+
|
| 488 |
+
/**
|
| 489 |
+
* Check if the request was an _XMLHttpRequest_.
|
| 490 |
+
*
|
| 491 |
+
* @return {Boolean}
|
| 492 |
+
* @public
|
| 493 |
+
*/
|
| 494 |
+
|
| 495 |
+
defineGetter(req, 'xhr', function xhr(){
|
| 496 |
+
var val = this.get('X-Requested-With') || '';
|
| 497 |
+
return val.toLowerCase() === 'xmlhttprequest';
|
| 498 |
+
});
|
| 499 |
+
|
| 500 |
+
/**
|
| 501 |
+
* Helper function for creating a getter on an object.
|
| 502 |
+
*
|
| 503 |
+
* @param {Object} obj
|
| 504 |
+
* @param {String} name
|
| 505 |
+
* @param {Function} getter
|
| 506 |
+
* @private
|
| 507 |
+
*/
|
| 508 |
+
function defineGetter(obj, name, getter) {
|
| 509 |
+
Object.defineProperty(obj, name, {
|
| 510 |
+
configurable: true,
|
| 511 |
+
enumerable: true,
|
| 512 |
+
get: getter
|
| 513 |
+
});
|
| 514 |
+
}
|
tools/ui/node_modules/express/lib/response.js
ADDED
|
@@ -0,0 +1,1053 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*!
|
| 2 |
+
* express
|
| 3 |
+
* Copyright(c) 2009-2013 TJ Holowaychuk
|
| 4 |
+
* Copyright(c) 2014-2015 Douglas Christopher Wilson
|
| 5 |
+
* MIT Licensed
|
| 6 |
+
*/
|
| 7 |
+
|
| 8 |
+
'use strict';
|
| 9 |
+
|
| 10 |
+
/**
|
| 11 |
+
* Module dependencies.
|
| 12 |
+
* @private
|
| 13 |
+
*/
|
| 14 |
+
|
| 15 |
+
var contentDisposition = require('content-disposition');
|
| 16 |
+
var createError = require('http-errors')
|
| 17 |
+
var deprecate = require('depd')('express');
|
| 18 |
+
var encodeUrl = require('encodeurl');
|
| 19 |
+
var escapeHtml = require('escape-html');
|
| 20 |
+
var http = require('node:http');
|
| 21 |
+
var onFinished = require('on-finished');
|
| 22 |
+
var mime = require('mime-types')
|
| 23 |
+
var path = require('node:path');
|
| 24 |
+
var pathIsAbsolute = require('node:path').isAbsolute;
|
| 25 |
+
var statuses = require('statuses')
|
| 26 |
+
var sign = require('cookie-signature').sign;
|
| 27 |
+
var normalizeType = require('./utils').normalizeType;
|
| 28 |
+
var normalizeTypes = require('./utils').normalizeTypes;
|
| 29 |
+
var setCharset = require('./utils').setCharset;
|
| 30 |
+
var cookie = require('cookie');
|
| 31 |
+
var send = require('send');
|
| 32 |
+
var extname = path.extname;
|
| 33 |
+
var resolve = path.resolve;
|
| 34 |
+
var vary = require('vary');
|
| 35 |
+
const { Buffer } = require('node:buffer');
|
| 36 |
+
|
| 37 |
+
/**
|
| 38 |
+
* Response prototype.
|
| 39 |
+
* @public
|
| 40 |
+
*/
|
| 41 |
+
|
| 42 |
+
var res = Object.create(http.ServerResponse.prototype)
|
| 43 |
+
|
| 44 |
+
/**
|
| 45 |
+
* Module exports.
|
| 46 |
+
* @public
|
| 47 |
+
*/
|
| 48 |
+
|
| 49 |
+
module.exports = res
|
| 50 |
+
|
| 51 |
+
/**
|
| 52 |
+
* Set the HTTP status code for the response.
|
| 53 |
+
*
|
| 54 |
+
* Expects an integer value between 100 and 999 inclusive.
|
| 55 |
+
* Throws an error if the provided status code is not an integer or if it's outside the allowable range.
|
| 56 |
+
*
|
| 57 |
+
* @param {number} code - The HTTP status code to set.
|
| 58 |
+
* @return {ServerResponse} - Returns itself for chaining methods.
|
| 59 |
+
* @throws {TypeError} If `code` is not an integer.
|
| 60 |
+
* @throws {RangeError} If `code` is outside the range 100 to 999.
|
| 61 |
+
* @public
|
| 62 |
+
*/
|
| 63 |
+
|
| 64 |
+
res.status = function status(code) {
|
| 65 |
+
// Check if the status code is not an integer
|
| 66 |
+
if (!Number.isInteger(code)) {
|
| 67 |
+
throw new TypeError(`Invalid status code: ${JSON.stringify(code)}. Status code must be an integer.`);
|
| 68 |
+
}
|
| 69 |
+
// Check if the status code is outside of Node's valid range
|
| 70 |
+
if (code < 100 || code > 999) {
|
| 71 |
+
throw new RangeError(`Invalid status code: ${JSON.stringify(code)}. Status code must be greater than 99 and less than 1000.`);
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
this.statusCode = code;
|
| 75 |
+
return this;
|
| 76 |
+
};
|
| 77 |
+
|
| 78 |
+
/**
|
| 79 |
+
* Set Link header field with the given `links`.
|
| 80 |
+
*
|
| 81 |
+
* Examples:
|
| 82 |
+
*
|
| 83 |
+
* res.links({
|
| 84 |
+
* next: 'http://api.example.com/users?page=2',
|
| 85 |
+
* last: 'http://api.example.com/users?page=5',
|
| 86 |
+
* pages: [
|
| 87 |
+
* 'http://api.example.com/users?page=1',
|
| 88 |
+
* 'http://api.example.com/users?page=2'
|
| 89 |
+
* ]
|
| 90 |
+
* });
|
| 91 |
+
*
|
| 92 |
+
* @param {Object} links
|
| 93 |
+
* @return {ServerResponse}
|
| 94 |
+
* @public
|
| 95 |
+
*/
|
| 96 |
+
|
| 97 |
+
res.links = function(links) {
|
| 98 |
+
var link = this.get('Link') || '';
|
| 99 |
+
if (link) link += ', ';
|
| 100 |
+
return this.set('Link', link + Object.keys(links).map(function(rel) {
|
| 101 |
+
// Allow multiple links if links[rel] is an array
|
| 102 |
+
if (Array.isArray(links[rel])) {
|
| 103 |
+
return links[rel].map(function (singleLink) {
|
| 104 |
+
return `<${singleLink}>; rel="${rel}"`;
|
| 105 |
+
}).join(', ');
|
| 106 |
+
} else {
|
| 107 |
+
return `<${links[rel]}>; rel="${rel}"`;
|
| 108 |
+
}
|
| 109 |
+
}).join(', '));
|
| 110 |
+
};
|
| 111 |
+
|
| 112 |
+
/**
|
| 113 |
+
* Send a response.
|
| 114 |
+
*
|
| 115 |
+
* Examples:
|
| 116 |
+
*
|
| 117 |
+
* res.send(Buffer.from('wahoo'));
|
| 118 |
+
* res.send({ some: 'json' });
|
| 119 |
+
* res.send('<p>some html</p>');
|
| 120 |
+
*
|
| 121 |
+
* @param {string|number|boolean|object|Buffer} body
|
| 122 |
+
* @public
|
| 123 |
+
*/
|
| 124 |
+
|
| 125 |
+
res.send = function send(body) {
|
| 126 |
+
var chunk = body;
|
| 127 |
+
var encoding;
|
| 128 |
+
var req = this.req;
|
| 129 |
+
var type;
|
| 130 |
+
|
| 131 |
+
// settings
|
| 132 |
+
var app = this.app;
|
| 133 |
+
|
| 134 |
+
switch (typeof chunk) {
|
| 135 |
+
// string defaulting to html
|
| 136 |
+
case 'string':
|
| 137 |
+
if (!this.get('Content-Type')) {
|
| 138 |
+
this.type('html');
|
| 139 |
+
}
|
| 140 |
+
break;
|
| 141 |
+
case 'boolean':
|
| 142 |
+
case 'number':
|
| 143 |
+
case 'object':
|
| 144 |
+
if (chunk === null) {
|
| 145 |
+
chunk = '';
|
| 146 |
+
} else if (ArrayBuffer.isView(chunk)) {
|
| 147 |
+
if (!this.get('Content-Type')) {
|
| 148 |
+
this.type('bin');
|
| 149 |
+
}
|
| 150 |
+
} else {
|
| 151 |
+
return this.json(chunk);
|
| 152 |
+
}
|
| 153 |
+
break;
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
// write strings in utf-8
|
| 157 |
+
if (typeof chunk === 'string') {
|
| 158 |
+
encoding = 'utf8';
|
| 159 |
+
type = this.get('Content-Type');
|
| 160 |
+
|
| 161 |
+
// reflect this in content-type
|
| 162 |
+
if (typeof type === 'string') {
|
| 163 |
+
this.set('Content-Type', setCharset(type, 'utf-8'));
|
| 164 |
+
}
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
// determine if ETag should be generated
|
| 168 |
+
var etagFn = app.get('etag fn')
|
| 169 |
+
var generateETag = !this.get('ETag') && typeof etagFn === 'function'
|
| 170 |
+
|
| 171 |
+
// populate Content-Length
|
| 172 |
+
var len
|
| 173 |
+
if (chunk !== undefined) {
|
| 174 |
+
if (Buffer.isBuffer(chunk)) {
|
| 175 |
+
// get length of Buffer
|
| 176 |
+
len = chunk.length
|
| 177 |
+
} else if (!generateETag && chunk.length < 1000) {
|
| 178 |
+
// just calculate length when no ETag + small chunk
|
| 179 |
+
len = Buffer.byteLength(chunk, encoding)
|
| 180 |
+
} else {
|
| 181 |
+
// convert chunk to Buffer and calculate
|
| 182 |
+
chunk = Buffer.from(chunk, encoding)
|
| 183 |
+
encoding = undefined;
|
| 184 |
+
len = chunk.length
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
this.set('Content-Length', len);
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
// populate ETag
|
| 191 |
+
var etag;
|
| 192 |
+
if (generateETag && len !== undefined) {
|
| 193 |
+
if ((etag = etagFn(chunk, encoding))) {
|
| 194 |
+
this.set('ETag', etag);
|
| 195 |
+
}
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
// freshness
|
| 199 |
+
if (req.fresh) this.status(304);
|
| 200 |
+
|
| 201 |
+
// strip irrelevant headers
|
| 202 |
+
if (204 === this.statusCode || 304 === this.statusCode) {
|
| 203 |
+
this.removeHeader('Content-Type');
|
| 204 |
+
this.removeHeader('Content-Length');
|
| 205 |
+
this.removeHeader('Transfer-Encoding');
|
| 206 |
+
chunk = '';
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
// alter headers for 205
|
| 210 |
+
if (this.statusCode === 205) {
|
| 211 |
+
this.set('Content-Length', '0')
|
| 212 |
+
this.removeHeader('Transfer-Encoding')
|
| 213 |
+
chunk = ''
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
if (req.method === 'HEAD') {
|
| 217 |
+
// skip body for HEAD
|
| 218 |
+
this.end();
|
| 219 |
+
} else {
|
| 220 |
+
// respond
|
| 221 |
+
this.end(chunk, encoding);
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
return this;
|
| 225 |
+
};
|
| 226 |
+
|
| 227 |
+
/**
|
| 228 |
+
* Send JSON response.
|
| 229 |
+
*
|
| 230 |
+
* Examples:
|
| 231 |
+
*
|
| 232 |
+
* res.json(null);
|
| 233 |
+
* res.json({ user: 'tj' });
|
| 234 |
+
*
|
| 235 |
+
* @param {string|number|boolean|object} obj
|
| 236 |
+
* @public
|
| 237 |
+
*/
|
| 238 |
+
|
| 239 |
+
res.json = function json(obj) {
|
| 240 |
+
// settings
|
| 241 |
+
var app = this.app;
|
| 242 |
+
var escape = app.get('json escape')
|
| 243 |
+
var replacer = app.get('json replacer');
|
| 244 |
+
var spaces = app.get('json spaces');
|
| 245 |
+
var body = stringify(obj, replacer, spaces, escape)
|
| 246 |
+
|
| 247 |
+
// content-type
|
| 248 |
+
if (!this.get('Content-Type')) {
|
| 249 |
+
this.set('Content-Type', 'application/json');
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
return this.send(body);
|
| 253 |
+
};
|
| 254 |
+
|
| 255 |
+
/**
|
| 256 |
+
* Send JSON response with JSONP callback support.
|
| 257 |
+
*
|
| 258 |
+
* Examples:
|
| 259 |
+
*
|
| 260 |
+
* res.jsonp(null);
|
| 261 |
+
* res.jsonp({ user: 'tj' });
|
| 262 |
+
*
|
| 263 |
+
* @param {string|number|boolean|object} obj
|
| 264 |
+
* @public
|
| 265 |
+
*/
|
| 266 |
+
|
| 267 |
+
res.jsonp = function jsonp(obj) {
|
| 268 |
+
// settings
|
| 269 |
+
var app = this.app;
|
| 270 |
+
var escape = app.get('json escape')
|
| 271 |
+
var replacer = app.get('json replacer');
|
| 272 |
+
var spaces = app.get('json spaces');
|
| 273 |
+
var body = stringify(obj, replacer, spaces, escape)
|
| 274 |
+
var callback = this.req.query[app.get('jsonp callback name')];
|
| 275 |
+
|
| 276 |
+
// content-type
|
| 277 |
+
if (!this.get('Content-Type')) {
|
| 278 |
+
this.set('X-Content-Type-Options', 'nosniff');
|
| 279 |
+
this.set('Content-Type', 'application/json');
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
// fixup callback
|
| 283 |
+
if (Array.isArray(callback)) {
|
| 284 |
+
callback = callback[0];
|
| 285 |
+
}
|
| 286 |
+
|
| 287 |
+
// jsonp
|
| 288 |
+
if (typeof callback === 'string' && callback.length !== 0) {
|
| 289 |
+
this.set('X-Content-Type-Options', 'nosniff');
|
| 290 |
+
this.set('Content-Type', 'text/javascript');
|
| 291 |
+
|
| 292 |
+
// restrict callback charset
|
| 293 |
+
callback = callback.replace(/[^\[\]\w$.]/g, '');
|
| 294 |
+
|
| 295 |
+
if (body === undefined) {
|
| 296 |
+
// empty argument
|
| 297 |
+
body = ''
|
| 298 |
+
} else if (typeof body === 'string') {
|
| 299 |
+
// replace chars not allowed in JavaScript that are in JSON
|
| 300 |
+
body = body
|
| 301 |
+
.replace(/\u2028/g, '\\u2028')
|
| 302 |
+
.replace(/\u2029/g, '\\u2029')
|
| 303 |
+
}
|
| 304 |
+
|
| 305 |
+
// the /**/ is a specific security mitigation for "Rosetta Flash JSONP abuse"
|
| 306 |
+
// the typeof check is just to reduce client error noise
|
| 307 |
+
body = '/**/ typeof ' + callback + ' === \'function\' && ' + callback + '(' + body + ');';
|
| 308 |
+
}
|
| 309 |
+
|
| 310 |
+
return this.send(body);
|
| 311 |
+
};
|
| 312 |
+
|
| 313 |
+
/**
|
| 314 |
+
* Send given HTTP status code.
|
| 315 |
+
*
|
| 316 |
+
* Sets the response status to `statusCode` and the body of the
|
| 317 |
+
* response to the standard description from node's http.STATUS_CODES
|
| 318 |
+
* or the statusCode number if no description.
|
| 319 |
+
*
|
| 320 |
+
* Examples:
|
| 321 |
+
*
|
| 322 |
+
* res.sendStatus(200);
|
| 323 |
+
*
|
| 324 |
+
* @param {number} statusCode
|
| 325 |
+
* @public
|
| 326 |
+
*/
|
| 327 |
+
|
| 328 |
+
res.sendStatus = function sendStatus(statusCode) {
|
| 329 |
+
var body = statuses.message[statusCode] || String(statusCode)
|
| 330 |
+
|
| 331 |
+
this.status(statusCode);
|
| 332 |
+
this.type('txt');
|
| 333 |
+
|
| 334 |
+
return this.send(body);
|
| 335 |
+
};
|
| 336 |
+
|
| 337 |
+
/**
|
| 338 |
+
* Transfer the file at the given `path`.
|
| 339 |
+
*
|
| 340 |
+
* Automatically sets the _Content-Type_ response header field.
|
| 341 |
+
* The callback `callback(err)` is invoked when the transfer is complete
|
| 342 |
+
* or when an error occurs. Be sure to check `res.headersSent`
|
| 343 |
+
* if you wish to attempt responding, as the header and some data
|
| 344 |
+
* may have already been transferred.
|
| 345 |
+
*
|
| 346 |
+
* Options:
|
| 347 |
+
*
|
| 348 |
+
* - `maxAge` defaulting to 0 (can be string converted by `ms`)
|
| 349 |
+
* - `root` root directory for relative filenames
|
| 350 |
+
* - `headers` object of headers to serve with file
|
| 351 |
+
* - `dotfiles` serve dotfiles, defaulting to false; can be `"allow"` to send them
|
| 352 |
+
*
|
| 353 |
+
* Other options are passed along to `send`.
|
| 354 |
+
*
|
| 355 |
+
* Examples:
|
| 356 |
+
*
|
| 357 |
+
* The following example illustrates how `res.sendFile()` may
|
| 358 |
+
* be used as an alternative for the `static()` middleware for
|
| 359 |
+
* dynamic situations. The code backing `res.sendFile()` is actually
|
| 360 |
+
* the same code, so HTTP cache support etc is identical.
|
| 361 |
+
*
|
| 362 |
+
* app.get('/user/:uid/photos/:file', function(req, res){
|
| 363 |
+
* var uid = req.params.uid
|
| 364 |
+
* , file = req.params.file;
|
| 365 |
+
*
|
| 366 |
+
* req.user.mayViewFilesFrom(uid, function(yes){
|
| 367 |
+
* if (yes) {
|
| 368 |
+
* res.sendFile('/uploads/' + uid + '/' + file);
|
| 369 |
+
* } else {
|
| 370 |
+
* res.send(403, 'Sorry! you cant see that.');
|
| 371 |
+
* }
|
| 372 |
+
* });
|
| 373 |
+
* });
|
| 374 |
+
*
|
| 375 |
+
* @public
|
| 376 |
+
*/
|
| 377 |
+
|
| 378 |
+
res.sendFile = function sendFile(path, options, callback) {
|
| 379 |
+
var done = callback;
|
| 380 |
+
var req = this.req;
|
| 381 |
+
var res = this;
|
| 382 |
+
var next = req.next;
|
| 383 |
+
var opts = options || {};
|
| 384 |
+
|
| 385 |
+
if (!path) {
|
| 386 |
+
throw new TypeError('path argument is required to res.sendFile');
|
| 387 |
+
}
|
| 388 |
+
|
| 389 |
+
if (typeof path !== 'string') {
|
| 390 |
+
throw new TypeError('path must be a string to res.sendFile')
|
| 391 |
+
}
|
| 392 |
+
|
| 393 |
+
// support function as second arg
|
| 394 |
+
if (typeof options === 'function') {
|
| 395 |
+
done = options;
|
| 396 |
+
opts = {};
|
| 397 |
+
}
|
| 398 |
+
|
| 399 |
+
if (!opts.root && !pathIsAbsolute(path)) {
|
| 400 |
+
throw new TypeError('path must be absolute or specify root to res.sendFile');
|
| 401 |
+
}
|
| 402 |
+
|
| 403 |
+
// create file stream
|
| 404 |
+
var pathname = encodeURI(path);
|
| 405 |
+
|
| 406 |
+
// wire application etag option to send
|
| 407 |
+
opts.etag = this.app.enabled('etag');
|
| 408 |
+
var file = send(req, pathname, opts);
|
| 409 |
+
|
| 410 |
+
// transfer
|
| 411 |
+
sendfile(res, file, opts, function (err) {
|
| 412 |
+
if (done) return done(err);
|
| 413 |
+
if (err && err.code === 'EISDIR') return next();
|
| 414 |
+
|
| 415 |
+
// next() all but write errors
|
| 416 |
+
if (err && err.code !== 'ECONNABORTED' && err.syscall !== 'write') {
|
| 417 |
+
next(err);
|
| 418 |
+
}
|
| 419 |
+
});
|
| 420 |
+
};
|
| 421 |
+
|
| 422 |
+
/**
|
| 423 |
+
* Transfer the file at the given `path` as an attachment.
|
| 424 |
+
*
|
| 425 |
+
* Optionally providing an alternate attachment `filename`,
|
| 426 |
+
* and optional callback `callback(err)`. The callback is invoked
|
| 427 |
+
* when the data transfer is complete, or when an error has
|
| 428 |
+
* occurred. Be sure to check `res.headersSent` if you plan to respond.
|
| 429 |
+
*
|
| 430 |
+
* Optionally providing an `options` object to use with `res.sendFile()`.
|
| 431 |
+
* This function will set the `Content-Disposition` header, overriding
|
| 432 |
+
* any `Content-Disposition` header passed as header options in order
|
| 433 |
+
* to set the attachment and filename.
|
| 434 |
+
*
|
| 435 |
+
* This method uses `res.sendFile()`.
|
| 436 |
+
*
|
| 437 |
+
* @public
|
| 438 |
+
*/
|
| 439 |
+
|
| 440 |
+
res.download = function download (path, filename, options, callback) {
|
| 441 |
+
var done = callback;
|
| 442 |
+
var name = filename;
|
| 443 |
+
var opts = options || null
|
| 444 |
+
|
| 445 |
+
// support function as second or third arg
|
| 446 |
+
if (typeof filename === 'function') {
|
| 447 |
+
done = filename;
|
| 448 |
+
name = null;
|
| 449 |
+
opts = null
|
| 450 |
+
} else if (typeof options === 'function') {
|
| 451 |
+
done = options
|
| 452 |
+
opts = null
|
| 453 |
+
}
|
| 454 |
+
|
| 455 |
+
// support optional filename, where options may be in it's place
|
| 456 |
+
if (typeof filename === 'object' &&
|
| 457 |
+
(typeof options === 'function' || options === undefined)) {
|
| 458 |
+
name = null
|
| 459 |
+
opts = filename
|
| 460 |
+
}
|
| 461 |
+
|
| 462 |
+
// set Content-Disposition when file is sent
|
| 463 |
+
var headers = {
|
| 464 |
+
'Content-Disposition': contentDisposition(name || path)
|
| 465 |
+
};
|
| 466 |
+
|
| 467 |
+
// merge user-provided headers
|
| 468 |
+
if (opts && opts.headers) {
|
| 469 |
+
var keys = Object.keys(opts.headers)
|
| 470 |
+
for (var i = 0; i < keys.length; i++) {
|
| 471 |
+
var key = keys[i]
|
| 472 |
+
if (key.toLowerCase() !== 'content-disposition') {
|
| 473 |
+
headers[key] = opts.headers[key]
|
| 474 |
+
}
|
| 475 |
+
}
|
| 476 |
+
}
|
| 477 |
+
|
| 478 |
+
// merge user-provided options
|
| 479 |
+
opts = Object.create(opts)
|
| 480 |
+
opts.headers = headers
|
| 481 |
+
|
| 482 |
+
// Resolve the full path for sendFile
|
| 483 |
+
var fullPath = !opts.root
|
| 484 |
+
? resolve(path)
|
| 485 |
+
: path
|
| 486 |
+
|
| 487 |
+
// send file
|
| 488 |
+
return this.sendFile(fullPath, opts, done)
|
| 489 |
+
};
|
| 490 |
+
|
| 491 |
+
/**
|
| 492 |
+
* Set _Content-Type_ response header with `type` through `mime.contentType()`
|
| 493 |
+
* when it does not contain "/", or set the Content-Type to `type` otherwise.
|
| 494 |
+
* When no mapping is found though `mime.contentType()`, the type is set to
|
| 495 |
+
* "application/octet-stream".
|
| 496 |
+
*
|
| 497 |
+
* Examples:
|
| 498 |
+
*
|
| 499 |
+
* res.type('.html');
|
| 500 |
+
* res.type('html');
|
| 501 |
+
* res.type('json');
|
| 502 |
+
* res.type('application/json');
|
| 503 |
+
* res.type('png');
|
| 504 |
+
*
|
| 505 |
+
* @param {String} type
|
| 506 |
+
* @return {ServerResponse} for chaining
|
| 507 |
+
* @public
|
| 508 |
+
*/
|
| 509 |
+
|
| 510 |
+
res.contentType =
|
| 511 |
+
res.type = function contentType(type) {
|
| 512 |
+
var ct = type.indexOf('/') === -1
|
| 513 |
+
? (mime.contentType(type) || 'application/octet-stream')
|
| 514 |
+
: type;
|
| 515 |
+
|
| 516 |
+
return this.set('Content-Type', ct);
|
| 517 |
+
};
|
| 518 |
+
|
| 519 |
+
/**
|
| 520 |
+
* Respond to the Acceptable formats using an `obj`
|
| 521 |
+
* of mime-type callbacks.
|
| 522 |
+
*
|
| 523 |
+
* This method uses `req.accepted`, an array of
|
| 524 |
+
* acceptable types ordered by their quality values.
|
| 525 |
+
* When "Accept" is not present the _first_ callback
|
| 526 |
+
* is invoked, otherwise the first match is used. When
|
| 527 |
+
* no match is performed the server responds with
|
| 528 |
+
* 406 "Not Acceptable".
|
| 529 |
+
*
|
| 530 |
+
* Content-Type is set for you, however if you choose
|
| 531 |
+
* you may alter this within the callback using `res.type()`
|
| 532 |
+
* or `res.set('Content-Type', ...)`.
|
| 533 |
+
*
|
| 534 |
+
* res.format({
|
| 535 |
+
* 'text/plain': function(){
|
| 536 |
+
* res.send('hey');
|
| 537 |
+
* },
|
| 538 |
+
*
|
| 539 |
+
* 'text/html': function(){
|
| 540 |
+
* res.send('<p>hey</p>');
|
| 541 |
+
* },
|
| 542 |
+
*
|
| 543 |
+
* 'application/json': function () {
|
| 544 |
+
* res.send({ message: 'hey' });
|
| 545 |
+
* }
|
| 546 |
+
* });
|
| 547 |
+
*
|
| 548 |
+
* In addition to canonicalized MIME types you may
|
| 549 |
+
* also use extnames mapped to these types:
|
| 550 |
+
*
|
| 551 |
+
* res.format({
|
| 552 |
+
* text: function(){
|
| 553 |
+
* res.send('hey');
|
| 554 |
+
* },
|
| 555 |
+
*
|
| 556 |
+
* html: function(){
|
| 557 |
+
* res.send('<p>hey</p>');
|
| 558 |
+
* },
|
| 559 |
+
*
|
| 560 |
+
* json: function(){
|
| 561 |
+
* res.send({ message: 'hey' });
|
| 562 |
+
* }
|
| 563 |
+
* });
|
| 564 |
+
*
|
| 565 |
+
* By default Express passes an `Error`
|
| 566 |
+
* with a `.status` of 406 to `next(err)`
|
| 567 |
+
* if a match is not made. If you provide
|
| 568 |
+
* a `.default` callback it will be invoked
|
| 569 |
+
* instead.
|
| 570 |
+
*
|
| 571 |
+
* @param {Object} obj
|
| 572 |
+
* @return {ServerResponse} for chaining
|
| 573 |
+
* @public
|
| 574 |
+
*/
|
| 575 |
+
|
| 576 |
+
res.format = function(obj){
|
| 577 |
+
var req = this.req;
|
| 578 |
+
var next = req.next;
|
| 579 |
+
|
| 580 |
+
var keys = Object.keys(obj)
|
| 581 |
+
.filter(function (v) { return v !== 'default' })
|
| 582 |
+
|
| 583 |
+
var key = keys.length > 0
|
| 584 |
+
? req.accepts(keys)
|
| 585 |
+
: false;
|
| 586 |
+
|
| 587 |
+
this.vary("Accept");
|
| 588 |
+
|
| 589 |
+
if (key) {
|
| 590 |
+
this.set('Content-Type', normalizeType(key).value);
|
| 591 |
+
obj[key](req, this, next);
|
| 592 |
+
} else if (obj.default) {
|
| 593 |
+
obj.default(req, this, next)
|
| 594 |
+
} else {
|
| 595 |
+
next(createError(406, {
|
| 596 |
+
types: normalizeTypes(keys).map(function (o) { return o.value })
|
| 597 |
+
}))
|
| 598 |
+
}
|
| 599 |
+
|
| 600 |
+
return this;
|
| 601 |
+
};
|
| 602 |
+
|
| 603 |
+
/**
|
| 604 |
+
* Set _Content-Disposition_ header to _attachment_ with optional `filename`.
|
| 605 |
+
*
|
| 606 |
+
* @param {String} filename
|
| 607 |
+
* @return {ServerResponse}
|
| 608 |
+
* @public
|
| 609 |
+
*/
|
| 610 |
+
|
| 611 |
+
res.attachment = function attachment(filename) {
|
| 612 |
+
if (filename) {
|
| 613 |
+
this.type(extname(filename));
|
| 614 |
+
}
|
| 615 |
+
|
| 616 |
+
this.set('Content-Disposition', contentDisposition(filename));
|
| 617 |
+
|
| 618 |
+
return this;
|
| 619 |
+
};
|
| 620 |
+
|
| 621 |
+
/**
|
| 622 |
+
* Append additional header `field` with value `val`.
|
| 623 |
+
*
|
| 624 |
+
* Example:
|
| 625 |
+
*
|
| 626 |
+
* res.append('Link', ['<http://localhost/>', '<http://localhost:3000/>']);
|
| 627 |
+
* res.append('Set-Cookie', 'foo=bar; Path=/; HttpOnly');
|
| 628 |
+
* res.append('Warning', '199 Miscellaneous warning');
|
| 629 |
+
*
|
| 630 |
+
* @param {String} field
|
| 631 |
+
* @param {String|Array} val
|
| 632 |
+
* @return {ServerResponse} for chaining
|
| 633 |
+
* @public
|
| 634 |
+
*/
|
| 635 |
+
|
| 636 |
+
res.append = function append(field, val) {
|
| 637 |
+
var prev = this.get(field);
|
| 638 |
+
var value = val;
|
| 639 |
+
|
| 640 |
+
if (prev) {
|
| 641 |
+
// concat the new and prev vals
|
| 642 |
+
value = Array.isArray(prev) ? prev.concat(val)
|
| 643 |
+
: Array.isArray(val) ? [prev].concat(val)
|
| 644 |
+
: [prev, val]
|
| 645 |
+
}
|
| 646 |
+
|
| 647 |
+
return this.set(field, value);
|
| 648 |
+
};
|
| 649 |
+
|
| 650 |
+
/**
|
| 651 |
+
* Set header `field` to `val`, or pass
|
| 652 |
+
* an object of header fields.
|
| 653 |
+
*
|
| 654 |
+
* Examples:
|
| 655 |
+
*
|
| 656 |
+
* res.set('Foo', ['bar', 'baz']);
|
| 657 |
+
* res.set('Accept', 'application/json');
|
| 658 |
+
* res.set({ Accept: 'text/plain', 'X-API-Key': 'tobi' });
|
| 659 |
+
*
|
| 660 |
+
* Aliased as `res.header()`.
|
| 661 |
+
*
|
| 662 |
+
* When the set header is "Content-Type", the type is expanded to include
|
| 663 |
+
* the charset if not present using `mime.contentType()`.
|
| 664 |
+
*
|
| 665 |
+
* @param {String|Object} field
|
| 666 |
+
* @param {String|Array} val
|
| 667 |
+
* @return {ServerResponse} for chaining
|
| 668 |
+
* @public
|
| 669 |
+
*/
|
| 670 |
+
|
| 671 |
+
res.set =
|
| 672 |
+
res.header = function header(field, val) {
|
| 673 |
+
if (arguments.length === 2) {
|
| 674 |
+
var value = Array.isArray(val)
|
| 675 |
+
? val.map(String)
|
| 676 |
+
: String(val);
|
| 677 |
+
|
| 678 |
+
// add charset to content-type
|
| 679 |
+
if (field.toLowerCase() === 'content-type') {
|
| 680 |
+
if (Array.isArray(value)) {
|
| 681 |
+
throw new TypeError('Content-Type cannot be set to an Array');
|
| 682 |
+
}
|
| 683 |
+
value = mime.contentType(value)
|
| 684 |
+
}
|
| 685 |
+
|
| 686 |
+
this.setHeader(field, value);
|
| 687 |
+
} else {
|
| 688 |
+
for (var key in field) {
|
| 689 |
+
this.set(key, field[key]);
|
| 690 |
+
}
|
| 691 |
+
}
|
| 692 |
+
return this;
|
| 693 |
+
};
|
| 694 |
+
|
| 695 |
+
/**
|
| 696 |
+
* Get value for header `field`.
|
| 697 |
+
*
|
| 698 |
+
* @param {String} field
|
| 699 |
+
* @return {String}
|
| 700 |
+
* @public
|
| 701 |
+
*/
|
| 702 |
+
|
| 703 |
+
res.get = function(field){
|
| 704 |
+
return this.getHeader(field);
|
| 705 |
+
};
|
| 706 |
+
|
| 707 |
+
/**
|
| 708 |
+
* Clear cookie `name`.
|
| 709 |
+
*
|
| 710 |
+
* @param {String} name
|
| 711 |
+
* @param {Object} [options]
|
| 712 |
+
* @return {ServerResponse} for chaining
|
| 713 |
+
* @public
|
| 714 |
+
*/
|
| 715 |
+
|
| 716 |
+
res.clearCookie = function clearCookie(name, options) {
|
| 717 |
+
// Force cookie expiration by setting expires to the past
|
| 718 |
+
const opts = { path: '/', ...options, expires: new Date(1)};
|
| 719 |
+
// ensure maxAge is not passed
|
| 720 |
+
delete opts.maxAge
|
| 721 |
+
|
| 722 |
+
return this.cookie(name, '', opts);
|
| 723 |
+
};
|
| 724 |
+
|
| 725 |
+
/**
|
| 726 |
+
* Set cookie `name` to `value`, with the given `options`.
|
| 727 |
+
*
|
| 728 |
+
* Options:
|
| 729 |
+
*
|
| 730 |
+
* - `maxAge` max-age in milliseconds, converted to `expires`
|
| 731 |
+
* - `signed` sign the cookie
|
| 732 |
+
* - `path` defaults to "/"
|
| 733 |
+
*
|
| 734 |
+
* Examples:
|
| 735 |
+
*
|
| 736 |
+
* // "Remember Me" for 15 minutes
|
| 737 |
+
* res.cookie('rememberme', '1', { expires: new Date(Date.now() + 900000), httpOnly: true });
|
| 738 |
+
*
|
| 739 |
+
* // same as above
|
| 740 |
+
* res.cookie('rememberme', '1', { maxAge: 900000, httpOnly: true })
|
| 741 |
+
*
|
| 742 |
+
* @param {String} name
|
| 743 |
+
* @param {String|Object} value
|
| 744 |
+
* @param {Object} [options]
|
| 745 |
+
* @return {ServerResponse} for chaining
|
| 746 |
+
* @public
|
| 747 |
+
*/
|
| 748 |
+
|
| 749 |
+
res.cookie = function (name, value, options) {
|
| 750 |
+
var opts = { ...options };
|
| 751 |
+
var secret = this.req.secret;
|
| 752 |
+
var signed = opts.signed;
|
| 753 |
+
|
| 754 |
+
if (signed && !secret) {
|
| 755 |
+
throw new Error('cookieParser("secret") required for signed cookies');
|
| 756 |
+
}
|
| 757 |
+
|
| 758 |
+
var val = typeof value === 'object'
|
| 759 |
+
? 'j:' + JSON.stringify(value)
|
| 760 |
+
: String(value);
|
| 761 |
+
|
| 762 |
+
if (signed) {
|
| 763 |
+
val = 's:' + sign(val, secret);
|
| 764 |
+
}
|
| 765 |
+
|
| 766 |
+
if (opts.maxAge != null) {
|
| 767 |
+
var maxAge = opts.maxAge - 0
|
| 768 |
+
|
| 769 |
+
if (!isNaN(maxAge)) {
|
| 770 |
+
opts.expires = new Date(Date.now() + maxAge)
|
| 771 |
+
opts.maxAge = Math.floor(maxAge / 1000)
|
| 772 |
+
}
|
| 773 |
+
}
|
| 774 |
+
|
| 775 |
+
if (opts.path == null) {
|
| 776 |
+
opts.path = '/';
|
| 777 |
+
}
|
| 778 |
+
|
| 779 |
+
this.append('Set-Cookie', cookie.serialize(name, String(val), opts));
|
| 780 |
+
|
| 781 |
+
return this;
|
| 782 |
+
};
|
| 783 |
+
|
| 784 |
+
/**
|
| 785 |
+
* Set the location header to `url`.
|
| 786 |
+
*
|
| 787 |
+
* The given `url` can also be "back", which redirects
|
| 788 |
+
* to the _Referrer_ or _Referer_ headers or "/".
|
| 789 |
+
*
|
| 790 |
+
* Examples:
|
| 791 |
+
*
|
| 792 |
+
* res.location('/foo/bar').;
|
| 793 |
+
* res.location('http://example.com');
|
| 794 |
+
* res.location('../login');
|
| 795 |
+
*
|
| 796 |
+
* @param {String} url
|
| 797 |
+
* @return {ServerResponse} for chaining
|
| 798 |
+
* @public
|
| 799 |
+
*/
|
| 800 |
+
|
| 801 |
+
res.location = function location(url) {
|
| 802 |
+
return this.set('Location', encodeUrl(url));
|
| 803 |
+
};
|
| 804 |
+
|
| 805 |
+
/**
|
| 806 |
+
* Redirect to the given `url` with optional response `status`
|
| 807 |
+
* defaulting to 302.
|
| 808 |
+
*
|
| 809 |
+
* Examples:
|
| 810 |
+
*
|
| 811 |
+
* res.redirect('/foo/bar');
|
| 812 |
+
* res.redirect('http://example.com');
|
| 813 |
+
* res.redirect(301, 'http://example.com');
|
| 814 |
+
* res.redirect('../login'); // /blog/post/1 -> /blog/login
|
| 815 |
+
*
|
| 816 |
+
* @public
|
| 817 |
+
*/
|
| 818 |
+
|
| 819 |
+
res.redirect = function redirect(url) {
|
| 820 |
+
var address = url;
|
| 821 |
+
var body;
|
| 822 |
+
var status = 302;
|
| 823 |
+
|
| 824 |
+
// allow status / url
|
| 825 |
+
if (arguments.length === 2) {
|
| 826 |
+
status = arguments[0]
|
| 827 |
+
address = arguments[1]
|
| 828 |
+
}
|
| 829 |
+
|
| 830 |
+
if (!address) {
|
| 831 |
+
deprecate('Provide a url argument');
|
| 832 |
+
}
|
| 833 |
+
|
| 834 |
+
if (typeof address !== 'string') {
|
| 835 |
+
deprecate('Url must be a string');
|
| 836 |
+
}
|
| 837 |
+
|
| 838 |
+
if (typeof status !== 'number') {
|
| 839 |
+
deprecate('Status must be a number');
|
| 840 |
+
}
|
| 841 |
+
|
| 842 |
+
// Set location header
|
| 843 |
+
address = this.location(address).get('Location');
|
| 844 |
+
|
| 845 |
+
// Support text/{plain,html} by default
|
| 846 |
+
this.format({
|
| 847 |
+
text: function(){
|
| 848 |
+
body = statuses.message[status] + '. Redirecting to ' + address
|
| 849 |
+
},
|
| 850 |
+
|
| 851 |
+
html: function(){
|
| 852 |
+
var u = escapeHtml(address);
|
| 853 |
+
body = '<p>' + statuses.message[status] + '. Redirecting to ' + u + '</p>'
|
| 854 |
+
},
|
| 855 |
+
|
| 856 |
+
default: function(){
|
| 857 |
+
body = '';
|
| 858 |
+
}
|
| 859 |
+
});
|
| 860 |
+
|
| 861 |
+
// Respond
|
| 862 |
+
this.status(status);
|
| 863 |
+
this.set('Content-Length', Buffer.byteLength(body));
|
| 864 |
+
|
| 865 |
+
if (this.req.method === 'HEAD') {
|
| 866 |
+
this.end();
|
| 867 |
+
} else {
|
| 868 |
+
this.end(body);
|
| 869 |
+
}
|
| 870 |
+
};
|
| 871 |
+
|
| 872 |
+
/**
|
| 873 |
+
* Add `field` to Vary. If already present in the Vary set, then
|
| 874 |
+
* this call is simply ignored.
|
| 875 |
+
*
|
| 876 |
+
* @param {Array|String} field
|
| 877 |
+
* @return {ServerResponse} for chaining
|
| 878 |
+
* @public
|
| 879 |
+
*/
|
| 880 |
+
|
| 881 |
+
res.vary = function(field){
|
| 882 |
+
vary(this, field);
|
| 883 |
+
|
| 884 |
+
return this;
|
| 885 |
+
};
|
| 886 |
+
|
| 887 |
+
/**
|
| 888 |
+
* Render `view` with the given `options` and optional callback `fn`.
|
| 889 |
+
* When a callback function is given a response will _not_ be made
|
| 890 |
+
* automatically, otherwise a response of _200_ and _text/html_ is given.
|
| 891 |
+
*
|
| 892 |
+
* Options:
|
| 893 |
+
*
|
| 894 |
+
* - `cache` boolean hinting to the engine it should cache
|
| 895 |
+
* - `filename` filename of the view being rendered
|
| 896 |
+
*
|
| 897 |
+
* @public
|
| 898 |
+
*/
|
| 899 |
+
|
| 900 |
+
res.render = function render(view, options, callback) {
|
| 901 |
+
var app = this.req.app;
|
| 902 |
+
var done = callback;
|
| 903 |
+
var opts = options || {};
|
| 904 |
+
var req = this.req;
|
| 905 |
+
var self = this;
|
| 906 |
+
|
| 907 |
+
// support callback function as second arg
|
| 908 |
+
if (typeof options === 'function') {
|
| 909 |
+
done = options;
|
| 910 |
+
opts = {};
|
| 911 |
+
}
|
| 912 |
+
|
| 913 |
+
// merge res.locals
|
| 914 |
+
opts._locals = self.locals;
|
| 915 |
+
|
| 916 |
+
// default callback to respond
|
| 917 |
+
done = done || function (err, str) {
|
| 918 |
+
if (err) return req.next(err);
|
| 919 |
+
self.send(str);
|
| 920 |
+
};
|
| 921 |
+
|
| 922 |
+
// render
|
| 923 |
+
app.render(view, opts, done);
|
| 924 |
+
};
|
| 925 |
+
|
| 926 |
+
// pipe the send file stream
|
| 927 |
+
function sendfile(res, file, options, callback) {
|
| 928 |
+
var done = false;
|
| 929 |
+
var streaming;
|
| 930 |
+
|
| 931 |
+
// request aborted
|
| 932 |
+
function onaborted() {
|
| 933 |
+
if (done) return;
|
| 934 |
+
done = true;
|
| 935 |
+
|
| 936 |
+
var err = new Error('Request aborted');
|
| 937 |
+
err.code = 'ECONNABORTED';
|
| 938 |
+
callback(err);
|
| 939 |
+
}
|
| 940 |
+
|
| 941 |
+
// directory
|
| 942 |
+
function ondirectory() {
|
| 943 |
+
if (done) return;
|
| 944 |
+
done = true;
|
| 945 |
+
|
| 946 |
+
var err = new Error('EISDIR, read');
|
| 947 |
+
err.code = 'EISDIR';
|
| 948 |
+
callback(err);
|
| 949 |
+
}
|
| 950 |
+
|
| 951 |
+
// errors
|
| 952 |
+
function onerror(err) {
|
| 953 |
+
if (done) return;
|
| 954 |
+
done = true;
|
| 955 |
+
callback(err);
|
| 956 |
+
}
|
| 957 |
+
|
| 958 |
+
// ended
|
| 959 |
+
function onend() {
|
| 960 |
+
if (done) return;
|
| 961 |
+
done = true;
|
| 962 |
+
callback();
|
| 963 |
+
}
|
| 964 |
+
|
| 965 |
+
// file
|
| 966 |
+
function onfile() {
|
| 967 |
+
streaming = false;
|
| 968 |
+
}
|
| 969 |
+
|
| 970 |
+
// finished
|
| 971 |
+
function onfinish(err) {
|
| 972 |
+
if (err && err.code === 'ECONNRESET') return onaborted();
|
| 973 |
+
if (err) return onerror(err);
|
| 974 |
+
if (done) return;
|
| 975 |
+
|
| 976 |
+
setImmediate(function () {
|
| 977 |
+
if (streaming !== false && !done) {
|
| 978 |
+
onaborted();
|
| 979 |
+
return;
|
| 980 |
+
}
|
| 981 |
+
|
| 982 |
+
if (done) return;
|
| 983 |
+
done = true;
|
| 984 |
+
callback();
|
| 985 |
+
});
|
| 986 |
+
}
|
| 987 |
+
|
| 988 |
+
// streaming
|
| 989 |
+
function onstream() {
|
| 990 |
+
streaming = true;
|
| 991 |
+
}
|
| 992 |
+
|
| 993 |
+
file.on('directory', ondirectory);
|
| 994 |
+
file.on('end', onend);
|
| 995 |
+
file.on('error', onerror);
|
| 996 |
+
file.on('file', onfile);
|
| 997 |
+
file.on('stream', onstream);
|
| 998 |
+
onFinished(res, onfinish);
|
| 999 |
+
|
| 1000 |
+
if (options.headers) {
|
| 1001 |
+
// set headers on successful transfer
|
| 1002 |
+
file.on('headers', function headers(res) {
|
| 1003 |
+
var obj = options.headers;
|
| 1004 |
+
var keys = Object.keys(obj);
|
| 1005 |
+
|
| 1006 |
+
for (var i = 0; i < keys.length; i++) {
|
| 1007 |
+
var k = keys[i];
|
| 1008 |
+
res.setHeader(k, obj[k]);
|
| 1009 |
+
}
|
| 1010 |
+
});
|
| 1011 |
+
}
|
| 1012 |
+
|
| 1013 |
+
// pipe
|
| 1014 |
+
file.pipe(res);
|
| 1015 |
+
}
|
| 1016 |
+
|
| 1017 |
+
/**
|
| 1018 |
+
* Stringify JSON, like JSON.stringify, but v8 optimized, with the
|
| 1019 |
+
* ability to escape characters that can trigger HTML sniffing.
|
| 1020 |
+
*
|
| 1021 |
+
* @param {*} value
|
| 1022 |
+
* @param {function} replacer
|
| 1023 |
+
* @param {number} spaces
|
| 1024 |
+
* @param {boolean} escape
|
| 1025 |
+
* @returns {string}
|
| 1026 |
+
* @private
|
| 1027 |
+
*/
|
| 1028 |
+
|
| 1029 |
+
function stringify (value, replacer, spaces, escape) {
|
| 1030 |
+
// v8 checks arguments.length for optimizing simple call
|
| 1031 |
+
// https://bugs.chromium.org/p/v8/issues/detail?id=4730
|
| 1032 |
+
var json = replacer || spaces
|
| 1033 |
+
? JSON.stringify(value, replacer, spaces)
|
| 1034 |
+
: JSON.stringify(value);
|
| 1035 |
+
|
| 1036 |
+
if (escape && typeof json === 'string') {
|
| 1037 |
+
json = json.replace(/[<>&]/g, function (c) {
|
| 1038 |
+
switch (c.charCodeAt(0)) {
|
| 1039 |
+
case 0x3c:
|
| 1040 |
+
return '\\u003c'
|
| 1041 |
+
case 0x3e:
|
| 1042 |
+
return '\\u003e'
|
| 1043 |
+
case 0x26:
|
| 1044 |
+
return '\\u0026'
|
| 1045 |
+
/* istanbul ignore next: unreachable default */
|
| 1046 |
+
default:
|
| 1047 |
+
return c
|
| 1048 |
+
}
|
| 1049 |
+
})
|
| 1050 |
+
}
|
| 1051 |
+
|
| 1052 |
+
return json
|
| 1053 |
+
}
|
tools/ui/node_modules/express/lib/utils.js
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*!
|
| 2 |
+
* express
|
| 3 |
+
* Copyright(c) 2009-2013 TJ Holowaychuk
|
| 4 |
+
* Copyright(c) 2014-2015 Douglas Christopher Wilson
|
| 5 |
+
* MIT Licensed
|
| 6 |
+
*/
|
| 7 |
+
|
| 8 |
+
'use strict';
|
| 9 |
+
|
| 10 |
+
/**
|
| 11 |
+
* Module dependencies.
|
| 12 |
+
* @api private
|
| 13 |
+
*/
|
| 14 |
+
|
| 15 |
+
var { METHODS } = require('node:http');
|
| 16 |
+
var contentType = require('content-type');
|
| 17 |
+
var etag = require('etag');
|
| 18 |
+
var mime = require('mime-types')
|
| 19 |
+
var proxyaddr = require('proxy-addr');
|
| 20 |
+
var qs = require('qs');
|
| 21 |
+
var querystring = require('node:querystring');
|
| 22 |
+
const { Buffer } = require('node:buffer');
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
/**
|
| 26 |
+
* A list of lowercased HTTP methods that are supported by Node.js.
|
| 27 |
+
* @api private
|
| 28 |
+
*/
|
| 29 |
+
exports.methods = METHODS.map((method) => method.toLowerCase());
|
| 30 |
+
|
| 31 |
+
/**
|
| 32 |
+
* Return strong ETag for `body`.
|
| 33 |
+
*
|
| 34 |
+
* @param {String|Buffer} body
|
| 35 |
+
* @param {String} [encoding]
|
| 36 |
+
* @return {String}
|
| 37 |
+
* @api private
|
| 38 |
+
*/
|
| 39 |
+
|
| 40 |
+
exports.etag = createETagGenerator({ weak: false })
|
| 41 |
+
|
| 42 |
+
/**
|
| 43 |
+
* Return weak ETag for `body`.
|
| 44 |
+
*
|
| 45 |
+
* @param {String|Buffer} body
|
| 46 |
+
* @param {String} [encoding]
|
| 47 |
+
* @return {String}
|
| 48 |
+
* @api private
|
| 49 |
+
*/
|
| 50 |
+
|
| 51 |
+
exports.wetag = createETagGenerator({ weak: true })
|
| 52 |
+
|
| 53 |
+
/**
|
| 54 |
+
* Normalize the given `type`, for example "html" becomes "text/html".
|
| 55 |
+
*
|
| 56 |
+
* @param {String} type
|
| 57 |
+
* @return {Object}
|
| 58 |
+
* @api private
|
| 59 |
+
*/
|
| 60 |
+
|
| 61 |
+
exports.normalizeType = function(type){
|
| 62 |
+
return ~type.indexOf('/')
|
| 63 |
+
? acceptParams(type)
|
| 64 |
+
: { value: (mime.lookup(type) || 'application/octet-stream'), params: {} }
|
| 65 |
+
};
|
| 66 |
+
|
| 67 |
+
/**
|
| 68 |
+
* Normalize `types`, for example "html" becomes "text/html".
|
| 69 |
+
*
|
| 70 |
+
* @param {Array} types
|
| 71 |
+
* @return {Array}
|
| 72 |
+
* @api private
|
| 73 |
+
*/
|
| 74 |
+
|
| 75 |
+
exports.normalizeTypes = function(types) {
|
| 76 |
+
return types.map(exports.normalizeType);
|
| 77 |
+
};
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
/**
|
| 81 |
+
* Parse accept params `str` returning an
|
| 82 |
+
* object with `.value`, `.quality` and `.params`.
|
| 83 |
+
*
|
| 84 |
+
* @param {String} str
|
| 85 |
+
* @return {Object}
|
| 86 |
+
* @api private
|
| 87 |
+
*/
|
| 88 |
+
|
| 89 |
+
function acceptParams (str) {
|
| 90 |
+
var length = str.length;
|
| 91 |
+
var colonIndex = str.indexOf(';');
|
| 92 |
+
var index = colonIndex === -1 ? length : colonIndex;
|
| 93 |
+
var ret = { value: str.slice(0, index).trim(), quality: 1, params: {} };
|
| 94 |
+
|
| 95 |
+
while (index < length) {
|
| 96 |
+
var splitIndex = str.indexOf('=', index);
|
| 97 |
+
if (splitIndex === -1) break;
|
| 98 |
+
|
| 99 |
+
var colonIndex = str.indexOf(';', index);
|
| 100 |
+
var endIndex = colonIndex === -1 ? length : colonIndex;
|
| 101 |
+
|
| 102 |
+
if (splitIndex > endIndex) {
|
| 103 |
+
index = str.lastIndexOf(';', splitIndex - 1) + 1;
|
| 104 |
+
continue;
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
var key = str.slice(index, splitIndex).trim();
|
| 108 |
+
var value = str.slice(splitIndex + 1, endIndex).trim();
|
| 109 |
+
|
| 110 |
+
if (key === 'q') {
|
| 111 |
+
ret.quality = parseFloat(value);
|
| 112 |
+
} else {
|
| 113 |
+
ret.params[key] = value;
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
index = endIndex + 1;
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
return ret;
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
/**
|
| 123 |
+
* Compile "etag" value to function.
|
| 124 |
+
*
|
| 125 |
+
* @param {Boolean|String|Function} val
|
| 126 |
+
* @return {Function}
|
| 127 |
+
* @api private
|
| 128 |
+
*/
|
| 129 |
+
|
| 130 |
+
exports.compileETag = function(val) {
|
| 131 |
+
var fn;
|
| 132 |
+
|
| 133 |
+
if (typeof val === 'function') {
|
| 134 |
+
return val;
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
switch (val) {
|
| 138 |
+
case true:
|
| 139 |
+
case 'weak':
|
| 140 |
+
fn = exports.wetag;
|
| 141 |
+
break;
|
| 142 |
+
case false:
|
| 143 |
+
break;
|
| 144 |
+
case 'strong':
|
| 145 |
+
fn = exports.etag;
|
| 146 |
+
break;
|
| 147 |
+
default:
|
| 148 |
+
throw new TypeError('unknown value for etag function: ' + val);
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
return fn;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
/**
|
| 155 |
+
* Compile "query parser" value to function.
|
| 156 |
+
*
|
| 157 |
+
* @param {String|Function} val
|
| 158 |
+
* @return {Function}
|
| 159 |
+
* @api private
|
| 160 |
+
*/
|
| 161 |
+
|
| 162 |
+
exports.compileQueryParser = function compileQueryParser(val) {
|
| 163 |
+
var fn;
|
| 164 |
+
|
| 165 |
+
if (typeof val === 'function') {
|
| 166 |
+
return val;
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
switch (val) {
|
| 170 |
+
case true:
|
| 171 |
+
case 'simple':
|
| 172 |
+
fn = querystring.parse;
|
| 173 |
+
break;
|
| 174 |
+
case false:
|
| 175 |
+
break;
|
| 176 |
+
case 'extended':
|
| 177 |
+
fn = parseExtendedQueryString;
|
| 178 |
+
break;
|
| 179 |
+
default:
|
| 180 |
+
throw new TypeError('unknown value for query parser function: ' + val);
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
return fn;
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
/**
|
| 187 |
+
* Compile "proxy trust" value to function.
|
| 188 |
+
*
|
| 189 |
+
* @param {Boolean|String|Number|Array|Function} val
|
| 190 |
+
* @return {Function}
|
| 191 |
+
* @api private
|
| 192 |
+
*/
|
| 193 |
+
|
| 194 |
+
exports.compileTrust = function(val) {
|
| 195 |
+
if (typeof val === 'function') return val;
|
| 196 |
+
|
| 197 |
+
if (val === true) {
|
| 198 |
+
// Support plain true/false
|
| 199 |
+
return function(){ return true };
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
if (typeof val === 'number') {
|
| 203 |
+
// Support trusting hop count
|
| 204 |
+
return function(a, i){ return i < val };
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
if (typeof val === 'string') {
|
| 208 |
+
// Support comma-separated values
|
| 209 |
+
val = val.split(',')
|
| 210 |
+
.map(function (v) { return v.trim() })
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
return proxyaddr.compile(val || []);
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
/**
|
| 217 |
+
* Set the charset in a given Content-Type string.
|
| 218 |
+
*
|
| 219 |
+
* @param {String} type
|
| 220 |
+
* @param {String} charset
|
| 221 |
+
* @return {String}
|
| 222 |
+
* @api private
|
| 223 |
+
*/
|
| 224 |
+
|
| 225 |
+
exports.setCharset = function setCharset(type, charset) {
|
| 226 |
+
if (!type || !charset) {
|
| 227 |
+
return type;
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
// parse type
|
| 231 |
+
var parsed = contentType.parse(type);
|
| 232 |
+
|
| 233 |
+
// set charset
|
| 234 |
+
parsed.parameters.charset = charset;
|
| 235 |
+
|
| 236 |
+
// format type
|
| 237 |
+
return contentType.format(parsed);
|
| 238 |
+
};
|
| 239 |
+
|
| 240 |
+
/**
|
| 241 |
+
* Create an ETag generator function, generating ETags with
|
| 242 |
+
* the given options.
|
| 243 |
+
*
|
| 244 |
+
* @param {object} options
|
| 245 |
+
* @return {function}
|
| 246 |
+
* @private
|
| 247 |
+
*/
|
| 248 |
+
|
| 249 |
+
function createETagGenerator (options) {
|
| 250 |
+
return function generateETag (body, encoding) {
|
| 251 |
+
var buf = !Buffer.isBuffer(body)
|
| 252 |
+
? Buffer.from(body, encoding)
|
| 253 |
+
: body
|
| 254 |
+
|
| 255 |
+
return etag(buf, options)
|
| 256 |
+
}
|
| 257 |
+
}
|
| 258 |
+
|
| 259 |
+
/**
|
| 260 |
+
* Parse an extended query string with qs.
|
| 261 |
+
*
|
| 262 |
+
* @param {String} str
|
| 263 |
+
* @return {Object}
|
| 264 |
+
* @private
|
| 265 |
+
*/
|
| 266 |
+
|
| 267 |
+
function parseExtendedQueryString(str) {
|
| 268 |
+
return qs.parse(str, {
|
| 269 |
+
allowPrototypes: true
|
| 270 |
+
});
|
| 271 |
+
}
|
tools/ui/node_modules/express/lib/view.js
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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right(c) 2013 Roman Shtylman
|
| 5 |
+
* Copyright(c) 2014-2015 Douglas Christopher Wilson
|
| 6 |
+
* MIT Licensed
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
'use strict';
|
| 10 |
+
|
| 11 |
+
/**
|
| 12 |
+
* Module dependencies.
|
| 13 |
+
* @private
|
| 14 |
+
*/
|
| 15 |
+
|
| 16 |
+
var debug = require('debug')('express:view');
|
| 17 |
+
var path = require('node:path');
|
| 18 |
+
var fs = require('node:fs');
|
| 19 |
+
|
| 20 |
+
/**
|
| 21 |
+
* Module variables.
|
| 22 |
+
* @private
|
| 23 |
+
*/
|
| 24 |
+
|
| 25 |
+
var dirname = path.dirname;
|
| 26 |
+
var basename = path.basename;
|
| 27 |
+
var extname = path.extname;
|
| 28 |
+
var join = path.join;
|
| 29 |
+
var resolve = path.resolve;
|
| 30 |
+
|
| 31 |
+
/**
|
| 32 |
+
* Module exports.
|
| 33 |
+
* @public
|
| 34 |
+
*/
|
| 35 |
+
|
| 36 |
+
module.exports = View;
|
| 37 |
+
|
| 38 |
+
/**
|
| 39 |
+
* Initialize a new `View` with the given `name`.
|
| 40 |
+
*
|
| 41 |
+
* Options:
|
| 42 |
+
*
|
| 43 |
+
* - `defaultEngine` the default template engine name
|
| 44 |
+
* - `engines` template engine require() cache
|
| 45 |
+
* - `root` root path for view lookup
|
| 46 |
+
*
|
| 47 |
+
* @param {string} name
|
| 48 |
+
* @param {object} options
|
| 49 |
+
* @public
|
| 50 |
+
*/
|
| 51 |
+
|
| 52 |
+
function View(name, options) {
|
| 53 |
+
var opts = options || {};
|
| 54 |
+
|
| 55 |
+
this.defaultEngine = opts.defaultEngine;
|
| 56 |
+
this.ext = extname(name);
|
| 57 |
+
this.name = name;
|
| 58 |
+
this.root = opts.root;
|
| 59 |
+
|
| 60 |
+
if (!this.ext && !this.defaultEngine) {
|
| 61 |
+
throw new Error('No default engine was specified and no extension was provided.');
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
var fileName = name;
|
| 65 |
+
|
| 66 |
+
if (!this.ext) {
|
| 67 |
+
// get extension from default engine name
|
| 68 |
+
this.ext = this.defaultEngine[0] !== '.'
|
| 69 |
+
? '.' + this.defaultEngine
|
| 70 |
+
: this.defaultEngine;
|
| 71 |
+
|
| 72 |
+
fileName += this.ext;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
if (!opts.engines[this.ext]) {
|
| 76 |
+
// load engine
|
| 77 |
+
var mod = this.ext.slice(1)
|
| 78 |
+
debug('require "%s"', mod)
|
| 79 |
+
|
| 80 |
+
// default engine export
|
| 81 |
+
var fn = require(mod).__express
|
| 82 |
+
|
| 83 |
+
if (typeof fn !== 'function') {
|
| 84 |
+
throw new Error('Module "' + mod + '" does not provide a view engine.')
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
opts.engines[this.ext] = fn
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
// store loaded engine
|
| 91 |
+
this.engine = opts.engines[this.ext];
|
| 92 |
+
|
| 93 |
+
// lookup path
|
| 94 |
+
this.path = this.lookup(fileName);
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
/**
|
| 98 |
+
* Lookup view by the given `name`
|
| 99 |
+
*
|
| 100 |
+
* @param {string} name
|
| 101 |
+
* @private
|
| 102 |
+
*/
|
| 103 |
+
|
| 104 |
+
View.prototype.lookup = function lookup(name) {
|
| 105 |
+
var path;
|
| 106 |
+
var roots = [].concat(this.root);
|
| 107 |
+
|
| 108 |
+
debug('lookup "%s"', name);
|
| 109 |
+
|
| 110 |
+
for (var i = 0; i < roots.length && !path; i++) {
|
| 111 |
+
var root = roots[i];
|
| 112 |
+
|
| 113 |
+
// resolve the path
|
| 114 |
+
var loc = resolve(root, name);
|
| 115 |
+
var dir = dirname(loc);
|
| 116 |
+
var file = basename(loc);
|
| 117 |
+
|
| 118 |
+
// resolve the file
|
| 119 |
+
path = this.resolve(dir, file);
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
return path;
|
| 123 |
+
};
|
| 124 |
+
|
| 125 |
+
/**
|
| 126 |
+
* Render with the given options.
|
| 127 |
+
*
|
| 128 |
+
* @param {object} options
|
| 129 |
+
* @param {function} callback
|
| 130 |
+
* @private
|
| 131 |
+
*/
|
| 132 |
+
|
| 133 |
+
View.prototype.render = function render(options, callback) {
|
| 134 |
+
var sync = true;
|
| 135 |
+
|
| 136 |
+
debug('render "%s"', this.path);
|
| 137 |
+
|
| 138 |
+
// render, normalizing sync callbacks
|
| 139 |
+
this.engine(this.path, options, function onRender() {
|
| 140 |
+
if (!sync) {
|
| 141 |
+
return callback.apply(this, arguments);
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
// copy arguments
|
| 145 |
+
var args = new Array(arguments.length);
|
| 146 |
+
var cntx = this;
|
| 147 |
+
|
| 148 |
+
for (var i = 0; i < arguments.length; i++) {
|
| 149 |
+
args[i] = arguments[i];
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
// force callback to be async
|
| 153 |
+
return process.nextTick(function renderTick() {
|
| 154 |
+
return callback.apply(cntx, args);
|
| 155 |
+
});
|
| 156 |
+
});
|
| 157 |
+
|
| 158 |
+
sync = false;
|
| 159 |
+
};
|
| 160 |
+
|
| 161 |
+
/**
|
| 162 |
+
* Resolve the file within the given directory.
|
| 163 |
+
*
|
| 164 |
+
* @param {string} dir
|
| 165 |
+
* @param {string} file
|
| 166 |
+
* @private
|
| 167 |
+
*/
|
| 168 |
+
|
| 169 |
+
View.prototype.resolve = function resolve(dir, file) {
|
| 170 |
+
var ext = this.ext;
|
| 171 |
+
|
| 172 |
+
// <path>.<ext>
|
| 173 |
+
var path = join(dir, file);
|
| 174 |
+
var stat = tryStat(path);
|
| 175 |
+
|
| 176 |
+
if (stat && stat.isFile()) {
|
| 177 |
+
return path;
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
// <path>/index.<ext>
|
| 181 |
+
path = join(dir, basename(file, ext), 'index' + ext);
|
| 182 |
+
stat = tryStat(path);
|
| 183 |
+
|
| 184 |
+
if (stat && stat.isFile()) {
|
| 185 |
+
return path;
|
| 186 |
+
}
|
| 187 |
+
};
|
| 188 |
+
|
| 189 |
+
/**
|
| 190 |
+
* Return a stat, maybe.
|
| 191 |
+
*
|
| 192 |
+
* @param {string} path
|
| 193 |
+
* @return {fs.Stats}
|
| 194 |
+
* @private
|
| 195 |
+
*/
|
| 196 |
+
|
| 197 |
+
function tryStat(path) {
|
| 198 |
+
debug('stat "%s"', path);
|
| 199 |
+
|
| 200 |
+
try {
|
| 201 |
+
return fs.statSync(path);
|
| 202 |
+
} catch (e) {
|
| 203 |
+
return undefined;
|
| 204 |
+
}
|
| 205 |
+
}
|
tools/ui/node_modules/express/package.json
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "express",
|
| 3 |
+
"description": "Fast, unopinionated, minimalist web framework",
|
| 4 |
+
"version": "5.2.1",
|
| 5 |
+
"author": "TJ Holowaychuk <tj@vision-media.ca>",
|
| 6 |
+
"contributors": [
|
| 7 |
+
"Aaron Heckmann <aaron.heckmann+github@gmail.com>",
|
| 8 |
+
"Ciaran Jessup <ciaranj@gmail.com>",
|
| 9 |
+
"Douglas Christopher Wilson <doug@somethingdoug.com>",
|
| 10 |
+
"Guillermo Rauch <rauchg@gmail.com>",
|
| 11 |
+
"Jonathan Ong <me@jongleberry.com>",
|
| 12 |
+
"Roman Shtylman <shtylman+expressjs@gmail.com>",
|
| 13 |
+
"Young Jae Sim <hanul@hanul.me>"
|
| 14 |
+
],
|
| 15 |
+
"license": "MIT",
|
| 16 |
+
"repository": "expressjs/express",
|
| 17 |
+
"homepage": "https://expressjs.com/",
|
| 18 |
+
"funding": {
|
| 19 |
+
"type": "opencollective",
|
| 20 |
+
"url": "https://opencollective.com/express"
|
| 21 |
+
},
|
| 22 |
+
"keywords": [
|
| 23 |
+
"express",
|
| 24 |
+
"framework",
|
| 25 |
+
"sinatra",
|
| 26 |
+
"web",
|
| 27 |
+
"http",
|
| 28 |
+
"rest",
|
| 29 |
+
"restful",
|
| 30 |
+
"router",
|
| 31 |
+
"app",
|
| 32 |
+
"api"
|
| 33 |
+
],
|
| 34 |
+
"dependencies": {
|
| 35 |
+
"accepts": "^2.0.0",
|
| 36 |
+
"body-parser": "^2.2.1",
|
| 37 |
+
"content-disposition": "^1.0.0",
|
| 38 |
+
"content-type": "^1.0.5",
|
| 39 |
+
"cookie": "^0.7.1",
|
| 40 |
+
"cookie-signature": "^1.2.1",
|
| 41 |
+
"debug": "^4.4.0",
|
| 42 |
+
"depd": "^2.0.0",
|
| 43 |
+
"encodeurl": "^2.0.0",
|
| 44 |
+
"escape-html": "^1.0.3",
|
| 45 |
+
"etag": "^1.8.1",
|
| 46 |
+
"finalhandler": "^2.1.0",
|
| 47 |
+
"fresh": "^2.0.0",
|
| 48 |
+
"http-errors": "^2.0.0",
|
| 49 |
+
"merge-descriptors": "^2.0.0",
|
| 50 |
+
"mime-types": "^3.0.0",
|
| 51 |
+
"on-finished": "^2.4.1",
|
| 52 |
+
"once": "^1.4.0",
|
| 53 |
+
"parseurl": "^1.3.3",
|
| 54 |
+
"proxy-addr": "^2.0.7",
|
| 55 |
+
"qs": "^6.14.0",
|
| 56 |
+
"range-parser": "^1.2.1",
|
| 57 |
+
"router": "^2.2.0",
|
| 58 |
+
"send": "^1.1.0",
|
| 59 |
+
"serve-static": "^2.2.0",
|
| 60 |
+
"statuses": "^2.0.1",
|
| 61 |
+
"type-is": "^2.0.1",
|
| 62 |
+
"vary": "^1.1.2"
|
| 63 |
+
},
|
| 64 |
+
"devDependencies": {
|
| 65 |
+
"after": "0.8.2",
|
| 66 |
+
"connect-redis": "^8.0.1",
|
| 67 |
+
"cookie-parser": "1.4.7",
|
| 68 |
+
"cookie-session": "2.1.1",
|
| 69 |
+
"ejs": "^3.1.10",
|
| 70 |
+
"eslint": "8.47.0",
|
| 71 |
+
"express-session": "^1.18.1",
|
| 72 |
+
"hbs": "4.2.0",
|
| 73 |
+
"marked": "^15.0.3",
|
| 74 |
+
"method-override": "3.0.0",
|
| 75 |
+
"mocha": "^10.7.3",
|
| 76 |
+
"morgan": "1.10.1",
|
| 77 |
+
"nyc": "^17.1.0",
|
| 78 |
+
"pbkdf2-password": "1.2.1",
|
| 79 |
+
"supertest": "^6.3.0",
|
| 80 |
+
"vhost": "~3.0.2"
|
| 81 |
+
},
|
| 82 |
+
"engines": {
|
| 83 |
+
"node": ">= 18"
|
| 84 |
+
},
|
| 85 |
+
"files": [
|
| 86 |
+
"LICENSE",
|
| 87 |
+
"Readme.md",
|
| 88 |
+
"index.js",
|
| 89 |
+
"lib/"
|
| 90 |
+
],
|
| 91 |
+
"scripts": {
|
| 92 |
+
"lint": "eslint .",
|
| 93 |
+
"lint:fix": "eslint . --fix",
|
| 94 |
+
"test": "mocha --require test/support/env --reporter spec --check-leaks test/ test/acceptance/",
|
| 95 |
+
"test-ci": "nyc --exclude examples --exclude test --exclude benchmarks --reporter=lcovonly --reporter=text npm test",
|
| 96 |
+
"test-cov": "nyc --exclude examples --exclude test --exclude benchmarks --reporter=html --reporter=text npm test",
|
| 97 |
+
"test-tap": "mocha --require test/support/env --reporter tap --check-leaks test/ test/acceptance/"
|
| 98 |
+
}
|
| 99 |
+
}
|
tools/ui/node_modules/extend/.editorconfig
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
root = true
|
| 2 |
+
|
| 3 |
+
[*]
|
| 4 |
+
indent_style = tab
|
| 5 |
+
indent_size = 4
|
| 6 |
+
end_of_line = lf
|
| 7 |
+
charset = utf-8
|
| 8 |
+
trim_trailing_whitespace = true
|
| 9 |
+
insert_final_newline = true
|
| 10 |
+
max_line_length = 150
|
| 11 |
+
|
| 12 |
+
[CHANGELOG.md]
|
| 13 |
+
indent_style = space
|
| 14 |
+
indent_size = 2
|
| 15 |
+
|
| 16 |
+
[*.json]
|
| 17 |
+
max_line_length = off
|
| 18 |
+
|
| 19 |
+
[Makefile]
|
| 20 |
+
max_line_length = off
|
tools/ui/node_modules/extend/.eslintrc
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"root": true,
|
| 3 |
+
|
| 4 |
+
"extends": "@ljharb",
|
| 5 |
+
|
| 6 |
+
"rules": {
|
| 7 |
+
"complexity": [2, 20],
|
| 8 |
+
"eqeqeq": [2, "allow-null"],
|
| 9 |
+
"func-name-matching": [1],
|
| 10 |
+
"max-depth": [1, 4],
|
| 11 |
+
"max-statements": [2, 26],
|
| 12 |
+
"no-extra-parens": [1],
|
| 13 |
+
"no-magic-numbers": [0],
|
| 14 |
+
"no-restricted-syntax": [2, "BreakStatement", "ContinueStatement", "DebuggerStatement", "LabeledStatement", "WithStatement"],
|
| 15 |
+
"sort-keys": [0],
|
| 16 |
+
}
|
| 17 |
+
}
|
tools/ui/node_modules/extend/.jscs.json
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"es3": true,
|
| 3 |
+
|
| 4 |
+
"additionalRules": [],
|
| 5 |
+
|
| 6 |
+
"requireSemicolons": true,
|
| 7 |
+
|
| 8 |
+
"disallowMultipleSpaces": true,
|
| 9 |
+
|
| 10 |
+
"disallowIdentifierNames": [],
|
| 11 |
+
|
| 12 |
+
"requireCurlyBraces": {
|
| 13 |
+
"allExcept": [],
|
| 14 |
+
"keywords": ["if", "else", "for", "while", "do", "try", "catch"]
|
| 15 |
+
},
|
| 16 |
+
|
| 17 |
+
"requireSpaceAfterKeywords": ["if", "else", "for", "while", "do", "switch", "return", "try", "catch", "function"],
|
| 18 |
+
|
| 19 |
+
"disallowSpaceAfterKeywords": [],
|
| 20 |
+
|
| 21 |
+
"disallowSpaceBeforeComma": true,
|
| 22 |
+
"disallowSpaceAfterComma": false,
|
| 23 |
+
"disallowSpaceBeforeSemicolon": true,
|
| 24 |
+
|
| 25 |
+
"disallowNodeTypes": [
|
| 26 |
+
"DebuggerStatement",
|
| 27 |
+
"LabeledStatement",
|
| 28 |
+
"SwitchCase",
|
| 29 |
+
"SwitchStatement",
|
| 30 |
+
"WithStatement"
|
| 31 |
+
],
|
| 32 |
+
|
| 33 |
+
"requireObjectKeysOnNewLine": { "allExcept": ["sameLine"] },
|
| 34 |
+
|
| 35 |
+
"requireSpacesInAnonymousFunctionExpression": { "beforeOpeningRoundBrace": true, "beforeOpeningCurlyBrace": true },
|
| 36 |
+
"requireSpacesInNamedFunctionExpression": { "beforeOpeningCurlyBrace": true },
|
| 37 |
+
"disallowSpacesInNamedFunctionExpression": { "beforeOpeningRoundBrace": true },
|
| 38 |
+
"requireSpacesInFunctionDeclaration": { "beforeOpeningCurlyBrace": true },
|
| 39 |
+
"disallowSpacesInFunctionDeclaration": { "beforeOpeningRoundBrace": true },
|
| 40 |
+
|
| 41 |
+
"requireSpaceBetweenArguments": true,
|
| 42 |
+
|
| 43 |
+
"disallowSpacesInsideParentheses": true,
|
| 44 |
+
|
| 45 |
+
"disallowSpacesInsideArrayBrackets": true,
|
| 46 |
+
|
| 47 |
+
"disallowQuotedKeysInObjects": { "allExcept": ["reserved"] },
|
| 48 |
+
|
| 49 |
+
"disallowSpaceAfterObjectKeys": true,
|
| 50 |
+
|
| 51 |
+
"requireCommaBeforeLineBreak": true,
|
| 52 |
+
|
| 53 |
+
"disallowSpaceAfterPrefixUnaryOperators": ["++", "--", "+", "-", "~", "!"],
|
| 54 |
+
"requireSpaceAfterPrefixUnaryOperators": [],
|
| 55 |
+
|
| 56 |
+
"disallowSpaceBeforePostfixUnaryOperators": ["++", "--"],
|
| 57 |
+
"requireSpaceBeforePostfixUnaryOperators": [],
|
| 58 |
+
|
| 59 |
+
"disallowSpaceBeforeBinaryOperators": [],
|
| 60 |
+
"requireSpaceBeforeBinaryOperators": ["+", "-", "/", "*", "=", "==", "===", "!=", "!=="],
|
| 61 |
+
|
| 62 |
+
"requireSpaceAfterBinaryOperators": ["+", "-", "/", "*", "=", "==", "===", "!=", "!=="],
|
| 63 |
+
"disallowSpaceAfterBinaryOperators": [],
|
| 64 |
+
|
| 65 |
+
"disallowImplicitTypeConversion": ["binary", "string"],
|
| 66 |
+
|
| 67 |
+
"disallowKeywords": ["with", "eval"],
|
| 68 |
+
|
| 69 |
+
"requireKeywordsOnNewLine": [],
|
| 70 |
+
"disallowKeywordsOnNewLine": ["else"],
|
| 71 |
+
|
| 72 |
+
"requireLineFeedAtFileEnd": true,
|
| 73 |
+
|
| 74 |
+
"disallowTrailingWhitespace": true,
|
| 75 |
+
|
| 76 |
+
"disallowTrailingComma": true,
|
| 77 |
+
|
| 78 |
+
"excludeFiles": ["node_modules/**", "vendor/**"],
|
| 79 |
+
|
| 80 |
+
"disallowMultipleLineStrings": true,
|
| 81 |
+
|
| 82 |
+
"requireDotNotation": { "allExcept": ["keywords"] },
|
| 83 |
+
|
| 84 |
+
"requireParenthesesAroundIIFE": true,
|
| 85 |
+
|
| 86 |
+
"validateLineBreaks": "LF",
|
| 87 |
+
|
| 88 |
+
"validateQuoteMarks": {
|
| 89 |
+
"escape": true,
|
| 90 |
+
"mark": "'"
|
| 91 |
+
},
|
| 92 |
+
|
| 93 |
+
"disallowOperatorBeforeLineBreak": [],
|
| 94 |
+
|
| 95 |
+
"requireSpaceBeforeKeywords": [
|
| 96 |
+
"do",
|
| 97 |
+
"for",
|
| 98 |
+
"if",
|
| 99 |
+
"else",
|
| 100 |
+
"switch",
|
| 101 |
+
"case",
|
| 102 |
+
"try",
|
| 103 |
+
"catch",
|
| 104 |
+
"finally",
|
| 105 |
+
"while",
|
| 106 |
+
"with",
|
| 107 |
+
"return"
|
| 108 |
+
],
|
| 109 |
+
|
| 110 |
+
"validateAlignedFunctionParameters": {
|
| 111 |
+
"lineBreakAfterOpeningBraces": true,
|
| 112 |
+
"lineBreakBeforeClosingBraces": true
|
| 113 |
+
},
|
| 114 |
+
|
| 115 |
+
"requirePaddingNewLinesBeforeExport": true,
|
| 116 |
+
|
| 117 |
+
"validateNewlineAfterArrayElements": {
|
| 118 |
+
"maximum": 6
|
| 119 |
+
},
|
| 120 |
+
|
| 121 |
+
"requirePaddingNewLinesAfterUseStrict": true,
|
| 122 |
+
|
| 123 |
+
"disallowArrowFunctions": true,
|
| 124 |
+
|
| 125 |
+
"disallowMultiLineTernary": true,
|
| 126 |
+
|
| 127 |
+
"validateOrderInObjectKeys": false,
|
| 128 |
+
|
| 129 |
+
"disallowIdenticalDestructuringNames": true,
|
| 130 |
+
|
| 131 |
+
"disallowNestedTernaries": { "maxLevel": 1 },
|
| 132 |
+
|
| 133 |
+
"requireSpaceAfterComma": { "allExcept": ["trailing"] },
|
| 134 |
+
"requireAlignedMultilineParams": false,
|
| 135 |
+
|
| 136 |
+
"requireSpacesInGenerator": {
|
| 137 |
+
"afterStar": true
|
| 138 |
+
},
|
| 139 |
+
|
| 140 |
+
"disallowSpacesInGenerator": {
|
| 141 |
+
"beforeStar": true
|
| 142 |
+
},
|
| 143 |
+
|
| 144 |
+
"disallowVar": false,
|
| 145 |
+
|
| 146 |
+
"requireArrayDestructuring": false,
|
| 147 |
+
|
| 148 |
+
"requireEnhancedObjectLiterals": false,
|
| 149 |
+
|
| 150 |
+
"requireObjectDestructuring": false,
|
| 151 |
+
|
| 152 |
+
"requireEarlyReturn": false,
|
| 153 |
+
|
| 154 |
+
"requireCapitalizedConstructorsNew": {
|
| 155 |
+
"allExcept": ["Function", "String", "Object", "Symbol", "Number", "Date", "RegExp", "Error", "Boolean", "Array"]
|
| 156 |
+
},
|
| 157 |
+
|
| 158 |
+
"requireImportAlphabetized": false,
|
| 159 |
+
|
| 160 |
+
"requireSpaceBeforeObjectValues": true,
|
| 161 |
+
"requireSpaceBeforeDestructuredValues": true,
|
| 162 |
+
|
| 163 |
+
"disallowSpacesInsideTemplateStringPlaceholders": true,
|
| 164 |
+
|
| 165 |
+
"disallowArrayDestructuringReturn": false,
|
| 166 |
+
|
| 167 |
+
"requireNewlineBeforeSingleStatementsInIf": false,
|
| 168 |
+
|
| 169 |
+
"disallowUnusedVariables": true,
|
| 170 |
+
|
| 171 |
+
"requireSpacesInsideImportedObjectBraces": true,
|
| 172 |
+
|
| 173 |
+
"requireUseStrict": true
|
| 174 |
+
}
|
| 175 |
+
|
tools/ui/node_modules/extend/.travis.yml
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
language: node_js
|
| 2 |
+
os:
|
| 3 |
+
- linux
|
| 4 |
+
node_js:
|
| 5 |
+
- "10.7"
|
| 6 |
+
- "9.11"
|
| 7 |
+
- "8.11"
|
| 8 |
+
- "7.10"
|
| 9 |
+
- "6.14"
|
| 10 |
+
- "5.12"
|
| 11 |
+
- "4.9"
|
| 12 |
+
- "iojs-v3.3"
|
| 13 |
+
- "iojs-v2.5"
|
| 14 |
+
- "iojs-v1.8"
|
| 15 |
+
- "0.12"
|
| 16 |
+
- "0.10"
|
| 17 |
+
- "0.8"
|
| 18 |
+
before_install:
|
| 19 |
+
- 'case "${TRAVIS_NODE_VERSION}" in 0.*) export NPM_CONFIG_STRICT_SSL=false ;; esac'
|
| 20 |
+
- 'nvm install-latest-npm'
|
| 21 |
+
install:
|
| 22 |
+
- 'if [ "${TRAVIS_NODE_VERSION}" = "0.6" ] || [ "${TRAVIS_NODE_VERSION}" = "0.9" ]; then nvm install --latest-npm 0.8 && npm install && nvm use "${TRAVIS_NODE_VERSION}"; else npm install; fi;'
|
| 23 |
+
script:
|
| 24 |
+
- 'if [ -n "${PRETEST-}" ]; then npm run pretest ; fi'
|
| 25 |
+
- 'if [ -n "${POSTTEST-}" ]; then npm run posttest ; fi'
|
| 26 |
+
- 'if [ -n "${COVERAGE-}" ]; then npm run coverage ; fi'
|
| 27 |
+
- 'if [ -n "${TEST-}" ]; then npm run tests-only ; fi'
|
| 28 |
+
sudo: false
|
| 29 |
+
env:
|
| 30 |
+
- TEST=true
|
| 31 |
+
matrix:
|
| 32 |
+
fast_finish: true
|
| 33 |
+
include:
|
| 34 |
+
- node_js: "lts/*"
|
| 35 |
+
env: PRETEST=true
|
| 36 |
+
- node_js: "lts/*"
|
| 37 |
+
env: POSTTEST=true
|
| 38 |
+
- node_js: "4"
|
| 39 |
+
env: COVERAGE=true
|
| 40 |
+
- node_js: "10.6"
|
| 41 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 42 |
+
- node_js: "10.5"
|
| 43 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 44 |
+
- node_js: "10.4"
|
| 45 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 46 |
+
- node_js: "10.3"
|
| 47 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 48 |
+
- node_js: "10.2"
|
| 49 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 50 |
+
- node_js: "10.1"
|
| 51 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 52 |
+
- node_js: "10.0"
|
| 53 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 54 |
+
- node_js: "9.10"
|
| 55 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 56 |
+
- node_js: "9.9"
|
| 57 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 58 |
+
- node_js: "9.8"
|
| 59 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 60 |
+
- node_js: "9.7"
|
| 61 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 62 |
+
- node_js: "9.6"
|
| 63 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 64 |
+
- node_js: "9.5"
|
| 65 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 66 |
+
- node_js: "9.4"
|
| 67 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 68 |
+
- node_js: "9.3"
|
| 69 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 70 |
+
- node_js: "9.2"
|
| 71 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 72 |
+
- node_js: "9.1"
|
| 73 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 74 |
+
- node_js: "9.0"
|
| 75 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 76 |
+
- node_js: "8.10"
|
| 77 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 78 |
+
- node_js: "8.9"
|
| 79 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 80 |
+
- node_js: "8.8"
|
| 81 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 82 |
+
- node_js: "8.7"
|
| 83 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 84 |
+
- node_js: "8.6"
|
| 85 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 86 |
+
- node_js: "8.5"
|
| 87 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 88 |
+
- node_js: "8.4"
|
| 89 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 90 |
+
- node_js: "8.3"
|
| 91 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 92 |
+
- node_js: "8.2"
|
| 93 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 94 |
+
- node_js: "8.1"
|
| 95 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 96 |
+
- node_js: "8.0"
|
| 97 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 98 |
+
- node_js: "7.9"
|
| 99 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 100 |
+
- node_js: "7.8"
|
| 101 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 102 |
+
- node_js: "7.7"
|
| 103 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 104 |
+
- node_js: "7.6"
|
| 105 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 106 |
+
- node_js: "7.5"
|
| 107 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 108 |
+
- node_js: "7.4"
|
| 109 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 110 |
+
- node_js: "7.3"
|
| 111 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 112 |
+
- node_js: "7.2"
|
| 113 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 114 |
+
- node_js: "7.1"
|
| 115 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 116 |
+
- node_js: "7.0"
|
| 117 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 118 |
+
- node_js: "6.13"
|
| 119 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 120 |
+
- node_js: "6.12"
|
| 121 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 122 |
+
- node_js: "6.11"
|
| 123 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 124 |
+
- node_js: "6.10"
|
| 125 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 126 |
+
- node_js: "6.9"
|
| 127 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 128 |
+
- node_js: "6.8"
|
| 129 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 130 |
+
- node_js: "6.7"
|
| 131 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 132 |
+
- node_js: "6.6"
|
| 133 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 134 |
+
- node_js: "6.5"
|
| 135 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 136 |
+
- node_js: "6.4"
|
| 137 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 138 |
+
- node_js: "6.3"
|
| 139 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 140 |
+
- node_js: "6.2"
|
| 141 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 142 |
+
- node_js: "6.1"
|
| 143 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 144 |
+
- node_js: "6.0"
|
| 145 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 146 |
+
- node_js: "5.11"
|
| 147 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 148 |
+
- node_js: "5.10"
|
| 149 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 150 |
+
- node_js: "5.9"
|
| 151 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 152 |
+
- node_js: "5.8"
|
| 153 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 154 |
+
- node_js: "5.7"
|
| 155 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 156 |
+
- node_js: "5.6"
|
| 157 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 158 |
+
- node_js: "5.5"
|
| 159 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 160 |
+
- node_js: "5.4"
|
| 161 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 162 |
+
- node_js: "5.3"
|
| 163 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 164 |
+
- node_js: "5.2"
|
| 165 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 166 |
+
- node_js: "5.1"
|
| 167 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 168 |
+
- node_js: "5.0"
|
| 169 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 170 |
+
- node_js: "4.8"
|
| 171 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 172 |
+
- node_js: "4.7"
|
| 173 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 174 |
+
- node_js: "4.6"
|
| 175 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 176 |
+
- node_js: "4.5"
|
| 177 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 178 |
+
- node_js: "4.4"
|
| 179 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 180 |
+
- node_js: "4.3"
|
| 181 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 182 |
+
- node_js: "4.2"
|
| 183 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 184 |
+
- node_js: "4.1"
|
| 185 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 186 |
+
- node_js: "4.0"
|
| 187 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 188 |
+
- node_js: "iojs-v3.2"
|
| 189 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 190 |
+
- node_js: "iojs-v3.1"
|
| 191 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 192 |
+
- node_js: "iojs-v3.0"
|
| 193 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 194 |
+
- node_js: "iojs-v2.4"
|
| 195 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 196 |
+
- node_js: "iojs-v2.3"
|
| 197 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 198 |
+
- node_js: "iojs-v2.2"
|
| 199 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 200 |
+
- node_js: "iojs-v2.1"
|
| 201 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 202 |
+
- node_js: "iojs-v2.0"
|
| 203 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 204 |
+
- node_js: "iojs-v1.7"
|
| 205 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 206 |
+
- node_js: "iojs-v1.6"
|
| 207 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 208 |
+
- node_js: "iojs-v1.5"
|
| 209 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 210 |
+
- node_js: "iojs-v1.4"
|
| 211 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 212 |
+
- node_js: "iojs-v1.3"
|
| 213 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 214 |
+
- node_js: "iojs-v1.2"
|
| 215 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 216 |
+
- node_js: "iojs-v1.1"
|
| 217 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 218 |
+
- node_js: "iojs-v1.0"
|
| 219 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 220 |
+
- node_js: "0.11"
|
| 221 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 222 |
+
- node_js: "0.9"
|
| 223 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 224 |
+
- node_js: "0.6"
|
| 225 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 226 |
+
- node_js: "0.4"
|
| 227 |
+
env: TEST=true ALLOW_FAILURE=true
|
| 228 |
+
allow_failures:
|
| 229 |
+
- os: osx
|
| 230 |
+
- env: TEST=true ALLOW_FAILURE=true
|
tools/ui/node_modules/extend/CHANGELOG.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
3.0.2 / 2018-07-19
|
| 2 |
+
==================
|
| 3 |
+
* [Fix] Prevent merging `__proto__` property (#48)
|
| 4 |
+
* [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `tape`
|
| 5 |
+
* [Tests] up to `node` `v10.7`, `v9.11`, `v8.11`, `v7.10`, `v6.14`, `v4.9`; use `nvm install-latest-npm`
|
| 6 |
+
|
| 7 |
+
3.0.1 / 2017-04-27
|
| 8 |
+
==================
|
| 9 |
+
* [Fix] deep extending should work with a non-object (#46)
|
| 10 |
+
* [Dev Deps] update `tape`, `eslint`, `@ljharb/eslint-config`
|
| 11 |
+
* [Tests] up to `node` `v7.9`, `v6.10`, `v4.8`; improve matrix
|
| 12 |
+
* [Docs] Switch from vb.teelaun.ch to versionbadg.es for the npm version badge SVG.
|
| 13 |
+
* [Docs] Add example to readme (#34)
|
| 14 |
+
|
| 15 |
+
3.0.0 / 2015-07-01
|
| 16 |
+
==================
|
| 17 |
+
* [Possible breaking change] Use global "strict" directive (#32)
|
| 18 |
+
* [Tests] `int` is an ES3 reserved word
|
| 19 |
+
* [Tests] Test up to `io.js` `v2.3`
|
| 20 |
+
* [Tests] Add `npm run eslint`
|
| 21 |
+
* [Dev Deps] Update `covert`, `jscs`
|
| 22 |
+
|
| 23 |
+
2.0.1 / 2015-04-25
|
| 24 |
+
==================
|
| 25 |
+
* Use an inline `isArray` check, for ES3 browsers. (#27)
|
| 26 |
+
* Some old browsers fail when an identifier is `toString`
|
| 27 |
+
* Test latest `node` and `io.js` versions on `travis-ci`; speed up builds
|
| 28 |
+
* Add license info to package.json (#25)
|
| 29 |
+
* Update `tape`, `jscs`
|
| 30 |
+
* Adding a CHANGELOG
|
| 31 |
+
|
| 32 |
+
2.0.0 / 2014-10-01
|
| 33 |
+
==================
|
| 34 |
+
* Increase code coverage to 100%; run code coverage as part of tests
|
| 35 |
+
* Add `npm run lint`; Run linter as part of tests
|
| 36 |
+
* Remove nodeType and setInterval checks in isPlainObject
|
| 37 |
+
* Updating `tape`, `jscs`, `covert`
|
| 38 |
+
* General style and README cleanup
|
| 39 |
+
|
| 40 |
+
1.3.0 / 2014-06-20
|
| 41 |
+
==================
|
| 42 |
+
* Add component.json for browser support (#18)
|
| 43 |
+
* Use SVG for badges in README (#16)
|
| 44 |
+
* Updating `tape`, `covert`
|
| 45 |
+
* Updating travis-ci to work with multiple node versions
|
| 46 |
+
* Fix `deep === false` bug (returning target as {}) (#14)
|
| 47 |
+
* Fixing constructor checks in isPlainObject
|
| 48 |
+
* Adding additional test coverage
|
| 49 |
+
* Adding `npm run coverage`
|
| 50 |
+
* Add LICENSE (#13)
|
| 51 |
+
* Adding a warning about `false`, per #11
|
| 52 |
+
* General style and whitespace cleanup
|
| 53 |
+
|
| 54 |
+
1.2.1 / 2013-09-14
|
| 55 |
+
==================
|
| 56 |
+
* Fixing hasOwnProperty bugs that would only have shown up in specific browsers. Fixes #8
|
| 57 |
+
* Updating `tape`
|
| 58 |
+
|
| 59 |
+
1.2.0 / 2013-09-02
|
| 60 |
+
==================
|
| 61 |
+
* Updating the README: add badges
|
| 62 |
+
* Adding a missing variable reference.
|
| 63 |
+
* Using `tape` instead of `buster` for tests; add more tests (#7)
|
| 64 |
+
* Adding node 0.10 to Travis CI (#6)
|
| 65 |
+
* Enabling "npm test" and cleaning up package.json (#5)
|
| 66 |
+
* Add Travis CI.
|
| 67 |
+
|
| 68 |
+
1.1.3 / 2012-12-06
|
| 69 |
+
==================
|
| 70 |
+
* Added unit tests.
|
| 71 |
+
* Ensure extend function is named. (Looks nicer in a stack trace.)
|
| 72 |
+
* README cleanup.
|
| 73 |
+
|
| 74 |
+
1.1.1 / 2012-11-07
|
| 75 |
+
==================
|
| 76 |
+
* README cleanup.
|
| 77 |
+
* Added installation instructions.
|
| 78 |
+
* Added a missing semicolon
|
| 79 |
+
|
| 80 |
+
1.0.0 / 2012-04-08
|
| 81 |
+
==================
|
| 82 |
+
* Initial commit
|
| 83 |
+
|
tools/ui/node_modules/extend/LICENSE
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
The MIT License (MIT)
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2014 Stefan Thomas
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining
|
| 6 |
+
a copy of this software and associated documentation files (the
|
| 7 |
+
"Software"), to deal in the Software without restriction, including
|
| 8 |
+
without limitation the rights to use, copy, modify, merge, publish,
|
| 9 |
+
distribute, sublicense, and/or sell copies of the Software, and to
|
| 10 |
+
permit persons to whom the Software is furnished to do so, subject to
|
| 11 |
+
the following conditions:
|
| 12 |
+
|
| 13 |
+
The above copyright notice and this permission notice shall be
|
| 14 |
+
included in all copies or substantial portions of the Software.
|
| 15 |
+
|
| 16 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
| 17 |
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
| 18 |
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
| 19 |
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
| 20 |
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
| 21 |
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
| 22 |
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
| 23 |
+
|
tools/ui/node_modules/extend/README.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[![Build Status][travis-svg]][travis-url]
|
| 2 |
+
[![dependency status][deps-svg]][deps-url]
|
| 3 |
+
[![dev dependency status][dev-deps-svg]][dev-deps-url]
|
| 4 |
+
|
| 5 |
+
# extend() for Node.js <sup>[![Version Badge][npm-version-png]][npm-url]</sup>
|
| 6 |
+
|
| 7 |
+
`node-extend` is a port of the classic extend() method from jQuery. It behaves as you expect. It is simple, tried and true.
|
| 8 |
+
|
| 9 |
+
Notes:
|
| 10 |
+
|
| 11 |
+
* Since Node.js >= 4,
|
| 12 |
+
[`Object.assign`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
|
| 13 |
+
now offers the same functionality natively (but without the "deep copy" option).
|
| 14 |
+
See [ECMAScript 2015 (ES6) in Node.js](https://nodejs.org/en/docs/es6).
|
| 15 |
+
* Some native implementations of `Object.assign` in both Node.js and many
|
| 16 |
+
browsers (since NPM modules are for the browser too) may not be fully
|
| 17 |
+
spec-compliant.
|
| 18 |
+
Check [`object.assign`](https://www.npmjs.com/package/object.assign) module for
|
| 19 |
+
a compliant candidate.
|
| 20 |
+
|
| 21 |
+
## Installation
|
| 22 |
+
|
| 23 |
+
This package is available on [npm][npm-url] as: `extend`
|
| 24 |
+
|
| 25 |
+
``` sh
|
| 26 |
+
npm install extend
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
## Usage
|
| 30 |
+
|
| 31 |
+
**Syntax:** extend **(** [`deep`], `target`, `object1`, [`objectN`] **)**
|
| 32 |
+
|
| 33 |
+
*Extend one object with one or more others, returning the modified object.*
|
| 34 |
+
|
| 35 |
+
**Example:**
|
| 36 |
+
|
| 37 |
+
``` js
|
| 38 |
+
var extend = require('extend');
|
| 39 |
+
extend(targetObject, object1, object2);
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
Keep in mind that the target object will be modified, and will be returned from extend().
|
| 43 |
+
|
| 44 |
+
If a boolean true is specified as the first argument, extend performs a deep copy, recursively copying any objects it finds. Otherwise, the copy will share structure with the original object(s).
|
| 45 |
+
Undefined properties are not copied. However, properties inherited from the object's prototype will be copied over.
|
| 46 |
+
Warning: passing `false` as the first argument is not supported.
|
| 47 |
+
|
| 48 |
+
### Arguments
|
| 49 |
+
|
| 50 |
+
* `deep` *Boolean* (optional)
|
| 51 |
+
If set, the merge becomes recursive (i.e. deep copy).
|
| 52 |
+
* `target` *Object*
|
| 53 |
+
The object to extend.
|
| 54 |
+
* `object1` *Object*
|
| 55 |
+
The object that will be merged into the first.
|
| 56 |
+
* `objectN` *Object* (Optional)
|
| 57 |
+
More objects to merge into the first.
|
| 58 |
+
|
| 59 |
+
## License
|
| 60 |
+
|
| 61 |
+
`node-extend` is licensed under the [MIT License][mit-license-url].
|
| 62 |
+
|
| 63 |
+
## Acknowledgements
|
| 64 |
+
|
| 65 |
+
All credit to the jQuery authors for perfecting this amazing utility.
|
| 66 |
+
|
| 67 |
+
Ported to Node.js by [Stefan Thomas][github-justmoon] with contributions by [Jonathan Buchanan][github-insin] and [Jordan Harband][github-ljharb].
|
| 68 |
+
|
| 69 |
+
[travis-svg]: https://travis-ci.org/justmoon/node-extend.svg
|
| 70 |
+
[travis-url]: https://travis-ci.org/justmoon/node-extend
|
| 71 |
+
[npm-url]: https://npmjs.org/package/extend
|
| 72 |
+
[mit-license-url]: http://opensource.org/licenses/MIT
|
| 73 |
+
[github-justmoon]: https://github.com/justmoon
|
| 74 |
+
[github-insin]: https://github.com/insin
|
| 75 |
+
[github-ljharb]: https://github.com/ljharb
|
| 76 |
+
[npm-version-png]: http://versionbadg.es/justmoon/node-extend.svg
|
| 77 |
+
[deps-svg]: https://david-dm.org/justmoon/node-extend.svg
|
| 78 |
+
[deps-url]: https://david-dm.org/justmoon/node-extend
|
| 79 |
+
[dev-deps-svg]: https://david-dm.org/justmoon/node-extend/dev-status.svg
|
| 80 |
+
[dev-deps-url]: https://david-dm.org/justmoon/node-extend#info=devDependencies
|
| 81 |
+
|
tools/ui/node_modules/extend/component.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "extend",
|
| 3 |
+
"author": "Stefan Thomas <justmoon@members.fsf.org> (http://www.justmoon.net)",
|
| 4 |
+
"version": "3.0.0",
|
| 5 |
+
"description": "Port of jQuery.extend for node.js and the browser.",
|
| 6 |
+
"scripts": [
|
| 7 |
+
"index.js"
|
| 8 |
+
],
|
| 9 |
+
"contributors": [
|
| 10 |
+
{
|
| 11 |
+
"name": "Jordan Harband",
|
| 12 |
+
"url": "https://github.com/ljharb"
|
| 13 |
+
}
|
| 14 |
+
],
|
| 15 |
+
"keywords": [
|
| 16 |
+
"extend",
|
| 17 |
+
"clone",
|
| 18 |
+
"merge"
|
| 19 |
+
],
|
| 20 |
+
"repository" : {
|
| 21 |
+
"type": "git",
|
| 22 |
+
"url": "https://github.com/justmoon/node-extend.git"
|
| 23 |
+
},
|
| 24 |
+
"dependencies": {
|
| 25 |
+
},
|
| 26 |
+
"devDependencies": {
|
| 27 |
+
"tape" : "~3.0.0",
|
| 28 |
+
"covert": "~0.4.0",
|
| 29 |
+
"jscs": "~1.6.2"
|
| 30 |
+
}
|
| 31 |
+
}
|
| 32 |
+
|
tools/ui/node_modules/extend/index.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict';
|
| 2 |
+
|
| 3 |
+
var hasOwn = Object.prototype.hasOwnProperty;
|
| 4 |
+
var toStr = Object.prototype.toString;
|
| 5 |
+
var defineProperty = Object.defineProperty;
|
| 6 |
+
var gOPD = Object.getOwnPropertyDescriptor;
|
| 7 |
+
|
| 8 |
+
var isArray = function isArray(arr) {
|
| 9 |
+
if (typeof Array.isArray === 'function') {
|
| 10 |
+
return Array.isArray(arr);
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
return toStr.call(arr) === '[object Array]';
|
| 14 |
+
};
|
| 15 |
+
|
| 16 |
+
var isPlainObject = function isPlainObject(obj) {
|
| 17 |
+
if (!obj || toStr.call(obj) !== '[object Object]') {
|
| 18 |
+
return false;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
var hasOwnConstructor = hasOwn.call(obj, 'constructor');
|
| 22 |
+
var hasIsPrototypeOf = obj.constructor && obj.constructor.prototype && hasOwn.call(obj.constructor.prototype, 'isPrototypeOf');
|
| 23 |
+
// Not own constructor property must be Object
|
| 24 |
+
if (obj.constructor && !hasOwnConstructor && !hasIsPrototypeOf) {
|
| 25 |
+
return false;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
// Own properties are enumerated firstly, so to speed up,
|
| 29 |
+
// if last one is own, then all properties are own.
|
| 30 |
+
var key;
|
| 31 |
+
for (key in obj) { /**/ }
|
| 32 |
+
|
| 33 |
+
return typeof key === 'undefined' || hasOwn.call(obj, key);
|
| 34 |
+
};
|
| 35 |
+
|
| 36 |
+
// If name is '__proto__', and Object.defineProperty is available, define __proto__ as an own property on target
|
| 37 |
+
var setProperty = function setProperty(target, options) {
|
| 38 |
+
if (defineProperty && options.name === '__proto__') {
|
| 39 |
+
defineProperty(target, options.name, {
|
| 40 |
+
enumerable: true,
|
| 41 |
+
configurable: true,
|
| 42 |
+
value: options.newValue,
|
| 43 |
+
writable: true
|
| 44 |
+
});
|
| 45 |
+
} else {
|
| 46 |
+
target[options.name] = options.newValue;
|
| 47 |
+
}
|
| 48 |
+
};
|
| 49 |
+
|
| 50 |
+
// Return undefined instead of __proto__ if '__proto__' is not an own property
|
| 51 |
+
var getProperty = function getProperty(obj, name) {
|
| 52 |
+
if (name === '__proto__') {
|
| 53 |
+
if (!hasOwn.call(obj, name)) {
|
| 54 |
+
return void 0;
|
| 55 |
+
} else if (gOPD) {
|
| 56 |
+
// In early versions of node, obj['__proto__'] is buggy when obj has
|
| 57 |
+
// __proto__ as an own property. Object.getOwnPropertyDescriptor() works.
|
| 58 |
+
return gOPD(obj, name).value;
|
| 59 |
+
}
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
return obj[name];
|
| 63 |
+
};
|
| 64 |
+
|
| 65 |
+
module.exports = function extend() {
|
| 66 |
+
var options, name, src, copy, copyIsArray, clone;
|
| 67 |
+
var target = arguments[0];
|
| 68 |
+
var i = 1;
|
| 69 |
+
var length = arguments.length;
|
| 70 |
+
var deep = false;
|
| 71 |
+
|
| 72 |
+
// Handle a deep copy situation
|
| 73 |
+
if (typeof target === 'boolean') {
|
| 74 |
+
deep = target;
|
| 75 |
+
target = arguments[1] || {};
|
| 76 |
+
// skip the boolean and the target
|
| 77 |
+
i = 2;
|
| 78 |
+
}
|
| 79 |
+
if (target == null || (typeof target !== 'object' && typeof target !== 'function')) {
|
| 80 |
+
target = {};
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
for (; i < length; ++i) {
|
| 84 |
+
options = arguments[i];
|
| 85 |
+
// Only deal with non-null/undefined values
|
| 86 |
+
if (options != null) {
|
| 87 |
+
// Extend the base object
|
| 88 |
+
for (name in options) {
|
| 89 |
+
src = getProperty(target, name);
|
| 90 |
+
copy = getProperty(options, name);
|
| 91 |
+
|
| 92 |
+
// Prevent never-ending loop
|
| 93 |
+
if (target !== copy) {
|
| 94 |
+
// Recurse if we're merging plain objects or arrays
|
| 95 |
+
if (deep && copy && (isPlainObject(copy) || (copyIsArray = isArray(copy)))) {
|
| 96 |
+
if (copyIsArray) {
|
| 97 |
+
copyIsArray = false;
|
| 98 |
+
clone = src && isArray(src) ? src : [];
|
| 99 |
+
} else {
|
| 100 |
+
clone = src && isPlainObject(src) ? src : {};
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
// Never move original objects, clone them
|
| 104 |
+
setProperty(target, { name: name, newValue: extend(deep, clone, copy) });
|
| 105 |
+
|
| 106 |
+
// Don't bring in undefined values
|
| 107 |
+
} else if (typeof copy !== 'undefined') {
|
| 108 |
+
setProperty(target, { name: name, newValue: copy });
|
| 109 |
+
}
|
| 110 |
+
}
|
| 111 |
+
}
|
| 112 |
+
}
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
// Return the modified object
|
| 116 |
+
return target;
|
| 117 |
+
};
|
tools/ui/node_modules/extend/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "extend",
|
| 3 |
+
"author": "Stefan Thomas <justmoon@members.fsf.org> (http://www.justmoon.net)",
|
| 4 |
+
"version": "3.0.2",
|
| 5 |
+
"description": "Port of jQuery.extend for node.js and the browser",
|
| 6 |
+
"main": "index",
|
| 7 |
+
"scripts": {
|
| 8 |
+
"pretest": "npm run lint",
|
| 9 |
+
"test": "npm run tests-only",
|
| 10 |
+
"posttest": "npm run coverage-quiet",
|
| 11 |
+
"tests-only": "node test",
|
| 12 |
+
"coverage": "covert test/index.js",
|
| 13 |
+
"coverage-quiet": "covert test/index.js --quiet",
|
| 14 |
+
"lint": "npm run jscs && npm run eslint",
|
| 15 |
+
"jscs": "jscs *.js */*.js",
|
| 16 |
+
"eslint": "eslint *.js */*.js"
|
| 17 |
+
},
|
| 18 |
+
"contributors": [
|
| 19 |
+
{
|
| 20 |
+
"name": "Jordan Harband",
|
| 21 |
+
"url": "https://github.com/ljharb"
|
| 22 |
+
}
|
| 23 |
+
],
|
| 24 |
+
"keywords": [
|
| 25 |
+
"extend",
|
| 26 |
+
"clone",
|
| 27 |
+
"merge"
|
| 28 |
+
],
|
| 29 |
+
"repository": {
|
| 30 |
+
"type": "git",
|
| 31 |
+
"url": "https://github.com/justmoon/node-extend.git"
|
| 32 |
+
},
|
| 33 |
+
"dependencies": {},
|
| 34 |
+
"devDependencies": {
|
| 35 |
+
"@ljharb/eslint-config": "^12.2.1",
|
| 36 |
+
"covert": "^1.1.0",
|
| 37 |
+
"eslint": "^4.19.1",
|
| 38 |
+
"jscs": "^3.0.7",
|
| 39 |
+
"tape": "^4.9.1"
|
| 40 |
+
},
|
| 41 |
+
"license": "MIT"
|
| 42 |
+
}
|
tools/ui/node_modules/fast-deep-equal/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2017 Evgeny Poberezkin
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
SOFTWARE.
|
tools/ui/node_modules/fast-deep-equal/README.md
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# fast-deep-equal
|
| 2 |
+
The fastest deep equal with ES6 Map, Set and Typed arrays support.
|
| 3 |
+
|
| 4 |
+
[](https://travis-ci.org/epoberezkin/fast-deep-equal)
|
| 5 |
+
[](https://www.npmjs.com/package/fast-deep-equal)
|
| 6 |
+
[](https://coveralls.io/github/epoberezkin/fast-deep-equal?branch=master)
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
## Install
|
| 10 |
+
|
| 11 |
+
```bash
|
| 12 |
+
npm install fast-deep-equal
|
| 13 |
+
```
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
## Features
|
| 17 |
+
|
| 18 |
+
- ES5 compatible
|
| 19 |
+
- works in node.js (8+) and browsers (IE9+)
|
| 20 |
+
- checks equality of Date and RegExp objects by value.
|
| 21 |
+
|
| 22 |
+
ES6 equal (`require('fast-deep-equal/es6')`) also supports:
|
| 23 |
+
- Maps
|
| 24 |
+
- Sets
|
| 25 |
+
- Typed arrays
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
## Usage
|
| 29 |
+
|
| 30 |
+
```javascript
|
| 31 |
+
var equal = require('fast-deep-equal');
|
| 32 |
+
console.log(equal({foo: 'bar'}, {foo: 'bar'})); // true
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
To support ES6 Maps, Sets and Typed arrays equality use:
|
| 36 |
+
|
| 37 |
+
```javascript
|
| 38 |
+
var equal = require('fast-deep-equal/es6');
|
| 39 |
+
console.log(equal(Int16Array([1, 2]), Int16Array([1, 2]))); // true
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
To use with React (avoiding the traversal of React elements' _owner
|
| 43 |
+
property that contains circular references and is not needed when
|
| 44 |
+
comparing the elements - borrowed from [react-fast-compare](https://github.com/FormidableLabs/react-fast-compare)):
|
| 45 |
+
|
| 46 |
+
```javascript
|
| 47 |
+
var equal = require('fast-deep-equal/react');
|
| 48 |
+
var equal = require('fast-deep-equal/es6/react');
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
## Performance benchmark
|
| 53 |
+
|
| 54 |
+
Node.js v12.6.0:
|
| 55 |
+
|
| 56 |
+
```
|
| 57 |
+
fast-deep-equal x 261,950 ops/sec ±0.52% (89 runs sampled)
|
| 58 |
+
fast-deep-equal/es6 x 212,991 ops/sec ±0.34% (92 runs sampled)
|
| 59 |
+
fast-equals x 230,957 ops/sec ±0.83% (85 runs sampled)
|
| 60 |
+
nano-equal x 187,995 ops/sec ±0.53% (88 runs sampled)
|
| 61 |
+
shallow-equal-fuzzy x 138,302 ops/sec ±0.49% (90 runs sampled)
|
| 62 |
+
underscore.isEqual x 74,423 ops/sec ±0.38% (89 runs sampled)
|
| 63 |
+
lodash.isEqual x 36,637 ops/sec ±0.72% (90 runs sampled)
|
| 64 |
+
deep-equal x 2,310 ops/sec ±0.37% (90 runs sampled)
|
| 65 |
+
deep-eql x 35,312 ops/sec ±0.67% (91 runs sampled)
|
| 66 |
+
ramda.equals x 12,054 ops/sec ±0.40% (91 runs sampled)
|
| 67 |
+
util.isDeepStrictEqual x 46,440 ops/sec ±0.43% (90 runs sampled)
|
| 68 |
+
assert.deepStrictEqual x 456 ops/sec ±0.71% (88 runs sampled)
|
| 69 |
+
|
| 70 |
+
The fastest is fast-deep-equal
|
| 71 |
+
```
|
| 72 |
+
|
| 73 |
+
To run benchmark (requires node.js 6+):
|
| 74 |
+
|
| 75 |
+
```bash
|
| 76 |
+
npm run benchmark
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
__Please note__: this benchmark runs against the available test cases. To choose the most performant library for your application, it is recommended to benchmark against your data and to NOT expect this benchmark to reflect the performance difference in your application.
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
## Enterprise support
|
| 83 |
+
|
| 84 |
+
fast-deep-equal package is a part of [Tidelift enterprise subscription](https://tidelift.com/subscription/pkg/npm-fast-deep-equal?utm_source=npm-fast-deep-equal&utm_medium=referral&utm_campaign=enterprise&utm_term=repo) - it provides a centralised commercial support to open-source software users, in addition to the support provided by software maintainers.
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
## Security contact
|
| 88 |
+
|
| 89 |
+
To report a security vulnerability, please use the
|
| 90 |
+
[Tidelift security contact](https://tidelift.com/security).
|
| 91 |
+
Tidelift will coordinate the fix and disclosure. Please do NOT report security vulnerability via GitHub issues.
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
## License
|
| 95 |
+
|
| 96 |
+
[MIT](https://github.com/epoberezkin/fast-deep-equal/blob/master/LICENSE)
|
tools/ui/node_modules/fast-deep-equal/es6/index.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
declare const equal: (a: any, b: any) => boolean;
|
| 2 |
+
export = equal;
|
tools/ui/node_modules/fast-deep-equal/es6/index.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict';
|
| 2 |
+
|
| 3 |
+
// do not edit .js files directly - edit src/index.jst
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
var envHasBigInt64Array = typeof BigInt64Array !== 'undefined';
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
module.exports = function equal(a, b) {
|
| 10 |
+
if (a === b) return true;
|
| 11 |
+
|
| 12 |
+
if (a && b && typeof a == 'object' && typeof b == 'object') {
|
| 13 |
+
if (a.constructor !== b.constructor) return false;
|
| 14 |
+
|
| 15 |
+
var length, i, keys;
|
| 16 |
+
if (Array.isArray(a)) {
|
| 17 |
+
length = a.length;
|
| 18 |
+
if (length != b.length) return false;
|
| 19 |
+
for (i = length; i-- !== 0;)
|
| 20 |
+
if (!equal(a[i], b[i])) return false;
|
| 21 |
+
return true;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
if ((a instanceof Map) && (b instanceof Map)) {
|
| 26 |
+
if (a.size !== b.size) return false;
|
| 27 |
+
for (i of a.entries())
|
| 28 |
+
if (!b.has(i[0])) return false;
|
| 29 |
+
for (i of a.entries())
|
| 30 |
+
if (!equal(i[1], b.get(i[0]))) return false;
|
| 31 |
+
return true;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
if ((a instanceof Set) && (b instanceof Set)) {
|
| 35 |
+
if (a.size !== b.size) return false;
|
| 36 |
+
for (i of a.entries())
|
| 37 |
+
if (!b.has(i[0])) return false;
|
| 38 |
+
return true;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
if (ArrayBuffer.isView(a) && ArrayBuffer.isView(b)) {
|
| 42 |
+
length = a.length;
|
| 43 |
+
if (length != b.length) return false;
|
| 44 |
+
for (i = length; i-- !== 0;)
|
| 45 |
+
if (a[i] !== b[i]) return false;
|
| 46 |
+
return true;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
|
| 51 |
+
if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
|
| 52 |
+
if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
|
| 53 |
+
|
| 54 |
+
keys = Object.keys(a);
|
| 55 |
+
length = keys.length;
|
| 56 |
+
if (length !== Object.keys(b).length) return false;
|
| 57 |
+
|
| 58 |
+
for (i = length; i-- !== 0;)
|
| 59 |
+
if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
|
| 60 |
+
|
| 61 |
+
for (i = length; i-- !== 0;) {
|
| 62 |
+
var key = keys[i];
|
| 63 |
+
|
| 64 |
+
if (!equal(a[key], b[key])) return false;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
return true;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
// true if both NaN, false otherwise
|
| 71 |
+
return a!==a && b!==b;
|
| 72 |
+
};
|
tools/ui/node_modules/fast-deep-equal/es6/react.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
declare const equal: (a: any, b: any) => boolean;
|
| 2 |
+
export = equal;
|
tools/ui/node_modules/fast-deep-equal/es6/react.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict';
|
| 2 |
+
|
| 3 |
+
// do not edit .js files directly - edit src/index.jst
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
var envHasBigInt64Array = typeof BigInt64Array !== 'undefined';
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
module.exports = function equal(a, b) {
|
| 10 |
+
if (a === b) return true;
|
| 11 |
+
|
| 12 |
+
if (a && b && typeof a == 'object' && typeof b == 'object') {
|
| 13 |
+
if (a.constructor !== b.constructor) return false;
|
| 14 |
+
|
| 15 |
+
var length, i, keys;
|
| 16 |
+
if (Array.isArray(a)) {
|
| 17 |
+
length = a.length;
|
| 18 |
+
if (length != b.length) return false;
|
| 19 |
+
for (i = length; i-- !== 0;)
|
| 20 |
+
if (!equal(a[i], b[i])) return false;
|
| 21 |
+
return true;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
if ((a instanceof Map) && (b instanceof Map)) {
|
| 26 |
+
if (a.size !== b.size) return false;
|
| 27 |
+
for (i of a.entries())
|
| 28 |
+
if (!b.has(i[0])) return false;
|
| 29 |
+
for (i of a.entries())
|
| 30 |
+
if (!equal(i[1], b.get(i[0]))) return false;
|
| 31 |
+
return true;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
if ((a instanceof Set) && (b instanceof Set)) {
|
| 35 |
+
if (a.size !== b.size) return false;
|
| 36 |
+
for (i of a.entries())
|
| 37 |
+
if (!b.has(i[0])) return false;
|
| 38 |
+
return true;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
if (ArrayBuffer.isView(a) && ArrayBuffer.isView(b)) {
|
| 42 |
+
length = a.length;
|
| 43 |
+
if (length != b.length) return false;
|
| 44 |
+
for (i = length; i-- !== 0;)
|
| 45 |
+
if (a[i] !== b[i]) return false;
|
| 46 |
+
return true;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
|
| 51 |
+
if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
|
| 52 |
+
if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
|
| 53 |
+
|
| 54 |
+
keys = Object.keys(a);
|
| 55 |
+
length = keys.length;
|
| 56 |
+
if (length !== Object.keys(b).length) return false;
|
| 57 |
+
|
| 58 |
+
for (i = length; i-- !== 0;)
|
| 59 |
+
if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
|
| 60 |
+
|
| 61 |
+
for (i = length; i-- !== 0;) {
|
| 62 |
+
var key = keys[i];
|
| 63 |
+
|
| 64 |
+
if (key === '_owner' && a.$$typeof) {
|
| 65 |
+
// React-specific: avoid traversing React elements' _owner.
|
| 66 |
+
// _owner contains circular references
|
| 67 |
+
// and is not needed when comparing the actual elements (and not their owners)
|
| 68 |
+
continue;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
if (!equal(a[key], b[key])) return false;
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
return true;
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
// true if both NaN, false otherwise
|
| 78 |
+
return a!==a && b!==b;
|
| 79 |
+
};
|
tools/ui/node_modules/fast-deep-equal/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
declare module 'fast-deep-equal' {
|
| 2 |
+
const equal: (a: any, b: any) => boolean;
|
| 3 |
+
export = equal;
|
| 4 |
+
}
|
tools/ui/node_modules/fast-deep-equal/index.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict';
|
| 2 |
+
|
| 3 |
+
// do not edit .js files directly - edit src/index.jst
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
module.exports = function equal(a, b) {
|
| 8 |
+
if (a === b) return true;
|
| 9 |
+
|
| 10 |
+
if (a && b && typeof a == 'object' && typeof b == 'object') {
|
| 11 |
+
if (a.constructor !== b.constructor) return false;
|
| 12 |
+
|
| 13 |
+
var length, i, keys;
|
| 14 |
+
if (Array.isArray(a)) {
|
| 15 |
+
length = a.length;
|
| 16 |
+
if (length != b.length) return false;
|
| 17 |
+
for (i = length; i-- !== 0;)
|
| 18 |
+
if (!equal(a[i], b[i])) return false;
|
| 19 |
+
return true;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
|
| 25 |
+
if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
|
| 26 |
+
if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
|
| 27 |
+
|
| 28 |
+
keys = Object.keys(a);
|
| 29 |
+
length = keys.length;
|
| 30 |
+
if (length !== Object.keys(b).length) return false;
|
| 31 |
+
|
| 32 |
+
for (i = length; i-- !== 0;)
|
| 33 |
+
if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
|
| 34 |
+
|
| 35 |
+
for (i = length; i-- !== 0;) {
|
| 36 |
+
var key = keys[i];
|
| 37 |
+
|
| 38 |
+
if (!equal(a[key], b[key])) return false;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
return true;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
// true if both NaN, false otherwise
|
| 45 |
+
return a!==a && b!==b;
|
| 46 |
+
};
|
tools/ui/node_modules/fast-deep-equal/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "fast-deep-equal",
|
| 3 |
+
"version": "3.1.3",
|
| 4 |
+
"description": "Fast deep equal",
|
| 5 |
+
"main": "index.js",
|
| 6 |
+
"scripts": {
|
| 7 |
+
"eslint": "eslint *.js benchmark/*.js spec/*.js",
|
| 8 |
+
"build": "node build",
|
| 9 |
+
"benchmark": "npm i && npm run build && cd ./benchmark && npm i && node ./",
|
| 10 |
+
"test-spec": "mocha spec/*.spec.js -R spec",
|
| 11 |
+
"test-cov": "nyc npm run test-spec",
|
| 12 |
+
"test-ts": "tsc --target ES5 --noImplicitAny index.d.ts",
|
| 13 |
+
"test": "npm run build && npm run eslint && npm run test-ts && npm run test-cov",
|
| 14 |
+
"prepublish": "npm run build"
|
| 15 |
+
},
|
| 16 |
+
"repository": {
|
| 17 |
+
"type": "git",
|
| 18 |
+
"url": "git+https://github.com/epoberezkin/fast-deep-equal.git"
|
| 19 |
+
},
|
| 20 |
+
"keywords": [
|
| 21 |
+
"fast",
|
| 22 |
+
"equal",
|
| 23 |
+
"deep-equal"
|
| 24 |
+
],
|
| 25 |
+
"author": "Evgeny Poberezkin",
|
| 26 |
+
"license": "MIT",
|
| 27 |
+
"bugs": {
|
| 28 |
+
"url": "https://github.com/epoberezkin/fast-deep-equal/issues"
|
| 29 |
+
},
|
| 30 |
+
"homepage": "https://github.com/epoberezkin/fast-deep-equal#readme",
|
| 31 |
+
"devDependencies": {
|
| 32 |
+
"coveralls": "^3.1.0",
|
| 33 |
+
"dot": "^1.1.2",
|
| 34 |
+
"eslint": "^7.2.0",
|
| 35 |
+
"mocha": "^7.2.0",
|
| 36 |
+
"nyc": "^15.1.0",
|
| 37 |
+
"pre-commit": "^1.2.2",
|
| 38 |
+
"react": "^16.12.0",
|
| 39 |
+
"react-test-renderer": "^16.12.0",
|
| 40 |
+
"sinon": "^9.0.2",
|
| 41 |
+
"typescript": "^3.9.5"
|
| 42 |
+
},
|
| 43 |
+
"nyc": {
|
| 44 |
+
"exclude": [
|
| 45 |
+
"**/spec/**",
|
| 46 |
+
"node_modules"
|
| 47 |
+
],
|
| 48 |
+
"reporter": [
|
| 49 |
+
"lcov",
|
| 50 |
+
"text-summary"
|
| 51 |
+
]
|
| 52 |
+
},
|
| 53 |
+
"files": [
|
| 54 |
+
"index.js",
|
| 55 |
+
"index.d.ts",
|
| 56 |
+
"react.js",
|
| 57 |
+
"react.d.ts",
|
| 58 |
+
"es6/"
|
| 59 |
+
],
|
| 60 |
+
"types": "index.d.ts"
|
| 61 |
+
}
|
tools/ui/node_modules/fast-deep-equal/react.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
declare const equal: (a: any, b: any) => boolean;
|
| 2 |
+
export = equal;
|