diff --git a/lib/Model.ts b/lib/Model.ts
index dc1537e..8f5389e 100644
--- a/lib/Model.ts
+++ b/lib/Model.ts
@@ -1,7 +1,5 @@
///
import MongoDB = require('mongodb');
-import Skmatc = require('skmatc');
-import Concoction = require('concoction');
import Bluebird = require('bluebird');
import util = require('util');
import _ = require('lodash');
diff --git a/lib/ModelHandlers.ts b/lib/ModelHandlers.ts
index c605fa4..cddd7d0 100644
--- a/lib/ModelHandlers.ts
+++ b/lib/ModelHandlers.ts
@@ -47,7 +47,7 @@ class ModelHandlers {
return Bluebird.all(documents.map((document: any) => {
return Bluebird.resolve().then(() => {
if (this.model.hooks.onRetrieved) this.model.hooks.onCreating(document);
- var validation: SkmatcCore.IResult = this.model.helpers.validate(document);
+ var validation: Skmatc.Result = this.model.helpers.validate(document);
if (validation.failed) return Bluebird.reject(validation.error);
return document;
});
diff --git a/lib/ModelHelpers.ts b/lib/ModelHelpers.ts
index 51f4183..93f58d5 100644
--- a/lib/ModelHelpers.ts
+++ b/lib/ModelHelpers.ts
@@ -1,8 +1,7 @@
///
import MongoDB = require('mongodb');
import Model = require('./Model');
-import Concoction = require('concoction');
-import Skmatc = require('skmatc');
+import skmatc = require('skmatc');
import Omnom = require('./utils/Omnom');
import _ = require('lodash');
import Bluebird = require('bluebird');
@@ -11,17 +10,17 @@ export = ModelHelpers;
class ModelHelpers {
constructor(public model: Model) {
- this._validator = new Skmatc(model.schema);
+ this._validator = new skmatc(model.schema);
}
- private _validator: Skmatc;
+ private _validator: Skmatc.Skmatc;
/**
* Validates a document to ensure that it matches the model's ISchema requirements
* @param {any} document The document to validate against the ISchema
* @returns {SkmatcCore.IResult} The result of the validation
*/
- validate(document: TDocument): SkmatcCore.IResult {
+ validate(document: TDocument): Skmatc.Result {
return this._validator.validate(document);
}
diff --git a/lib/ModelOptions.ts b/lib/ModelOptions.ts
index fb9499c..4c48d3c 100644
--- a/lib/ModelOptions.ts
+++ b/lib/ModelOptions.ts
@@ -38,9 +38,12 @@ export interface RemoveOptions {
}
export interface IModelOptions {
- validators?: SkmatcCore.IValidator[];
+ validators?: Skmatc.Validator[];
cache?: CacheDirector;
indexes?: (Index.Index | Index.IndexSpecification)[];
properties?: { [key: string]: (General.PropertyGetter | General.Property) };
- identifier?: Concoction.Ingredient;
+ identifier?: {
+ apply(fromSource: any): any;
+ reverse(toSource: any): any;
+ };
}
\ No newline at end of file
diff --git a/lib/Plugins.ts b/lib/Plugins.ts
index 942c969..132f4ea 100644
--- a/lib/Plugins.ts
+++ b/lib/Plugins.ts
@@ -8,5 +8,5 @@ export = IPlugin;
interface IPlugin {
newModel? (model: ModelInterfaces.IModel);
newInstance? (instance: any, model: ModelInterfaces.IModelBase);
- validate?: SkmatcCore.IValidator | SkmatcCore.IValidator[];
+ validate?: Skmatc.Validator | Skmatc.Validator[];
}
\ No newline at end of file
diff --git a/typings/skmatc/skmatc.d.ts b/typings/skmatc/skmatc.d.ts
index 45c37ef..0c00fd0 100644
--- a/typings/skmatc/skmatc.d.ts
+++ b/typings/skmatc/skmatc.d.ts
@@ -1,72 +1,65 @@
declare module "skmatc" {
- export = Skmatc;
+ export = Skmatc.Skmatc;
}
-declare class Skmatc {
- constructor(schema: any);
-
- static validators: [SkmatcCore.IValidator];
- static Validator: SkmatcCore.IValidatorStatic;
- static Result: SkmatcCore.IResultStatic;
- static Failure: SkmatcCore.IFailureStatic;
- static create(handles: (schema: any) => boolean, validate: (schema: any, data: any, path: string) => SkmatcCore.IResult, options?: any): SkmatcCore.IValidator;
- static validate(validators: [SkmatcCore.IValidator], schema: any, data: any, path?: string): SkmatcCore.IResult;
- static register(validator: SkmatcCore.IValidator);
-
- schema: any;
- validators: [SkmatcCore.IValidator];
- validate(data: any, path?: string): SkmatcCore.IResult;
- register(validator: SkmatcCore.IValidator);
-}
-
-declare module SkmatcCore {
- interface IValidatorStatic {
- (skmatc: Skmatc, options?: any): IValidator;
- create(handles: (schema: any) => boolean, validate: (schema: any, data: any, path: string) => IResult, options?: any): IValidator;
- module(handles: (schema: any) => boolean, validate: (schema: any, data: any, path: string) => IResult, options?: any): IValidator;
+declare module Skmatc {
+ export class Skmatc {
+ constructor(schema: any);
+
+ static validators: [Validator];
+ static Validator: typeof Validator;
+ static Result: typeof Result;
+ static Failure: typeof Failure;
+ static create(handles: (schema: any) => boolean, validate: (schema: any, data: any, path: string) => Result, options?: any): Validator;
+ static validate(validators: [Validator], schema: any, data: any, path?: string): Result;
+ static register(validator: Validator);
+
+ schema: any;
+ validators: [Validator];
+ validate(data: any, path?: string): Result;
+ register(validator: Validator);
}
+
+ export class Validator {
+ constructor(skmatc: Skmatc, options?: any);
+ static create(handles: (schema: any) => boolean, validate: (schema: any, data: any, path: string) => Result, options?: any): Validator;
+ static module(handles: (schema: any) => boolean, validate: (schema: any, data: any, path: string) => Result, options?: any): Validator;
- interface IValidator {
name: string;
skmatc: Skmatc;
handles(schema: any): boolean;
- validate(schema: any, data: any, path: string): IResult;
- assert(schema: any, data: any, path: string, test: boolean, message?: string): IResult;
- fail(schema: any, data: any, path: string, message?: string): IResult;
+ validate(schema: any, data: any, path: string): Result;
+ assert(schema: any, data: any, path: string, test: boolean, message?: string): Result;
+ fail(schema: any, data: any, path: string, message?: string): Result;
}
-
- interface IResultStatic {
- (failures: [IFailure]): IResult;
- compound(results: [IResult]): IResult;
- }
-
- interface IResult {
- failures: [IFailure];
+
+ export class Result {
+ constructor(failures: [Failure]);
+ static compound(results: [Result]): Result;
+
+ failures: [Failure];
success: boolean;
failed: boolean;
message: string;
messages: [string];
error: Error;
}
-
- interface IFailureStatic {
- (validator: IValidator, schema: any, data: any, path: string, message?: string): IFailure;
- }
-
- interface IFailure {
- validator: IValidator;
+
+ export class Failure {
+ constructor(validator: Validator, schema: any, data: any, path: string, message?: string);
+ validator: Validator;
schema: any;
data: any;
path: string;
message: string;
}
- interface IValidationHandler {
+ export interface IValidationHandler {
(thisArg: {
validator: IValidationHandler;
skmatc: Skmatc;
fail(message?: string);
assert(test: boolean, message?: string);
- }, schema: any, data: any, path: string): IResult;
+ }, schema: any, data: any, path: string): Result;
}
}
\ No newline at end of file