mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[6.x] Expose core config schema validation system as @kbn/config-schema
package. (#23802)
This commit is contained in:
parent
f90cb803de
commit
d758441fab
87 changed files with 79 additions and 24 deletions
|
@ -31,6 +31,7 @@ module.exports = {
|
|||
{
|
||||
files: [
|
||||
'.eslintrc.js',
|
||||
'packages/kbn-config-schema/**/*',
|
||||
'packages/kbn-pm/**/*',
|
||||
'packages/kbn-es/**/*',
|
||||
'packages/kbn-datemath/**/*.js',
|
||||
|
|
|
@ -80,6 +80,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",
|
||||
|
|
20
packages/kbn-config-schema/package.json
Normal file
20
packages/kbn-config-schema/package.json
Normal 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"
|
||||
}
|
||||
}
|
|
@ -66,6 +66,9 @@ const anyCustomRule: Rules = {
|
|||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export const internals = Joi.extend([
|
||||
{
|
||||
name: 'any',
|
|
@ -81,6 +81,9 @@ export abstract class Type<V> {
|
|||
return validatedValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public getSchema() {
|
||||
return this.internalSchema;
|
||||
}
|
16
packages/kbn-config-schema/tsconfig.json
Normal file
16
packages/kbn-config-schema/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
|
@ -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 {
|
7
packages/kbn-config-schema/yarn.lock
Normal file
7
packages/kbn-config-schema/yarn.lock
Normal 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"
|
|
@ -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__';
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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({
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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 = /(^$|^\/.*[^\/]$)/;
|
||||
|
|
|
@ -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';
|
||||
|
||||
|
|
|
@ -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';
|
||||
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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> {
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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') }),
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
|
||||
jest.mock('../../layouts/layouts', () => {
|
||||
const { schema } = require('../../../config/schema');
|
||||
const { schema } = require('@kbn/config-schema');
|
||||
return {
|
||||
Layouts: {
|
||||
configSchema: schema.object({
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
|
||||
jest.mock('../../layouts/layouts', () => {
|
||||
const { schema } = require('../../../config/schema');
|
||||
const { schema } = require('@kbn/config-schema');
|
||||
return {
|
||||
Layouts: {
|
||||
configSchema: schema.object({
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -164,6 +164,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 ""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue