-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from medishen/dev/v2
Fix Validator Engine and Improve Rule Action Logic with Enhanced Validation Handling
- Loading branch information
Showing
15 changed files
with
400 additions
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Qiks } from '@medishn/qiks'; | ||
import { CacheConfigQiks } from '@medishn/qiks/dist/types/CacheTypes'; | ||
|
||
/** | ||
* A caching system built on top of @medishn/qiks. | ||
*/ | ||
export class MemoryCacheStore<K, V> extends Qiks<K, V> { | ||
constructor(options?: CacheConfigQiks<K>) { | ||
super(options); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "@gland/cache", | ||
"version": "1.0.0", | ||
"author": "Mahdi", | ||
"license": "MIT", | ||
"scripts": { | ||
"build": "tsc" | ||
}, | ||
"devDependencies": { | ||
"typescript": "^5.5.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"rootDir": ".", | ||
"outDir": "." | ||
}, | ||
"files": [], | ||
"include": ["**/*.ts"], | ||
"exclude": ["node_modules"], | ||
"references": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { SinonStubbedInstance } from 'sinon'; | ||
import sinon from 'sinon'; | ||
|
||
export interface Mock<T> { | ||
setup(): void; | ||
restore(): void; | ||
reset(): void; | ||
get stub(): SinonStubbedInstance<T>; | ||
} | ||
|
||
export abstract class MockBase<T extends object> implements Mock<T> { | ||
protected original: Partial<T> = {}; | ||
protected stubs: SinonStubbedInstance<T> = {} as SinonStubbedInstance<T>; | ||
protected target: any; | ||
|
||
constructor(protected mockTarget: T) { | ||
this.target = mockTarget; | ||
} | ||
|
||
abstract setup(): void; | ||
abstract restore(): void; | ||
|
||
reset(): void { | ||
Object.values(this.stubs).forEach((stub: any) => { | ||
if (typeof stub.reset === 'function') stub.reset(); | ||
}); | ||
} | ||
|
||
get stub(): SinonStubbedInstance<T> { | ||
return this.stubs; | ||
} | ||
|
||
protected createStubs(methods: Array<keyof T>): void { | ||
methods.forEach((method) => { | ||
if (typeof this.mockTarget[method] === 'function') { | ||
this.original[method] = this.mockTarget[method]; | ||
(this.stubs as any)[method] = sinon.stub(this.target, method as string); | ||
} | ||
}); | ||
} | ||
protected restoreMethods(methods: Array<keyof T>): void { | ||
methods.forEach((method) => { | ||
if (this.original[method]) { | ||
this.target[method] = this.original[method]; | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './reflector.mock'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,22 @@ | ||
import sinon from 'sinon'; | ||
import Reflector from '../../dist/metadata'; | ||
|
||
export const createMockReflector = () => { | ||
const mockReflector = { | ||
define: sinon.stub(), | ||
has: sinon.stub().returns(false), | ||
get: sinon.stub().returns(undefined), | ||
delete: sinon.stub().returns(false), | ||
clear: sinon.stub(), | ||
keys: sinon.stub().returns([]), | ||
list: sinon.stub().returns(null), | ||
allList: sinon.stub().returns(new Map()), | ||
getRoutes: sinon.stub().returns([]), | ||
update: sinon.stub(), | ||
}; | ||
|
||
// Save original methods | ||
const originalMethods = { | ||
define: Reflector.define, | ||
has: Reflector.has, | ||
get: Reflector.get, | ||
delete: Reflector.delete, | ||
clear: Reflector.clear, | ||
keys: Reflector.keys, | ||
list: Reflector.list, | ||
allList: Reflector.allList, | ||
getRoutes: Reflector.getRoutes, | ||
update: Reflector.update, | ||
}; | ||
|
||
// Override Reflector | ||
Object.assign(Reflector, mockReflector); | ||
|
||
const restore = () => { | ||
Object.assign(Reflector, originalMethods); | ||
import Reflector from '../../packages/metadata'; | ||
import { MockBase } from './base-mock'; | ||
export class ReflectorMock extends MockBase<typeof Reflector> { | ||
private methods: (keyof typeof Reflector)[] = ['clearMetadata', 'defineMetadata', 'deleteMetadata', 'getMetadata', 'getMetadataKeys', 'hasMetadata', 'listMetadata', 'metadata']; | ||
constructor() { | ||
super(Reflector); | ||
} | ||
setup(): void { | ||
this.createStubs(this.methods); | ||
// Default stubs | ||
this.stub.hasMetadata.returns(false); | ||
this.stub.getMetadata.returns(undefined); | ||
this.stub.deleteMetadata.returns(false); | ||
this.stub.getMetadataKeys.returns([]); | ||
this.stub.listMetadata.returns(null); | ||
} | ||
restore(): void { | ||
this.restoreMethods(this.methods); | ||
sinon.restore(); | ||
}; | ||
|
||
return { mockReflector, restore }; | ||
}; | ||
} | ||
} |
Oops, something went wrong.