Expose core config schema validation system as @kbn/config-schema package. (#23609)

This commit is contained in:
Aleh Zasypkin 2018-10-04 09:18:40 +02:00 committed by GitHub
parent 125e4fa6ad
commit b2baf32fba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
87 changed files with 79 additions and 24 deletions

View file

@ -32,6 +32,7 @@ module.exports = {
files: [
'.eslintrc.js',
'packages/eslint-plugin-kibana-custom/**/*',
'packages/kbn-config-schema/**/*',
'packages/kbn-pm/**/*',
'packages/kbn-es/**/*',
'packages/kbn-datemath/**/*',

View file

@ -64,6 +64,7 @@
"@elastic/numeral": "2.3.2",
"@elastic/ui-ace": "0.2.3",
"@kbn/babel-preset": "link:packages/kbn-babel-preset",
"@kbn/config-schema": "link:packages/kbn-config-schema",
"@kbn/datemath": "link:packages/kbn-datemath",
"@kbn/i18n": "link:packages/kbn-i18n",
"@kbn/pm": "link:packages/kbn-pm",

View file

@ -0,0 +1,20 @@
{
"name": "@kbn/config-schema",
"main": "./target/out/index.js",
"types": "./target/types/index.d.ts",
"version": "1.0.0",
"license": "Apache-2.0",
"private": true,
"scripts": {
"build": "tsc",
"kbn:bootstrap": "yarn build"
},
"devDependencies": {
"typescript": "^3.0.3"
},
"peerDependencies": {
"joi": "10.4.1",
"moment": "^2.20.1",
"type-detect": "^4.0.8"
}
}

View file

@ -66,6 +66,9 @@ const anyCustomRule: Rules = {
},
};
/**
* @internal
*/
export const internals = Joi.extend([
{
name: 'any',

View file

@ -81,6 +81,9 @@ export abstract class Type<V> {
return validatedValue;
}
/**
* @internal
*/
public getSchema() {
return this.internalSchema;
}

View file

@ -0,0 +1,16 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"declaration": true,
"declarationDir": "./target/types",
"outDir": "./target/out",
"stripInternal": true
},
"include": [
"./types/joi.d.ts",
"./src/**/*.ts"
],
"exclude": [
"target"
]
}

View file

@ -17,7 +17,7 @@
* under the License.
*/
import * as Joi from 'joi';
import { ByteSizeValue } from '../byte_size_value';
import { ByteSizeValue } from '../src/byte_size_value';
declare module 'joi' {
interface BytesSchema extends AnySchema {

View file

@ -0,0 +1,7 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
typescript@^3.0.3:
version "3.1.1"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.1.1.tgz#3362ba9dd1e482ebb2355b02dfe8bcd19a2c7c96"

View file

@ -25,7 +25,7 @@ import { first } from 'rxjs/operators';
const mockPackage = new Proxy({ raw: {} as any }, { get: (obj, prop) => obj.raw[prop] });
jest.mock('../../../utils/package_json', () => ({ pkg: mockPackage }));
import { schema, Type, TypeOf } from './schema';
import { schema, Type, TypeOf } from '@kbn/config-schema';
import { ConfigService, Env, ObjectToConfigAdapter } from '.';
import { logger } from '../logging/__mocks__';

View file

@ -17,13 +17,13 @@
* under the License.
*/
import { Type } from '@kbn/config-schema';
import { isEqual } from 'lodash';
import { Observable } from 'rxjs';
import { distinctUntilChanged, first, map } from 'rxjs/operators';
import { Config, ConfigPath, ConfigWithSchema, Env } from '.';
import { Logger, LoggerFactory } from '../logging';
import { Type } from './schema';
export class ConfigService {
private readonly log: Logger;

View file

@ -18,8 +18,8 @@
*/
// TODO inline all of these
import { Type, TypeOf } from '@kbn/config-schema';
import { Env } from './env';
import { Type, TypeOf } from './schema';
/**
* Interface that defines the static side of a config class.

View file

@ -17,7 +17,7 @@
* under the License.
*/
import { schema, TypeOf } from '../config/schema';
import { schema, TypeOf } from '@kbn/config-schema';
const createDevSchema = schema.object({
basePathProxyTarget: schema.number({

View file

@ -17,10 +17,10 @@
* under the License.
*/
import { ByteSizeValue } from '@kbn/config-schema';
import { Server } from 'hapi-latest';
import { Agent as HttpsAgent, ServerOptions as TlsOptions } from 'https';
import { sample } from 'lodash';
import { ByteSizeValue } from '../config/schema';
import { DevConfig } from '../dev';
import { Logger } from '../logging';
import { HttpConfig } from './http_config';

View file

@ -17,8 +17,8 @@
* under the License.
*/
import { ByteSizeValue, schema, TypeOf } from '@kbn/config-schema';
import { Env } from '../config';
import { ByteSizeValue, schema, TypeOf } from '../config/schema';
import { SslConfig } from './ssl_config';
const validBasePathRegex = /(^$|^\/.*[^\/]$)/;

View file

@ -26,8 +26,8 @@ jest.mock('fs', () => ({
import Chance from 'chance';
import supertest from 'supertest';
import { ByteSizeValue } from '@kbn/config-schema';
import { HttpConfig, Router } from '.';
import { ByteSizeValue } from '../config/schema';
import { logger } from '../logging/__mocks__';
import { HttpServer } from './http_server';

View file

@ -25,8 +25,8 @@ import Chance from 'chance';
import { Server } from 'http';
import supertest from 'supertest';
import { ByteSizeValue } from '@kbn/config-schema';
import { HttpConfig } from '.';
import { ByteSizeValue } from '../config/schema';
import { logger } from '../logging/__mocks__';
import { HttpsRedirectServer } from './https_redirect_server';

View file

@ -17,8 +17,8 @@
* under the License.
*/
import { ObjectType, TypeOf } from '@kbn/config-schema';
import { Request } from 'hapi-latest';
import { ObjectType, TypeOf } from '../../config/schema';
import { filterHeaders, Headers } from './headers';
import { RouteSchemas } from './route';

View file

@ -17,7 +17,7 @@
* under the License.
*/
import { ObjectType, Schema } from '../../config/schema';
import { ObjectType, Schema } from '@kbn/config-schema';
export type RouteMethod = 'GET' | 'POST' | 'PUT' | 'DELETE';
export interface RouteConfig<P extends ObjectType, Q extends ObjectType, B extends ObjectType> {

View file

@ -17,8 +17,8 @@
* under the License.
*/
import { ObjectType, schema, TypeOf } from '@kbn/config-schema';
import { Request, ResponseObject, ResponseToolkit } from 'hapi-latest';
import { ObjectType, schema, TypeOf } from '../../config/schema';
import { KibanaRequest } from './request';
import { KibanaResponse, ResponseFactory, responseFactory } from './response';

View file

@ -17,8 +17,8 @@
* under the License.
*/
import { schema, TypeOf } from '@kbn/config-schema';
import crypto from 'crypto';
import { schema, TypeOf } from '../config/schema';
// `crypto` type definitions doesn't currently include `crypto.constants`, see
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/fa5baf1733f49cf26228a4e509914572c1b74adf/types/node/v6/index.d.ts#L3412

View file

@ -17,7 +17,7 @@
* under the License.
*/
import { schema } from '../../../config/schema';
import { schema } from '@kbn/config-schema';
import { DisposableAppender } from '../../../logging/appenders/appenders';
import { LogRecord } from '../../../logging/log_record';
import { LegacyLoggingServer } from '../legacy_logging_server';

View file

@ -19,7 +19,7 @@
const mockCreateLayout = jest.fn();
jest.mock('../layouts/layouts', () => {
const { schema } = require('../../config/schema');
const { schema } = require('@kbn/config-schema');
return {
Layouts: {
configSchema: schema.object({ kind: schema.literal('mock') }),

View file

@ -17,7 +17,7 @@
* under the License.
*/
import { schema, TypeOf } from '../../config/schema';
import { schema, TypeOf } from '@kbn/config-schema';
import { assertNever } from '../../../utils';
import { LegacyAppender } from '../../legacy_compat/logging/appenders/legacy_appender';

View file

@ -18,7 +18,7 @@
*/
jest.mock('../../layouts/layouts', () => {
const { schema } = require('../../../config/schema');
const { schema } = require('@kbn/config-schema');
return {
Layouts: {
configSchema: schema.object({

View file

@ -17,7 +17,7 @@
* under the License.
*/
import { schema } from '../../../config/schema';
import { schema } from '@kbn/config-schema';
import { Layout, Layouts } from '../../layouts/layouts';
import { LogRecord } from '../../log_record';

View file

@ -18,7 +18,7 @@
*/
jest.mock('../../layouts/layouts', () => {
const { schema } = require('../../../config/schema');
const { schema } = require('@kbn/config-schema');
return {
Layouts: {
configSchema: schema.object({

View file

@ -17,8 +17,8 @@
* under the License.
*/
import { schema } from '@kbn/config-schema';
import { createWriteStream, WriteStream } from 'fs';
import { schema } from '../../../config/schema';
import { Layout, Layouts } from '../../layouts/layouts';
import { LogRecord } from '../../log_record';

View file

@ -17,7 +17,7 @@
* under the License.
*/
import { schema, TypeOf } from '../../config/schema';
import { schema, TypeOf } from '@kbn/config-schema';
import { LogRecord } from '../log_record';
import { Layout } from './layouts';

View file

@ -17,7 +17,7 @@
* under the License.
*/
import { schema } from '../../config/schema';
import { schema } from '@kbn/config-schema';
import { assertNever } from '../../../utils';
import { LogRecord } from '../log_record';

View file

@ -17,8 +17,8 @@
* under the License.
*/
import { schema, TypeOf } from '@kbn/config-schema';
import chalk from 'chalk';
import { schema, TypeOf } from '../../config/schema';
import { LogLevel } from '../log_level';
import { LogRecord } from '../log_record';

View file

@ -17,7 +17,7 @@
* under the License.
*/
import { schema, TypeOf } from '../config/schema';
import { schema, TypeOf } from '@kbn/config-schema';
import { AppenderConfigType, Appenders } from './appenders/appenders';
// We need this helper for the types to be correct

View file

@ -171,6 +171,10 @@
version "0.0.0"
uid ""
"@kbn/config-schema@link:packages/kbn-config-schema":
version "0.0.0"
uid ""
"@kbn/datemath@link:packages/kbn-datemath":
version "0.0.0"
uid ""