wx.d.ts

2022-10-17  本文已影响0人  凡凡的小web

/**

declare const canvas: HTMLCanvasElement;

declare const Jye1: string;

declare function requirePlugin(name: string, option: object): any;

/**

// /** 输出日志*/
// interface Console {
// debug(message?: any, ...optionalParams: any[]): void;
// error(message?: any, ...optionalParams: any[]): void;
// group(groupTitle?: string, ...optionalParams: any[]): void;
// groupEnd(): void;
// info(message?: any, ...optionalParams: any[]): void;
// log(message?: any, ...optionalParams: any[]): void;
// warn(message?: any, ...optionalParams: any[]): void;
// }

// /** 输出日志*/
// declare const Console: {
// prototype: Console;
// new (): Console;
// };

// declare let console: Console;
/**

/**

/**

/**

/**

/** /
interface cloudEnvType { env: string }
/
* /
type cloudCallFailType = (err: { errCode: string; errMsg: string }) => void;
/
* */
type cloudEmptyFunction = () => void;

interface Database {
command: Command;
serverDate(options?: object): ServerDate;
// eslint-disable-next-line @typescript-eslint/member-ordering
Geo: Geo;
// eslint-disable-next-line @typescript-eslint/member-ordering
createCollection: Promise<CreateCollectionSuccess>;
collection(name: string): Collection;
RegExp(options: RegExpOptions): DBRegExp;
}

type DBRegExp = RegExp;

type ServerDate = Date;

interface RegExpOptions {
regexp: string; // 正则表达式,字符串形式
options: 'i' | 'm' | 's'; // flags,包括 i, m, s 但前端不做强限制
}

interface Query {
get(): Promise<GetCollectionResult>;
update(options: CommonOption): Promise<UpateCollectionResult>;
remove(): Promise<RemoveCollectionResult>;
count(): Promise<CountCollectionResult>;
orderBy(fieldName: string, order: 'asc' | 'desc'): Collection | Query;
limit(max: number): Collection | Query;
skip(offset: number): Collection | Query;
field(definition: object): Collection | Query | Document;
}

interface Collection extends Query {
doc(id: string | number): Document;
add(options: CommonOption): Promise<AddCollectionResult>;
where(rule: object): Query;

aggregate(): Aggregate;
}

interface CommonOption<T = any> {
data: T;
}

interface GetCollectionResult {
data: any[];
}

interface AddCollectionResult {
_id: string | number;
}

interface UpateCollectionResult {
stats: {
updated: number;
};
}

interface RemoveCollectionResult {
stats: {
removed: number;
};
}

interface CountCollectionResult {
stats: {
total: number;
};
}

interface Document {
get(): Promise<{ data: any }>;
update(options: CommonOption): Promise<{ stats: { updated: 0 | 1 } }>;
set(options: CommonOption): Promise<{
_id: string | number;
stats: { updated: 0 | 1; created: 0 | 1 };
}>;
remove(): Promise<{ stats: { removed: 0 | 1 } }>;
}

// collection(name: string): Collection
interface Command {
eq(value: any): Command;
neq(value: any): Command;
lt(value: number): Command;
lte(value: number): Command;
gt(value: number): Command;
gte(value: number): Command;
in(values: any[]): Command;
nin(values: any[]): Command;
and(command: Command): Command;
and(...commands: Command[]): Command;
or(command: Command | CrosFieldCommand[]): Command;
or(...commands: Command[]): Command;
set(value: any): Command;
remove(): Command;
inc(value: number): Command;
mul(value: number): Command;
push(values: any[]): Command;
pop(): Command;
shift(): Command;
unshift(values: any[]): Command;

geoNear(options: GeoNearOptions): Command;
geoWithin(options: GeoWithinOptions): Command;
geoIntersects(options: GeoIntersectsOptions): Command;

// aggregate: AggregationOperators
// eslint-disable-next-line @typescript-eslint/member-ordering
aggregate: any;
}

interface CrosFieldCommand {
[filed: string]: Command | boolean;
}

interface GeoNearOptions {
geometry: Point; // 点的地理位置
maxDistance?: number; // 选填,最大距离,单位为米
minDistance?: number; // 选填,最小距离,单位为米
}

interface GeoWithinOptions {
geometry: Polygon | MultiPolygon;
}

interface GeoIntersectsOptions {
geometry:
| Point
| LineString
| MultiPoint
| MultiLineString
| Polygon
| MultiPolygon; // 地理位置
}

interface Geo {
Point: Point;
LineString: LineString;
Polygon: Polygon;
}

// type Point = (longitude: number, latitude: number) => Point;

type PointCoordinates = [number, number];

interface Point {
type: 'Point';
coordinates: PointCoordinates;
}

// type LineString = (points: Point[]) => LineString;

interface LineString {
type: 'LineString';
coordinates: PointCoordinates[];
}

// type Polygon = (lineStrings: LineString[]) => Polygon;

interface Polygon {
type: 'Polygon';
coordinates: PointCoordinates[][];
}

// type MultiPoint = (points: Point[]) => MultiPoint;

interface MultiPoint {
type: 'MultiPoint';
coordinates: PointCoordinates[];
}

// type MultiLineString = (polygons: LineString[]) => MultiLineString;

interface MultiLineString {
type: 'MultiLineString';
coordinates: PointCoordinates[][];
}

// type MultiPolygon = (polygons: Polygon[]) => MultiPolygon;

interface MultiPolygon {
type: 'MultiPolygon';
coordinates: PointCoordinates[][][];
}

// interface GeoJSON<T> {
// type: T;
// coordinates: [];
// }

interface CreateCollectionSuccess {
errMsg: string;
}

interface Aggregate {
addFields(fieldObj: { [fieldName: string]: any }): Aggregate;
bucket(bucketObj: {
groupBy: any;
boundaries: any[];
default?: any;
output?: object;
}): Aggregate;
bucketAuto(bucketObj: {
groupBy: any;
buckets: number;
granularity?: any;
output?: object;
}): Aggregate;
count(expr: string): any;
geoNear(geoNearObj: {
near: Point;
spherical: true;
limit?: number;
maxDistance?: number;
minDistance?: number;
query?: object;
distanceMultiplier?: number;
distanceField: string;
includeLocs?: string;
key?: string;
}): Aggregate;
group(groupObj: { _id: any; [fieldName: string]: any }): Aggregate;
limit(limitRecords: number): any;
match(matchObj: { [fieldName: string]: any }): Aggregate;
project(projectObj: { [fieldName: string]: any }): Aggregate;
replaceRoot(replaceRootObj: { newRoot: any }): Aggregate;
sample(replaceRootObj: { size: number }): Aggregate;
skip(skipNum: number): any;
sort(replaceRootObj: { [fieldName: string]: 1 | -1 }): Aggregate;
sortByCount(fieldName: string): Aggregate;
unwind(unwindObj: {
path: string;
includeArrayIndex?: string;
preserveNullAndEmptyArrays?: boolean;
}): Aggregate;
end(): void;
}

// type
interface AggregationOperators {
abs(operand: number): number;
add(...operand: any[]): any;
addToSet(expression: string): any;
allElementsTrue(expression: [string]): boolean;
and(expression: boolean[]): boolean;
lt(expression: string, value: number): boolean;
lte(expression: string, value: number): boolean;
anyElementTrue(expression: [string]): boolean;
arrayElemAt(expression: [string, number]): any;
arrayToObject(expression: string): object;
// arrayToObject(expression: [string, any][]): object
// arrayToObject(expression: {k: string; v: any}[]): object
avg(expression: string): number;
}

// /**
// * 基础库 2.0.0 开始支持,低版本需做兼容处理。
// * 将一个 Canvas 对应的 Texture 绑定到 WebGL 上下文。
// /
// declare const WebGLRenderingContext: {
// /
*
// *
// * @param texture WebGL 的纹理类型枚举值
// * @param canvas 需要绑定为 Texture 的 Canvas
// */
// wxBindCanvasTexture: (texture: number, canvas: wx.Canvas) => void
// }
}

上一篇 下一篇

猜你喜欢

热点阅读