auto-views
Advanced tools
Comparing version 0.0.13 to 0.0.14
@@ -19,17 +19,17 @@ # Schema repo | ||
* addDefinition: | ||
* addSchema: | ||
adds a schema definition to repo | ||
```ts | ||
myRepo.addDefinition(def:JSONSchema) | ||
myRepo.addSchema(def:JSONSchema) | ||
``` | ||
* addDefinitions: | ||
* addSchemas: | ||
adds a schema definition to repo | ||
```ts | ||
addDefinitions(defs:JSONSchema[]) | ||
myRepo.addSchemas(defs:JSONSchema[]) | ||
``` | ||
* getDefinition: | ||
* getSchema: | ||
@@ -39,3 +39,3 @@ returns a JSON schema if exists | ||
```ts | ||
myRepo.getDefinition(id:string):JSONSchema | null | ||
myRepo.getSchema(id:string):JSONSchema | null | ||
``` | ||
@@ -42,0 +42,0 @@ |
@@ -0,1 +1,3 @@ | ||
/// <reference types="react" /> | ||
import { Validator } from 'jsonschema'; | ||
export interface SchemaProperty { | ||
@@ -15,6 +17,14 @@ title: string; | ||
}; | ||
controllers: { | ||
[key: string]: React.ComponentType; | ||
}; | ||
validator: Validator; | ||
addSchema(schema: AutoFormSchema): void; | ||
addSchemas(schemas: AutoFormSchema[]): void; | ||
getSchema(id: string): AutoFormSchema; | ||
clear(): void; | ||
mapOverProperties<T>(id: string, propertyVisitor: (property: SchemaProperty, key: string) => T): Array<T>; | ||
registerController(controllerID: string, controller: React.ComponentType): void; | ||
getController(controllerID: string): React.ComponentType | null; | ||
validate(json: any, schemaId: string): boolean; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var jsonschema_1 = require("jsonschema"); | ||
var SchemaRepository = (function () { | ||
function SchemaRepository() { | ||
this.schemas = {}; | ||
this.controllers = {}; | ||
this.validator = new jsonschema_1.Validator(); | ||
} | ||
@@ -10,2 +13,6 @@ SchemaRepository.prototype.addSchema = function (schema) { | ||
}; | ||
SchemaRepository.prototype.addSchemas = function (schemas) { | ||
var _this = this; | ||
schemas.forEach(function (schema) { return _this.addSchema(schema); }); | ||
}; | ||
SchemaRepository.prototype.getSchema = function (id) { | ||
@@ -22,2 +29,11 @@ return this.schemas[id]; | ||
}; | ||
SchemaRepository.prototype.registerController = function (controllerID, controller) { | ||
this.controllers[controllerID] = controller; | ||
}; | ||
SchemaRepository.prototype.getController = function (controllerID) { | ||
return this.controllers[controllerID]; | ||
}; | ||
SchemaRepository.prototype.validate = function (json, schemaId) { | ||
return this.validator.validate(json, this.getSchema(schemaId)).valid; | ||
}; | ||
return SchemaRepository; | ||
@@ -24,0 +40,0 @@ }()); |
{ | ||
"name": "auto-views", | ||
"version": "0.0.13", | ||
"version": "0.0.14", | ||
"description": "Common, fully-tested, strictly-typed, Wix-styled, auto views library", | ||
@@ -47,3 +47,6 @@ "main": "./lib/index.js", | ||
"license": "MIT", | ||
"dependencies": { | ||
"jsonschema": "^1.1.1" | ||
}, | ||
"private": false | ||
} |
@@ -0,1 +1,3 @@ | ||
import {Validator} from 'jsonschema'; | ||
export interface SchemaProperty { | ||
@@ -13,2 +15,4 @@ title: string; | ||
schemas:{[key:string]:AutoFormSchema} = {}; | ||
controllers: {[key:string]:React.ComponentType} = {}; | ||
validator:Validator = new Validator(); | ||
@@ -19,2 +23,6 @@ addSchema(schema:AutoFormSchema):void { | ||
addSchemas(schemas:AutoFormSchema[]):void { | ||
schemas.forEach((schema)=>this.addSchema(schema)); | ||
} | ||
getSchema(id:string):AutoFormSchema { | ||
@@ -33,2 +41,14 @@ return this.schemas[id]; | ||
} | ||
registerController(controllerID: string, controller: React.ComponentType):void { | ||
this.controllers[controllerID] = controller; | ||
} | ||
getController(controllerID: string): React.ComponentType | null { | ||
return this.controllers[controllerID]; | ||
} | ||
validate(json: any, schemaId: string) { | ||
return this.validator.validate(json,this.getSchema(schemaId)).valid; | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46429
564
2
+ Addedjsonschema@^1.1.1
+ Addedjsonschema@1.4.1(transitive)