From 228df4dadce5f45982a3f4b9d329a4eb7d62fb68 Mon Sep 17 00:00:00 2001 From: maslow Date: Tue, 19 Oct 2021 16:40:08 +0800 Subject: [PATCH] refactor(db-ql): remove deprecated classes & api(Ruler,Entry); --- packages/database-proxy/README.md | 2 +- packages/database-proxy/src/policy/index.ts | 12 +--------- packages/database-proxy/src/policy/policy.ts | 5 ++++- packages/database-proxy/src/proxy.ts | 8 +------ .../database-proxy/tests/mongo_db/add.test.js | 4 ++-- .../tests/mongo_db/count.test.js | 4 ++-- .../tests/mongo_db/dbi.test.js.js | 2 +- .../tests/mongo_db/read.test.js | 4 ++-- .../tests/mongo_db/remove.test.js | 4 ++-- .../tests/mongo_db/update.test.js | 4 ++-- .../tests/mysql_db/count.test.js | 4 ++-- .../tests/mysql_db/delete.test.js | 4 ++-- .../tests/mysql_db/insert.test.js | 4 ++-- .../tests/mysql_db/join.test.js | 4 ++-- .../tests/mysql_db/read.test.js | 4 ++-- .../tests/mysql_db/update.test.js | 4 ++-- .../data.add.constraints/condition.test.js | 4 ++-- .../data.add.constraints/default.test.js | 4 ++-- .../policy/data.add.constraints/in.test.js | 4 ++-- .../data.add.constraints/length.test.js | 4 ++-- .../policy/data.add.constraints/match.test.js | 4 ++-- .../data.add.constraints/number.test.js | 4 ++-- .../data.add.constraints/required.test.js | 4 ++-- .../units/policy/data.add.constraints/test.js | 4 ++-- .../data.replace.test.js | 4 ++-- .../data.update.constraints/default.test.js | 4 ++-- .../data.update.constraints/required.test.js | 4 ++-- .../query.constraints/condition.test.js | 4 ++-- .../policy/query.constraints/default.test.js | 4 ++-- .../units/policy/query.constraints/in.test.js | 4 ++-- .../policy/query.constraints/length.test.js | 4 ++-- .../policy/query.constraints/match.test.js | 4 ++-- .../policy/query.constraints/number.test.js | 4 ++-- .../policy/query.constraints/required.test.js | 4 ++-- .../tests/units/policy/ruler.schema.js | 6 ++--- .../tests/units/policy/ruler.test.js | 22 +++++++++---------- .../tests/units/policy/validator.join.test.js | 6 ++--- .../units/policy/validator.multi.test.js | 8 +++---- .../database-proxy/tests/units/proxy.test.js | 10 ++++----- 39 files changed, 92 insertions(+), 105 deletions(-) diff --git a/packages/database-proxy/README.md b/packages/database-proxy/README.md index 88d3d09ed8..ca35f477d7 100644 --- a/packages/database-proxy/README.md +++ b/packages/database-proxy/README.md @@ -105,7 +105,7 @@ const res = await db.collection('articles') }) ``` -更多使用参考[客户端使用文档](./packages/less-api-client-js/README.md) +更多使用参考[客户端使用文档](./packages/laf-client-sdk/README.md) ### 数据访问安全规则示例 diff --git a/packages/database-proxy/src/policy/index.ts b/packages/database-proxy/src/policy/index.ts index da224f01ff..8d7185de29 100644 --- a/packages/database-proxy/src/policy/index.ts +++ b/packages/database-proxy/src/policy/index.ts @@ -1,13 +1,3 @@ -import { Policy } from './policy' export * from './interface' - - -export { - Policy, - - /** - * Ruler 为别名,为了兼容老版本命名 - */ - Policy as Ruler -} +export * from './policy' diff --git a/packages/database-proxy/src/policy/policy.ts b/packages/database-proxy/src/policy/policy.ts index 3698f49c32..27d5686ba7 100644 --- a/packages/database-proxy/src/policy/policy.ts +++ b/packages/database-proxy/src/policy/policy.ts @@ -35,6 +35,7 @@ export enum PermissionType { REMOVE = 'remove', COUNT = 'count', WATCH = 'watch', + AGGREGATE = 'aggregate' } // 数据库规则 @@ -382,6 +383,8 @@ export class Policy implements PolicyInterface { return PermissionType.ADD case ActionType.READ: return PermissionType.READ + case ActionType.AGGREGATE: + return PermissionType.AGGREGATE case ActionType.UPDATE: return PermissionType.UPDATE case ActionType.REMOVE: @@ -390,7 +393,7 @@ export class Policy implements PolicyInterface { return PermissionType.COUNT default: - throw new Error('getPermissionName() unknow action') + throw new Error('getPermissionName() unknown action') } } } \ No newline at end of file diff --git a/packages/database-proxy/src/proxy.ts b/packages/database-proxy/src/proxy.ts index 7d416445f8..12e2e700f7 100644 --- a/packages/database-proxy/src/proxy.ts +++ b/packages/database-proxy/src/proxy.ts @@ -116,10 +116,4 @@ export class Proxy { return params } -} - - -/** - * Proxy 的别名,为了兼容老版本命名 - */ -export class Entry extends Proxy { } \ No newline at end of file +} \ No newline at end of file diff --git a/packages/database-proxy/tests/mongo_db/add.test.js b/packages/database-proxy/tests/mongo_db/add.test.js index 6ee615946f..b346ff7b64 100644 --- a/packages/database-proxy/tests/mongo_db/add.test.js +++ b/packages/database-proxy/tests/mongo_db/add.test.js @@ -1,5 +1,5 @@ const assert = require('assert') -const { Entry, MongoAccessor, ActionType } = require('../../dist') +const { Proxy, MongoAccessor, ActionType } = require('../../dist') const { dbconfig } = require('./_db') @@ -13,7 +13,7 @@ describe('Database add', function () { this.timeout(10000) const accessor = new MongoAccessor(dbconfig.dbName, dbconfig.url, dbconfig.connSettings) - let entry = new Entry(accessor) + let entry = new Proxy(accessor) let coll = null before(async () => { diff --git a/packages/database-proxy/tests/mongo_db/count.test.js b/packages/database-proxy/tests/mongo_db/count.test.js index b6d80391a3..3a1e30ad8b 100644 --- a/packages/database-proxy/tests/mongo_db/count.test.js +++ b/packages/database-proxy/tests/mongo_db/count.test.js @@ -1,5 +1,5 @@ const assert = require('assert') -const { Entry, MongoAccessor, ActionType } = require('../../dist') +const { Proxy, MongoAccessor, ActionType } = require('../../dist') const { dbconfig } = require('./_db') const TEST_DATA = [ @@ -12,7 +12,7 @@ describe('Database count', function () { this.timeout(10000) const accessor = new MongoAccessor(dbconfig.dbName, dbconfig.url, dbconfig.connSettings) - let entry = new Entry(accessor) + let entry = new Proxy(accessor) let coll = null before(async () => { diff --git a/packages/database-proxy/tests/mongo_db/dbi.test.js.js b/packages/database-proxy/tests/mongo_db/dbi.test.js.js index dd420a9ec2..3a888f3eb1 100644 --- a/packages/database-proxy/tests/mongo_db/dbi.test.js.js +++ b/packages/database-proxy/tests/mongo_db/dbi.test.js.js @@ -1,5 +1,5 @@ const assert = require('assert') -const { Entry, MongoAccessor, ActionType, getDb } = require('../../dist') +const { Proxy, MongoAccessor, ActionType, getDb } = require('../../dist') const { dbconfig } = require('./_db') diff --git a/packages/database-proxy/tests/mongo_db/read.test.js b/packages/database-proxy/tests/mongo_db/read.test.js index 9afec0519b..fb12e49307 100644 --- a/packages/database-proxy/tests/mongo_db/read.test.js +++ b/packages/database-proxy/tests/mongo_db/read.test.js @@ -1,5 +1,5 @@ const assert = require('assert') -const { Entry, MongoAccessor, ActionType, Policy } = require('../../dist') +const { Proxy, MongoAccessor, ActionType, Policy } = require('../../dist') const { dbconfig } = require('./_db') @@ -13,7 +13,7 @@ describe('Database read', function () { this.timeout(10000) const accessor = new MongoAccessor(dbconfig.dbName, dbconfig.url, dbconfig.connSettings) - let entry = new Entry(accessor, new Policy) + let entry = new Proxy(accessor, new Policy) let coll = null before(async () => { diff --git a/packages/database-proxy/tests/mongo_db/remove.test.js b/packages/database-proxy/tests/mongo_db/remove.test.js index 65262cdfd8..19ea9b48a7 100644 --- a/packages/database-proxy/tests/mongo_db/remove.test.js +++ b/packages/database-proxy/tests/mongo_db/remove.test.js @@ -1,5 +1,5 @@ const assert = require('assert') -const { Entry, MongoAccessor, ActionType } = require('../../dist') +const { Proxy, MongoAccessor, ActionType } = require('../../dist') const { dbconfig } = require('./_db') const COLL_NAME = 'test_remove' @@ -19,7 +19,7 @@ describe('Database remove', function () { this.timeout(10000) const accessor = new MongoAccessor(dbconfig.dbName, dbconfig.url, dbconfig.connSettings) - let entry = new Entry(accessor) + let entry = new Proxy(accessor) let coll = null before(async () => { diff --git a/packages/database-proxy/tests/mongo_db/update.test.js b/packages/database-proxy/tests/mongo_db/update.test.js index 7ce7644dd8..585fd14b5e 100644 --- a/packages/database-proxy/tests/mongo_db/update.test.js +++ b/packages/database-proxy/tests/mongo_db/update.test.js @@ -1,5 +1,5 @@ const assert = require('assert') -const { Entry, MongoAccessor, ActionType } = require('../../dist') +const { Proxy, MongoAccessor, ActionType } = require('../../dist') const { dbconfig } = require('./_db') const COLL_NAME = 'test_update' @@ -20,7 +20,7 @@ describe('Database update', function () { this.timeout(10000) const accessor = new MongoAccessor(dbconfig.dbName, dbconfig.url, dbconfig.connSettings) - let entry = new Entry(accessor) + let entry = new Proxy(accessor) let coll = null before(async () => { diff --git a/packages/database-proxy/tests/mysql_db/count.test.js b/packages/database-proxy/tests/mysql_db/count.test.js index 812b948f91..d67f9de642 100644 --- a/packages/database-proxy/tests/mysql_db/count.test.js +++ b/packages/database-proxy/tests/mysql_db/count.test.js @@ -1,6 +1,6 @@ const assert = require('assert') -const { MysqlAccessor, Entry, ActionType } = require('../../dist') +const { MysqlAccessor, Proxy, ActionType } = require('../../dist') const config = require('./_db') describe('Database Mysql count', function () { @@ -16,7 +16,7 @@ describe('Database Mysql count', function () { const table = 'test_table' - let entry = new Entry(accessor) + let entry = new Proxy(accessor) before(async () => { await entry.init() diff --git a/packages/database-proxy/tests/mysql_db/delete.test.js b/packages/database-proxy/tests/mysql_db/delete.test.js index 266f4214e7..8d089110c7 100644 --- a/packages/database-proxy/tests/mysql_db/delete.test.js +++ b/packages/database-proxy/tests/mysql_db/delete.test.js @@ -1,6 +1,6 @@ const assert = require('assert') -const { MysqlAccessor, Entry, ActionType } = require('../../dist') +const { MysqlAccessor, Proxy, ActionType } = require('../../dist') const config = require('./_db') describe('Database Mysql delete', function () { @@ -16,7 +16,7 @@ describe('Database Mysql delete', function () { const table = 'test_table' - let entry = new Entry(accessor) + let entry = new Proxy(accessor) before(async () => { await entry.init() diff --git a/packages/database-proxy/tests/mysql_db/insert.test.js b/packages/database-proxy/tests/mysql_db/insert.test.js index 7c95748ca0..38fe6029bb 100644 --- a/packages/database-proxy/tests/mysql_db/insert.test.js +++ b/packages/database-proxy/tests/mysql_db/insert.test.js @@ -1,6 +1,6 @@ const assert = require('assert') -const { MysqlAccessor, Entry, ActionType } = require('../../dist') +const { MysqlAccessor, Proxy, ActionType } = require('../../dist') const config = require('./_db') describe('Database Mysql add', function () { @@ -16,7 +16,7 @@ describe('Database Mysql add', function () { const table = 'test_table' - let entry = new Entry(accessor) + let entry = new Proxy(accessor) before(async () => { await entry.init() diff --git a/packages/database-proxy/tests/mysql_db/join.test.js b/packages/database-proxy/tests/mysql_db/join.test.js index 5c0ac3a073..ff51032590 100644 --- a/packages/database-proxy/tests/mysql_db/join.test.js +++ b/packages/database-proxy/tests/mysql_db/join.test.js @@ -1,6 +1,6 @@ const assert = require('assert') -const { MysqlAccessor, Entry, ActionType } = require('../../dist') +const { MysqlAccessor, Proxy, ActionType } = require('../../dist') const { SqlBuilder } = require('../../dist/accessor/sql_builder') const config = require('./_db') @@ -18,7 +18,7 @@ describe('Database Mysql join', function () { const table = 'test_tbl' const sub_table = 'test_subtbl' - let entry = new Entry(accessor) + let entry = new Proxy(accessor) before(async () => { await entry.init() diff --git a/packages/database-proxy/tests/mysql_db/read.test.js b/packages/database-proxy/tests/mysql_db/read.test.js index b833e64104..ec78d0b402 100644 --- a/packages/database-proxy/tests/mysql_db/read.test.js +++ b/packages/database-proxy/tests/mysql_db/read.test.js @@ -1,6 +1,6 @@ const assert = require('assert') -const { MysqlAccessor, Entry, ActionType } = require('../../dist') +const { MysqlAccessor, Proxy, ActionType } = require('../../dist') const config = require('./_db') describe('Database Mysql read', function () { @@ -16,7 +16,7 @@ describe('Database Mysql read', function () { const table = 'test_table' - let entry = new Entry(accessor) + let entry = new Proxy(accessor) before(async () => { await entry.init() diff --git a/packages/database-proxy/tests/mysql_db/update.test.js b/packages/database-proxy/tests/mysql_db/update.test.js index fb769b0278..aad1082544 100644 --- a/packages/database-proxy/tests/mysql_db/update.test.js +++ b/packages/database-proxy/tests/mysql_db/update.test.js @@ -1,6 +1,6 @@ const assert = require('assert') -const { MysqlAccessor, Entry, ActionType } = require('../../dist') +const { MysqlAccessor, Proxy, ActionType } = require('../../dist') const config = require('./_db') describe('Database Mysql update', function () { @@ -16,7 +16,7 @@ describe('Database Mysql update', function () { const table = 'test_table' - let entry = new Entry(accessor) + let entry = new Proxy(accessor) before(async () => { await entry.init() diff --git a/packages/database-proxy/tests/units/policy/data.add.constraints/condition.test.js b/packages/database-proxy/tests/units/policy/data.add.constraints/condition.test.js index ef220ab279..da17646785 100644 --- a/packages/database-proxy/tests/units/policy/data.add.constraints/condition.test.js +++ b/packages/database-proxy/tests/units/policy/data.add.constraints/condition.test.js @@ -1,5 +1,5 @@ const assert = require('assert') -const { Ruler } = require('../../../../dist/policy') +const { Policy } = require('../../../../dist/policy') describe('Data validator - condition', () => { const rules = { @@ -16,7 +16,7 @@ describe('Data validator - condition', () => { } } - const ruler = new Ruler() + const ruler = new Policy() ruler.load(rules) let params = { diff --git a/packages/database-proxy/tests/units/policy/data.add.constraints/default.test.js b/packages/database-proxy/tests/units/policy/data.add.constraints/default.test.js index dddfdc75db..f82c9525bf 100644 --- a/packages/database-proxy/tests/units/policy/data.add.constraints/default.test.js +++ b/packages/database-proxy/tests/units/policy/data.add.constraints/default.test.js @@ -1,5 +1,5 @@ const assert = require('assert') -const { Ruler } = require('../../../../dist/policy') +const { Policy } = require('../../../../dist/policy') @@ -16,7 +16,7 @@ describe('Data Validator - default', () => { } } - const ruler = new Ruler() + const ruler = new Policy() ruler.load(rules) let params = { diff --git a/packages/database-proxy/tests/units/policy/data.add.constraints/in.test.js b/packages/database-proxy/tests/units/policy/data.add.constraints/in.test.js index 63afc17df6..a30563c0bd 100644 --- a/packages/database-proxy/tests/units/policy/data.add.constraints/in.test.js +++ b/packages/database-proxy/tests/units/policy/data.add.constraints/in.test.js @@ -1,5 +1,5 @@ const assert = require('assert') -const { Ruler } = require('../../../../dist/policy') +const { Policy } = require('../../../../dist/policy') describe('Data Validator - in', () => { @@ -15,7 +15,7 @@ describe('Data Validator - in', () => { } } - const ruler = new Ruler() + const ruler = new Policy() ruler.load(rules) let params = { diff --git a/packages/database-proxy/tests/units/policy/data.add.constraints/length.test.js b/packages/database-proxy/tests/units/policy/data.add.constraints/length.test.js index 6049c8478e..6ffe856ca3 100644 --- a/packages/database-proxy/tests/units/policy/data.add.constraints/length.test.js +++ b/packages/database-proxy/tests/units/policy/data.add.constraints/length.test.js @@ -1,5 +1,5 @@ const assert = require('assert') -const { Ruler } = require('../../../../dist/policy') +const { Policy } = require('../../../../dist/policy') describe('Data Validator - length', () => { @@ -15,7 +15,7 @@ describe('Data Validator - length', () => { } } - const ruler = new Ruler() + const ruler = new Policy() ruler.load(rules) let params = { diff --git a/packages/database-proxy/tests/units/policy/data.add.constraints/match.test.js b/packages/database-proxy/tests/units/policy/data.add.constraints/match.test.js index 62ac7f59a0..c016d80281 100644 --- a/packages/database-proxy/tests/units/policy/data.add.constraints/match.test.js +++ b/packages/database-proxy/tests/units/policy/data.add.constraints/match.test.js @@ -1,5 +1,5 @@ const assert = require('assert') -const { Ruler } = require('../../../../dist/policy') +const { Policy } = require('../../../../dist/policy') @@ -15,7 +15,7 @@ describe('Data Validator - match', () => { } } - const ruler = new Ruler() + const ruler = new Policy() ruler.load(rules) let params = { diff --git a/packages/database-proxy/tests/units/policy/data.add.constraints/number.test.js b/packages/database-proxy/tests/units/policy/data.add.constraints/number.test.js index 86bf78b7e7..25f1ea6348 100644 --- a/packages/database-proxy/tests/units/policy/data.add.constraints/number.test.js +++ b/packages/database-proxy/tests/units/policy/data.add.constraints/number.test.js @@ -1,5 +1,5 @@ const assert = require('assert') -const { Ruler } = require('../../../../dist/policy') +const { Policy } = require('../../../../dist/policy') describe('Data Validator - number', () => { const rules = { @@ -13,7 +13,7 @@ describe('Data Validator - number', () => { } } - const ruler = new Ruler() + const ruler = new Policy() ruler.load(rules) let params = { diff --git a/packages/database-proxy/tests/units/policy/data.add.constraints/required.test.js b/packages/database-proxy/tests/units/policy/data.add.constraints/required.test.js index 311a00e98d..2aa363b91f 100644 --- a/packages/database-proxy/tests/units/policy/data.add.constraints/required.test.js +++ b/packages/database-proxy/tests/units/policy/data.add.constraints/required.test.js @@ -1,5 +1,5 @@ const assert = require('assert') -const { Ruler } = require('../../../../dist/policy') +const { Policy } = require('../../../../dist/policy') describe('Data Validator - required', () => { const rules = { @@ -15,7 +15,7 @@ describe('Data Validator - required', () => { } } - const ruler = new Ruler() + const ruler = new Policy() ruler.load(rules) let params = { diff --git a/packages/database-proxy/tests/units/policy/data.add.constraints/test.js b/packages/database-proxy/tests/units/policy/data.add.constraints/test.js index 7f0215f24b..8d319df574 100644 --- a/packages/database-proxy/tests/units/policy/data.add.constraints/test.js +++ b/packages/database-proxy/tests/units/policy/data.add.constraints/test.js @@ -1,5 +1,5 @@ const assert = require('assert') -const { Ruler } = require('../../../../dist/policy') +const { Policy } = require('../../../../dist/policy') describe('Date Validator - add', () => { const rules = { @@ -15,7 +15,7 @@ describe('Date Validator - add', () => { } } - const ruler = new Ruler() + const ruler = new Policy() ruler.load(rules) let params = { diff --git a/packages/database-proxy/tests/units/policy/data.update.constraints/data.replace.test.js b/packages/database-proxy/tests/units/policy/data.update.constraints/data.replace.test.js index c3358ce417..c368883358 100644 --- a/packages/database-proxy/tests/units/policy/data.update.constraints/data.replace.test.js +++ b/packages/database-proxy/tests/units/policy/data.update.constraints/data.replace.test.js @@ -1,5 +1,5 @@ const assert = require('assert') -const { Ruler } = require('../../../../dist') +const { Policy } = require('../../../../dist') describe('Date Validator - merge options (replace & update)', () => { const rules = { @@ -15,7 +15,7 @@ describe('Date Validator - merge options (replace & update)', () => { } } - const ruler = new Ruler() + const ruler = new Policy() ruler.load(rules) let params = { diff --git a/packages/database-proxy/tests/units/policy/data.update.constraints/default.test.js b/packages/database-proxy/tests/units/policy/data.update.constraints/default.test.js index 96a30719d4..48cc13737e 100644 --- a/packages/database-proxy/tests/units/policy/data.update.constraints/default.test.js +++ b/packages/database-proxy/tests/units/policy/data.update.constraints/default.test.js @@ -1,5 +1,5 @@ const assert = require('assert') -const { Ruler } = require('../../../../dist') +const { Policy } = require('../../../../dist') describe('Data Validator - default', () => { const rules = { @@ -15,7 +15,7 @@ describe('Data Validator - default', () => { } } - const ruler = new Ruler() + const ruler = new Policy() ruler.load(rules) let params = { diff --git a/packages/database-proxy/tests/units/policy/data.update.constraints/required.test.js b/packages/database-proxy/tests/units/policy/data.update.constraints/required.test.js index d6b03ad198..0a73656c31 100644 --- a/packages/database-proxy/tests/units/policy/data.update.constraints/required.test.js +++ b/packages/database-proxy/tests/units/policy/data.update.constraints/required.test.js @@ -1,5 +1,5 @@ const assert = require('assert') -const { Ruler } = require('../../../../dist') +const { Policy } = require('../../../../dist') describe('Data Validator - required', () => { @@ -16,7 +16,7 @@ describe('Data Validator - required', () => { } } - const ruler = new Ruler() + const ruler = new Policy() ruler.load(rules) let params = { diff --git a/packages/database-proxy/tests/units/policy/query.constraints/condition.test.js b/packages/database-proxy/tests/units/policy/query.constraints/condition.test.js index 996b2a43b1..7cf3e40469 100644 --- a/packages/database-proxy/tests/units/policy/query.constraints/condition.test.js +++ b/packages/database-proxy/tests/units/policy/query.constraints/condition.test.js @@ -1,5 +1,5 @@ const assert = require('assert') -const { Ruler } = require('../../../../dist/policy') +const { Policy } = require('../../../../dist/policy') describe('Query validator - condition', () => { const rules = { @@ -15,7 +15,7 @@ describe('Query validator - condition', () => { } } - const ruler = new Ruler() + const ruler = new Policy() ruler.load(rules) let params = { diff --git a/packages/database-proxy/tests/units/policy/query.constraints/default.test.js b/packages/database-proxy/tests/units/policy/query.constraints/default.test.js index 082ea6acaf..c1ac1d5c19 100644 --- a/packages/database-proxy/tests/units/policy/query.constraints/default.test.js +++ b/packages/database-proxy/tests/units/policy/query.constraints/default.test.js @@ -1,5 +1,5 @@ const assert = require('assert') -const { Ruler } = require('../../../../dist/policy') +const { Policy } = require('../../../../dist/policy') describe('Query Validator - default', () => { const rules = { @@ -14,7 +14,7 @@ describe('Query Validator - default', () => { } } - const ruler = new Ruler() + const ruler = new Policy() ruler.load(rules) let params = { diff --git a/packages/database-proxy/tests/units/policy/query.constraints/in.test.js b/packages/database-proxy/tests/units/policy/query.constraints/in.test.js index ed3a1df700..c6cb373548 100644 --- a/packages/database-proxy/tests/units/policy/query.constraints/in.test.js +++ b/packages/database-proxy/tests/units/policy/query.constraints/in.test.js @@ -1,5 +1,5 @@ const assert = require('assert') -const { Ruler } = require('../../../../dist/policy') +const { Policy } = require('../../../../dist/policy') describe('Query Validator - in', () => { const rules = { @@ -14,7 +14,7 @@ describe('Query Validator - in', () => { } } - const ruler = new Ruler() + const ruler = new Policy() ruler.load(rules) let params = { diff --git a/packages/database-proxy/tests/units/policy/query.constraints/length.test.js b/packages/database-proxy/tests/units/policy/query.constraints/length.test.js index 391fbcda8d..dcb6b728f0 100644 --- a/packages/database-proxy/tests/units/policy/query.constraints/length.test.js +++ b/packages/database-proxy/tests/units/policy/query.constraints/length.test.js @@ -1,5 +1,5 @@ const assert = require('assert') -const { Ruler } = require('../../../../dist/policy') +const { Policy } = require('../../../../dist/policy') describe('Query Validator - length', () => { @@ -15,7 +15,7 @@ describe('Query Validator - length', () => { } } - const ruler = new Ruler() + const ruler = new Policy() ruler.load(rules) let params = { diff --git a/packages/database-proxy/tests/units/policy/query.constraints/match.test.js b/packages/database-proxy/tests/units/policy/query.constraints/match.test.js index 2cc88be3d2..448a68d1e8 100644 --- a/packages/database-proxy/tests/units/policy/query.constraints/match.test.js +++ b/packages/database-proxy/tests/units/policy/query.constraints/match.test.js @@ -1,5 +1,5 @@ const assert = require('assert') -const { Ruler } = require('../../../../dist/policy') +const { Policy } = require('../../../../dist/policy') describe('Query Validator - match', () => { const rules = { @@ -13,7 +13,7 @@ describe('Query Validator - match', () => { } } - const ruler = new Ruler() + const ruler = new Policy() ruler.load(rules) let params = { diff --git a/packages/database-proxy/tests/units/policy/query.constraints/number.test.js b/packages/database-proxy/tests/units/policy/query.constraints/number.test.js index e04877a035..87af0bddee 100644 --- a/packages/database-proxy/tests/units/policy/query.constraints/number.test.js +++ b/packages/database-proxy/tests/units/policy/query.constraints/number.test.js @@ -1,5 +1,5 @@ const assert = require('assert') -const { Ruler } = require('../../../../dist/policy') +const { Policy } = require('../../../../dist/policy') describe('Query Validator - number', () => { @@ -14,7 +14,7 @@ describe('Query Validator - number', () => { } } - const ruler = new Ruler() + const ruler = new Policy() ruler.load(rules) let params = { diff --git a/packages/database-proxy/tests/units/policy/query.constraints/required.test.js b/packages/database-proxy/tests/units/policy/query.constraints/required.test.js index 9d5a0bf73d..987ce4c534 100644 --- a/packages/database-proxy/tests/units/policy/query.constraints/required.test.js +++ b/packages/database-proxy/tests/units/policy/query.constraints/required.test.js @@ -1,5 +1,5 @@ const assert = require('assert') -const { Ruler } = require('../../../../dist/policy') +const { Policy } = require('../../../../dist/policy') describe('Query Validator - required', () => { @@ -16,7 +16,7 @@ describe('Query Validator - required', () => { } } - const ruler = new Ruler() + const ruler = new Policy() ruler.load(rules) let params = { diff --git a/packages/database-proxy/tests/units/policy/ruler.schema.js b/packages/database-proxy/tests/units/policy/ruler.schema.js index 64958df2ed..1ed83f4dae 100644 --- a/packages/database-proxy/tests/units/policy/ruler.schema.js +++ b/packages/database-proxy/tests/units/policy/ruler.schema.js @@ -1,10 +1,10 @@ const assert = require('assert') const { DefaultLogger } = require('../../../dist') // const { Processor } = require('../../../dist') -const { Ruler } = require('../../../dist/policy') +const { Policy } = require('../../../dist/policy') -describe('class Ruler validate() - schema', () => { +describe('class Policy validate() - schema', () => { const rules = { categories: { read: true, @@ -20,7 +20,7 @@ describe('class Ruler validate() - schema', () => { } } - const ruler = new Ruler() + const ruler = new Policy() ruler.setLogger(new DefaultLogger(0)) ruler.load(rules) const injections = { diff --git a/packages/database-proxy/tests/units/policy/ruler.test.js b/packages/database-proxy/tests/units/policy/ruler.test.js index 032fa77ca9..b343e9c394 100644 --- a/packages/database-proxy/tests/units/policy/ruler.test.js +++ b/packages/database-proxy/tests/units/policy/ruler.test.js @@ -1,14 +1,14 @@ const assert = require('assert') const { Processor } = require('../../../dist') -const { Ruler } = require('../../../dist/policy') +const { Policy } = require('../../../dist/policy') const buildins = require('../../../dist/validators') -describe('class Ruler', () => { +describe('class Policy', () => { it('loadBuiltins() ok', () => { // 初始化 validator 是否正确 - const ruler = new Ruler() + const ruler = new Policy() const validtrs = ruler.validators assert.equal(Object.keys(buildins).length, Object.keys(validtrs).length) @@ -20,7 +20,7 @@ describe('class Ruler', () => { }) it('register() ok', () => { - const ruler = new Ruler() + const ruler = new Policy() ruler.register('test', (config, context) => { return true }) @@ -36,7 +36,7 @@ describe('class Ruler', () => { "update": "false", } } - const ruler = new Ruler() + const ruler = new Policy() ruler.load(rules) const r = ruler.rules.categories @@ -64,12 +64,12 @@ describe('class Ruler', () => { }, } } - const ruler = new Ruler() + const ruler = new Policy() assert.throws(() => ruler.load(rules)) }) }) -describe('class Ruler validate() - condition', () => { +describe('class Policy validate() - condition', () => { const rules = { categories: { "read": true, @@ -81,7 +81,7 @@ describe('class Ruler validate() - condition', () => { } } - const ruler = new Ruler() + const ruler = new Policy() ruler.load(rules) const injections = { $admin: true @@ -121,7 +121,7 @@ describe('class Ruler validate() - condition', () => { it('read should be rejected', async () => { rules.categories['read'] = false - const ruler = new Ruler() + const ruler = new Policy() ruler.load(rules) const injections = { $admin: false } const params = { collection: 'categories', action: 'database.queryDocument', injections } @@ -190,7 +190,7 @@ describe('class Ruler validate() - condition', () => { }) -describe('class Ruler validate() - multiple rules', () => { +describe('class Policy validate() - multiple rules', () => { const rules = { categories: { "read": [ @@ -200,7 +200,7 @@ describe('class Ruler validate() - multiple rules', () => { ] } } - const ruler = new Ruler() + const ruler = new Policy() ruler.load(rules) it('injections with { $role: "admin" } should be ok', async () => { diff --git a/packages/database-proxy/tests/units/policy/validator.join.test.js b/packages/database-proxy/tests/units/policy/validator.join.test.js index 50a76a6485..876547cba8 100644 --- a/packages/database-proxy/tests/units/policy/validator.join.test.js +++ b/packages/database-proxy/tests/units/policy/validator.join.test.js @@ -1,5 +1,5 @@ const assert = require('assert') -const { Ruler } = require('../../../dist') +const { Policy } = require('../../../dist') describe('Join Validator - [no join configured]', () => { const rules = { @@ -10,7 +10,7 @@ describe('Join Validator - [no join configured]', () => { } } - const ruler = new Ruler() + const ruler = new Policy() ruler.load(rules) it('.read with joins when no join configuration given should be rejected', async () => { @@ -58,7 +58,7 @@ describe('Join Validator - [join configured]', () => { } } - const ruler = new Ruler() + const ruler = new Policy() ruler.load(rules) it('.read with left joins should be ok', async () => { diff --git a/packages/database-proxy/tests/units/policy/validator.multi.test.js b/packages/database-proxy/tests/units/policy/validator.multi.test.js index 9f50a9cf78..81acd2d59f 100644 --- a/packages/database-proxy/tests/units/policy/validator.multi.test.js +++ b/packages/database-proxy/tests/units/policy/validator.multi.test.js @@ -1,5 +1,5 @@ const assert = require('assert') -const { Ruler } = require('../../../dist') +const { Policy } = require('../../../dist') describe('Multi Validator - [multi config as true]', () => { const rules = { @@ -14,7 +14,7 @@ describe('Multi Validator - [multi config as true]', () => { } } - const ruler = new Ruler() + const ruler = new Policy() ruler.load(rules) it('.read should be ok', async () => { @@ -75,7 +75,7 @@ describe('Multi Validator - [multi config as false]', () => { } } - const ruler = new Ruler() + const ruler = new Policy() ruler.load(rules) it('.read should be ok', async () => { @@ -182,7 +182,7 @@ describe('Multi Validator - [multi config as expression]', () => { } } - const ruler = new Ruler() + const ruler = new Policy() ruler.load(rules) it('remove should be ok', async () => { diff --git a/packages/database-proxy/tests/units/proxy.test.js b/packages/database-proxy/tests/units/proxy.test.js index 62855f2bc0..e5aac488c3 100644 --- a/packages/database-proxy/tests/units/proxy.test.js +++ b/packages/database-proxy/tests/units/proxy.test.js @@ -1,18 +1,18 @@ const assert = require('assert') -const { Entry, MongoAccessor } = require('../../dist') +const { Proxy, MongoAccessor } = require('../../dist') -describe('class Entry', () => { +describe('class Proxy', () => { const accessor = new MongoAccessor('test-db', 'mongodb://localhost:27017') it('constructor() ok', () => { - const entry = new Entry(accessor) + const entry = new Proxy(accessor) assert.ok(entry.accessor instanceof MongoAccessor) assert.equal(accessor, entry.accessor) }) it('parseParams() ok', () => { - const entry = new Entry(accessor) + const entry = new Proxy(accessor) const reqParams = { collectionName: 'test-name', @@ -31,7 +31,7 @@ describe('class Entry', () => { }) it('parseParams() unknown action should get an error', () => { - const entry = new Entry(accessor) + const entry = new Proxy(accessor) try { entry.parseParams({ action: 'database.unknowAction'})