Skip to content

Commit

Permalink
refactor(db-ql): remove deprecated classes & api(Ruler,Entry);
Browse files Browse the repository at this point in the history
  • Loading branch information
maslow committed Oct 19, 2021
1 parent 3802d19 commit 228df4d
Show file tree
Hide file tree
Showing 39 changed files with 92 additions and 105 deletions.
2 changes: 1 addition & 1 deletion packages/database-proxy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const res = await db.collection('articles')
})
```

更多使用参考[客户端使用文档](./packages/less-api-client-js/README.md)
更多使用参考[客户端使用文档](./packages/laf-client-sdk/README.md)

### 数据访问安全规则示例

Expand Down
12 changes: 1 addition & 11 deletions packages/database-proxy/src/policy/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
import { Policy } from './policy'

export * from './interface'


export {
Policy,

/**
* Ruler 为别名,为了兼容老版本命名
*/
Policy as Ruler
}
export * from './policy'
5 changes: 4 additions & 1 deletion packages/database-proxy/src/policy/policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export enum PermissionType {
REMOVE = 'remove',
COUNT = 'count',
WATCH = 'watch',
AGGREGATE = 'aggregate'
}

// 数据库规则
Expand Down Expand Up @@ -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:
Expand All @@ -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')
}
}
}
8 changes: 1 addition & 7 deletions packages/database-proxy/src/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,4 @@ export class Proxy {

return params
}
}


/**
* Proxy 的别名,为了兼容老版本命名
*/
export class Entry extends Proxy { }
}
4 changes: 2 additions & 2 deletions packages/database-proxy/tests/mongo_db/add.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const assert = require('assert')
const { Entry, MongoAccessor, ActionType } = require('../../dist')
const { Proxy, MongoAccessor, ActionType } = require('../../dist')

const { dbconfig } = require('./_db')

Expand All @@ -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 () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/database-proxy/tests/mongo_db/count.test.js
Original file line number Diff line number Diff line change
@@ -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 = [
Expand All @@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/database-proxy/tests/mongo_db/dbi.test.js.js
Original file line number Diff line number Diff line change
@@ -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')

Expand Down
4 changes: 2 additions & 2 deletions packages/database-proxy/tests/mongo_db/read.test.js
Original file line number Diff line number Diff line change
@@ -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')

Expand All @@ -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 () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/database-proxy/tests/mongo_db/remove.test.js
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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 () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/database-proxy/tests/mongo_db/update.test.js
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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 () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/database-proxy/tests/mysql_db/count.test.js
Original file line number Diff line number Diff line change
@@ -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 () {
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions packages/database-proxy/tests/mysql_db/delete.test.js
Original file line number Diff line number Diff line change
@@ -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 () {
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions packages/database-proxy/tests/mysql_db/insert.test.js
Original file line number Diff line number Diff line change
@@ -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 () {
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions packages/database-proxy/tests/mysql_db/join.test.js
Original file line number Diff line number Diff line change
@@ -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')

Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions packages/database-proxy/tests/mysql_db/read.test.js
Original file line number Diff line number Diff line change
@@ -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 () {
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions packages/database-proxy/tests/mysql_db/update.test.js
Original file line number Diff line number Diff line change
@@ -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 () {
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const assert = require('assert')
const { Ruler } = require('../../../../dist/policy')
const { Policy } = require('../../../../dist/policy')

describe('Data validator - condition', () => {
const rules = {
Expand All @@ -16,7 +16,7 @@ describe('Data validator - condition', () => {
}
}

const ruler = new Ruler()
const ruler = new Policy()
ruler.load(rules)

let params = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const assert = require('assert')
const { Ruler } = require('../../../../dist/policy')
const { Policy } = require('../../../../dist/policy')



Expand All @@ -16,7 +16,7 @@ describe('Data Validator - default', () => {
}
}

const ruler = new Ruler()
const ruler = new Policy()
ruler.load(rules)

let params = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const assert = require('assert')
const { Ruler } = require('../../../../dist/policy')
const { Policy } = require('../../../../dist/policy')


describe('Data Validator - in', () => {
Expand All @@ -15,7 +15,7 @@ describe('Data Validator - in', () => {
}
}

const ruler = new Ruler()
const ruler = new Policy()
ruler.load(rules)

let params = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const assert = require('assert')
const { Ruler } = require('../../../../dist/policy')
const { Policy } = require('../../../../dist/policy')


describe('Data Validator - length', () => {
Expand All @@ -15,7 +15,7 @@ describe('Data Validator - length', () => {
}
}

const ruler = new Ruler()
const ruler = new Policy()
ruler.load(rules)

let params = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const assert = require('assert')
const { Ruler } = require('../../../../dist/policy')
const { Policy } = require('../../../../dist/policy')



Expand All @@ -15,7 +15,7 @@ describe('Data Validator - match', () => {
}
}

const ruler = new Ruler()
const ruler = new Policy()
ruler.load(rules)

let params = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const assert = require('assert')
const { Ruler } = require('../../../../dist/policy')
const { Policy } = require('../../../../dist/policy')

describe('Data Validator - number', () => {
const rules = {
Expand All @@ -13,7 +13,7 @@ describe('Data Validator - number', () => {
}
}

const ruler = new Ruler()
const ruler = new Policy()
ruler.load(rules)

let params = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const assert = require('assert')
const { Ruler } = require('../../../../dist/policy')
const { Policy } = require('../../../../dist/policy')

describe('Data Validator - required', () => {
const rules = {
Expand All @@ -15,7 +15,7 @@ describe('Data Validator - required', () => {
}
}

const ruler = new Ruler()
const ruler = new Policy()
ruler.load(rules)

let params = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const assert = require('assert')
const { Ruler } = require('../../../../dist/policy')
const { Policy } = require('../../../../dist/policy')

describe('Date Validator - add', () => {
const rules = {
Expand All @@ -15,7 +15,7 @@ describe('Date Validator - add', () => {
}
}

const ruler = new Ruler()
const ruler = new Policy()
ruler.load(rules)

let params = {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -15,7 +15,7 @@ describe('Date Validator - merge options (replace & update)', () => {
}
}

const ruler = new Ruler()
const ruler = new Policy()
ruler.load(rules)

let params = {
Expand Down
Loading

0 comments on commit 228df4d

Please sign in to comment.