>>;
export type ExtractDefaultPropTypes> = {
@@ -27,29 +28,29 @@ export type LooseRequired = {
export type DefaultKeys = {
[K in keyof T]: T[K] extends {
- default: any
+ default: any;
} | BooleanConstructor | {
- type: BooleanConstructor
+ type: BooleanConstructor;
} ? T[K] extends {
- type: BooleanConstructor
- required: true
+ type: BooleanConstructor;
+ required: true;
} ? never : K : never;
}[keyof T];
export type RequiredKeys = {
[K in keyof T]: T[K] extends
| {
- required: true
+ required: true;
}
| {
- default: any
+ default: any;
}
| BooleanConstructor
| {
- type: BooleanConstructor
+ type: BooleanConstructor;
}
? T[K] extends {
- default: undefined | (() => undefined)
+ default: undefined | (() => undefined);
}
? never
: K
@@ -60,7 +61,7 @@ export type OptionalKeys = Exclude>;
export type InKeys = {
[K in keyof T]: T[K] extends {
- in: In
+ in: In;
}
? K
: never;
@@ -72,36 +73,36 @@ export type InferPropType = [T] extends [null]
? any
: [T] extends [
{
- type: null | true
+ type: null | true;
}
]
? any
: [T] extends [
- | ObjectConstructor
- | {
- type: ObjectConstructor
- }
+ | ObjectConstructor
+ | {
+ type: ObjectConstructor;
+ }
]
? Record
: [T] extends [
- | BooleanConstructor
- | {
- type: BooleanConstructor
- }
+ | BooleanConstructor
+ | {
+ type: BooleanConstructor;
+ }
]
? boolean
: [T] extends [
- | DateConstructor
- | {
- type: DateConstructor
- }
+ | DateConstructor
+ | {
+ type: DateConstructor;
+ }
]
? Date
: [T] extends [
- | (infer U)[]
- | {
- type: (infer U)[]
- }
+ | (infer U)[]
+ | {
+ type: (infer U)[];
+ }
]
? U extends DateConstructor
? Date | InferPropType
@@ -124,10 +125,10 @@ type Prop = PropOptions | PropType;
type PropConstructor =
| {
- new(...args: any[]): T & {}
+ new(...args: any[]): NonNullable;
}
| {
- (): T
+ (): T;
}
| PropMethod;
@@ -135,29 +136,29 @@ type PropMethod = [T] extends [
((...args: any) => any) | undefined
]
? {
- new(): TConstructor
- (): T
- readonly prototype: TConstructor
+ new(): TConstructor;
+ (): T;
+ readonly prototype: TConstructor;
}
: never;
export interface PropOptions {
- type: PropType
- required?: boolean
- default?: Default | DefaultFactory | null | undefined | object
- validator?(value: unknown): boolean
- transform?(value: unknown): Type
- meta?: Record
- in?: PropIn
+ type: PropType;
+ required?: boolean;
+ default?: Default | DefaultFactory | null | undefined | object;
+ validator?(value: unknown): boolean;
+ transform?(value: unknown): Type;
+ meta?: Record;
+ in?: PropIn;
}
export interface NormalizedProps
extends PropOptions {
- meta: Record
- in?: PropIn
- required: boolean
- type: PropType
- default?: Default | DefaultFactory | null | undefined | object
+ meta: Record;
+ in?: PropIn;
+ required: boolean;
+ type: PropType;
+ default?: Default | DefaultFactory | null | undefined | object;
}
declare type DefaultFactory = (props: DefaultData) => T | null | undefined;
@@ -166,7 +167,7 @@ export type PropType = PropConstructor | PropConstructor[];
export function isExtends(types: PropType, value: PropType): boolean {
if (Array.isArray(types)) {
- return types.some((e) => isExtends(e, value));
+ return types.some(e => isExtends(e, value));
}
return value === types;
}
@@ -192,7 +193,7 @@ function getType(fn: PropType) {
*/
export function isInstanceOf(type: PropType | PropType[], value: any): value is D {
if (Array.isArray(type)) {
- return type.some((e) => isInstanceOf(e, value));
+ return type.some(e => isInstanceOf(e, value));
}
const expectedType = getType(type);
let valid = true;
@@ -239,7 +240,7 @@ export function normalizeProps(
result[key] = {
type: prop,
in: "query",
- required: prop.some((p) => isExtends(p as PropType, Boolean)),
+ required: prop.some(p => isExtends(p as PropType, Boolean)),
meta: {}
};
continue;
@@ -261,7 +262,10 @@ export function normalizeProps(
}
export function withDefaults<
- T = Record, P extends ObjectProps = ObjectProps, D = ExtractPropTypes, Defaults = ExtractDefaultPropTypes
+ T = Record,
+P extends ObjectProps = ObjectProps,
+D = ExtractPropTypes,
+Defaults = ExtractDefaultPropTypes
>(props: Partial & Omit, propsOptions: P, propIn?: PropIn): D {
if (Array.isArray(propsOptions)) {
return props as D;
@@ -287,7 +291,7 @@ export function withDefaults<
if (propIn) {
continue;
}
- if (opt.some((e) => isExtends(e, Boolean))) {
+ if (opt.some(e => isExtends(e, Boolean))) {
rs[k] = false as D[typeof k];
}
continue;
@@ -326,10 +330,9 @@ export function validateProps(
}
}
-
export function defineExtends(props: P): ({
- (): P
- (extraProps: E): P & E
+ (): P;
+ (extraProps: E): P & E;
}) {
return (extraProps?: E) => {
return {
@@ -338,4 +341,3 @@ export function defineExtends(props: P): ({
};
};
}
-
diff --git a/packages/core/src/shared/request.ts b/packages/core/src/shared/request.ts
index fffb769c..4831034f 100644
--- a/packages/core/src/shared/request.ts
+++ b/packages/core/src/shared/request.ts
@@ -28,57 +28,62 @@ export const FOURZE_METHODS = [
export type RequestMethod = typeof FOURZE_METHODS[number];
export interface FourzeRequestOptions {
- url: string
- method?: string
- headers?: PolyfillHeaderInit
- body?: any
- params?: Record
- query?: Record
- meta?: Record
- request?: IncomingMessage
- contentTypeParsers?: Map any>
+ url: string;
+ method?: string;
+ headers?: PolyfillHeaderInit;
+ body?: any;
+ params?: Record;
+ query?: Record;
+ meta?: Record;
+ request?: IncomingMessage;
+ contentTypeParsers?: Map any>;
}
export interface FourzeRequest<
- Props extends ObjectProps = DefaultData, Meta = FourzeRouteMeta, Data = ExtractPropTypes, Query = ExtractPropTypesWithIn, Body = ExtractPropTypesWithIn, Params = ExtractPropTypesWithIn
+ Props extends ObjectProps = DefaultData,
+Meta = FourzeRouteMeta,
+Data = ExtractPropTypes,
+Query = ExtractPropTypesWithIn,
+Body = ExtractPropTypesWithIn,
+Params = ExtractPropTypesWithIn
> extends IncomingMessage {
- url: string
- method: string
- headers: Record
+ url: string;
+ method: string;
+ headers: Record;
- route: FourzeRoute
+ route: FourzeRoute;
- app?: FourzeApp
+ app?: FourzeApp;
- meta: Meta & FourzeRouteMeta
+ meta: Meta & FourzeRouteMeta;
- contextPath: string
+ contextPath: string;
- setRoute(route: FourzeRoute, matchParams?: Record | null): void
+ setRoute(route: FourzeRoute, matchParams?: Record | null): void;
- withScope(scope: string): FourzeRequest
+ withScope(scope: string): FourzeRequest;
- readonly contentType: string
+ readonly contentType: string;
- readonly req?: IncomingMessage
+ readonly req?: IncomingMessage;
- readonly originalPath: string
+ readonly originalPath: string;
- readonly params: Params
+ readonly params: Params;
- readonly query: Query
+ readonly query: Query;
- readonly body: Body
+ readonly body: Body;
/**
* {...query, ...params, ...body}
*/
- readonly data: Data
+ readonly data: Data;
- readonly raw: string
+ readonly raw: string;
- readonly path: string
+ readonly path: string;
- readonly [FourzeRequestFlag]: true
+ readonly [FourzeRequestFlag]: true;
}
export function createRequest(options: FourzeRequestOptions) {
diff --git a/packages/core/src/shared/response.ts b/packages/core/src/shared/response.ts
index cdd4d6e1..22ee8245 100644
--- a/packages/core/src/shared/response.ts
+++ b/packages/core/src/shared/response.ts
@@ -6,10 +6,10 @@ import { FourzeError } from "./error";
import type { FourzeRequest } from "./request";
export interface FourzeResponseOptions {
- url: string
- method: string
- request: FourzeRequest
- response?: OutgoingMessage
+ url: string;
+ method: string;
+ request: FourzeRequest;
+ response?: OutgoingMessage;
}
const FourzeResponseFlag = "__isFourzeResponse";
@@ -17,75 +17,75 @@ const FourzeResponseFlag = "__isFourzeResponse";
export interface FourzeBaseResponse extends ServerResponse {
}
export interface FourzeResponse extends FourzeBaseResponse {
- json(payload: any): this
+ json(payload: any): this;
- image(payload: Buffer): this
+ image(payload: Buffer): this;
- text(payload: string): this
+ text(payload: string): this;
- binary(payload: Buffer): this
+ binary(payload: Buffer): this;
- redirect(url: string): this
+ redirect(url: string): this;
- appendHeader(key: string, value: string | string[]): this
+ appendHeader(key: string, value: string | string[]): this;
- removeHeader(key: string): this
+ removeHeader(key: string): this;
/**
* 发送数据
* @param payload
* @param contentType
*/
- send(payload: any, contentType?: string | null): this
+ send(payload: any, contentType?: string | null): this;
- send(payload: any, statusCode?: number): this
+ send(payload: any, statusCode?: number): this;
- send(payload: any, statusCode?: number, contentType?: string | null): this
+ send(payload: any, statusCode?: number, contentType?: string | null): this;
/**
* 获取Content-Type
* @param payload 如果没有指定contentType,则会根据payload的类型自动推断
*/
- getContentType(payload?: any): string | undefined
+ getContentType(payload?: any): string | undefined;
/**
* 设置Content-Type
* @param contentType
*/
- setContentType(contentType: string): this
+ setContentType(contentType: string): this;
- status(code: number): this
+ status(code: number): this;
/**
* 发送错误
* @param code
* @param error
*/
- sendError(code: number, error?: string | Error): this
+ sendError(code: number, error?: string | Error): this;
/**
* 发送错误
* @param error
*/
- sendError(error?: string | Error): this
+ sendError(error?: string | Error): this;
/**
* 等待所有的异步操作完成
*/
- done(): Promise
+ done(): Promise;
- sent: boolean
+ sent: boolean;
- readonly res?: OutgoingMessage
+ readonly res?: OutgoingMessage;
- readonly request: FourzeRequest
+ readonly request: FourzeRequest;
- readonly url: string
+ readonly url: string;
- readonly payload: any
+ readonly payload: any;
- readonly error: FourzeError | undefined
+ readonly error: FourzeError | undefined;
- readonly [FourzeResponseFlag]: true
+ readonly [FourzeResponseFlag]: true;
}
export function createResponse(options: FourzeResponseOptions) {
@@ -181,7 +181,7 @@ export function createResponse(options: FourzeResponseOptions) {
name,
[oldValue, value]
.flat()
- .filter((r) => !!r)
+ .filter(r => !!r)
.join(",")
);
} else {
diff --git a/packages/core/src/shared/route.ts b/packages/core/src/shared/route.ts
index 699ce781..b9192dda 100644
--- a/packages/core/src/shared/route.ts
+++ b/packages/core/src/shared/route.ts
@@ -8,39 +8,45 @@ import type { FourzeHandle } from "./interface";
const FourzeRouteFlag = "__isFourzeRoute";
export interface FourzeRouteOptions {
- method?: RequestMethod
- props?: Props
- meta?: Meta & FourzeRouteMeta
+ method?: RequestMethod;
+ props?: Props;
+ meta?: Meta & FourzeRouteMeta;
}
export interface FourzeBaseRoute<
- Result = unknown, Props extends ObjectProps = DefaultData, Meta = FourzeRouteMeta
+ Result = unknown,
+Props extends ObjectProps = DefaultData,
+Meta = FourzeRouteMeta
> {
- path: string
- method?: RequestMethod
- handle: FourzeHandle
- meta?: Meta
- props?: Props
+ path: string;
+ method?: RequestMethod;
+ handle: FourzeHandle;
+ meta?: Meta;
+ props?: Props;
}
export interface FourzeRoute<
- Result = unknown, Props extends ObjectProps = DefaultData, Meta = FourzeRouteMeta
+ Result = unknown,
+Props extends ObjectProps = DefaultData,
+Meta = FourzeRouteMeta
> extends FourzeBaseRoute {
- readonly [FourzeRouteFlag]: true
- readonly props: Props
- readonly meta: Meta
+ readonly [FourzeRouteFlag]: true;
+ readonly props: Props;
+ readonly meta: Meta;
}
export type FourzeRouteGenerator = {
[K in RequestMethod]: {
<
- Result = any, Props extends ObjectProps = DefaultData, Meta = FourzeRouteMeta
+ Result = any,
+Props extends ObjectProps = DefaultData,
+Meta = FourzeRouteMeta
>(
path: string,
options: FourzeRouteOptions,
handle: FourzeHandle
- ): This
- (path: string, handle: FourzeHandle): This
+ ): This;
+ (path: string, handle: FourzeHandle): This;
};
};
@@ -60,7 +66,9 @@ export function defineRouteProps(
}
export function defineRoute<
- Result = unknown, Props extends ObjectProps = DefaultData, Meta = FourzeRouteMeta
+ Result = unknown,
+Props extends ObjectProps = DefaultData,
+Meta = FourzeRouteMeta
>(
route: FourzeBaseRoute & { base?: string }
): FourzeRoute {
@@ -91,4 +99,3 @@ export function defineRoute<
}
};
}
-
diff --git a/packages/core/src/utils/array.ts b/packages/core/src/utils/array.ts
index cf7eca6e..c0b07f4a 100644
--- a/packages/core/src/utils/array.ts
+++ b/packages/core/src/utils/array.ts
@@ -11,168 +11,168 @@ export type PredicateParameter = [PredicateFn] | [keyof T, ...T[keyof T][]
export type MapParameter = keyof T | MapFn;
export interface Predicate extends PredicateFn {
- and(...args: PredicateParameter): this
- or(...args: PredicateParameter): this
+ and(...args: PredicateParameter): this;
+ or(...args: PredicateParameter): this;
}
export interface ExtraArrayMethods {
- where(fn: PredicateFn): CollectionQuery
- select(mapFn: MapFn): CollectionQuery
- select(): CollectionQuery
+ where(fn: PredicateFn): CollectionQuery;
+ select(mapFn: MapFn): CollectionQuery;
+ select(): CollectionQuery;
}
export interface MathQuery {
- max(fn?: MapFn): typeof fn extends undefined ? T extends number ? T : never : number
- min(fn?: MapFn): typeof fn extends undefined ? T extends number ? T : never : number
- sum(fn?: MapFn): typeof fn extends undefined ? T extends number ? T : never : number
- average(fn?: MapFn): typeof fn extends undefined ? T extends number ? T : never : number
+ max(fn?: MapFn): typeof fn extends undefined ? T extends number ? T : never : number;
+ min(fn?: MapFn): typeof fn extends undefined ? T extends number ? T : never : number;
+ sum(fn?: MapFn): typeof fn extends undefined ? T extends number ? T : never : number;
+ average(fn?: MapFn): typeof fn extends undefined ? T extends number ? T : never : number;
}
export interface ArrayQuery extends Iterable {
join(
separator?: string
- ): string
+ ): string;
- at(index: number): T | undefined
+ at(index: number): T | undefined;
- fill(value: T, start?: number, end?: number): this
- sort(compareFn?: CompareFn): this
- reverse(): this
+ fill(value: T, start?: number, end?: number): this;
+ sort(compareFn?: CompareFn): this;
+ reverse(): this;
- includes(value: T, fromIndex?: number): boolean
+ includes(value: T, fromIndex?: number): boolean;
- some(fn: PredicateFn): boolean
- every(fn: PredicateFn): boolean
+ some(fn: PredicateFn): boolean;
+ every(fn: PredicateFn): boolean;
- find(fn: PredicateFn): T | undefined
- findIndex(fn: PredicateFn): number
- findLast(fn: PredicateFn): T | undefined
- findLastIndex(fn: PredicateFn): number
+ find(fn: PredicateFn): T | undefined;
+ findIndex(fn: PredicateFn): number;
+ findLast(fn: PredicateFn): T | undefined;
+ findLastIndex(fn: PredicateFn): number;
reduce(
callbackfn: (previousValue: U, currentValue: T, currentIndex: number) => U,
initialValue: U
- ): U
+ ): U;
reduceRight(
callbackfn: (previousValue: U, currentValue: T, currentIndex: number) => U,
initialValue: U
- ): U
- forEach(fn: (item: T, index: number) => void): void
+ ): U;
+ forEach(fn: (item: T, index: number) => void): void;
- indexOf(value: T, fromIndex?: number): number
- lastIndexOf(value: T, fromIndex?: number): number
+ indexOf(value: T, fromIndex?: number): number;
+ lastIndexOf(value: T, fromIndex?: number): number;
}
export interface CollectionBase extends Iterable {
- append(...items: T[]): this
- prepend(...items: T[]): this
- insert(index: number, ...items: T[]): this
- delete(index: number): this
- delete(fn: PredicateFn, deleteLimit?: number): this
- replace(fn: PredicateFn, item: T): this
- set(index: number, value: T): this
- get(index: number): T | undefined
- clear(): this
- reset(source?: Iterable