Skip to content

Commit

Permalink
Breaks down the io-ts packages to decrease the size within the lists …
Browse files Browse the repository at this point in the history
…plugin and for other plugins
  • Loading branch information
FrankHassanabad committed May 13, 2021
1 parent cbdd1b2 commit f252c60
Show file tree
Hide file tree
Showing 306 changed files with 822 additions and 350 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@
"@kbn/securitysolution-constants": "link:bazel-bin/packages/kbn-securitysolution-constants/npm_module",
"@kbn/securitysolution-utils": "link:bazel-bin/packages/kbn-securitysolution-utils/npm_module",
"@kbn/securitysolution-es-utils": "link:bazel-bin/packages/kbn-securitysolution-es-utils/npm_module",
"@kbn/securitysolution-io-ts-types": "link:bazel-bin/packages/kbn-securitysolution-io-ts-types/npm_module",
"@kbn/securitysolution-io-ts-alerting-types": "link:bazel-bin/packages/kbn-securitysolution-io-ts-alerting-types/npm_module",
"@kbn/securitysolution-io-ts-list-types": "link:bazel-bin/packages/kbn-securitysolution-io-ts-list-types/npm_module",
"@kbn/securitysolution-io-ts-utils": "link:bazel-bin/packages/kbn-securitysolution-io-ts-utils/npm_module",
"@kbn/server-http-tools": "link:packages/kbn-server-http-tools",
"@kbn/server-route-repository": "link:packages/kbn-server-route-repository",
Expand Down
3 changes: 3 additions & 0 deletions packages/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ filegroup(
"//packages/kbn-logging:build",
"//packages/kbn-plugin-generator:build",
"//packages/kbn-securitysolution-constants:build",
"//packages/kbn-securitysolution-io-ts-types:build",
"//packages/kbn-securitysolution-io-ts-alerting-types:build",
"//packages/kbn-securitysolution-io-ts-list-types:build",
"//packages/kbn-securitysolution-io-ts-utils:build",
"//packages/kbn-securitysolution-utils:build",
"//packages/kbn-securitysolution-es-utils:build",
Expand Down
93 changes: 93 additions & 0 deletions packages/kbn-securitysolution-io-ts-alerting-types/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
load("@npm//@bazel/typescript:index.bzl", "ts_config", "ts_project")
load("@build_bazel_rules_nodejs//:index.bzl", "js_library", "pkg_npm")

PKG_BASE_NAME = "kbn-securitysolution-io-ts-alerting-types"
PKG_REQUIRE_NAME = "@kbn/securitysolution-io-ts-alerting-types"

SOURCE_FILES = glob(
[
"src/**/*.ts",
],
exclude = [
"**/*.test.*",
"**/*.mock.*"
],
)

SRCS = SOURCE_FILES

filegroup(
name = "srcs",
srcs = SRCS,
)

NPM_MODULE_EXTRA_FILES = [
"package.json",
"README.md",
]

SRC_DEPS = [
"//packages/kbn-securitysolution-io-ts-types",
"//packages/elastic-datemath",
"@npm//fp-ts",
"@npm//io-ts",
"@npm//lodash",
"@npm//moment",
"@npm//tslib",
"@npm//uuid",
]

TYPES_DEPS = [
"@npm//@types/flot",
"@npm//@types/jest",
"@npm//@types/lodash",
"@npm//@types/node",
"@npm//@types/uuid"
]

DEPS = SRC_DEPS + TYPES_DEPS

ts_config(
name = "tsconfig",
src = "tsconfig.json",
deps = [
"//:tsconfig.base.json",
],
)

ts_project(
name = "tsc",
args = ['--pretty'],
srcs = SRCS,
deps = DEPS,
declaration = True,
declaration_map = True,
incremental = True,
out_dir = "target",
source_map = True,
root_dir = "src",
tsconfig = ":tsconfig",
)

js_library(
name = PKG_BASE_NAME,
srcs = NPM_MODULE_EXTRA_FILES,
deps = [":tsc"] + DEPS,
package_name = PKG_REQUIRE_NAME,
visibility = ["//visibility:public"],
)

pkg_npm(
name = "npm_module",
deps = [
":%s" % PKG_BASE_NAME,
]
)

filegroup(
name = "build",
srcs = [
":npm_module",
],
visibility = ["//visibility:public"],
)
8 changes: 8 additions & 0 deletions packages/kbn-securitysolution-io-ts-alerting-types/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# kbn-securitysolution-io-ts-alerting-types

Types that are specific to the security solution alerting to be shared among plugins.

Related packages are
* kbn-securitysolution-io-ts-utils
* kbn-securitysolution-io-ts-list-types
* kbn-securitysolution-io-ts-types
13 changes: 13 additions & 0 deletions packages/kbn-securitysolution-io-ts-alerting-types/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

module.exports = {
preset: '@kbn/test',
rootDir: '../..',
roots: ['<rootDir>/packages/kbn-securitysolution-io-ts-utils'],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@kbn/securitysolution-io-ts-alerting-types",
"version": "1.0.0",
"description": "io ts utilities and types to be shared with plugins from the security solution project",
"license": "SSPL-1.0 OR Elastic License 2.0",
"main": "./target/index.js",
"types": "./target/index.d.ts",
"private": true
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import * as t from 'io-ts';
import { Either } from 'fp-ts/lib/Either';
import { PositiveIntegerGreaterThanZero } from '../positive_integer_greater_than_zero';
import { PositiveIntegerGreaterThanZero } from '@kbn/securitysolution-io-ts-types';

/**
* Types the DefaultPerPage as:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import * as t from 'io-ts';
import { Either } from 'fp-ts/lib/Either';
import { PositiveIntegerGreaterThanZero } from '../positive_integer_greater_than_zero';
import { PositiveIntegerGreaterThanZero } from '@kbn/securitysolution-io-ts-types';

/**
* Types the DefaultPerPage as:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import * as t from 'io-ts';
import { Either } from 'fp-ts/lib/Either';
import uuid from 'uuid';
import { NonEmptyString } from '@kbn/securitysolution-io-ts-types';

/**
* Types the DefaultUuid as:
* - If null or undefined, then a default string uuid.v4() will be
* created otherwise it will be checked just against an empty string
*/
export const DefaultUuid = new t.Type<string, string | undefined, unknown>(
'DefaultUuid',
t.string.is,
(input, context): Either<t.Errors, string> =>
input == null ? t.success(uuid.v4()) : NonEmptyString.validate(input, context),
t.identity
);
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import { Either } from 'fp-ts/lib/Either';
import * as t from 'io-ts';
import { parseScheduleDates } from '../parse_schedule_dates';
import { parseScheduleDates } from '@kbn/securitysolution-io-ts-types';

const stringValidator = (input: unknown): input is string => typeof input === 'string';

Expand Down
40 changes: 40 additions & 0 deletions packages/kbn-securitysolution-io-ts-alerting-types/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export * from './actions';
export * from './constants';
export * from './default_actions_array';
export * from './default_export_file_name';
export * from './default_from_string';
export * from './default_interval_string';
export * from './default_language_string';
export * from './default_max_signals_number';
export * from './default_page';
export * from './default_per_page';
export * from './default_risk_score_mapping_array';
export * from './default_severity_mapping_array';
export * from './default_threat_array';
export * from './default_throttle_null';
export * from './default_to_string';
export * from './default_uuid';
export * from './from';
export * from './language';
export * from './max_signals';
export * from './normalized_ml_job_id';
export * from './references_default_array';
export * from './risk_score';
export * from './risk_score_mapping';
export * from './saved_object_attributes';
export * from './severity';
export * from './severity_mapping';
export * from './threat';
export * from './threat_mapping';
export * from './threat_subtechnique';
export * from './threat_tactic';
export * from './threat_technique';
export * from './throttle';
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/* eslint-disable @typescript-eslint/naming-convention */

import * as t from 'io-ts';
import { PositiveIntegerGreaterThanZero } from '../positive_integer_greater_than_zero';
import { PositiveIntegerGreaterThanZero } from '@kbn/securitysolution-io-ts-types';

export const max_signals = PositiveIntegerGreaterThanZero;
export type MaxSignals = t.TypeOf<typeof max_signals>;
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import * as t from 'io-ts';

import { NonEmptyArray } from '../non_empty_array';
import { NonEmptyArray } from '@kbn/securitysolution-io-ts-types';

export const machine_learning_job_id_normalized = NonEmptyArray(t.string);
export type MachineLearningJobIdNormalized = t.TypeOf<typeof machine_learning_job_id_normalized>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
/* eslint-disable @typescript-eslint/naming-convention */

import * as t from 'io-ts';
import { operator } from '@kbn/securitysolution-io-ts-types';
import { RiskScore } from '../risk_score';

import { operator } from '../operator';

export const riskScoreOrUndefined = t.union([RiskScore, t.undefined]);
export type RiskScoreOrUndefined = t.TypeOf<typeof riskScoreOrUndefined>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import * as t from 'io-ts';

import { operator } from '../operator';
import { operator } from '@kbn/securitysolution-io-ts-types';
import { severity } from '../severity';

export const severity_mapping_field = t.string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
/* eslint-disable @typescript-eslint/naming-convention */

import * as t from 'io-ts';
import {
NonEmptyArray,
NonEmptyString,
PositiveIntegerGreaterThanZero,
} from '@kbn/securitysolution-io-ts-types';
import { language } from '../language';
import { NonEmptyArray } from '../non_empty_array';
import { NonEmptyString } from '../non_empty_string';
import { PositiveIntegerGreaterThanZero } from '../positive_integer_greater_than_zero';

export const threat_query = t.string;
export type ThreatQuery = t.TypeOf<typeof threat_query>;
Expand Down
19 changes: 19 additions & 0 deletions packages/kbn-securitysolution-io-ts-alerting-types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"declaration": true,
"declarationMap": true,
"incremental": true,
"outDir": "target",
"rootDir": "src",
"sourceMap": true,
"sourceRoot": "../../../../packages/kbn-securitysolution-io-ts-alerting-types/src",
"types": [
"jest",
"node"
]
},
"include": [
"src/**/*"
]
}
Loading

0 comments on commit f252c60

Please sign in to comment.