Skip to content
This repository has been archived by the owner on Feb 8, 2020. It is now read-only.

Commit

Permalink
Merge branch 'devel' into int/google-assistant
Browse files Browse the repository at this point in the history
  • Loading branch information
killix authored Feb 6, 2017
2 parents 39d86fb + 0c20847 commit bb94d9f
Show file tree
Hide file tree
Showing 7 changed files with 495 additions and 1,513 deletions.
41 changes: 16 additions & 25 deletions integrations/broid-schemas/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,28 @@
"node": ">=6.0.0"
},
"scripts": {
"build": "make && babel src --out-dir lib",
"build": "npm run clean && make && tsc",
"clean": "rm -rf lib",
"lint": "tslint -c tslint.json src/*",
"lint:watch": "watch 'tslint -c tslint.json src/*' src",
"nsp-check": "nsp check -o summary",
"release": "npm run nsp-check && npm run build && npm publish",
"test": "echo \"Error: no test specified\" && exit 1",
"travis": "npm run nsp-check"
},
"babel": {
"presets": [
"es2015",
"stage-0"
],
"plugins": [
[
"coverage",
{
"only": "src/*/"
}
],
"transform-runtime"
]
"test": "echo \"Error: no test specified\" && exit 0",
"travis": "npm run test",
"tsc:watch": "tsc --watch",
"watch": "concurrently --kill-others \"npm run lint:watch\" \"npm run tsc:watch\""
},
"dependencies": {
"ajv": "^4.10.0",
"ajv": "^5.0.1-beta.1",
"bluebird": "^3.4.6"
},
"devDependencies": {
"babel-cli": "^6.18.0",
"babel-eslint": "^7.1.1",
"babel-plugin-coverage": "^1.0.0",
"babel-plugin-transform-runtime": "^6.15.0",
"babel-preset-es2015": "^6.18.0",
"babel-preset-stage-0": "^6.16.0"
"@types/bluebird": "^3.0.37",
"@types/node": "^7.0.5",
"concurrently": "^3.1.0",
"tslint": "^4.4.2",
"tslint-eslint-rules": "^3.3.0",
"typescript": "^2.1.5",
"watch": "^1.0.1"
}
}
20 changes: 0 additions & 20 deletions integrations/broid-schemas/src/index.js

This file was deleted.

72 changes: 72 additions & 0 deletions integrations/broid-schemas/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import * as Ajv from "ajv";
import * as Promise from "bluebird";

export interface IASBase {
id: string;
name?: string;
type: string;
}

export interface IASContext {
content: string;
name?: string;
type: string;
}

export interface IASMedia {
content?: string;
context?: IASContext;
id?: string;
mediaType?: string;
name?: string;
preview?: string;
type: string;
url: string;
}

export interface IASObject {
attachment?: IASMedia | IASMedia[] | null;
content?: string;
context?: IASContext;
id: string;
mediaType?: string;
name?: string;
preview?: string;
type: string;
url?: string;
}

export interface IActivityStream {
readonly "@context": string;
readonly published: number;
readonly type: string;
readonly generator: IASBase;
actor?: IASBase;
target?: IASBase;
object?: IASObject;
}

export default function(data: any, schema: string): Promise<any> {
const BASE_URL = "http://schemas.broid.ai/";
const ajv: any = new Ajv({
allErrors: true,
extendRefs: true,
});

const schemas = require("./schemas");
schemas.forEach((schemaName) =>
ajv.addSchema(require(`./schemas/${schemaName}`), schemaName));

if (schema.indexOf("http") < 0) {
schema = `${BASE_URL}${schema}.json`;
}

return new Promise((resolve, reject) => {
const valid = ajv.validate(schema, data);
if (!valid) {
return reject(new Error(ajv.errorsText()));
}

return resolve(true);
});
}
4 changes: 4 additions & 0 deletions integrations/broid-schemas/src/typings.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module "*.json" {
const value: any;
export default value;
}
27 changes: 27 additions & 0 deletions integrations/broid-schemas/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"compilerOptions": {
"removeComments": true,
"preserveConstEnums": true,
"moduleResolution": "node",
"target": "es2015",
"module": "commonjs",
"outDir": "lib",
"removeComments": true,
"preserveConstEnums": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noEmitOnError": true,
"strictNullChecks": true,
"sourceMap": false,
"declaration": true
},
"include": [
"src/**/*.ts",
"src/**/*.json"
],
"exclude": [
"node_modules"
]
}
7 changes: 7 additions & 0 deletions integrations/broid-schemas/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "tslint:latest",
"rulesDirectory": "node_modules/tslint-eslint-rules/dist/rules",
"rules": {
"max-line-length": [true, 200]
}
}
Loading

0 comments on commit bb94d9f

Please sign in to comment.