@cloudbase/oauth 0.1.1-alpha → 0.1.1-alpha.2
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/Dockerfile +15 -0
- package/README.md +1 -1
- package/_exmaple/assets/scripts/function/function.ts +99 -0
- package/_exmaple/assets/scripts/index.ts +99 -0
- package/_exmaple/assets/scripts/request.ts +11 -0
- package/_exmaple/index.html +15 -0
- package/_exmaple/package.json +33 -0
- package/_exmaple/tsconfig.json +71 -0
- package/_exmaple/typings.d.ts +0 -0
- package/_exmaple/webpack.config.js +42 -0
- package/cdnjs/1.0.0/cloudbase.auth.js +1 -0
- package/cdnjs/1.0.0/cloudbase.database.js +8 -0
- package/cdnjs/1.0.0/cloudbase.full.js +8 -0
- package/cdnjs/1.0.0/cloudbase.functions.js +1 -0
- package/cdnjs/1.0.0/cloudbase.js +1 -0
- package/cdnjs/1.0.0/cloudbase.storage.js +1 -0
- package/cdnjs/1.0.1/cloudbase.auth.js +1 -0
- package/cdnjs/1.0.1/cloudbase.database.js +8 -0
- package/cdnjs/1.0.1/cloudbase.full.js +8 -0
- package/cdnjs/1.0.1/cloudbase.functions.js +1 -0
- package/cdnjs/1.0.1/cloudbase.js +1 -0
- package/cdnjs/1.0.1/cloudbase.storage.js +1 -0
- package/cdnjs/1.0.2/cloudbase.auth.js +1 -0
- package/cdnjs/1.0.2/cloudbase.database.js +8 -0
- package/cdnjs/1.0.2/cloudbase.full.js +8 -0
- package/cdnjs/1.0.2/cloudbase.functions.js +1 -0
- package/cdnjs/1.0.2/cloudbase.js +1 -0
- package/cdnjs/1.0.2/cloudbase.storage.js +1 -0
- package/cdnjs/1.0.3/cloudbase.auth.js +1 -0
- package/cdnjs/1.0.3/cloudbase.database.js +8 -0
- package/cdnjs/1.0.3/cloudbase.full.js +8 -0
- package/cdnjs/1.0.3/cloudbase.functions.js +1 -0
- package/cdnjs/1.0.3/cloudbase.js +1 -0
- package/cdnjs/1.0.3/cloudbase.storage.js +1 -0
- package/cdnjs/1.0.4/cloudbase.auth.js +1 -0
- package/cdnjs/1.0.4/cloudbase.database.js +8 -0
- package/cdnjs/1.0.4/cloudbase.full.js +8 -0
- package/cdnjs/1.0.4/cloudbase.functions.js +1 -0
- package/cdnjs/1.0.4/cloudbase.js +1 -0
- package/cdnjs/1.0.4/cloudbase.storage.js +1 -0
- package/cdnjs/1.1.0/cloudbase.auth.js +1 -0
- package/cdnjs/1.1.0/cloudbase.database.js +8 -0
- package/cdnjs/1.1.0/cloudbase.full.js +8 -0
- package/cdnjs/1.1.0/cloudbase.functions.js +1 -0
- package/cdnjs/1.1.0/cloudbase.js +1 -0
- package/cdnjs/1.1.0/cloudbase.storage.js +1 -0
- package/cdnjs/1.1.1/cloudbase.auth.js +1 -0
- package/cdnjs/1.1.1/cloudbase.database.js +8 -0
- package/cdnjs/1.1.1/cloudbase.full.js +8 -0
- package/cdnjs/1.1.1/cloudbase.functions.js +1 -0
- package/cdnjs/1.1.1/cloudbase.js +1 -0
- package/cdnjs/1.1.1/cloudbase.storage.js +1 -0
- package/cdnjs/1.1.2/cloudbase.auth.js +1 -0
- package/cdnjs/1.1.2/cloudbase.database.js +8 -0
- package/cdnjs/1.1.2/cloudbase.full.js +8 -0
- package/cdnjs/1.1.2/cloudbase.functions.js +1 -0
- package/cdnjs/1.1.2/cloudbase.js +1 -0
- package/cdnjs/1.1.2/cloudbase.storage.js +1 -0
- package/cdnjs/1.1.3/cloudbase.auth.js +1 -0
- package/cdnjs/1.1.3/cloudbase.database.js +8 -0
- package/cdnjs/1.1.3/cloudbase.full.js +8 -0
- package/cdnjs/1.1.3/cloudbase.functions.js +1 -0
- package/cdnjs/1.1.3/cloudbase.js +1 -0
- package/cdnjs/1.1.3/cloudbase.storage.js +1 -0
- package/cdnjs/1.1.4/cloudbase.auth.js +1 -0
- package/cdnjs/1.1.4/cloudbase.database.js +8 -0
- package/cdnjs/1.1.4/cloudbase.full.js +8 -0
- package/cdnjs/1.1.4/cloudbase.functions.js +1 -0
- package/cdnjs/1.1.4/cloudbase.js +1 -0
- package/cdnjs/1.1.4/cloudbase.storage.js +1 -0
- package/cdnjs/1.2.1/cloudbase.auth.js +1 -0
- package/cdnjs/1.2.1/cloudbase.database.js +8 -0
- package/cdnjs/1.2.1/cloudbase.full.js +8 -0
- package/cdnjs/1.2.1/cloudbase.functions.js +1 -0
- package/cdnjs/1.2.1/cloudbase.js +1 -0
- package/cdnjs/1.2.1/cloudbase.storage.js +1 -0
- package/cdnjs/1.2.2/cloudbase.auth.js +1 -0
- package/cdnjs/1.2.2/cloudbase.database.js +8 -0
- package/cdnjs/1.2.2/cloudbase.full.js +8 -0
- package/cdnjs/1.2.2/cloudbase.functions.js +1 -0
- package/cdnjs/1.2.2/cloudbase.js +1 -0
- package/cdnjs/1.2.2/cloudbase.storage.js +1 -0
- package/cdnjs/1.2.3/cloudbase.auth.js +1 -0
- package/cdnjs/1.2.3/cloudbase.database.js +8 -0
- package/cdnjs/1.2.3/cloudbase.full.js +8 -0
- package/cdnjs/1.2.3/cloudbase.functions.js +1 -0
- package/cdnjs/1.2.3/cloudbase.js +1 -0
- package/cdnjs/1.2.3/cloudbase.storage.js +1 -0
- package/cdnjs/1.3.0/cloudbase.auth.js +1 -0
- package/cdnjs/1.3.0/cloudbase.database.js +8 -0
- package/cdnjs/1.3.0/cloudbase.full.js +8 -0
- package/cdnjs/1.3.0/cloudbase.functions.js +1 -0
- package/cdnjs/1.3.0/cloudbase.js +1 -0
- package/cdnjs/1.3.0/cloudbase.realtime.js +1 -0
- package/cdnjs/1.3.0/cloudbase.storage.js +1 -0
- package/cdnjs/1.3.1/cloudbase.auth.js +1 -0
- package/cdnjs/1.3.1/cloudbase.database.js +8 -0
- package/cdnjs/1.3.1/cloudbase.full.js +8 -0
- package/cdnjs/1.3.1/cloudbase.functions.js +1 -0
- package/cdnjs/1.3.1/cloudbase.js +1 -0
- package/cdnjs/1.3.1/cloudbase.realtime.js +1 -0
- package/cdnjs/1.3.1/cloudbase.storage.js +1 -0
- package/cdnjs/1.3.2/cloudbase.auth.js +1 -0
- package/cdnjs/1.3.2/cloudbase.database.js +8 -0
- package/cdnjs/1.3.2/cloudbase.full.js +8 -0
- package/cdnjs/1.3.2/cloudbase.functions.js +1 -0
- package/cdnjs/1.3.2/cloudbase.js +1 -0
- package/cdnjs/1.3.2/cloudbase.realtime.js +1 -0
- package/cdnjs/1.3.2/cloudbase.storage.js +1 -0
- package/cdnjs/1.3.3/cloudbase.auth.js +1 -0
- package/cdnjs/1.3.3/cloudbase.database.js +8 -0
- package/cdnjs/1.3.3/cloudbase.full.js +8 -0
- package/cdnjs/1.3.3/cloudbase.functions.js +1 -0
- package/cdnjs/1.3.3/cloudbase.js +1 -0
- package/cdnjs/1.3.3/cloudbase.realtime.js +1 -0
- package/cdnjs/1.3.3/cloudbase.storage.js +1 -0
- package/cdnjs/1.3.4-alpha.0/cloudbase.auth.js +1 -0
- package/cdnjs/1.3.4-alpha.0/cloudbase.database.js +8 -0
- package/cdnjs/1.3.4-alpha.0/cloudbase.full.js +8 -0
- package/cdnjs/1.3.4-alpha.0/cloudbase.functions.js +1 -0
- package/cdnjs/1.3.4-alpha.0/cloudbase.js +1 -0
- package/cdnjs/1.3.4-alpha.0/cloudbase.realtime.js +1 -0
- package/cdnjs/1.3.4-alpha.0/cloudbase.storage.js +1 -0
- package/cdnjs/1.3.5/cloudbase.analytics.js +1 -0
- package/cdnjs/1.3.5/cloudbase.auth.js +1 -0
- package/cdnjs/1.3.5/cloudbase.database.js +10 -0
- package/cdnjs/1.3.5/cloudbase.full.js +10 -0
- package/cdnjs/1.3.5/cloudbase.functions.js +1 -0
- package/cdnjs/1.3.5/cloudbase.js +1 -0
- package/cdnjs/1.3.5/cloudbase.realtime.js +1 -0
- package/cdnjs/1.3.5/cloudbase.storage.js +1 -0
- package/cdnjs/1.3.5-alpha.0/cloudbase.auth.js +1 -0
- package/cdnjs/1.3.5-alpha.0/cloudbase.database.js +10 -0
- package/cdnjs/1.3.5-alpha.0/cloudbase.full.js +10 -0
- package/cdnjs/1.3.5-alpha.0/cloudbase.functions.js +1 -0
- package/cdnjs/1.3.5-alpha.0/cloudbase.js +1 -0
- package/cdnjs/1.3.5-alpha.0/cloudbase.realtime.js +1 -0
- package/cdnjs/1.3.5-alpha.0/cloudbase.storage.js +1 -0
- package/cdnjs/1.4.0/cloudbase.analytics.js +1 -0
- package/cdnjs/1.4.0/cloudbase.auth.js +1 -0
- package/cdnjs/1.4.0/cloudbase.database.js +10 -0
- package/cdnjs/1.4.0/cloudbase.full.js +10 -0
- package/cdnjs/1.4.0/cloudbase.functions.js +1 -0
- package/cdnjs/1.4.0/cloudbase.js +1 -0
- package/cdnjs/1.4.0/cloudbase.realtime.js +1 -0
- package/cdnjs/1.4.0/cloudbase.storage.js +1 -0
- package/cdnjs/1.4.1/cloudbase.analytics.js +1 -0
- package/cdnjs/1.4.1/cloudbase.auth.js +1 -0
- package/cdnjs/1.4.1/cloudbase.database.js +10 -0
- package/cdnjs/1.4.1/cloudbase.full.js +10 -0
- package/cdnjs/1.4.1/cloudbase.functions.js +1 -0
- package/cdnjs/1.4.1/cloudbase.js +1 -0
- package/cdnjs/1.4.1/cloudbase.realtime.js +1 -0
- package/cdnjs/1.4.1/cloudbase.storage.js +1 -0
- package/cdnjs/1.4.1-alpha.0/cloudbase.analytics.js +1 -0
- package/cdnjs/1.4.1-alpha.0/cloudbase.auth.js +1 -0
- package/cdnjs/1.4.1-alpha.0/cloudbase.database.js +10 -0
- package/cdnjs/1.4.1-alpha.0/cloudbase.full.js +10 -0
- package/cdnjs/1.4.1-alpha.0/cloudbase.functions.js +1 -0
- package/cdnjs/1.4.1-alpha.0/cloudbase.js +1 -0
- package/cdnjs/1.4.1-alpha.0/cloudbase.realtime.js +1 -0
- package/cdnjs/1.4.1-alpha.0/cloudbase.storage.js +1 -0
- package/cdnjs/1.4.2-alpha.0/cloudbase.analytics.js +1 -0
- package/cdnjs/1.4.2-alpha.0/cloudbase.auth.js +1 -0
- package/cdnjs/1.4.2-alpha.0/cloudbase.database.js +10 -0
- package/cdnjs/1.4.2-alpha.0/cloudbase.full.js +10 -0
- package/cdnjs/1.4.2-alpha.0/cloudbase.functions.js +1 -0
- package/cdnjs/1.4.2-alpha.0/cloudbase.js +1 -0
- package/cdnjs/1.4.2-alpha.0/cloudbase.realtime.js +1 -0
- package/cdnjs/1.4.2-alpha.0/cloudbase.storage.js +1 -0
- package/cdnjs/1.5.0/cloudbase.analytics.js +1 -0
- package/cdnjs/1.5.0/cloudbase.auth.js +1 -0
- package/cdnjs/1.5.0/cloudbase.database.js +10 -0
- package/cdnjs/1.5.0/cloudbase.full.js +10 -0
- package/cdnjs/1.5.0/cloudbase.functions.js +1 -0
- package/cdnjs/1.5.0/cloudbase.js +1 -0
- package/cdnjs/1.5.0/cloudbase.realtime.js +1 -0
- package/cdnjs/1.5.0/cloudbase.storage.js +1 -0
- package/cdnjs/1.5.1/cloudbase.analytics.js +1 -0
- package/cdnjs/1.5.1/cloudbase.auth.js +1 -0
- package/cdnjs/1.5.1/cloudbase.database.js +26 -0
- package/cdnjs/1.5.1/cloudbase.full.js +26 -0
- package/cdnjs/1.5.1/cloudbase.functions.js +1 -0
- package/cdnjs/1.5.1/cloudbase.js +1 -0
- package/cdnjs/1.5.1/cloudbase.realtime.js +1 -0
- package/cdnjs/1.5.1/cloudbase.storage.js +1 -0
- package/cdnjs/1.5.1-alpha.0/cloudbase.analytics.js +1 -0
- package/cdnjs/1.5.1-alpha.0/cloudbase.auth.js +1 -0
- package/cdnjs/1.5.1-alpha.0/cloudbase.database.js +10 -0
- package/cdnjs/1.5.1-alpha.0/cloudbase.full.js +10 -0
- package/cdnjs/1.5.1-alpha.0/cloudbase.functions.js +1 -0
- package/cdnjs/1.5.1-alpha.0/cloudbase.js +1 -0
- package/cdnjs/1.5.1-alpha.0/cloudbase.realtime.js +1 -0
- package/cdnjs/1.5.1-alpha.0/cloudbase.storage.js +1 -0
- package/cdnjs/1.5.3-alpha.0/cloudbase.analytics.js +1 -0
- package/cdnjs/1.5.3-alpha.0/cloudbase.auth.js +1 -0
- package/cdnjs/1.5.3-alpha.0/cloudbase.database.js +26 -0
- package/cdnjs/1.5.3-alpha.0/cloudbase.full.js +26 -0
- package/cdnjs/1.5.3-alpha.0/cloudbase.functions.js +1 -0
- package/cdnjs/1.5.3-alpha.0/cloudbase.js +1 -0
- package/cdnjs/1.5.3-alpha.0/cloudbase.realtime.js +1 -0
- package/cdnjs/1.5.3-alpha.0/cloudbase.storage.js +1 -0
- package/cdnjs/1.6.0/cloudbase.analytics.js +1 -0
- package/cdnjs/1.6.0/cloudbase.auth.js +1 -0
- package/cdnjs/1.6.0/cloudbase.database.js +26 -0
- package/cdnjs/1.6.0/cloudbase.full.js +26 -0
- package/cdnjs/1.6.0/cloudbase.functions.js +1 -0
- package/cdnjs/1.6.0/cloudbase.js +1 -0
- package/cdnjs/1.6.0/cloudbase.realtime.js +1 -0
- package/cdnjs/1.6.0/cloudbase.storage.js +1 -0
- package/{CHANGELOG.md → changelog.md} +0 -0
- package/dist/README.md +153 -0
- package/{app → dist/app}/index.d.ts +1 -0
- package/{app → dist/app}/index.js +0 -0
- package/dist/app/index.js.map +1 -0
- package/{app → dist/app}/internal.d.ts +0 -0
- package/{app → dist/app}/internal.js +0 -0
- package/{app → dist/app}/internal.js.map +0 -0
- package/{app → dist/app}/openuri.d.ts +0 -0
- package/{app → dist/app}/openuri.js +2 -1
- package/{app → dist/app}/openuri.js.map +1 -1
- package/{app → dist/app}/request.d.ts +4 -3
- package/{app → dist/app}/request.js +20 -12
- package/dist/app/request.js.map +1 -0
- package/{app → dist/app}/storage.d.ts +0 -0
- package/{app → dist/app}/storage.js +0 -0
- package/{app → dist/app}/storage.js.map +0 -0
- package/{auth → dist/auth}/consts.d.ts +21 -4
- package/{auth → dist/auth}/consts.js +27 -5
- package/dist/auth/consts.js.map +1 -0
- package/{auth → dist/auth}/index.d.ts +83 -34
- package/{auth → dist/auth}/index.js +239 -92
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/models.d.ts +284 -0
- package/{oauthclient → dist/auth}/models.js +1 -0
- package/dist/auth/models.js.map +1 -0
- package/{captcha → dist/captcha}/index.d.ts +0 -0
- package/{captcha → dist/captcha}/index.js +4 -2
- package/dist/captcha/index.js.map +1 -0
- package/dist/changelog.md +30 -0
- package/dist/function/index.d.ts +38 -0
- package/dist/function/index.js +80 -0
- package/dist/function/index.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/{oauthclient → dist/oauthclient}/consts.d.ts +0 -0
- package/{oauthclient → dist/oauthclient}/consts.js +0 -0
- package/{oauthclient → dist/oauthclient}/consts.js.map +0 -0
- package/{oauthclient → dist/oauthclient}/index.d.ts +0 -0
- package/{oauthclient → dist/oauthclient}/index.js +2 -2
- package/dist/oauthclient/index.js.map +1 -0
- package/{oauthclient → dist/oauthclient}/interface.d.ts +4 -0
- package/{oauthclient → dist/oauthclient}/interface.js +0 -0
- package/{oauthclient → dist/oauthclient}/interface.js.map +1 -1
- package/{oauthclient → dist/oauthclient}/models.d.ts +12 -11
- package/{auth → dist/oauthclient}/models.js +0 -0
- package/{oauthclient → dist/oauthclient}/models.js.map +0 -0
- package/{oauthclient → dist/oauthclient}/oauthclient.d.ts +11 -7
- package/{oauthclient → dist/oauthclient}/oauthclient.js +27 -12
- package/dist/oauthclient/oauthclient.js.map +1 -0
- package/dist/package.json +32 -0
- package/{utils/single-promise.d.ts → dist/utils/promise.d.ts} +3 -3
- package/{utils/single-promise.js → dist/utils/promise.js} +6 -6
- package/dist/utils/promise.js.map +1 -0
- package/{utils → dist/utils}/uuid.d.ts +0 -0
- package/{utils → dist/utils}/uuid.js +0 -0
- package/{utils → dist/utils}/uuid.js.map +0 -0
- package/docs/dev.md +71 -0
- package/docs/errlog.md +79 -0
- package/package.json +3 -2
- package/publish.sh +2 -0
- package/src/app/index.ts +83 -0
- package/src/app/internal.ts +26 -0
- package/src/app/openuri.ts +111 -0
- package/src/app/request.ts +66 -0
- package/src/app/storage.ts +58 -0
- package/src/auth/consts.ts +74 -0
- package/src/auth/index.ts +718 -0
- package/src/auth/models.ts +352 -0
- package/src/captcha/index.ts +170 -0
- package/src/function/index.ts +103 -0
- package/src/index.ts +32 -0
- package/src/oauthclient/consts.ts +48 -0
- package/src/oauthclient/index.ts +33 -0
- package/src/oauthclient/interface.ts +34 -0
- package/src/oauthclient/models.ts +50 -0
- package/src/oauthclient/oauthclient.ts +487 -0
- package/src/utils/promise.ts +41 -0
- package/src/utils/uuid.ts +11 -0
- package/test/e2e/cases/custom-login.test.js +122 -0
- package/test/e2e/cases/index.test.js +61 -0
- package/test/e2e/cases/login-state.test.js +89 -0
- package/test/e2e/environment.js +39 -0
- package/test/e2e/global_setup.js +33 -0
- package/test/e2e/global_teardown.js +15 -0
- package/test/e2e/setup.js +37 -0
- package/test/unit/index.test.js +89 -0
- package/test/web/cases/auth/index.js +256 -0
- package/test/web/cases/database/collection.js +173 -0
- package/test/web/cases/database/command.js +754 -0
- package/test/web/cases/database/date.js +122 -0
- package/test/web/cases/database/db.js +20 -0
- package/test/web/cases/database/document.js +160 -0
- package/test/web/cases/database/geo-advanced.js +327 -0
- package/test/web/cases/database/geo.js +105 -0
- package/test/web/cases/database/index.js +315 -0
- package/test/web/cases/database/order.js +83 -0
- package/test/web/cases/database/realtime.js +102 -0
- package/test/web/cases/database/regex.js +140 -0
- package/test/web/cases/ext/index.js +88 -0
- package/test/web/cases/function/index.js +77 -0
- package/test/web/cases/storage/cos.jpeg +0 -0
- package/test/web/cases/storage/index.js +207 -0
- package/test/web/index.html +63 -0
- package/test/web/index.js +109 -0
- package/test/web/util.js +80 -0
- package/tsconfig.json +35 -0
- package/wiki/README.md +75 -0
- package/app/index.js.map +0 -1
- package/app/request.js.map +0 -1
- package/auth/consts.js.map +0 -1
- package/auth/index.js.map +0 -1
- package/auth/models.d.ts +0 -158
- package/auth/models.js.map +0 -1
- package/captcha/index.js.map +0 -1
- package/index.d.ts +0 -8
- package/index.js +0 -17
- package/index.js.map +0 -1
- package/oauthclient/index.js.map +0 -1
- package/oauthclient/oauthclient.js.map +0 -1
- package/utils/single-promise.js.map +0 -1
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import * as assert from 'power-assert';
|
|
2
|
+
import { callbackWithTryCatch, catchCallback, isSuccess } from '../../util';
|
|
3
|
+
import * as util from 'util';
|
|
4
|
+
import { registerCase } from '.';
|
|
5
|
+
|
|
6
|
+
export function registerDate(app, collName) {
|
|
7
|
+
const db = app.database();
|
|
8
|
+
const collection = db.collection(collName);
|
|
9
|
+
// const nameList = ["f", "b", "e", "d", "a", "c"];
|
|
10
|
+
|
|
11
|
+
registerCase('database date: CRUD', async () => {
|
|
12
|
+
const date = new Date();
|
|
13
|
+
const offset = 60 * 1000;
|
|
14
|
+
const timestamp = Math.floor(Number(new Date()) / 1000);
|
|
15
|
+
const initialData = {
|
|
16
|
+
name: 'test',
|
|
17
|
+
date,
|
|
18
|
+
// eslint-disable-next-line
|
|
19
|
+
serverDate1: new db.serverDate(),
|
|
20
|
+
serverDate2: db.serverDate({ offset }),
|
|
21
|
+
timestamp: {
|
|
22
|
+
$timestamp: timestamp
|
|
23
|
+
},
|
|
24
|
+
foo: {
|
|
25
|
+
bar: db.serverDate({ offset })
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
await new Promise(async resolve => {
|
|
30
|
+
try {
|
|
31
|
+
// Create
|
|
32
|
+
const res = await collection.add(initialData).catch(callbackWithTryCatch(err => {
|
|
33
|
+
assert(false, { err });
|
|
34
|
+
}, () => {
|
|
35
|
+
resolve();
|
|
36
|
+
}));
|
|
37
|
+
assert(isSuccess(0, res) && res.id, { res });
|
|
38
|
+
assert(isSuccess(0, res) && res.requestId, { res });
|
|
39
|
+
|
|
40
|
+
// Read
|
|
41
|
+
const { id } = res;
|
|
42
|
+
let result = await collection.where({
|
|
43
|
+
_id: id
|
|
44
|
+
}).get().catch(callbackWithTryCatch(err => {
|
|
45
|
+
assert(false, { err });
|
|
46
|
+
}, () => {
|
|
47
|
+
resolve();
|
|
48
|
+
}));
|
|
49
|
+
assert.strictEqual(result.data[0].date.getTime(), date.getTime());
|
|
50
|
+
assert(util.isDate(result.data[0].foo.bar));
|
|
51
|
+
assert.strictEqual(assert.strictEqual(result.data[0].serverDate1.getDate(), date.getDate()));
|
|
52
|
+
assert.strictEqual(result.data[0].serverDate1.getTime() + offset, result.data[0].serverDate2.getTime());
|
|
53
|
+
assert.strictEqual(result.data[0].timestamp.getTime(), timestamp * 1000);
|
|
54
|
+
|
|
55
|
+
result = await collection.where({
|
|
56
|
+
date: db.command.eq(date)
|
|
57
|
+
}).get().catch(callbackWithTryCatch(err => {
|
|
58
|
+
assert(false, { err });
|
|
59
|
+
}, () => {
|
|
60
|
+
resolve();
|
|
61
|
+
}));
|
|
62
|
+
assert.strictEqual(result.data[0].date.getTime(), date.getTime());
|
|
63
|
+
|
|
64
|
+
result = await collection.where({
|
|
65
|
+
date: db.command.lte(date)
|
|
66
|
+
}).get().catch(callbackWithTryCatch(err => {
|
|
67
|
+
assert(false, { err });
|
|
68
|
+
}, () => {
|
|
69
|
+
resolve();
|
|
70
|
+
}));
|
|
71
|
+
assert(result.data.length > 0);
|
|
72
|
+
|
|
73
|
+
result = await collection.where({
|
|
74
|
+
date: db.command.lte(date).and(db.command.gte(date))
|
|
75
|
+
}).get().catch(callbackWithTryCatch(err => {
|
|
76
|
+
assert(false, { err });
|
|
77
|
+
}, () => {
|
|
78
|
+
resolve();
|
|
79
|
+
}));
|
|
80
|
+
assert(result.data.length > 0);
|
|
81
|
+
|
|
82
|
+
// Update
|
|
83
|
+
const newDate = new Date();
|
|
84
|
+
// eslint-disable-next-line
|
|
85
|
+
const newServerDate = new db.serverDate({ offset: 1000 * 60 * 60 }); // offset一小时
|
|
86
|
+
result = await collection.where({
|
|
87
|
+
date: db.command.lte(date).and(db.command.gte(date))
|
|
88
|
+
}).update({
|
|
89
|
+
date: newDate,
|
|
90
|
+
serverDate2: newServerDate
|
|
91
|
+
}).catch(callbackWithTryCatch(err => {
|
|
92
|
+
assert(false, { err });
|
|
93
|
+
}, () => {
|
|
94
|
+
resolve();
|
|
95
|
+
}));
|
|
96
|
+
assert.strictEqual(result.updated, 1);
|
|
97
|
+
|
|
98
|
+
result = await collection.where({
|
|
99
|
+
_id: id
|
|
100
|
+
}).get().catch(callbackWithTryCatch(err => {
|
|
101
|
+
assert(false, { err });
|
|
102
|
+
}, () => {
|
|
103
|
+
resolve();
|
|
104
|
+
}));
|
|
105
|
+
assert.strictEqual(result.data[0].date.getTime(), newDate.getTime());
|
|
106
|
+
assert(result.data[0].serverDate2.getTime() - result.data[0].serverDate1.getTime() > 1000 * 60 * 60);
|
|
107
|
+
|
|
108
|
+
// Delete
|
|
109
|
+
const deleteRes = await collection.doc(id).remove().catch(callbackWithTryCatch(err => {
|
|
110
|
+
assert(false, { err });
|
|
111
|
+
}, () => {
|
|
112
|
+
resolve();
|
|
113
|
+
}));
|
|
114
|
+
assert(deleteRes.deleted === 1, { res: deleteRes });
|
|
115
|
+
} catch (e) {
|
|
116
|
+
catchCallback(e);
|
|
117
|
+
} finally {
|
|
118
|
+
resolve();
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// database db
|
|
2
|
+
import * as assert from 'power-assert';
|
|
3
|
+
import { registerCase } from '.';
|
|
4
|
+
|
|
5
|
+
export function registerDb(app, collName) {
|
|
6
|
+
const db = app.database();
|
|
7
|
+
|
|
8
|
+
registerCase('database db: get collection reference', () => {
|
|
9
|
+
const collection = db.collection(collName);
|
|
10
|
+
assert(collection.name === collName);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
registerCase('database db: Error: get collection without collection name', () => {
|
|
14
|
+
try {
|
|
15
|
+
db.collection();
|
|
16
|
+
} catch (e) {
|
|
17
|
+
assert(e.message === 'Collection name is required');
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import * as assert from 'power-assert';
|
|
2
|
+
import { callbackWithTryCatch, catchCallback, isSuccess } from '../../util';
|
|
3
|
+
import { Util } from '@cloudbase/database/dist/esm/util';
|
|
4
|
+
import { registerCase } from '.';
|
|
5
|
+
|
|
6
|
+
export function registerDocument(app, collName) {
|
|
7
|
+
const docIDGenerated = Util.generateDocId();
|
|
8
|
+
const db = app.database();
|
|
9
|
+
const _ = db.command;
|
|
10
|
+
const collection = db.collection(collName);
|
|
11
|
+
|
|
12
|
+
registerCase('database document: docID test', () => {
|
|
13
|
+
const document = collection.doc(docIDGenerated);
|
|
14
|
+
assert(document.id === docIDGenerated);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
registerCase('database document: API - set data in empty document', async () => {
|
|
18
|
+
await new Promise(async resolve => {
|
|
19
|
+
try {
|
|
20
|
+
const document = collection.doc(docIDGenerated);
|
|
21
|
+
await document.set({
|
|
22
|
+
name: 'jude'
|
|
23
|
+
}).catch(callbackWithTryCatch(err => {
|
|
24
|
+
assert(false, { err });
|
|
25
|
+
}));
|
|
26
|
+
|
|
27
|
+
let res = await collection.where({
|
|
28
|
+
name: _.eq('jude')
|
|
29
|
+
}).get().catch(callbackWithTryCatch(err => {
|
|
30
|
+
assert(false, { err });
|
|
31
|
+
}, () => {
|
|
32
|
+
resolve();
|
|
33
|
+
}));
|
|
34
|
+
assert(isSuccess(0, res) && Array.isArray(res.data));
|
|
35
|
+
|
|
36
|
+
res = await collection.where({
|
|
37
|
+
name: _.eq('jude')
|
|
38
|
+
}).remove().catch(callbackWithTryCatch(err => {
|
|
39
|
+
assert(false, { err });
|
|
40
|
+
}, () => {
|
|
41
|
+
resolve();
|
|
42
|
+
}));
|
|
43
|
+
assert(isSuccess(0, res) && res.deleted >= 1, { res });
|
|
44
|
+
} catch (e) {
|
|
45
|
+
catchCallback(e);
|
|
46
|
+
} finally {
|
|
47
|
+
resolve();
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
registerCase('database document: API - set data in document existed', async () => {
|
|
53
|
+
await new Promise(async resolve => {
|
|
54
|
+
try {
|
|
55
|
+
let res = await collection.add({ data: 'test' }).catch(callbackWithTryCatch(err => {
|
|
56
|
+
assert(false, { err });
|
|
57
|
+
}, () => {
|
|
58
|
+
resolve();
|
|
59
|
+
}));
|
|
60
|
+
assert(isSuccess(0, res) && res.id, { res });
|
|
61
|
+
|
|
62
|
+
const documents = await collection.limit(1).get().catch(callbackWithTryCatch(err => {
|
|
63
|
+
assert(false, { err });
|
|
64
|
+
}, () => {
|
|
65
|
+
resolve();
|
|
66
|
+
}));
|
|
67
|
+
const docId = documents.data[0]._id;
|
|
68
|
+
|
|
69
|
+
res = await collection.doc(docId).set({
|
|
70
|
+
data: { type: 'set' }
|
|
71
|
+
}).catch(callbackWithTryCatch(err => {
|
|
72
|
+
assert(false, { err });
|
|
73
|
+
}, () => {
|
|
74
|
+
resolve();
|
|
75
|
+
}));
|
|
76
|
+
assert(isSuccess(0, res) && res.updated === 1, { res });
|
|
77
|
+
|
|
78
|
+
res = await collection.doc(docId).set({
|
|
79
|
+
data: { arr: [1, 2, 3], foo: 123 },
|
|
80
|
+
array: [0, 0, 0]
|
|
81
|
+
}).catch(callbackWithTryCatch(err => {
|
|
82
|
+
assert(false, { err });
|
|
83
|
+
}, () => {
|
|
84
|
+
resolve();
|
|
85
|
+
}));
|
|
86
|
+
assert(isSuccess(0, res) && res.updated === 1, { res });
|
|
87
|
+
|
|
88
|
+
res = await collection.doc(docId).update({
|
|
89
|
+
data: { arr: db.command.push([4, 5, 6]), foo: db.command.inc(1) },
|
|
90
|
+
array: db.command.pop()
|
|
91
|
+
}).catch(callbackWithTryCatch(err => {
|
|
92
|
+
assert(false, { err });
|
|
93
|
+
}, () => {
|
|
94
|
+
resolve();
|
|
95
|
+
}));
|
|
96
|
+
assert(isSuccess(0, res) && res.updated === 1, { res });
|
|
97
|
+
|
|
98
|
+
res = await collection.doc(docId).remove().catch(callbackWithTryCatch(err => {
|
|
99
|
+
assert(false, { err });
|
|
100
|
+
}, () => {
|
|
101
|
+
resolve();
|
|
102
|
+
}));
|
|
103
|
+
assert(isSuccess(0, res) && res.deleted >= 1, { res });
|
|
104
|
+
} catch (e) {
|
|
105
|
+
catchCallback(e);
|
|
106
|
+
} finally {
|
|
107
|
+
resolve();
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
registerCase('database document: API - remove document that not exist', async () => {
|
|
113
|
+
await new Promise(async resolve => {
|
|
114
|
+
try {
|
|
115
|
+
const document = collection.doc(docIDGenerated);
|
|
116
|
+
const res = await document.remove().catch(callbackWithTryCatch(err => {
|
|
117
|
+
assert(false, { err });
|
|
118
|
+
}, () => {
|
|
119
|
+
resolve();
|
|
120
|
+
}));
|
|
121
|
+
assert(isSuccess(0, res) && !res.deleted, { res });
|
|
122
|
+
} catch (e) {
|
|
123
|
+
catchCallback(e);
|
|
124
|
+
} finally {
|
|
125
|
+
resolve();
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
registerCase('database document: API - remove document should success', async () => {
|
|
131
|
+
await new Promise(async resolve => {
|
|
132
|
+
try {
|
|
133
|
+
let res = await collection.add({ data: 'test' }).catch(callbackWithTryCatch(err => {
|
|
134
|
+
assert(false, { err });
|
|
135
|
+
}, () => {
|
|
136
|
+
resolve();
|
|
137
|
+
}));
|
|
138
|
+
assert(isSuccess(0, res) && res.id, { res });
|
|
139
|
+
|
|
140
|
+
const documents = await collection.get().catch(callbackWithTryCatch(err => {
|
|
141
|
+
assert(false, { err });
|
|
142
|
+
}, () => {
|
|
143
|
+
resolve();
|
|
144
|
+
}));
|
|
145
|
+
const docId = documents.data[0]._id;
|
|
146
|
+
|
|
147
|
+
res = await collection.doc(docId).remove().catch(callbackWithTryCatch(err => {
|
|
148
|
+
assert(false, { err });
|
|
149
|
+
}, () => {
|
|
150
|
+
resolve();
|
|
151
|
+
}));
|
|
152
|
+
assert(isSuccess(0, res) && res.deleted >= 1, { res });
|
|
153
|
+
} catch (e) {
|
|
154
|
+
catchCallback(e);
|
|
155
|
+
} finally {
|
|
156
|
+
resolve();
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
}
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import * as assert from 'power-assert';
|
|
2
|
+
import { catchCallback, isSuccess, callbackWithTryCatch } from '../../util';
|
|
3
|
+
import { registerCase } from '.';
|
|
4
|
+
|
|
5
|
+
export function registerGeoAdvanced(app, collName) {
|
|
6
|
+
const db = app.database();
|
|
7
|
+
const collection = db.collection(collName);
|
|
8
|
+
|
|
9
|
+
const { Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon } = db.Geo;
|
|
10
|
+
function randomPoint() {
|
|
11
|
+
return new Point(180 - 360 * Math.random(), 90 - 180 * Math.random());
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const geoNearPoint = new Point(0, 0);
|
|
15
|
+
const line = new LineString([randomPoint(), randomPoint()]);
|
|
16
|
+
|
|
17
|
+
// “回”字的外环
|
|
18
|
+
const point1 = new Point(-2, -2);
|
|
19
|
+
const point2 = new Point(2, -2);
|
|
20
|
+
const point3 = new Point(2, 2);
|
|
21
|
+
const point4 = new Point(-2, 2);
|
|
22
|
+
// “回”字的内环
|
|
23
|
+
const point5 = new Point(-1, -1);
|
|
24
|
+
const point6 = new Point(1, -1);
|
|
25
|
+
const point7 = new Point(1, 1);
|
|
26
|
+
const point8 = new Point(-1, 1);
|
|
27
|
+
const polygon = new Polygon([
|
|
28
|
+
new LineString([point1, point2, point3, point4, point1]),
|
|
29
|
+
new LineString([point5, point6, point7, point8, point5])
|
|
30
|
+
]);
|
|
31
|
+
|
|
32
|
+
const multiPoint = new MultiPoint([randomPoint(), randomPoint(), randomPoint(), randomPoint()]);
|
|
33
|
+
const multiLineString = new MultiLineString([
|
|
34
|
+
new LineString([randomPoint(), randomPoint()]),
|
|
35
|
+
new LineString([randomPoint(), randomPoint()]),
|
|
36
|
+
new LineString([randomPoint(), randomPoint()]),
|
|
37
|
+
new LineString([randomPoint(), randomPoint()])
|
|
38
|
+
]);
|
|
39
|
+
const multiPolygon = new MultiPolygon([
|
|
40
|
+
new Polygon([new LineString([point1, point2, point3, point4, point1])]),
|
|
41
|
+
new Polygon([new LineString([point5, point6, point7, point8, point5])])
|
|
42
|
+
]);
|
|
43
|
+
|
|
44
|
+
const initialData = {
|
|
45
|
+
point: randomPoint(),
|
|
46
|
+
geoNearPoint,
|
|
47
|
+
line,
|
|
48
|
+
polygon,
|
|
49
|
+
multiPoint,
|
|
50
|
+
multiLineString,
|
|
51
|
+
multiPolygon
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
registerCase('database geo: GEO Advanced - CRUD', async () => {
|
|
55
|
+
await new Promise(async resolve => {
|
|
56
|
+
try {
|
|
57
|
+
// Create
|
|
58
|
+
let res = await collection.add(initialData).catch(
|
|
59
|
+
callbackWithTryCatch(
|
|
60
|
+
err => {
|
|
61
|
+
assert(false, { err });
|
|
62
|
+
},
|
|
63
|
+
() => {
|
|
64
|
+
resolve();
|
|
65
|
+
}
|
|
66
|
+
)
|
|
67
|
+
);
|
|
68
|
+
assert(isSuccess(0, res) && res.id, { res });
|
|
69
|
+
assert(isSuccess(0, res) && res.requestId, { res });
|
|
70
|
+
|
|
71
|
+
// Read
|
|
72
|
+
const readRes = await collection
|
|
73
|
+
.where({
|
|
74
|
+
_id: res.id
|
|
75
|
+
})
|
|
76
|
+
.get()
|
|
77
|
+
.catch(
|
|
78
|
+
callbackWithTryCatch(
|
|
79
|
+
err => {
|
|
80
|
+
assert(false, { err });
|
|
81
|
+
},
|
|
82
|
+
() => {
|
|
83
|
+
resolve();
|
|
84
|
+
}
|
|
85
|
+
)
|
|
86
|
+
);
|
|
87
|
+
assert(isSuccess(0, readRes) && readRes.data.length > 0, { readRes });
|
|
88
|
+
const data = readRes.data[0];
|
|
89
|
+
|
|
90
|
+
assert(data.point instanceof Point);
|
|
91
|
+
assert(data.line instanceof LineString);
|
|
92
|
+
assert(data.polygon instanceof Polygon);
|
|
93
|
+
assert(data.multiPoint instanceof MultiPoint);
|
|
94
|
+
assert(data.multiLineString instanceof MultiLineString);
|
|
95
|
+
assert(data.multiPolygon instanceof MultiPolygon);
|
|
96
|
+
|
|
97
|
+
assert.deepStrictEqual(data.point, initialData.point);
|
|
98
|
+
assert.deepStrictEqual(data.line, line);
|
|
99
|
+
assert.deepStrictEqual(data.polygon, polygon);
|
|
100
|
+
assert.deepStrictEqual(data.multiPoint, multiPoint);
|
|
101
|
+
assert.deepStrictEqual(data.multiLineString, multiLineString);
|
|
102
|
+
assert.deepStrictEqual(data.multiPolygon, multiPolygon);
|
|
103
|
+
|
|
104
|
+
// Update
|
|
105
|
+
let result = await collection
|
|
106
|
+
.doc(res.id)
|
|
107
|
+
.set(initialData)
|
|
108
|
+
.catch(
|
|
109
|
+
callbackWithTryCatch(
|
|
110
|
+
err => {
|
|
111
|
+
assert(false, { err });
|
|
112
|
+
},
|
|
113
|
+
() => {
|
|
114
|
+
resolve();
|
|
115
|
+
}
|
|
116
|
+
)
|
|
117
|
+
);
|
|
118
|
+
assert(isSuccess(0, result) && result.requestId, { result });
|
|
119
|
+
assert.strictEqual(result.updated, 1);
|
|
120
|
+
|
|
121
|
+
// Delete
|
|
122
|
+
const deleteRes = await collection
|
|
123
|
+
.where({
|
|
124
|
+
_id: res.id
|
|
125
|
+
})
|
|
126
|
+
.remove()
|
|
127
|
+
.catch(
|
|
128
|
+
callbackWithTryCatch(
|
|
129
|
+
err => {
|
|
130
|
+
assert(false, { err });
|
|
131
|
+
},
|
|
132
|
+
() => {
|
|
133
|
+
resolve();
|
|
134
|
+
}
|
|
135
|
+
)
|
|
136
|
+
);
|
|
137
|
+
assert(isSuccess(0, deleteRes) && deleteRes.deleted >= 1, { deleteRes });
|
|
138
|
+
} catch (e) {
|
|
139
|
+
catchCallback(e);
|
|
140
|
+
} finally {
|
|
141
|
+
resolve();
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
registerCase('database geo: GEO - bad create', async () => {
|
|
147
|
+
await new Promise(async resolve => {
|
|
148
|
+
try {
|
|
149
|
+
// bad Point
|
|
150
|
+
assert.throws(() => new Point());
|
|
151
|
+
assert.throws(() => new Point([], {}));
|
|
152
|
+
|
|
153
|
+
// bad LineString
|
|
154
|
+
assert.throws(() => new LineString({}));
|
|
155
|
+
assert.throws(() => new LineString([]));
|
|
156
|
+
assert.throws(() => new LineString([123, []]));
|
|
157
|
+
|
|
158
|
+
// bad Polygon
|
|
159
|
+
assert.throws(() => new Polygon(null));
|
|
160
|
+
assert.throws(() => new Polygon([]));
|
|
161
|
+
assert.throws(() => new Polygon([666, 789]));
|
|
162
|
+
assert.throws(
|
|
163
|
+
() => new Polygon([new LineString([point1, point2, point3, point4, point8])])
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
// bad MultiPoint
|
|
167
|
+
assert.throws(() => new MultiPoint({}));
|
|
168
|
+
assert.throws(() => new MultiPoint([]));
|
|
169
|
+
assert.throws(() => new MultiPoint([{}, {}]));
|
|
170
|
+
|
|
171
|
+
// bad MultiLineString
|
|
172
|
+
assert.throws(() => new MultiLineString({}));
|
|
173
|
+
assert.throws(() => new MultiLineString([]));
|
|
174
|
+
assert.throws(() => new MultiLineString([123, null]));
|
|
175
|
+
|
|
176
|
+
// bad MultiPolygon
|
|
177
|
+
assert.throws(() => new MultiPolygon(123));
|
|
178
|
+
assert.throws(() => new MultiPolygon([]));
|
|
179
|
+
assert.throws(() => new MultiPolygon([666, 666]));
|
|
180
|
+
} catch (e) {
|
|
181
|
+
catchCallback(e);
|
|
182
|
+
} finally {
|
|
183
|
+
resolve();
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
registerCase('database geo: GEO - geoNear', async () => {
|
|
189
|
+
await new Promise(async resolve => {
|
|
190
|
+
try {
|
|
191
|
+
// Create
|
|
192
|
+
const geoPoint = new Point(22, 33);
|
|
193
|
+
const res = await collection
|
|
194
|
+
.add({
|
|
195
|
+
...initialData,
|
|
196
|
+
point: geoPoint
|
|
197
|
+
})
|
|
198
|
+
.catch(
|
|
199
|
+
callbackWithTryCatch(
|
|
200
|
+
err => {
|
|
201
|
+
assert(false, { err });
|
|
202
|
+
},
|
|
203
|
+
() => {
|
|
204
|
+
resolve();
|
|
205
|
+
}
|
|
206
|
+
)
|
|
207
|
+
);
|
|
208
|
+
assert(isSuccess(0, res) && res.id, { res });
|
|
209
|
+
assert(res.requestId);
|
|
210
|
+
|
|
211
|
+
// Read
|
|
212
|
+
const readRes = await collection
|
|
213
|
+
.where({
|
|
214
|
+
point: db.command.geoNear({
|
|
215
|
+
geometry: geoPoint,
|
|
216
|
+
maxDistance: 1,
|
|
217
|
+
minDistance: 0
|
|
218
|
+
})
|
|
219
|
+
})
|
|
220
|
+
.get()
|
|
221
|
+
.catch(
|
|
222
|
+
callbackWithTryCatch(
|
|
223
|
+
err => {
|
|
224
|
+
assert(false, { err });
|
|
225
|
+
},
|
|
226
|
+
() => {
|
|
227
|
+
resolve();
|
|
228
|
+
}
|
|
229
|
+
)
|
|
230
|
+
);
|
|
231
|
+
assert(isSuccess(0, readRes) && readRes.data.length > 0, { readRes });
|
|
232
|
+
assert.deepStrictEqual(readRes.data[0].point, geoPoint);
|
|
233
|
+
|
|
234
|
+
// Delete
|
|
235
|
+
const deleteRes = await collection
|
|
236
|
+
.where({
|
|
237
|
+
_id: res.id
|
|
238
|
+
})
|
|
239
|
+
.remove()
|
|
240
|
+
.catch(
|
|
241
|
+
callbackWithTryCatch(
|
|
242
|
+
err => {
|
|
243
|
+
assert(false, { err });
|
|
244
|
+
},
|
|
245
|
+
() => {
|
|
246
|
+
resolve();
|
|
247
|
+
}
|
|
248
|
+
)
|
|
249
|
+
);
|
|
250
|
+
assert(isSuccess(0, deleteRes) && deleteRes.deleted >= 1, { deleteRes });
|
|
251
|
+
} catch (e) {
|
|
252
|
+
catchCallback(e);
|
|
253
|
+
} finally {
|
|
254
|
+
resolve();
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
registerCase('database geo: GEO - geoWithin', async () => {
|
|
260
|
+
await new Promise(async resolve => {
|
|
261
|
+
try {
|
|
262
|
+
// Create
|
|
263
|
+
const res = await collection
|
|
264
|
+
.add({
|
|
265
|
+
...initialData,
|
|
266
|
+
point: new Point(0, 0)
|
|
267
|
+
})
|
|
268
|
+
.catch(
|
|
269
|
+
callbackWithTryCatch(
|
|
270
|
+
err => {
|
|
271
|
+
assert(false, { err });
|
|
272
|
+
},
|
|
273
|
+
() => {
|
|
274
|
+
resolve();
|
|
275
|
+
}
|
|
276
|
+
)
|
|
277
|
+
);
|
|
278
|
+
assert(isSuccess(0, res) && res.id, { res });
|
|
279
|
+
|
|
280
|
+
// Read
|
|
281
|
+
const readRes = await collection
|
|
282
|
+
.where({
|
|
283
|
+
point: db.command.geoWithin({
|
|
284
|
+
geometry: new Polygon([new LineString([point1, point2, point3, point4, point1])])
|
|
285
|
+
})
|
|
286
|
+
})
|
|
287
|
+
.get()
|
|
288
|
+
.catch(
|
|
289
|
+
callbackWithTryCatch(
|
|
290
|
+
err => {
|
|
291
|
+
assert(false, { err });
|
|
292
|
+
},
|
|
293
|
+
() => {
|
|
294
|
+
resolve();
|
|
295
|
+
}
|
|
296
|
+
)
|
|
297
|
+
);
|
|
298
|
+
assert(isSuccess(0, readRes) && readRes.data.length > 0, { readRes });
|
|
299
|
+
assert.deepStrictEqual(readRes.data[0].point, new Point(0, 0));
|
|
300
|
+
|
|
301
|
+
// Delete
|
|
302
|
+
const deleteRes = await collection
|
|
303
|
+
.where({
|
|
304
|
+
point: db.command.geoWithin({
|
|
305
|
+
geometry: new Polygon([new LineString([point1, point2, point3, point4, point1])])
|
|
306
|
+
})
|
|
307
|
+
})
|
|
308
|
+
.remove()
|
|
309
|
+
.catch(
|
|
310
|
+
callbackWithTryCatch(
|
|
311
|
+
err => {
|
|
312
|
+
assert(false, { err });
|
|
313
|
+
},
|
|
314
|
+
() => {
|
|
315
|
+
resolve();
|
|
316
|
+
}
|
|
317
|
+
)
|
|
318
|
+
);
|
|
319
|
+
assert(isSuccess(0, deleteRes) && deleteRes.deleted >= 1, { deleteRes });
|
|
320
|
+
} catch (e) {
|
|
321
|
+
catchCallback(e);
|
|
322
|
+
} finally {
|
|
323
|
+
resolve();
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
}
|