mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[Move @kbn/config-schema
to server] kbn-object-versioning
(#191691)
This commit is contained in:
parent
525d9f6899
commit
52cbd493c2
18 changed files with 110 additions and 32 deletions
1
.github/CODEOWNERS
vendored
1
.github/CODEOWNERS
vendored
|
@ -629,6 +629,7 @@ test/common/plugins/newsfeed @elastic/kibana-core
|
|||
src/plugins/no_data_page @elastic/appex-sharedux
|
||||
x-pack/plugins/notifications @elastic/appex-sharedux
|
||||
packages/kbn-object-versioning @elastic/appex-sharedux
|
||||
packages/kbn-object-versioning-utils @elastic/appex-sharedux
|
||||
x-pack/plugins/observability_solution/observability_ai_assistant_app @elastic/obs-ai-assistant
|
||||
x-pack/plugins/observability_solution/observability_ai_assistant_management @elastic/obs-ai-assistant
|
||||
x-pack/plugins/observability_solution/observability_ai_assistant @elastic/obs-ai-assistant
|
||||
|
|
|
@ -662,6 +662,7 @@
|
|||
"@kbn/no-data-page-plugin": "link:src/plugins/no_data_page",
|
||||
"@kbn/notifications-plugin": "link:x-pack/plugins/notifications",
|
||||
"@kbn/object-versioning": "link:packages/kbn-object-versioning",
|
||||
"@kbn/object-versioning-utils": "link:packages/kbn-object-versioning-utils",
|
||||
"@kbn/observability-ai-assistant-app-plugin": "link:x-pack/plugins/observability_solution/observability_ai_assistant_app",
|
||||
"@kbn/observability-ai-assistant-management-plugin": "link:x-pack/plugins/observability_solution/observability_ai_assistant_management",
|
||||
"@kbn/observability-ai-assistant-plugin": "link:x-pack/plugins/observability_solution/observability_ai_assistant",
|
||||
|
|
3
packages/kbn-object-versioning-utils/README.md
Normal file
3
packages/kbn-object-versioning-utils/README.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
# @kbn/object-versioning-utils
|
||||
|
||||
Exports common utils from `@kbn/object-versioning` that are safe to be used both in the server and the browser.
|
9
packages/kbn-object-versioning-utils/index.ts
Normal file
9
packages/kbn-object-versioning-utils/index.ts
Normal file
|
@ -0,0 +1,9 @@
|
|||
/*
|
||||
* 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 { validateVersion } from './lib/validate_version';
|
13
packages/kbn-object-versioning-utils/jest.config.js
Normal file
13
packages/kbn-object-versioning-utils/jest.config.js
Normal file
|
@ -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-object-versioning-utils'],
|
||||
};
|
5
packages/kbn-object-versioning-utils/kibana.jsonc
Normal file
5
packages/kbn-object-versioning-utils/kibana.jsonc
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"type": "shared-common",
|
||||
"id": "@kbn/object-versioning-utils",
|
||||
"owner": "@elastic/appex-sharedux"
|
||||
}
|
39
packages/kbn-object-versioning-utils/lib/validate_version.ts
Normal file
39
packages/kbn-object-versioning-utils/lib/validate_version.ts
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* 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 type { Version } from '@kbn/object-versioning';
|
||||
// Declaring it directly to avoid circular dependencies.
|
||||
type Version = number;
|
||||
|
||||
export const validateVersion = (
|
||||
version: unknown
|
||||
): { result: true; value: Version } | { result: false; value: null } => {
|
||||
if (typeof version === 'string') {
|
||||
const isValid = /^\d+$/.test(version);
|
||||
if (isValid) {
|
||||
const parsed = parseInt(version, 10);
|
||||
if (Number.isNaN(parsed)) {
|
||||
return { result: false, value: null };
|
||||
}
|
||||
return { result: true, value: parsed };
|
||||
}
|
||||
return { result: false, value: null };
|
||||
} else {
|
||||
const isValid = Number.isInteger(version);
|
||||
if (isValid) {
|
||||
return {
|
||||
result: true,
|
||||
value: version as Version,
|
||||
};
|
||||
}
|
||||
return {
|
||||
result: false,
|
||||
value: null,
|
||||
};
|
||||
}
|
||||
};
|
6
packages/kbn-object-versioning-utils/package.json
Normal file
6
packages/kbn-object-versioning-utils/package.json
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"name": "@kbn/object-versioning-utils",
|
||||
"private": true,
|
||||
"version": "1.0.0",
|
||||
"license": "SSPL-1.0 OR Elastic License 2.0"
|
||||
}
|
20
packages/kbn-object-versioning-utils/tsconfig.json
Normal file
20
packages/kbn-object-versioning-utils/tsconfig.json
Normal file
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "target/types",
|
||||
"types": [
|
||||
"jest",
|
||||
"node",
|
||||
"react"
|
||||
]
|
||||
},
|
||||
"include": [
|
||||
"**/*.ts",
|
||||
"**/*.tsx",
|
||||
],
|
||||
"exclude": [
|
||||
"target/**/*"
|
||||
],
|
||||
"kbn_references": [
|
||||
]
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"type": "shared-common",
|
||||
"type": "shared-server",
|
||||
"id": "@kbn/object-versioning",
|
||||
"owner": "@elastic/appex-sharedux"
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
*/
|
||||
|
||||
import type { Type, ValidationError } from '@kbn/config-schema';
|
||||
import { Version } from './types';
|
||||
|
||||
/**
|
||||
* Validate an object based on a schema.
|
||||
|
@ -29,30 +28,4 @@ export const validateObj = (obj: unknown, objSchema?: Type<any>): ValidationErro
|
|||
}
|
||||
};
|
||||
|
||||
export const validateVersion = (
|
||||
version: unknown
|
||||
): { result: true; value: Version } | { result: false; value: null } => {
|
||||
if (typeof version === 'string') {
|
||||
const isValid = /^\d+$/.test(version);
|
||||
if (isValid) {
|
||||
const parsed = parseInt(version, 10);
|
||||
if (Number.isNaN(parsed)) {
|
||||
return { result: false, value: null };
|
||||
}
|
||||
return { result: true, value: parsed };
|
||||
}
|
||||
return { result: false, value: null };
|
||||
} else {
|
||||
const isValid = Number.isInteger(version);
|
||||
if (isValid) {
|
||||
return {
|
||||
result: true,
|
||||
value: version as Version,
|
||||
};
|
||||
}
|
||||
return {
|
||||
result: false,
|
||||
value: null,
|
||||
};
|
||||
}
|
||||
};
|
||||
export { validateVersion } from '@kbn/object-versioning-utils';
|
||||
|
|
|
@ -18,5 +18,6 @@
|
|||
"kbn_references": [
|
||||
"@kbn/config-schema",
|
||||
"@kbn/safer-lodash-set",
|
||||
"@kbn/object-versioning-utils",
|
||||
]
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
import { schema } from '@kbn/config-schema';
|
||||
import { validateVersion } from '@kbn/object-versioning/lib/utils';
|
||||
import { validateVersion } from '@kbn/object-versioning-utils';
|
||||
|
||||
export const procedureNames = [
|
||||
'get',
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
*/
|
||||
|
||||
import { QueryClient } from '@tanstack/react-query';
|
||||
import { validateVersion } from '@kbn/object-versioning/lib/utils';
|
||||
import { validateVersion } from '@kbn/object-versioning-utils';
|
||||
import type { Version } from '@kbn/object-versioning';
|
||||
import { createQueryObservable } from './query_observable';
|
||||
import type { CrudClient } from '../crud_client';
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { validateVersion } from '@kbn/object-versioning/lib/utils';
|
||||
import { validateVersion } from '@kbn/object-versioning-utils';
|
||||
|
||||
import type { ContentTypeDefinition } from './content_type_definition';
|
||||
import { ContentType } from './content_type';
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
"@kbn/saved-objects-settings",
|
||||
"@kbn/core-http-server",
|
||||
"@kbn/content-management-favorites-server",
|
||||
"@kbn/object-versioning-utils",
|
||||
],
|
||||
"exclude": [
|
||||
"target/**/*",
|
||||
|
|
|
@ -1252,6 +1252,8 @@
|
|||
"@kbn/notifications-plugin/*": ["x-pack/plugins/notifications/*"],
|
||||
"@kbn/object-versioning": ["packages/kbn-object-versioning"],
|
||||
"@kbn/object-versioning/*": ["packages/kbn-object-versioning/*"],
|
||||
"@kbn/object-versioning-utils": ["packages/kbn-object-versioning-utils"],
|
||||
"@kbn/object-versioning-utils/*": ["packages/kbn-object-versioning-utils/*"],
|
||||
"@kbn/observability-ai-assistant-app-plugin": ["x-pack/plugins/observability_solution/observability_ai_assistant_app"],
|
||||
"@kbn/observability-ai-assistant-app-plugin/*": ["x-pack/plugins/observability_solution/observability_ai_assistant_app/*"],
|
||||
"@kbn/observability-ai-assistant-management-plugin": ["x-pack/plugins/observability_solution/observability_ai_assistant_management"],
|
||||
|
|
|
@ -5754,6 +5754,10 @@
|
|||
version "0.0.0"
|
||||
uid ""
|
||||
|
||||
"@kbn/object-versioning-utils@link:packages/kbn-object-versioning-utils":
|
||||
version "0.0.0"
|
||||
uid ""
|
||||
|
||||
"@kbn/object-versioning@link:packages/kbn-object-versioning":
|
||||
version "0.0.0"
|
||||
uid ""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue