Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 类型补全Aggregate #341

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions types/wx/lib.wx.cloud.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,77 @@ declare namespace DB {
collection(collectionName: string): CollectionReference
}

interface Aggregate {
/**
* @description 聚合阶段。添加新字段到输出的记录。经过 addFields 聚合阶段,输出的所有记录中除了输入时带有的字段外,还将带有 addFields 指定的字段。
*/
addFields(object: any): Aggregate
/**
* @description 聚合阶段。将输入记录根据给定的条件和边界划分成不同的组,每组即一个 bucket。
*/
bucket(object: any): Aggregate
/**
* @description 聚合阶段。将输入记录根据给定的条件划分成不同的组,每组即一个 bucket。与 bucket 的其中一个不同之处在于无需指定 boundaries,bucketAuto 会自动尝试将记录尽可能平均地分散到每组中。
*/
bucketAuto(object: any): Aggregate
/**
* @description 聚合阶段。计算上一聚合阶段输入到本阶段的记录数,输出一个记录,其中指定字段的值为记录数。
*/
count(fieldName: string): Aggregate
/**
* @description 标志聚合操作定义完成,发起实际聚合操作。
*/
end(): Promise<any>
/**
* @description 聚合阶段。将记录按照离给定点从近到远输出。
*/
geoNear(object: any): Aggregate
/**
* @description 聚合阶段。将输入记录按给定表达式分组,输出时每个记录代表一个分组,每个记录的 _id 是区分不同组的 key。输出记录中也可以包括累计值,将输出字段设为累计值即会从该分组中计算累计值。
*/
group(object: any): Aggregate
/**
* @description 聚合阶段。限制输出到下一阶段的记录数。
*/
limit(value: number): Aggregate
/**
* @description 聚合阶段。聚合阶段。联表查询。与同个数据库下的一个指定的集合做 left outer join(左外连接)。对该阶段的每一个输入记录,lookup 会在该记录中增加一个数组字段,该数组是被联表中满足匹配条件的记录列表。lookup 会将连接后的结果输出给下个阶段。
*/
lookup(object: any): Aggregate
/**
* @description 聚合阶段。根据条件过滤文档,并且把符合条件的文档传递给下一个流水线阶段。
*/
match(object: any): Aggregate
/**
* @description 聚合阶段。把指定的字段传递给下一个流水线,指定的字段可以是某个已经存在的字段,也可以是计算出来的新字段。
*/
project(object: any): Aggregate
/**
* @description 聚合阶段。指定一个已有字段作为输出的根节点,也可以指定一个计算出的新字段作为根节点。
*/
replaceRoot(object: any): Aggregate
/**
* @description 聚合阶段。随机从文档中选取指定数量的记录。
*/
sample(size: number): Aggregate
/**
* @description 聚合阶段。指定一个正整数,跳过对应数量的文档,输出剩下的文档。
*/
skip(value: number): Aggregate
/**
* @description 聚合阶段。根据指定的字段,对输入的文档进行排序。
*/
sort(object: any): Aggregate
/**
* @description 聚合阶段。根据传入的表达式,将传入的集合进行分组(group)。然后计算不同组的数量,并且将这些组按照它们的数量进行排序,返回排序后的结果。
*/
sortByCount(object: any): Aggregate
/**
* @description 聚合阶段。使用指定的数组字段中的每个元素,对文档进行拆分。拆分后,文档会从一个变为一个或多个,分别对应数组的每个元素。
*/
unwind(value: string | object): Aggregate
}

class CollectionReference extends Query {
readonly collectionName: string

Expand All @@ -348,6 +419,7 @@ declare namespace DB {

add(options: OQ<IAddDocumentOptions>): void
add(options: RQ<IAddDocumentOptions>): Promise<IAddResult>
aggregate(): Aggregate
}

class DocumentReference {
Expand Down
Loading