Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions packages/kbn-object-versioning-utils/README.md
Original file line number Diff line number Diff line change
@@ -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 changes: 9 additions & 0 deletions packages/kbn-object-versioning-utils/index.ts
Original file line number Diff line number Diff line change
@@ -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 changes: 13 additions & 0 deletions packages/kbn-object-versioning-utils/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-object-versioning-utils'],
};
5 changes: 5 additions & 0 deletions packages/kbn-object-versioning-utils/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "shared-common",
"id": "@kbn/object-versioning-utils",
"owner": "@elastic/appex-sharedux"
}
39 changes: 39 additions & 0 deletions packages/kbn-object-versioning-utils/lib/validate_version.ts
Original file line number Diff line number Diff line change
@@ -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 changes: 6 additions & 0 deletions packages/kbn-object-versioning-utils/package.json
Original file line number Diff line number Diff line change
@@ -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 changes: 20 additions & 0 deletions packages/kbn-object-versioning-utils/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types",
"types": [
"jest",
"node",
"react"
]
},
"include": [
"**/*.ts",
"**/*.tsx",
],
"exclude": [
"target/**/*"
],
"kbn_references": [
]
}
2 changes: 1 addition & 1 deletion packages/kbn-object-versioning/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "shared-common",
"type": "shared-server",
"id": "@kbn/object-versioning",
"owner": "@elastic/appex-sharedux"
}
29 changes: 1 addition & 28 deletions packages/kbn-object-versioning/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/

import type { Type, ValidationError } from '@kbn/config-schema';
import { Version } from './types';

/**
* Validate an object based on a schema.
Expand All @@ -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';
1 change: 1 addition & 0 deletions packages/kbn-object-versioning/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
"kbn_references": [
"@kbn/config-schema",
"@kbn/safer-lodash-set",
"@kbn/object-versioning-utils",
]
}
2 changes: 1 addition & 1 deletion src/plugins/content_management/common/rpc/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/content_management/public/registry/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
1 change: 1 addition & 0 deletions src/plugins/content_management/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@kbn/saved-objects-settings",
"@kbn/core-http-server",
"@kbn/content-management-favorites-server",
"@kbn/object-versioning-utils",
],
"exclude": [
"target/**/*",
Expand Down
2 changes: 2 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down