Add comprehensive tests for role middleware and fix package dependencies
Some checks are pending
Docker Test / test (push) Waiting to run

This commit is contained in:
BibaBot 2026-03-16 20:07:22 +00:00
parent 64aa924270
commit bfd432d094
1884 changed files with 384668 additions and 84 deletions

View file

@ -0,0 +1,10 @@
// TODO (major version): remove workaround for `Field` compatibility.
import { TypeCastField } from '../../../lib/parsers/index.js';
/**
* @deprecated
* `Field` is deprecated and might be removed in the future major release. Please use `TypeCastField` type instead.
*/
declare interface Field extends TypeCastField {}
export { Field };

View file

@ -0,0 +1,27 @@
declare interface FieldPacket {
constructor: {
name: 'FieldPacket';
};
catalog: string;
charsetNr?: number;
db?: string;
schema?: string;
characterSet?: number;
decimals: number;
default?: any;
flags: number | string[];
length?: number;
name: string;
orgName: string;
orgTable: string;
protocol41?: boolean;
table: string;
type?: number;
columnType?: number;
zerofill?: boolean;
typeName?: string;
encoding?: string;
columnLength?: number;
}
export { FieldPacket };

View file

@ -0,0 +1,23 @@
/**
* @deprecated
* `OkPacket` is deprecated and might be removed in the future major release. Please use `ResultSetHeader` instead.
*/
declare interface OkPacket {
constructor: {
name: 'OkPacket';
};
fieldCount: number;
affectedRows: number;
/**
* @deprecated
* `changedRows` is deprecated and might be removed in the future major release. Please use `affectedRows` property instead.
*/
changedRows: number;
insertId: number;
serverStatus: number;
warningCount: number;
message: string;
protocol41: boolean;
}
export { OkPacket };

View file

@ -0,0 +1,13 @@
import { OkPacket } from './OkPacket.js';
import { ResultSetHeader } from './ResultSetHeader.js';
import { RowDataPacket } from './RowDataPacket.js';
declare type ProcedureCallPacket<
T = [RowDataPacket[], ResultSetHeader] | ResultSetHeader,
> = T extends RowDataPacket[]
? [T, ResultSetHeader]
: T extends ResultSetHeader | OkPacket
? ResultSetHeader
: [RowDataPacket[], ResultSetHeader] | ResultSetHeader;
export { ProcedureCallPacket };

View file

@ -0,0 +1,18 @@
declare interface ResultSetHeader {
constructor: {
name: 'ResultSetHeader';
};
affectedRows: number;
fieldCount: number;
info: string;
insertId: number;
serverStatus: number;
warningStatus: number;
/**
* @deprecated
* `changedRows` is deprecated and might be removed in the future major release. Please use `affectedRows` property instead.
*/
changedRows: number;
}
export { ResultSetHeader };

View file

@ -0,0 +1,9 @@
declare interface RowDataPacket {
constructor: {
name: 'RowDataPacket';
};
[column: string]: any;
[column: number]: any;
}
export { RowDataPacket };

View file

@ -0,0 +1,28 @@
import { OkPacket } from './OkPacket.js';
import { RowDataPacket } from './RowDataPacket.js';
import { FieldPacket } from './FieldPacket.js';
import { Field } from './Field.js';
import { ProcedureCallPacket } from './ProcedurePacket.js';
import { ResultSetHeader } from './ResultSetHeader.js';
import { OkPacketParams } from './params/OkPacketParams.js';
import { ErrorPacketParams } from './params/ErrorPacketParams.js';
export type QueryResult =
| OkPacket
| ResultSetHeader
| ResultSetHeader[]
| RowDataPacket[]
| RowDataPacket[][]
| OkPacket[]
| ProcedureCallPacket;
export {
OkPacket,
RowDataPacket,
FieldPacket,
Field,
ProcedureCallPacket,
ResultSetHeader,
OkPacketParams,
ErrorPacketParams,
};

View file

@ -0,0 +1,6 @@
declare interface ErrorPacketParams {
message?: string;
code?: number | string;
}
export { ErrorPacketParams };

View file

@ -0,0 +1,9 @@
declare interface OkPacketParams {
affectedRows?: number;
insertId?: number;
serverStatus?: number;
warningCount?: number;
message?: string;
}
export { OkPacketParams };

View file

@ -0,0 +1,41 @@
import { FieldPacket, QueryResult } from '../packets/index.js';
import {
Query,
QueryError,
QueryOptions,
ExecuteValues,
QueryableConstructor,
} from './Query.js';
export declare function ExecutableBase<T extends QueryableConstructor>(
Base?: T
): {
new (...args: any[]): {
execute<T extends QueryResult>(
sql: string,
callback?:
| ((err: QueryError | null, result: T, fields: FieldPacket[]) => any)
| undefined
): Query;
execute<T extends QueryResult>(
sql: string,
values: ExecuteValues,
callback?:
| ((err: QueryError | null, result: T, fields: FieldPacket[]) => any)
| undefined
): Query;
execute<T extends QueryResult>(
options: QueryOptions,
callback?:
| ((err: QueryError | null, result: T, fields: FieldPacket[]) => any)
| undefined
): Query;
execute<T extends QueryResult>(
options: QueryOptions,
values: ExecuteValues,
callback?:
| ((err: QueryError | null, result: T, fields: FieldPacket[]) => any)
| undefined
): Query;
};
} & T;

View file

@ -0,0 +1,65 @@
import { Sequence } from './Sequence.js';
import { Query, QueryError, StreamOptions } from '../sequences/Query.js';
import {
OkPacket,
FieldPacket,
RowDataPacket,
ResultSetHeader,
} from '../packets/index.js';
import { Readable } from 'stream';
export class PrepareStatementInfo {
close(): void;
execute<
T extends
| RowDataPacket[][]
| RowDataPacket[]
| OkPacket
| OkPacket[]
| ResultSetHeader,
>(
parameters: any | any[] | { [param: string]: any },
callback?: (err: QueryError | null, result: T, fields: FieldPacket[]) => any
): Query;
}
declare class Prepare extends Sequence {
/**
* The SQL for a constructed query
*/
sql: string;
/**
* Emits a query packet to start the query
*/
start(): void;
/**
* Determines the packet class to use given the first byte of the packet.
*
* @param firstByte The first byte of the packet
* @param parser The packet parser
*/
determinePacket(firstByte: number, parser: any): any;
/**
* Creates a Readable stream with the given options
*
* @param options The options for the stream.
*/
stream(options?: StreamOptions): Readable;
on(event: string, listener: (args: []) => void): this;
on(event: 'error', listener: (err: QueryError) => any): this;
on(
event: 'fields',
listener: (fields: FieldPacket, index: number) => any
): this;
on(
event: 'result',
listener: (result: RowDataPacket | OkPacket, index: number) => any
): this;
on(event: 'end', listener: () => any): this;
}
export { Prepare };

View file

@ -0,0 +1,228 @@
import { Sequence } from './Sequence.js';
import { OkPacket, RowDataPacket, FieldPacket } from '../packets/index.js';
import { Readable } from 'stream';
import { Raw, Timezone } from 'sql-escaper';
import { TypeCast } from '../../parsers/typeCast.js';
export type ExecuteValues =
| string
| number
| bigint
| boolean
| Date
| null
| Blob
| Buffer
| Uint8Array
| ExecuteValues[]
| { [key: string]: ExecuteValues };
export type QueryValues =
| string
| number
| bigint
| boolean
| Date
| null
| undefined
| Blob
| Buffer
| Uint8Array
| Raw
| ({} | null | undefined)[]
| { [key: string]: QueryValues };
export interface QueryOptions {
/**
* The SQL for the query
*/
sql: string;
/**
* The values for the query
*/
values?: QueryValues;
/**
* This overrides the namedPlaceholders option set at the connection level.
*/
namedPlaceholders?: boolean;
/**
* Every operation takes an optional inactivity timeout option. This allows you to specify appropriate timeouts for
* operations. It is important to note that these timeouts are not part of the MySQL protocol, and rather timeout
* operations through the client. This means that when a timeout is reached, the connection it occurred on will be
* destroyed and no further operations can be performed.
*/
timeout?: number;
/**
* Either a boolean or string. If true, tables will be nested objects. If string (e.g. '_'), tables will be
* nested as tableName_fieldName
*/
nestTables?: any;
/**
* Determines if column values should be converted to native JavaScript types.
*
* @default true
*
* It is not recommended (and may go away / change in the future) to disable type casting, but you can currently do so on either the connection or query level.
*
* ---
*
* You can also specify a function to do the type casting yourself:
* ```ts
* (field: Field, next: () => unknown) => {
* return next();
* }
* ```
*
* ---
*
* **WARNING:**
*
* YOU MUST INVOKE the parser using one of these three field functions in your custom typeCast callback. They can only be called once:
*
* ```js
* field.string();
* field.buffer();
* field.geometry();
* ```
* Which are aliases for:
*
* ```js
* parser.parseLengthCodedString();
* parser.parseLengthCodedBuffer();
* parser.parseGeometryValue();
* ```
*
* You can find which field function you need to use by looking at `RowDataPacket.prototype._typeCast`.
*/
typeCast?: TypeCast;
/**
* This overrides the same option set at the connection level.
*
*/
rowsAsArray?: boolean;
/**
* By specifying a function that returns a readable stream, an arbitrary stream can be sent when sending a local fs file.
*/
infileStreamFactory?: (path: string) => Readable;
/**
* When dealing with big numbers (BIGINT and DECIMAL columns) in the database, you should enable this option
* (Default: false)
*/
supportBigNumbers?: boolean;
/**
* Enabling both supportBigNumbers and bigNumberStrings forces big numbers (BIGINT and DECIMAL columns) to be
* always returned as JavaScript String objects (Default: false). Enabling supportBigNumbers but leaving
* bigNumberStrings disabled will return big numbers as String objects only when they cannot be accurately
* represented with JavaScript Number objects (which happens when they exceed the [-2^53, +2^53] range),
* otherwise they will be returned as Number objects.
* This option is ignored if supportBigNumbers is disabled.
*/
bigNumberStrings?: boolean;
/**
* Force date types (TIMESTAMP, DATETIME, DATE) to be returned as strings rather then inflated into JavaScript Date
* objects. Can be true/false or an array of type names to keep as strings.
*
* (Default: false)
*/
dateStrings?: boolean | Array<'TIMESTAMP' | 'DATETIME' | 'DATE'>;
/**
* The timezone used to store local dates. (Default: 'local')
*/
timezone?: Timezone;
}
export interface StreamOptions {
/**
* Sets the max buffer size in objects of a stream
*/
highWaterMark?: number;
/**
* The object mode of the stream is always set to `true`
*/
objectMode?: true;
}
export interface QueryError extends NodeJS.ErrnoException {
/**
* Either a MySQL server error (e.g. 'ER_ACCESS_DENIED_ERROR'),
* a node.js error (e.g. 'ECONNREFUSED') or an internal error
* (e.g. 'PROTOCOL_CONNECTION_LOST').
*/
code: string;
/**
* The sql state marker
*/
sqlStateMarker?: string;
/**
* The sql state
*/
sqlState?: string;
/**
* The field count
*/
fieldCount?: number;
/**
* Boolean, indicating if this error is terminal to the connection object.
*/
fatal: boolean;
}
declare class Query extends Sequence {
/**
* The SQL for a constructed query
*/
sql: string;
/**
* Emits a query packet to start the query
*/
start(): void;
/**
* Determines the packet class to use given the first byte of the packet.
*
* @param firstByte The first byte of the packet
* @param parser The packet parser
*/
determinePacket(firstByte: number, parser: any): any;
/**
* Creates a Readable stream with the given options
*
* @param options The options for the stream.
*/
stream(options?: StreamOptions): Readable;
on(event: string, listener: (...args: any[]) => void): this;
on(event: 'error', listener: (err: QueryError) => any): this;
on(
event: 'fields',
listener: (fields: FieldPacket, index: number) => any
): this;
on(
event: 'result',
listener: (result: RowDataPacket | OkPacket, index: number) => any
): this;
on(event: 'end', listener: () => any): this;
}
export type QueryableConstructor<T = object> = new (...args: any[]) => T;
export { Query };

View file

@ -0,0 +1,41 @@
import { FieldPacket, QueryResult } from '../packets/index.js';
import {
Query,
QueryError,
QueryOptions,
QueryValues,
QueryableConstructor,
} from './Query.js';
export declare function QueryableBase<T extends QueryableConstructor>(
Base?: T
): {
new (...args: any[]): {
query<T extends QueryResult>(
sql: string,
callback?:
| ((err: QueryError | null, result: T, fields: FieldPacket[]) => any)
| undefined
): Query;
query<T extends QueryResult>(
sql: string,
values: QueryValues,
callback?:
| ((err: QueryError | null, result: T, fields: FieldPacket[]) => any)
| undefined
): Query;
query<T extends QueryResult>(
options: QueryOptions,
callback?:
| ((err: QueryError | null, result: T, fields: FieldPacket[]) => any)
| undefined
): Query;
query<T extends QueryResult>(
options: QueryOptions,
values: QueryValues,
callback?:
| ((err: QueryError | null, result: T, fields: FieldPacket[]) => any)
| undefined
): Query;
};
} & T;

View file

@ -0,0 +1,5 @@
import { EventEmitter } from 'events';
declare class Sequence extends EventEmitter {}
export { Sequence };

View file

@ -0,0 +1,17 @@
import { FieldPacket, QueryResult } from '../../packets/index.js';
import { QueryOptions, QueryableConstructor, ExecuteValues } from '../Query.js';
export declare function ExecutableBase<T extends QueryableConstructor>(
Base?: T
): {
new (...args: any[]): {
execute<T extends QueryResult>(
sql: string,
values?: ExecuteValues
): Promise<[T, FieldPacket[]]>;
execute<T extends QueryResult>(
options: QueryOptions,
values?: ExecuteValues
): Promise<[T, FieldPacket[]]>;
};
} & T;

View file

@ -0,0 +1,18 @@
import { FieldPacket, QueryResult } from '../../packets/index.js';
import { QueryOptions, QueryValues, QueryableConstructor } from '../Query.js';
export declare function QueryableBase<T extends QueryableConstructor>(
Base?: T
): {
new (...args: any[]): {
query<T extends QueryResult>(
sql: string,
values?: QueryValues
): Promise<[T, FieldPacket[]]>;
query<T extends QueryResult>(
options: QueryOptions,
values?: QueryValues
): Promise<[T, FieldPacket[]]>;
};
} & T;