Skip to content

Commit

Permalink
feat: switch dependency to our own package: @casbin/expression-eval 5…
Browse files Browse the repository at this point in the history
….2.0 (#488)

* feat: update to @casbin/expression-eval 5.2.0

* fix: the lint error
  • Loading branch information
tx2002 authored Oct 28, 2024
1 parent 980ef14 commit ab23171
Show file tree
Hide file tree
Showing 6 changed files with 4,239 additions and 3,138 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"await-lock": "^2.0.1",
"buffer": "^6.0.3",
"csv-parse": "^5.3.5",
"expression-eval": "^5.0.0",
"@casbin/expression-eval": "^5.2.0",
"minimatch": "^7.4.2"
},
"files": [
Expand Down
2 changes: 1 addition & 1 deletion src/coreEnforcer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import { compile, compileAsync, addBinaryOp } from 'expression-eval';
import { compile, compileAsync, addBinaryOp } from '@casbin/expression-eval';

import { DefaultEffector, Effect, Effector } from './effect';
import { FunctionMap, Model, newModelFromFile, PolicyOp } from './model';
Expand Down
4 changes: 2 additions & 2 deletions src/util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ function deepCopy(obj: Array<any> | any): any {

function customIn(a: number | string, b: number | string): number {
if ((b as any) instanceof Array) {
return (((b as any) as Array<any>).includes(a) as unknown) as number;
return (b as any as Array<any>).includes(a) as unknown as number;
}
return ((a in (b as any)) as unknown) as number;
return (a in (b as any)) as unknown as number;
}

function bracketCompatible(exp: string): string {
Expand Down
14 changes: 7 additions & 7 deletions test/enforcer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -597,9 +597,9 @@ test('test ABAC multiple eval()', async () => {
);

const e = await newEnforcer(m, policy);
await testEnforce(e, 56, (98 as unknown) as string, 'read', true);
await testEnforce(e, 23, (67 as unknown) as string, 'read', false);
await testEnforce(e, 78, (34 as unknown) as string, 'read', false);
await testEnforce(e, 56, 98 as unknown as string, 'read', true);
await testEnforce(e, 23, 67 as unknown as string, 'read', false);
await testEnforce(e, 78, 34 as unknown as string, 'read', false);
});

// https://github.com/casbin/node-casbin/issues/438
Expand All @@ -617,10 +617,10 @@ test('test ABAC single eval() with r. in unexpected places', async () => {
);

const e = await newEnforcer(m, policy);
await testEnforce(e, { id: 3 }, ({ owner: { id: 3 } } as unknown) as string, 'read', true);
await testEnforce(e, {}, ({ owner: {} } as unknown) as string, 'read', false);
await testEnforce(e, { id: 3 }, ({ owner: {} } as unknown) as string, 'read', false);
await testEnforce(e, { id: 3 }, ({ owner: { id: 2 } } as unknown) as string, 'read', false);
await testEnforce(e, { id: 3 }, { owner: { id: 3 } } as unknown as string, 'read', true);
await testEnforce(e, {}, { owner: {} } as unknown as string, 'read', false);
await testEnforce(e, { id: 3 }, { owner: {} } as unknown as string, 'read', false);
await testEnforce(e, { id: 3 }, { owner: { id: 2 } } as unknown as string, 'read', false);
});

test('TestEnforceSync', async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

import { getLogger, logPrint, Util as util } from '../src';
import { compile } from 'expression-eval';
import { compile } from '@casbin/expression-eval';

test('test enableLog success', () => {
getLogger().enableLog(true);
Expand Down
Loading

0 comments on commit ab23171

Please sign in to comment.