UNPKG

@hankei6km/reposition

Version:

`reposition` is a command line tool to send a repository list to Notion database.

86 lines (85 loc) 2.01 kB
import Ajv from 'ajv'; import addFormats from 'ajv-formats'; const ajv = new Ajv(); addFormats(ajv); //export const RepoItemSchema: JSONSchemaType<RepoItem> = { export const RepoItemSchema = { type: 'object', required: [ 'createdAt', 'name', 'nameWithOwner', 'openGraphImageUrl', 'owner', 'pushedAt', 'updatedAt', 'url' ], properties: { createdAt: { type: 'string', format: 'date-time' }, description: { type: 'string' }, isPrivate: { type: 'boolean' }, name: { type: 'string' }, nameWithOwner: { type: 'string' }, openGraphImageUrl: { type: 'string', format: 'uri' }, owner: { type: 'object', required: ['login'], properties: { login: { type: 'string' } } }, repositoryTopics: { type: ['array', 'null'], items: { type: 'object', required: ['name'], properties: { name: { type: 'string' } } } }, pushedAt: { type: 'string', format: 'date-time' }, updatedAt: { type: 'string', format: 'date-time' }, url: { type: 'string', format: 'uri' } } }; const validate = ajv.compile(RepoItemSchema); export function validateRepoItem(repo) { if (validate(repo)) { return true; } const msg = validate.errors .filter((err) => typeof err.message === 'string') .map(({ message }) => message) .join(','); // repo 名を出すのは? throw new Error(`Validate Repo Item: ${msg}`); }