[Move @kbn/config-schema to server] kbn-object-versioning (#191691)

This commit is contained in:
Alejandro Fernández Haro 2024-08-29 12:39:09 +02:00 committed by GitHub
parent 525d9f6899
commit 52cbd493c2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 110 additions and 32 deletions

1
.github/CODEOWNERS vendored
View file

@ -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

View file

@ -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",

View 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.

View 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';

View 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'],
};

View file

@ -0,0 +1,5 @@
{
"type": "shared-common",
"id": "@kbn/object-versioning-utils",
"owner": "@elastic/appex-sharedux"
}

View 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,
};
}
};

View 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"
}

View file

@ -0,0 +1,20 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types",
"types": [
"jest",
"node",
"react"
]
},
"include": [
"**/*.ts",
"**/*.tsx",
],
"exclude": [
"target/**/*"
],
"kbn_references": [
]
}

View file

@ -1,5 +1,5 @@
{
"type": "shared-common",
"type": "shared-server",
"id": "@kbn/object-versioning",
"owner": "@elastic/appex-sharedux"
}

View file

@ -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';

View file

@ -18,5 +18,6 @@
"kbn_references": [
"@kbn/config-schema",
"@kbn/safer-lodash-set",
"@kbn/object-versioning-utils",
]
}

View file

@ -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',

View file

@ -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';

View file

@ -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';

View file

@ -17,6 +17,7 @@
"@kbn/saved-objects-settings",
"@kbn/core-http-server",
"@kbn/content-management-favorites-server",
"@kbn/object-versioning-utils",
],
"exclude": [
"target/**/*",

View file

@ -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"],

View file

@ -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 ""