@cloudbase/database 0.9.22 → 0.10.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +101 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +210 -0
- package/coverage/lcov.info +0 -0
- package/dist/commonjs/aggregate.js +3 -3
- package/dist/commonjs/collection.d.ts +1 -1
- package/dist/commonjs/collection.js +5 -2
- package/dist/commonjs/command.d.ts +5 -5
- package/dist/commonjs/command.js +9 -8
- package/dist/commonjs/commands/logic.js +3 -2
- package/dist/commonjs/commands/query.js +11 -8
- package/dist/commonjs/commands/update.js +1 -0
- package/dist/commonjs/config/error.config.js +1 -0
- package/dist/commonjs/const/code.js +1 -0
- package/dist/commonjs/constant.d.ts +7 -7
- package/dist/commonjs/constant.js +1 -0
- package/dist/commonjs/document.js +11 -10
- package/dist/commonjs/geo/index.js +20 -9
- package/dist/commonjs/geo/lineString.d.ts +1 -1
- package/dist/commonjs/geo/lineString.js +7 -6
- package/dist/commonjs/geo/multiLineString.d.ts +1 -1
- package/dist/commonjs/geo/multiLineString.js +7 -6
- package/dist/commonjs/geo/multiPoint.d.ts +1 -1
- package/dist/commonjs/geo/multiPoint.js +7 -6
- package/dist/commonjs/geo/multiPolygon.d.ts +1 -1
- package/dist/commonjs/geo/multiPolygon.js +7 -6
- package/dist/commonjs/geo/point.d.ts +1 -1
- package/dist/commonjs/geo/point.js +4 -3
- package/dist/commonjs/geo/polygon.d.ts +1 -1
- package/dist/commonjs/geo/polygon.js +8 -7
- package/dist/commonjs/helper/symbol.js +16 -4
- package/dist/commonjs/index.d.ts +9 -2
- package/dist/commonjs/index.js +19 -4
- package/dist/commonjs/lib/util.js +4 -3
- package/dist/commonjs/operator-map.js +1 -0
- package/dist/commonjs/query.js +10 -9
- package/dist/commonjs/regexp/index.d.ts +1 -1
- package/dist/commonjs/regexp/index.js +2 -1
- package/dist/commonjs/serializer/common.d.ts +2 -2
- package/dist/commonjs/serializer/common.js +23 -17
- package/dist/commonjs/serializer/datatype.d.ts +2 -2
- package/dist/commonjs/serializer/datatype.js +20 -14
- package/dist/commonjs/serializer/query.d.ts +1 -1
- package/dist/commonjs/serializer/query.js +24 -23
- package/dist/commonjs/serializer/update.d.ts +1 -1
- package/dist/commonjs/serializer/update.js +12 -11
- package/dist/commonjs/serverDate/index.d.ts +1 -1
- package/dist/commonjs/serverDate/index.js +3 -2
- package/dist/commonjs/transaction/collection.d.ts +1 -1
- package/dist/commonjs/transaction/collection.js +5 -2
- package/dist/commonjs/transaction/document.d.ts +1 -1
- package/dist/commonjs/transaction/document.js +5 -5
- package/dist/commonjs/transaction/index.js +3 -2
- package/dist/commonjs/transaction/query.js +1 -0
- package/dist/commonjs/typings/index.d.ts +3 -3
- package/dist/commonjs/typings/realtime.d.ts +16 -16
- package/dist/commonjs/util.js +1 -0
- package/dist/commonjs/utils/error.d.ts +2 -1
- package/dist/commonjs/utils/error.js +15 -9
- package/dist/commonjs/utils/symbol.js +5 -4
- package/dist/commonjs/utils/type.d.ts +1 -1
- package/dist/commonjs/utils/type.js +23 -11
- package/dist/commonjs/utils/utils.js +6 -3
- package/dist/commonjs/validate.js +1 -0
- package/dist/esm/aggregate.d.ts.map +1 -0
- package/dist/esm/aggregate.js +3 -3
- package/dist/esm/collection.d.ts +1 -1
- package/dist/esm/collection.d.ts.map +1 -0
- package/dist/esm/collection.js +4 -2
- package/dist/esm/command.d.ts +5 -5
- package/dist/esm/command.d.ts.map +1 -0
- package/dist/esm/commands/logic.d.ts.map +1 -0
- package/dist/esm/commands/query.d.ts.map +1 -0
- package/dist/esm/commands/query.js +8 -6
- package/dist/esm/commands/update.d.ts.map +1 -0
- package/dist/esm/config/app.config.d.ts.map +1 -0
- package/dist/esm/config/error.config.d.ts.map +1 -0
- package/dist/esm/const/code.d.ts.map +1 -0
- package/dist/esm/constant.d.ts +7 -7
- package/dist/esm/constant.d.ts.map +1 -0
- package/dist/esm/document.d.ts.map +1 -0
- package/dist/esm/document.js +2 -2
- package/dist/esm/geo/index.d.ts.map +1 -0
- package/dist/esm/geo/interface.d.ts.map +1 -0
- package/dist/esm/geo/interface.js +1 -0
- package/dist/esm/geo/lineString.d.ts +1 -1
- package/dist/esm/geo/lineString.d.ts.map +1 -0
- package/dist/esm/geo/lineString.js +3 -3
- package/dist/esm/geo/multiLineString.d.ts +1 -1
- package/dist/esm/geo/multiLineString.d.ts.map +1 -0
- package/dist/esm/geo/multiLineString.js +3 -3
- package/dist/esm/geo/multiPoint.d.ts +1 -1
- package/dist/esm/geo/multiPoint.d.ts.map +1 -0
- package/dist/esm/geo/multiPoint.js +3 -3
- package/dist/esm/geo/multiPolygon.d.ts +1 -1
- package/dist/esm/geo/multiPolygon.d.ts.map +1 -0
- package/dist/esm/geo/multiPolygon.js +3 -3
- package/dist/esm/geo/point.d.ts +1 -1
- package/dist/esm/geo/point.d.ts.map +1 -0
- package/dist/esm/geo/point.js +2 -2
- package/dist/esm/geo/polygon.d.ts +1 -1
- package/dist/esm/geo/polygon.d.ts.map +1 -0
- package/dist/esm/geo/polygon.js +4 -4
- package/dist/esm/helper/symbol.d.ts.map +1 -0
- package/dist/esm/index.d.ts +9 -2
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +15 -1
- package/dist/esm/lib/util.d.ts.map +1 -0
- package/dist/esm/lib/util.js +1 -2
- package/dist/esm/operator-map.d.ts.map +1 -0
- package/dist/esm/query.d.ts.map +1 -0
- package/dist/esm/query.js +4 -4
- package/dist/esm/regexp/index.d.ts +1 -1
- package/dist/esm/regexp/index.d.ts.map +1 -0
- package/dist/esm/regexp/index.js +1 -1
- package/dist/esm/serializer/common.d.ts +2 -2
- package/dist/esm/serializer/common.d.ts.map +1 -0
- package/dist/esm/serializer/common.js +15 -10
- package/dist/esm/serializer/datatype.d.ts +2 -2
- package/dist/esm/serializer/datatype.d.ts.map +1 -0
- package/dist/esm/serializer/datatype.js +12 -7
- package/dist/esm/serializer/query.d.ts +1 -1
- package/dist/esm/serializer/query.d.ts.map +1 -0
- package/dist/esm/serializer/query.js +2 -2
- package/dist/esm/serializer/update.d.ts +1 -1
- package/dist/esm/serializer/update.d.ts.map +1 -0
- package/dist/esm/serverDate/index.d.ts +1 -1
- package/dist/esm/serverDate/index.d.ts.map +1 -0
- package/dist/esm/serverDate/index.js +2 -2
- package/dist/esm/transaction/collection.d.ts +1 -1
- package/dist/esm/transaction/collection.d.ts.map +1 -0
- package/dist/esm/transaction/collection.js +4 -2
- package/dist/esm/transaction/document.d.ts +1 -1
- package/dist/esm/transaction/document.d.ts.map +1 -0
- package/dist/esm/transaction/document.js +2 -3
- package/dist/esm/transaction/index.d.ts.map +1 -0
- package/dist/esm/transaction/index.js +2 -2
- package/dist/esm/transaction/query.d.ts.map +1 -0
- package/dist/esm/typings/index.d.ts +3 -3
- package/dist/esm/typings/index.d.ts.map +1 -0
- package/dist/esm/typings/index.js +1 -0
- package/dist/esm/typings/realtime.d.ts +16 -16
- package/dist/esm/typings/realtime.d.ts.map +1 -0
- package/dist/esm/typings/realtime.js +1 -0
- package/dist/esm/util.d.ts.map +1 -0
- package/dist/esm/utils/error.d.ts +2 -1
- package/dist/esm/utils/error.d.ts.map +1 -0
- package/dist/esm/utils/error.js +7 -5
- package/dist/esm/utils/msg.d.ts.map +1 -0
- package/dist/esm/utils/symbol.d.ts.map +1 -0
- package/dist/esm/utils/symbol.js +4 -4
- package/dist/esm/utils/type.d.ts +1 -1
- package/dist/esm/utils/type.d.ts.map +1 -0
- package/dist/esm/utils/utils.d.ts.map +1 -0
- package/dist/esm/utils/utils.js +1 -1
- package/dist/esm/validate.d.ts.map +1 -0
- package/jest.config.js +14 -0
- package/package.json +9 -4
- package/src/aggregate.ts +1 -1
- package/src/document.ts +1 -1
- package/src/index.ts +40 -4
- package/src/lib/util.ts +1 -2
- package/src/query.ts +4 -4
- package/src/transaction/index.ts +1 -1
- package/src/utils/utils.ts +1 -1
- package/tests/index.test.ts +111 -0
- package/tsconfig.esm.json +2 -1
- package/tsconfig.json +14 -5
- package/tsconfig.test.json +15 -0
- package/.trunk/configs/.markdownlint.yaml +0 -10
- package/.trunk/trunk.yaml +0 -26
package/dist/esm/utils/symbol.js
CHANGED
|
@@ -2,10 +2,12 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
2
2
|
var extendStatics = function (d, b) {
|
|
3
3
|
extendStatics = Object.setPrototypeOf ||
|
|
4
4
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
-
function (d, b) { for (var p in b) if (
|
|
5
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
6
|
return extendStatics(d, b);
|
|
7
7
|
};
|
|
8
8
|
return function (d, b) {
|
|
9
|
+
if (typeof b !== "function" && b !== null)
|
|
10
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
9
11
|
extendStatics(d, b);
|
|
10
12
|
function __() { this.constructor = d; }
|
|
11
13
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
@@ -29,12 +31,10 @@ var HiddenSymbol = (function () {
|
|
|
29
31
|
var InternalSymbol = (function (_super) {
|
|
30
32
|
__extends(InternalSymbol, _super);
|
|
31
33
|
function InternalSymbol(target, __mark__) {
|
|
32
|
-
var _this = this;
|
|
33
34
|
if (__mark__ !== __internalMark__) {
|
|
34
35
|
throw new TypeError('InternalSymbol cannot be constructed with new operator');
|
|
35
36
|
}
|
|
36
|
-
|
|
37
|
-
return _this;
|
|
37
|
+
return _super.call(this, target) || this;
|
|
38
38
|
}
|
|
39
39
|
InternalSymbol.for = function (target) {
|
|
40
40
|
for (var i = 0, len = _symbols.length; i < len; i++) {
|
package/dist/esm/utils/type.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export declare const isObject: <T extends object>(x: any) => x is T;
|
|
|
3
3
|
export declare const isString: (x: any) => x is string;
|
|
4
4
|
export declare const isNumber: (x: any) => x is number;
|
|
5
5
|
export declare const isPromise: <T extends Promise<any> = Promise<any>>(x: any) => x is T;
|
|
6
|
-
|
|
6
|
+
type AnyFn = (...args: any[]) => any;
|
|
7
7
|
export declare const isFunction: <T extends AnyFn = AnyFn>(x: any) => x is T;
|
|
8
8
|
export declare const isArray: <T extends any[] = any[]>(x: any) => x is T;
|
|
9
9
|
export declare const isDate: (x: any) => x is Date;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../../src/utils/type.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,OAAO,oBAAmF,CAAA;AAEvG,eAAO,MAAM,QAAQ,sCAAgE,CAAA;AAErF,eAAO,MAAM,QAAQ,yBAAmD,CAAA;AAExE,eAAO,MAAM,QAAQ,yBAAmD,CAAA;AAExE,eAAO,MAAM,SAAS,2DAAsF,CAAA;AAE5G,aAAK,KAAK,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAA;AACpC,eAAO,MAAM,UAAU,6CAAuE,CAAA;AAE9F,eAAO,MAAM,OAAO,6CAA+D,CAAA;AAEnF,eAAO,MAAM,MAAM,uBAA+C,CAAA;AAElE,eAAO,MAAM,QAAQ,yBAAmD,CAAA;AAExE,eAAO,MAAM,gBAAgB,qBAAwE,CAAA;AAErG,eAAO,MAAM,aAAa,6BASzB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/utils/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,KAAK,CAAC;AAEzB,eAAO,MAAM,KAAK,mCAA0D,CAAA;AAI5E,eAAO,MAAM,SAAS,6BAKrB,CAAA;AAMD,wBAAgB,aAAa,CAAC,EAAE,EAAE,EAAE,OAoBnC"}
|
package/dist/esm/utils/utils.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/validate.ts"],"names":[],"mappings":""}
|
package/jest.config.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
preset: 'ts-jest',
|
|
3
|
+
testEnvironment: 'node',
|
|
4
|
+
testMatch: ['**/tests/**/*.ts'],
|
|
5
|
+
moduleFileExtensions: ['ts', 'js'],
|
|
6
|
+
transform: {
|
|
7
|
+
'^.+\\.ts$': ['ts-jest', {
|
|
8
|
+
tsconfig: 'tsconfig.test.json'
|
|
9
|
+
}]
|
|
10
|
+
},
|
|
11
|
+
transformIgnorePatterns: [
|
|
12
|
+
'/node_modules/(?!@types)/'
|
|
13
|
+
]
|
|
14
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/database",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0-alpha.0",
|
|
4
4
|
"description": "database for (node.)js sdk ",
|
|
5
5
|
"main": "dist/commonjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -10,22 +10,27 @@
|
|
|
10
10
|
"scripts": {
|
|
11
11
|
"eslint": "eslint \"./**/*.ts\"",
|
|
12
12
|
"eslint-fix": "eslint --fix \"./**/*.ts\"",
|
|
13
|
-
"test": "
|
|
13
|
+
"test": "jest",
|
|
14
14
|
"build": "tsc -p tsconfig.json && tsc -p tsconfig.esm.json",
|
|
15
15
|
"prepublishOnly": "npm run build"
|
|
16
16
|
},
|
|
17
17
|
"author": "",
|
|
18
18
|
"license": "ISC",
|
|
19
19
|
"devDependencies": {
|
|
20
|
+
"@types/jest": "26.0.24",
|
|
21
|
+
"@types/node": "14.14.31",
|
|
20
22
|
"eslint": "^5.15.3",
|
|
21
23
|
"eslint-config-prettier": "^4.1.0",
|
|
22
24
|
"eslint-plugin-prettier": "^3.0.1",
|
|
23
25
|
"eslint-plugin-typescript": "^0.14.0",
|
|
24
|
-
"
|
|
26
|
+
"jest": "26.6.3",
|
|
27
|
+
"ts-jest": "26.5.6",
|
|
28
|
+
"typescript": "^4.1.0",
|
|
25
29
|
"typescript-eslint-parser": "^22.0.0"
|
|
26
30
|
},
|
|
27
31
|
"sideEffects": false,
|
|
28
32
|
"dependencies": {
|
|
29
33
|
"bson": "^4.0.2"
|
|
30
|
-
}
|
|
34
|
+
},
|
|
35
|
+
"packageManager": "yarn@1.22.22"
|
|
31
36
|
}
|
package/src/aggregate.ts
CHANGED
package/src/document.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -9,6 +9,20 @@ import { LogicCommand } from './commands/logic'
|
|
|
9
9
|
import { QueryCommand } from './commands/query'
|
|
10
10
|
import { UpdateCommand } from './commands/update'
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* 数据库配置接口
|
|
14
|
+
*/
|
|
15
|
+
export interface IDbConfig {
|
|
16
|
+
/** 数据库环境 ID */
|
|
17
|
+
env?: string;
|
|
18
|
+
/** 实例 ID(可选) */
|
|
19
|
+
instance?: string;
|
|
20
|
+
/** 数据库名称(可选) */
|
|
21
|
+
database?: string;
|
|
22
|
+
/** 可能的其他配置属性(用于扩展) */
|
|
23
|
+
[key: string]: any;
|
|
24
|
+
}
|
|
25
|
+
|
|
12
26
|
/**
|
|
13
27
|
* 地理位置类型
|
|
14
28
|
*/
|
|
@@ -55,9 +69,9 @@ export class Db {
|
|
|
55
69
|
*
|
|
56
70
|
* 默认是 `default` 数据库,为今后扩展使用
|
|
57
71
|
*
|
|
58
|
-
* @param config
|
|
72
|
+
* @param config - 数据库配置
|
|
59
73
|
*/
|
|
60
|
-
config:
|
|
74
|
+
config: IDbConfig
|
|
61
75
|
|
|
62
76
|
static ws: any
|
|
63
77
|
|
|
@@ -78,7 +92,29 @@ export class Db {
|
|
|
78
92
|
// 应用签名信息,由jssdk传入
|
|
79
93
|
static appSecretInfo: any
|
|
80
94
|
|
|
81
|
-
|
|
95
|
+
// 创建请求实例的包装方法,自动添加instance和database参数
|
|
96
|
+
static createRequest(config: IDbConfig): any {
|
|
97
|
+
const request = new Db.reqClass(config)
|
|
98
|
+
const originalSend = request.send
|
|
99
|
+
|
|
100
|
+
// 包装send方法,自动添加instance和database参数
|
|
101
|
+
request.send = function(action: string, data: any): any {
|
|
102
|
+
// 如果配置中包含instance或database参数,添加到请求数据中
|
|
103
|
+
if (config.instance) {
|
|
104
|
+
data.instance = config.instance
|
|
105
|
+
}
|
|
106
|
+
if (config.database) {
|
|
107
|
+
data.database = config.database
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// 调用原始的send方法
|
|
111
|
+
return originalSend.call(this, action, data)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return request
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
constructor(config?: IDbConfig) {
|
|
82
118
|
this.config = config
|
|
83
119
|
this.Geo = Geo
|
|
84
120
|
this.serverDate = ServerDateConstructor
|
|
@@ -109,7 +145,7 @@ export class Db {
|
|
|
109
145
|
* 创建集合
|
|
110
146
|
*/
|
|
111
147
|
createCollection(collName: string) {
|
|
112
|
-
let request =
|
|
148
|
+
let request = Db.createRequest(this.config)
|
|
113
149
|
|
|
114
150
|
const params = {
|
|
115
151
|
collectionName: collName
|
package/src/lib/util.ts
CHANGED
package/src/query.ts
CHANGED
|
@@ -144,7 +144,7 @@ export class Query {
|
|
|
144
144
|
// this._wsURL = "ws://localhost:3000"
|
|
145
145
|
|
|
146
146
|
/* eslint-disable new-cap */
|
|
147
|
-
this._request =
|
|
147
|
+
this._request = Db.createRequest(this._db.config)
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
/**
|
|
@@ -204,9 +204,9 @@ export class Query {
|
|
|
204
204
|
data: documents,
|
|
205
205
|
requestId: res.requestId
|
|
206
206
|
}
|
|
207
|
-
if (res.total) result.total = res.total
|
|
208
|
-
if (res.limit) result.limit = res.limit
|
|
209
|
-
if (res.offset) result.offset = res.offset
|
|
207
|
+
if (res.total !== undefined) result.total = res.total
|
|
208
|
+
if (res.limit !== undefined) result.limit = res.limit
|
|
209
|
+
if (res.offset !== undefined) result.offset = res.offset
|
|
210
210
|
callback(0, result)
|
|
211
211
|
}
|
|
212
212
|
})
|
package/src/transaction/index.ts
CHANGED
package/src/utils/utils.ts
CHANGED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { Db } from '../src/index'
|
|
2
|
+
|
|
3
|
+
describe('数据库请求参数测试', function() {
|
|
4
|
+
// 模拟请求类,用于捕获和验证请求参数
|
|
5
|
+
class MockRequest {
|
|
6
|
+
private config: any;
|
|
7
|
+
|
|
8
|
+
constructor(config: any) {
|
|
9
|
+
this.config = config;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async send(action: string, data: any) {
|
|
13
|
+
// 验证 instance 和 database 参数是否正确传递
|
|
14
|
+
if (this.config.instance) {
|
|
15
|
+
expect(data).toHaveProperty('instance', this.config.instance);
|
|
16
|
+
}
|
|
17
|
+
if (this.config.database) {
|
|
18
|
+
expect(data).toHaveProperty('database', this.config.database);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// 返回符合各操作期望的数据结构
|
|
22
|
+
switch (action) {
|
|
23
|
+
case 'database.queryDocument':
|
|
24
|
+
return {
|
|
25
|
+
data: {
|
|
26
|
+
list: [
|
|
27
|
+
{ _id: 'doc1', name: '测试文档1', value: 100 },
|
|
28
|
+
{ _id: 'doc2', name: '测试文档2', value: 200 }
|
|
29
|
+
]
|
|
30
|
+
},
|
|
31
|
+
requestId: 'mock-request-id-123456',
|
|
32
|
+
total: 2,
|
|
33
|
+
limit: 100,
|
|
34
|
+
offset: 0
|
|
35
|
+
};
|
|
36
|
+
default:
|
|
37
|
+
return { data: { ok: 1 } };
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// 测试配置
|
|
43
|
+
const testConfig = {
|
|
44
|
+
env: 'test-env',
|
|
45
|
+
instance: 'test-instance',
|
|
46
|
+
database: 'test-database'
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// 在每个测试前配置
|
|
50
|
+
beforeEach(function() {
|
|
51
|
+
Db.reqClass = MockRequest;
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('集合查询操作应包含 instance 和 database 参数', async function() {
|
|
55
|
+
const db = new Db(testConfig);
|
|
56
|
+
const coll = db.collection('test-collection');
|
|
57
|
+
await coll.where({}).get();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('集合添加操作应包含 instance 和 database 参数', async function() {
|
|
61
|
+
const db = new Db(testConfig);
|
|
62
|
+
const coll = db.collection('test-collection');
|
|
63
|
+
await coll.add({ name: '新文档', value: 300 });
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('文档更新操作应包含 instance 和 database 参数', async function() {
|
|
67
|
+
const db = new Db(testConfig);
|
|
68
|
+
const coll = db.collection('test-collection');
|
|
69
|
+
const doc = coll.doc('doc1');
|
|
70
|
+
await doc.update({ value: 150 });
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('聚合操作应包含 instance 和 database 参数', async function() {
|
|
74
|
+
const db = new Db(testConfig);
|
|
75
|
+
const coll = db.collection('test-collection');
|
|
76
|
+
const aggregate = coll
|
|
77
|
+
.aggregate()
|
|
78
|
+
.match({ value: { $gt: 50 } })
|
|
79
|
+
.group({ _id: null, total: { $sum: '$value' } });
|
|
80
|
+
await aggregate.end();
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('创建集合操作应包含 instance 和 database 参数', async function() {
|
|
84
|
+
const db = new Db(testConfig);
|
|
85
|
+
await db.createCollection('new-collection');
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('应支持 const res = await db.collection(\'xxx\').get() 方式调用', async function() {
|
|
89
|
+
const db = new Db(testConfig);
|
|
90
|
+
const coll = db.collection('test-collection');
|
|
91
|
+
|
|
92
|
+
// 测试直接调用 get() 而不传递 where 条件
|
|
93
|
+
const res = await coll.get();
|
|
94
|
+
console.log(res)
|
|
95
|
+
|
|
96
|
+
// 验证返回结果的结构
|
|
97
|
+
expect(res).toHaveProperty('data');
|
|
98
|
+
expect(res).toHaveProperty('requestId');
|
|
99
|
+
expect(res).toHaveProperty('total');
|
|
100
|
+
expect(res).toHaveProperty('limit');
|
|
101
|
+
expect(res).toHaveProperty('offset');
|
|
102
|
+
|
|
103
|
+
// 验证返回的数据
|
|
104
|
+
expect(Array.isArray(res.data)).toBe(true);
|
|
105
|
+
expect(res.data.length).toBe(2);
|
|
106
|
+
expect(res.data[0]).toHaveProperty('_id', 'doc1');
|
|
107
|
+
expect(res.data[0]).toHaveProperty('name', '测试文档1');
|
|
108
|
+
expect(res.data[1]).toHaveProperty('_id', 'doc2');
|
|
109
|
+
expect(res.data[1]).toHaveProperty('name', '测试文档2');
|
|
110
|
+
});
|
|
111
|
+
});
|
package/tsconfig.esm.json
CHANGED
package/tsconfig.json
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
"allowJs": false,
|
|
5
5
|
"allowUnreachableCode": false,
|
|
6
6
|
"allowUnusedLabels": false,
|
|
7
|
-
"charset": "utf8",
|
|
8
7
|
"declaration": true,
|
|
9
8
|
"experimentalDecorators": true,
|
|
10
9
|
"emitDecoratorMetadata": true,
|
|
@@ -24,8 +23,18 @@
|
|
|
24
23
|
"downlevelIteration": true,
|
|
25
24
|
"skipLibCheck": true,
|
|
26
25
|
"target": "es5",
|
|
27
|
-
"lib": [
|
|
26
|
+
"lib": [
|
|
27
|
+
"es2015",
|
|
28
|
+
"es6",
|
|
29
|
+
"dom"
|
|
30
|
+
]
|
|
28
31
|
},
|
|
29
|
-
"include": [
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
"include": [
|
|
33
|
+
"src/**/*"
|
|
34
|
+
],
|
|
35
|
+
"exclude": [
|
|
36
|
+
"node_modules",
|
|
37
|
+
"test",
|
|
38
|
+
"tests"
|
|
39
|
+
]
|
|
40
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"target": "es6",
|
|
5
|
+
"module": "commonjs",
|
|
6
|
+
"isolatedModules": true,
|
|
7
|
+
"skipLibCheck": true,
|
|
8
|
+
"strict": false,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"moduleResolution": "node",
|
|
11
|
+
"allowJs": true
|
|
12
|
+
},
|
|
13
|
+
"include": ["tests/**/*.ts", "src/**/*.ts"],
|
|
14
|
+
"exclude": ["node_modules"]
|
|
15
|
+
}
|
package/.trunk/trunk.yaml
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
version: 0.1
|
|
2
|
-
cli:
|
|
3
|
-
version: 1.4.1
|
|
4
|
-
plugins:
|
|
5
|
-
sources:
|
|
6
|
-
- id: trunk
|
|
7
|
-
ref: v0.0.10
|
|
8
|
-
uri: https://github.com/trunk-io/plugins
|
|
9
|
-
lint:
|
|
10
|
-
enabled:
|
|
11
|
-
- eslint@8.33.0
|
|
12
|
-
- markdownlint@0.33.0
|
|
13
|
-
- git-diff-check
|
|
14
|
-
- gitleaks@8.15.3
|
|
15
|
-
- prettier@2.8.4
|
|
16
|
-
runtimes:
|
|
17
|
-
enabled:
|
|
18
|
-
- go@1.18.3
|
|
19
|
-
- node@18.12.1
|
|
20
|
-
actions:
|
|
21
|
-
disabled:
|
|
22
|
-
- trunk-announce
|
|
23
|
-
- trunk-check-pre-push
|
|
24
|
-
- trunk-fmt-pre-commit
|
|
25
|
-
enabled:
|
|
26
|
-
- trunk-upgrade-available
|