This repository has been archived by the owner on Feb 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'devel' into int/google-assistant
- Loading branch information
Showing
7 changed files
with
495 additions
and
1,513 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
This file was deleted.
Oops, something went wrong.
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,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); | ||
}); | ||
} |
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,4 @@ | ||
declare module "*.json" { | ||
const value: any; | ||
export default value; | ||
} |
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,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" | ||
] | ||
} |
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,7 @@ | ||
{ | ||
"extends": "tslint:latest", | ||
"rulesDirectory": "node_modules/tslint-eslint-rules/dist/rules", | ||
"rules": { | ||
"max-line-length": [true, 200] | ||
} | ||
} |
Oops, something went wrong.