diff --git a/package.json b/package.json index 1066262b34267..6390e367c9187 100644 --- a/package.json +++ b/package.json @@ -237,11 +237,14 @@ "@kbn/core-preboot-server-mocks": "link:bazel-bin/packages/core/preboot/core-preboot-server-mocks", "@kbn/core-saved-objects-api-browser": "link:bazel-bin/packages/core/saved-objects/core-saved-objects-api-browser", "@kbn/core-saved-objects-api-server": "link:bazel-bin/packages/core/saved-objects/core-saved-objects-api-server", + "@kbn/core-saved-objects-base-server-internal": "link:bazel-bin/packages/core/saved-objects/core-saved-objects-base-server-internal", + "@kbn/core-saved-objects-base-server-mocks": "link:bazel-bin/packages/core/saved-objects/core-saved-objects-base-server-mocks", "@kbn/core-saved-objects-browser": "link:bazel-bin/packages/core/saved-objects/core-saved-objects-browser", "@kbn/core-saved-objects-browser-internal": "link:bazel-bin/packages/core/saved-objects/core-saved-objects-browser-internal", "@kbn/core-saved-objects-browser-mocks": "link:bazel-bin/packages/core/saved-objects/core-saved-objects-browser-mocks", "@kbn/core-saved-objects-common": "link:bazel-bin/packages/core/saved-objects/core-saved-objects-common", "@kbn/core-saved-objects-server": "link:bazel-bin/packages/core/saved-objects/core-saved-objects-server", + "@kbn/core-saved-objects-utils-server": "link:bazel-bin/packages/core/saved-objects/core-saved-objects-utils-server", "@kbn/core-test-helpers-deprecations-getters": "link:bazel-bin/packages/core/test-helpers/core-test-helpers-deprecations-getters", "@kbn/core-test-helpers-http-setup-browser": "link:bazel-bin/packages/core/test-helpers/core-test-helpers-http-setup-browser", "@kbn/core-theme-browser": "link:bazel-bin/packages/core/theme/core-theme-browser", @@ -894,11 +897,14 @@ "@types/kbn__core-public-internal-base": "link:bazel-bin/packages/core/public/internal-base/npm_module_types", "@types/kbn__core-saved-objects-api-browser": "link:bazel-bin/packages/core/saved-objects/core-saved-objects-api-browser/npm_module_types", "@types/kbn__core-saved-objects-api-server": "link:bazel-bin/packages/core/saved-objects/core-saved-objects-api-server/npm_module_types", + "@types/kbn__core-saved-objects-base-server-internal": "link:bazel-bin/packages/core/saved-objects/core-saved-objects-base-server-internal/npm_module_types", + "@types/kbn__core-saved-objects-base-server-mocks": "link:bazel-bin/packages/core/saved-objects/core-saved-objects-base-server-mocks/npm_module_types", "@types/kbn__core-saved-objects-browser": "link:bazel-bin/packages/core/saved-objects/core-saved-objects-browser/npm_module_types", "@types/kbn__core-saved-objects-browser-internal": "link:bazel-bin/packages/core/saved-objects/core-saved-objects-browser-internal/npm_module_types", "@types/kbn__core-saved-objects-browser-mocks": "link:bazel-bin/packages/core/saved-objects/core-saved-objects-browser-mocks/npm_module_types", "@types/kbn__core-saved-objects-common": "link:bazel-bin/packages/core/saved-objects/core-saved-objects-common/npm_module_types", "@types/kbn__core-saved-objects-server": "link:bazel-bin/packages/core/saved-objects/core-saved-objects-server/npm_module_types", + "@types/kbn__core-saved-objects-utils-server": "link:bazel-bin/packages/core/saved-objects/core-saved-objects-utils-server/npm_module_types", "@types/kbn__core-server-internal-base": "link:bazel-bin/packages/core/server/internal-base/npm_module_types", "@types/kbn__core-test-helpers-deprecations-getters": "link:bazel-bin/packages/core/test-helpers/core-test-helpers-deprecations-getters/npm_module_types", "@types/kbn__core-test-helpers-http-setup-browser": "link:bazel-bin/packages/core/test-helpers/core-test-helpers-http-setup-browser/npm_module_types", diff --git a/packages/BUILD.bazel b/packages/BUILD.bazel index a9a0377b679dd..b084fa8617929 100644 --- a/packages/BUILD.bazel +++ b/packages/BUILD.bazel @@ -102,11 +102,14 @@ filegroup( "//packages/core/preboot/core-preboot-server:build", "//packages/core/saved-objects/core-saved-objects-api-browser:build", "//packages/core/saved-objects/core-saved-objects-api-server:build", + "//packages/core/saved-objects/core-saved-objects-base-server-internal:build", + "//packages/core/saved-objects/core-saved-objects-base-server-mocks:build", "//packages/core/saved-objects/core-saved-objects-browser-internal:build", "//packages/core/saved-objects/core-saved-objects-browser-mocks:build", "//packages/core/saved-objects/core-saved-objects-browser:build", "//packages/core/saved-objects/core-saved-objects-common:build", "//packages/core/saved-objects/core-saved-objects-server:build", + "//packages/core/saved-objects/core-saved-objects-utils-server:build", "//packages/core/test-helpers/core-test-helpers-deprecations-getters:build", "//packages/core/test-helpers/core-test-helpers-http-setup-browser:build", "//packages/core/theme/core-theme-browser-internal:build", @@ -375,11 +378,14 @@ filegroup( "//packages/core/preboot/core-preboot-server:build_types", "//packages/core/saved-objects/core-saved-objects-api-browser:build_types", "//packages/core/saved-objects/core-saved-objects-api-server:build_types", + "//packages/core/saved-objects/core-saved-objects-base-server-internal:build_types", + "//packages/core/saved-objects/core-saved-objects-base-server-mocks:build_types", "//packages/core/saved-objects/core-saved-objects-browser-internal:build_types", "//packages/core/saved-objects/core-saved-objects-browser-mocks:build_types", "//packages/core/saved-objects/core-saved-objects-browser:build_types", "//packages/core/saved-objects/core-saved-objects-common:build_types", "//packages/core/saved-objects/core-saved-objects-server:build_types", + "//packages/core/saved-objects/core-saved-objects-utils-server:build_types", "//packages/core/test-helpers/core-test-helpers-deprecations-getters:build_types", "//packages/core/test-helpers/core-test-helpers-http-setup-browser:build_types", "//packages/core/theme/core-theme-browser-internal:build_types", diff --git a/packages/core/saved-objects/core-saved-objects-base-server-internal/BUILD.bazel b/packages/core/saved-objects/core-saved-objects-base-server-internal/BUILD.bazel new file mode 100644 index 0000000000000..d64f0bb533a0f --- /dev/null +++ b/packages/core/saved-objects/core-saved-objects-base-server-internal/BUILD.bazel @@ -0,0 +1,111 @@ +load("@npm//@bazel/typescript:index.bzl", "ts_config") +load("@build_bazel_rules_nodejs//:index.bzl", "js_library") +load("//src/dev/bazel:index.bzl", "jsts_transpiler", "pkg_npm", "pkg_npm_types", "ts_project") + +PKG_DIRNAME = "core-saved-objects-base-server-internal" +PKG_REQUIRE_NAME = "@kbn/core-saved-objects-base-server-internal" + +SOURCE_FILES = glob( + [ + "src/**/*.ts", + ], + exclude = [ + "**/*.test.*", + "**/*.stories.*", + ], +) + +SRCS = SOURCE_FILES + +filegroup( + name = "srcs", + srcs = SRCS, +) + +NPM_MODULE_EXTRA_FILES = [ + "package.json", +] + +RUNTIME_DEPS = [ + "@npm//lodash", + "@npm//semver", + "//packages/kbn-config-schema", + ### test dependencies + "//packages/kbn-logging-mocks", + "@npm//@hapi/boom", +] + +TYPES_DEPS = [ + "@npm//@types/node", + "@npm//@types/jest", + "@npm//@types/lodash", + "@npm//@types/semver", + "//packages/kbn-logging:npm_module_types", + "//packages/kbn-config-schema:npm_module_types", + "//packages/core/base/core-base-server-internal:npm_module_types", + "//packages/core/saved-objects/core-saved-objects-server:npm_module_types", + "//packages/core/saved-objects/core-saved-objects-utils-server:npm_module_types", +] + +jsts_transpiler( + name = "target_node", + srcs = SRCS, + build_pkg_name = package_name(), + root_input_dir = "src", +) + +ts_config( + name = "tsconfig", + src = "tsconfig.json", + deps = [ + "//:tsconfig.base.json", + "//:tsconfig.bazel.json", + ], +) + +ts_project( + name = "tsc_types", + args = ['--pretty'], + srcs = SRCS, + deps = TYPES_DEPS, + declaration = True, + declaration_map = True, + emit_declaration_only = True, + out_dir = "target_types", + root_dir = "src", + tsconfig = ":tsconfig", +) + +js_library( + name = PKG_DIRNAME, + srcs = NPM_MODULE_EXTRA_FILES, + deps = RUNTIME_DEPS + [":target_node"], + package_name = PKG_REQUIRE_NAME, + visibility = ["//visibility:public"], +) + +pkg_npm( + name = "npm_module", + deps = [":" + PKG_DIRNAME], +) + +filegroup( + name = "build", + srcs = [":npm_module"], + visibility = ["//visibility:public"], +) + +pkg_npm_types( + name = "npm_module_types", + srcs = SRCS, + deps = [":tsc_types"], + package_name = PKG_REQUIRE_NAME, + tsconfig = ":tsconfig", + visibility = ["//visibility:public"], +) + +filegroup( + name = "build_types", + srcs = [":npm_module_types"], + visibility = ["//visibility:public"], +) diff --git a/packages/core/saved-objects/core-saved-objects-base-server-internal/README.md b/packages/core/saved-objects/core-saved-objects-base-server-internal/README.md new file mode 100644 index 0000000000000..0315d68aca7b0 --- /dev/null +++ b/packages/core/saved-objects/core-saved-objects-base-server-internal/README.md @@ -0,0 +1,4 @@ +# @kbn/core-saved-objects-base-server-internal + +This package contains the base parts of the server-side savedObjects internal implementation, +used by all the other internal server-side savedObjects packages. \ No newline at end of file diff --git a/packages/core/saved-objects/core-saved-objects-base-server-internal/jest.config.js b/packages/core/saved-objects/core-saved-objects-base-server-internal/jest.config.js new file mode 100644 index 0000000000000..384625b895fcd --- /dev/null +++ b/packages/core/saved-objects/core-saved-objects-base-server-internal/jest.config.js @@ -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/jest_node', + rootDir: '../../../..', + roots: ['/packages/core/saved-objects/core-saved-objects-base-server-internal'], +}; diff --git a/packages/core/saved-objects/core-saved-objects-base-server-internal/package.json b/packages/core/saved-objects/core-saved-objects-base-server-internal/package.json new file mode 100644 index 0000000000000..ff4b901f49056 --- /dev/null +++ b/packages/core/saved-objects/core-saved-objects-base-server-internal/package.json @@ -0,0 +1,7 @@ +{ + "name": "@kbn/core-saved-objects-base-server-internal", + "private": true, + "version": "1.0.0", + "main": "./target_node/index.js", + "license": "SSPL-1.0 OR Elastic License 2.0" +} diff --git a/packages/core/saved-objects/core-saved-objects-base-server-internal/src/index.ts b/packages/core/saved-objects/core-saved-objects-base-server-internal/src/index.ts new file mode 100644 index 0000000000000..5b504f43244d6 --- /dev/null +++ b/packages/core/saved-objects/core-saved-objects-base-server-internal/src/index.ts @@ -0,0 +1,29 @@ +/* + * 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 { LEGACY_URL_ALIAS_TYPE, type LegacyUrlAlias } from './legacy_alias'; +export { + getProperty, + getRootProperties, + getRootPropertiesObjects, + getTypes, + type IndexMapping, + type IndexMappingMeta, + type SavedObjectsTypeMappingDefinitions, +} from './mappings'; +export { SavedObjectsSerializer } from './serialization'; +export { SavedObjectsTypeValidator } from './validation'; +export { decodeRequestVersion, decodeVersion, encodeVersion, encodeHitVersion } from './version'; +export { + savedObjectsConfig, + savedObjectsMigrationConfig, + SavedObjectConfig, + type SavedObjectsConfigType, + type SavedObjectsMigrationConfigType, +} from './saved_objects_config'; +export { SavedObjectTypeRegistry } from './saved_objects_type_registry'; diff --git a/src/core/server/saved_objects/object_types/constants.ts b/packages/core/saved-objects/core-saved-objects-base-server-internal/src/legacy_alias/constants.ts similarity index 100% rename from src/core/server/saved_objects/object_types/constants.ts rename to packages/core/saved-objects/core-saved-objects-base-server-internal/src/legacy_alias/constants.ts diff --git a/src/core/server/saved_objects/version/index.ts b/packages/core/saved-objects/core-saved-objects-base-server-internal/src/legacy_alias/index.ts similarity index 70% rename from src/core/server/saved_objects/version/index.ts rename to packages/core/saved-objects/core-saved-objects-base-server-internal/src/legacy_alias/index.ts index 715073fb98e7d..f782267bd2096 100644 --- a/src/core/server/saved_objects/version/index.ts +++ b/packages/core/saved-objects/core-saved-objects-base-server-internal/src/legacy_alias/index.ts @@ -6,7 +6,5 @@ * Side Public License, v 1. */ -export * from './encode_version'; -export * from './encode_hit_version'; -export * from './decode_version'; -export * from './decode_request_version'; +export type { LegacyUrlAlias } from './types'; +export { LEGACY_URL_ALIAS_TYPE } from './constants'; diff --git a/src/core/server/saved_objects/object_types/types.ts b/packages/core/saved-objects/core-saved-objects-base-server-internal/src/legacy_alias/types.ts similarity index 100% rename from src/core/server/saved_objects/object_types/types.ts rename to packages/core/saved-objects/core-saved-objects-base-server-internal/src/legacy_alias/types.ts diff --git a/src/core/server/saved_objects/mappings/index.ts b/packages/core/saved-objects/core-saved-objects-base-server-internal/src/mappings/index.ts similarity index 100% rename from src/core/server/saved_objects/mappings/index.ts rename to packages/core/saved-objects/core-saved-objects-base-server-internal/src/mappings/index.ts diff --git a/src/core/server/saved_objects/mappings/lib/get_property.test.ts b/packages/core/saved-objects/core-saved-objects-base-server-internal/src/mappings/lib/get_property.test.ts similarity index 100% rename from src/core/server/saved_objects/mappings/lib/get_property.test.ts rename to packages/core/saved-objects/core-saved-objects-base-server-internal/src/mappings/lib/get_property.test.ts diff --git a/src/core/server/saved_objects/mappings/lib/get_property.ts b/packages/core/saved-objects/core-saved-objects-base-server-internal/src/mappings/lib/get_property.ts similarity index 100% rename from src/core/server/saved_objects/mappings/lib/get_property.ts rename to packages/core/saved-objects/core-saved-objects-base-server-internal/src/mappings/lib/get_property.ts diff --git a/src/core/server/saved_objects/mappings/lib/get_root_properties.ts b/packages/core/saved-objects/core-saved-objects-base-server-internal/src/mappings/lib/get_root_properties.ts similarity index 100% rename from src/core/server/saved_objects/mappings/lib/get_root_properties.ts rename to packages/core/saved-objects/core-saved-objects-base-server-internal/src/mappings/lib/get_root_properties.ts diff --git a/src/core/server/saved_objects/mappings/lib/get_root_properties_objects.test.ts b/packages/core/saved-objects/core-saved-objects-base-server-internal/src/mappings/lib/get_root_properties_objects.test.ts similarity index 100% rename from src/core/server/saved_objects/mappings/lib/get_root_properties_objects.test.ts rename to packages/core/saved-objects/core-saved-objects-base-server-internal/src/mappings/lib/get_root_properties_objects.test.ts diff --git a/src/core/server/saved_objects/mappings/lib/get_root_properties_objects.ts b/packages/core/saved-objects/core-saved-objects-base-server-internal/src/mappings/lib/get_root_properties_objects.ts similarity index 100% rename from src/core/server/saved_objects/mappings/lib/get_root_properties_objects.ts rename to packages/core/saved-objects/core-saved-objects-base-server-internal/src/mappings/lib/get_root_properties_objects.ts diff --git a/src/core/server/saved_objects/mappings/lib/get_types.ts b/packages/core/saved-objects/core-saved-objects-base-server-internal/src/mappings/lib/get_types.ts similarity index 100% rename from src/core/server/saved_objects/mappings/lib/get_types.ts rename to packages/core/saved-objects/core-saved-objects-base-server-internal/src/mappings/lib/get_types.ts diff --git a/src/core/server/saved_objects/mappings/lib/index.ts b/packages/core/saved-objects/core-saved-objects-base-server-internal/src/mappings/lib/index.ts similarity index 100% rename from src/core/server/saved_objects/mappings/lib/index.ts rename to packages/core/saved-objects/core-saved-objects-base-server-internal/src/mappings/lib/index.ts diff --git a/src/core/server/saved_objects/mappings/types.ts b/packages/core/saved-objects/core-saved-objects-base-server-internal/src/mappings/types.ts similarity index 100% rename from src/core/server/saved_objects/mappings/types.ts rename to packages/core/saved-objects/core-saved-objects-base-server-internal/src/mappings/types.ts diff --git a/src/core/server/saved_objects/saved_objects_config.ts b/packages/core/saved-objects/core-saved-objects-base-server-internal/src/saved_objects_config.ts similarity index 100% rename from src/core/server/saved_objects/saved_objects_config.ts rename to packages/core/saved-objects/core-saved-objects-base-server-internal/src/saved_objects_config.ts diff --git a/src/core/server/saved_objects/saved_objects_type_registry.test.ts b/packages/core/saved-objects/core-saved-objects-base-server-internal/src/saved_objects_type_registry.test.ts similarity index 100% rename from src/core/server/saved_objects/saved_objects_type_registry.test.ts rename to packages/core/saved-objects/core-saved-objects-base-server-internal/src/saved_objects_type_registry.test.ts diff --git a/src/core/server/saved_objects/saved_objects_type_registry.ts b/packages/core/saved-objects/core-saved-objects-base-server-internal/src/saved_objects_type_registry.ts similarity index 100% rename from src/core/server/saved_objects/saved_objects_type_registry.ts rename to packages/core/saved-objects/core-saved-objects-base-server-internal/src/saved_objects_type_registry.ts diff --git a/src/core/server/saved_objects/serialization/index.ts b/packages/core/saved-objects/core-saved-objects-base-server-internal/src/serialization/index.ts similarity index 100% rename from src/core/server/saved_objects/serialization/index.ts rename to packages/core/saved-objects/core-saved-objects-base-server-internal/src/serialization/index.ts diff --git a/src/core/server/saved_objects/serialization/serializer.test.ts b/packages/core/saved-objects/core-saved-objects-base-server-internal/src/serialization/serializer.test.ts similarity index 96% rename from src/core/server/saved_objects/serialization/serializer.test.ts rename to packages/core/saved-objects/core-saved-objects-base-server-internal/src/serialization/serializer.test.ts index e0ef357c0d9be..230993bd06d29 100644 --- a/src/core/server/saved_objects/serialization/serializer.test.ts +++ b/packages/core/saved-objects/core-saved-objects-base-server-internal/src/serialization/serializer.test.ts @@ -7,28 +7,47 @@ */ import _ from 'lodash'; -import type { SavedObjectsRawDoc } from '@kbn/core-saved-objects-server'; +import type { SavedObjectsRawDoc, ISavedObjectTypeRegistry } from '@kbn/core-saved-objects-server'; import { SavedObjectsSerializer } from './serializer'; -import { typeRegistryMock } from '../saved_objects_type_registry.mock'; import { encodeVersion } from '../version'; -import { LEGACY_URL_ALIAS_TYPE } from '../object_types'; +import { LEGACY_URL_ALIAS_TYPE } from '../legacy_alias'; + +const createMockedTypeRegistry = ({ + isNamespaceAgnostic, + isSingleNamespace, + isMultiNamespace, +}: { + isNamespaceAgnostic: boolean; + isSingleNamespace: boolean; + isMultiNamespace: boolean; +}): ISavedObjectTypeRegistry => { + const typeRegistry: Partial = { + isNamespaceAgnostic: jest.fn().mockReturnValue(isNamespaceAgnostic), + isSingleNamespace: jest.fn().mockReturnValue(isSingleNamespace), + isMultiNamespace: jest.fn().mockReturnValue(isMultiNamespace), + }; + return typeRegistry as ISavedObjectTypeRegistry; +}; -let typeRegistry = typeRegistryMock.create(); -typeRegistry.isNamespaceAgnostic.mockReturnValue(true); -typeRegistry.isSingleNamespace.mockReturnValue(false); -typeRegistry.isMultiNamespace.mockReturnValue(false); +let typeRegistry = createMockedTypeRegistry({ + isNamespaceAgnostic: true, + isSingleNamespace: false, + isMultiNamespace: false, +}); const namespaceAgnosticSerializer = new SavedObjectsSerializer(typeRegistry); -typeRegistry = typeRegistryMock.create(); -typeRegistry.isNamespaceAgnostic.mockReturnValue(false); -typeRegistry.isSingleNamespace.mockReturnValue(true); -typeRegistry.isMultiNamespace.mockReturnValue(false); +typeRegistry = typeRegistry = createMockedTypeRegistry({ + isNamespaceAgnostic: false, + isSingleNamespace: true, + isMultiNamespace: false, +}); const singleNamespaceSerializer = new SavedObjectsSerializer(typeRegistry); -typeRegistry = typeRegistryMock.create(); -typeRegistry.isNamespaceAgnostic.mockReturnValue(false); -typeRegistry.isSingleNamespace.mockReturnValue(false); -typeRegistry.isMultiNamespace.mockReturnValue(true); +typeRegistry = typeRegistry = createMockedTypeRegistry({ + isNamespaceAgnostic: false, + isSingleNamespace: false, + isMultiNamespace: true, +}); const multiNamespaceSerializer = new SavedObjectsSerializer(typeRegistry); const sampleTemplate = { diff --git a/src/core/server/saved_objects/serialization/serializer.ts b/packages/core/saved-objects/core-saved-objects-base-server-internal/src/serialization/serializer.ts similarity index 98% rename from src/core/server/saved_objects/serialization/serializer.ts rename to packages/core/saved-objects/core-saved-objects-base-server-internal/src/serialization/serializer.ts index 2e13708ee2f9d..340926abd0bce 100644 --- a/src/core/server/saved_objects/serialization/serializer.ts +++ b/packages/core/saved-objects/core-saved-objects-base-server-internal/src/serialization/serializer.ts @@ -14,9 +14,9 @@ import type { SavedObjectSanitizedDoc, SavedObjectsRawDocParseOptions, } from '@kbn/core-saved-objects-server'; -import { LEGACY_URL_ALIAS_TYPE } from '../object_types'; +import { SavedObjectsUtils } from '@kbn/core-saved-objects-utils-server'; +import { LEGACY_URL_ALIAS_TYPE } from '../legacy_alias'; import { decodeVersion, encodeVersion } from '../version'; -import { SavedObjectsUtils } from '../service'; /** * Core internal implementation of {@link ISavedObjectsSerializer} diff --git a/src/core/server/saved_objects/validation/index.ts b/packages/core/saved-objects/core-saved-objects-base-server-internal/src/validation/index.ts similarity index 100% rename from src/core/server/saved_objects/validation/index.ts rename to packages/core/saved-objects/core-saved-objects-base-server-internal/src/validation/index.ts diff --git a/src/core/server/saved_objects/validation/schema.test.ts b/packages/core/saved-objects/core-saved-objects-base-server-internal/src/validation/schema.test.ts similarity index 100% rename from src/core/server/saved_objects/validation/schema.test.ts rename to packages/core/saved-objects/core-saved-objects-base-server-internal/src/validation/schema.test.ts diff --git a/src/core/server/saved_objects/validation/schema.ts b/packages/core/saved-objects/core-saved-objects-base-server-internal/src/validation/schema.ts similarity index 97% rename from src/core/server/saved_objects/validation/schema.ts rename to packages/core/saved-objects/core-saved-objects-base-server-internal/src/validation/schema.ts index 8e90c4aef9c70..221f21b5aa992 100644 --- a/src/core/server/saved_objects/validation/schema.ts +++ b/packages/core/saved-objects/core-saved-objects-base-server-internal/src/validation/schema.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import { schema, Type } from '@kbn/config-schema'; +import { schema, type Type } from '@kbn/config-schema'; import type { SavedObjectsValidationSpec, SavedObjectSanitizedDoc, diff --git a/src/core/server/saved_objects/validation/validator.test.ts b/packages/core/saved-objects/core-saved-objects-base-server-internal/src/validation/validator.test.ts similarity index 95% rename from src/core/server/saved_objects/validation/validator.test.ts rename to packages/core/saved-objects/core-saved-objects-base-server-internal/src/validation/validator.test.ts index b059070fdf75f..96bc93be54c1a 100644 --- a/src/core/server/saved_objects/validation/validator.test.ts +++ b/packages/core/saved-objects/core-saved-objects-base-server-internal/src/validation/validator.test.ts @@ -7,12 +7,12 @@ */ import { schema } from '@kbn/config-schema'; +import { loggerMock, type MockedLogger } from '@kbn/logging-mocks'; import type { SavedObjectSanitizedDoc, SavedObjectsValidationMap, } from '@kbn/core-saved-objects-server'; -import { SavedObjectsTypeValidator } from '.'; -import { loggerMock, MockedLogger } from '@kbn/logging-mocks'; +import { SavedObjectsTypeValidator } from './validator'; describe('Saved Objects type validator', () => { let validator: SavedObjectsTypeValidator; diff --git a/src/core/server/saved_objects/validation/validator.ts b/packages/core/saved-objects/core-saved-objects-base-server-internal/src/validation/validator.ts similarity index 100% rename from src/core/server/saved_objects/validation/validator.ts rename to packages/core/saved-objects/core-saved-objects-base-server-internal/src/validation/validator.ts diff --git a/src/core/server/saved_objects/version/base64.ts b/packages/core/saved-objects/core-saved-objects-base-server-internal/src/version/base64.ts similarity index 100% rename from src/core/server/saved_objects/version/base64.ts rename to packages/core/saved-objects/core-saved-objects-base-server-internal/src/version/base64.ts diff --git a/src/core/server/saved_objects/version/decode_request_version.test.ts b/packages/core/saved-objects/core-saved-objects-base-server-internal/src/version/decode_request_version.test.ts similarity index 100% rename from src/core/server/saved_objects/version/decode_request_version.test.ts rename to packages/core/saved-objects/core-saved-objects-base-server-internal/src/version/decode_request_version.test.ts diff --git a/src/core/server/saved_objects/version/decode_request_version.ts b/packages/core/saved-objects/core-saved-objects-base-server-internal/src/version/decode_request_version.ts similarity index 100% rename from src/core/server/saved_objects/version/decode_request_version.ts rename to packages/core/saved-objects/core-saved-objects-base-server-internal/src/version/decode_request_version.ts diff --git a/src/core/server/saved_objects/version/decode_version.test.ts b/packages/core/saved-objects/core-saved-objects-base-server-internal/src/version/decode_version.test.ts similarity index 100% rename from src/core/server/saved_objects/version/decode_version.test.ts rename to packages/core/saved-objects/core-saved-objects-base-server-internal/src/version/decode_version.test.ts diff --git a/src/core/server/saved_objects/version/decode_version.ts b/packages/core/saved-objects/core-saved-objects-base-server-internal/src/version/decode_version.ts similarity index 93% rename from src/core/server/saved_objects/version/decode_version.ts rename to packages/core/saved-objects/core-saved-objects-base-server-internal/src/version/decode_version.ts index 4166e7eef06c7..dd4bdcdc8186f 100644 --- a/src/core/server/saved_objects/version/decode_version.ts +++ b/packages/core/saved-objects/core-saved-objects-base-server-internal/src/version/decode_version.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import { SavedObjectsErrorHelpers } from '../service/lib/errors'; +import { SavedObjectsErrorHelpers } from '@kbn/core-saved-objects-utils-server'; import { decodeBase64 } from './base64'; /** diff --git a/src/core/server/saved_objects/version/encode_hit_version.test.ts b/packages/core/saved-objects/core-saved-objects-base-server-internal/src/version/encode_hit_version.test.ts similarity index 100% rename from src/core/server/saved_objects/version/encode_hit_version.test.ts rename to packages/core/saved-objects/core-saved-objects-base-server-internal/src/version/encode_hit_version.test.ts diff --git a/src/core/server/saved_objects/version/encode_hit_version.ts b/packages/core/saved-objects/core-saved-objects-base-server-internal/src/version/encode_hit_version.ts similarity index 100% rename from src/core/server/saved_objects/version/encode_hit_version.ts rename to packages/core/saved-objects/core-saved-objects-base-server-internal/src/version/encode_hit_version.ts diff --git a/src/core/server/saved_objects/version/encode_version.test.ts b/packages/core/saved-objects/core-saved-objects-base-server-internal/src/version/encode_version.test.ts similarity index 100% rename from src/core/server/saved_objects/version/encode_version.test.ts rename to packages/core/saved-objects/core-saved-objects-base-server-internal/src/version/encode_version.test.ts diff --git a/src/core/server/saved_objects/version/encode_version.ts b/packages/core/saved-objects/core-saved-objects-base-server-internal/src/version/encode_version.ts similarity index 100% rename from src/core/server/saved_objects/version/encode_version.ts rename to packages/core/saved-objects/core-saved-objects-base-server-internal/src/version/encode_version.ts diff --git a/packages/core/saved-objects/core-saved-objects-base-server-internal/src/version/index.ts b/packages/core/saved-objects/core-saved-objects-base-server-internal/src/version/index.ts new file mode 100644 index 0000000000000..2fb31940d4408 --- /dev/null +++ b/packages/core/saved-objects/core-saved-objects-base-server-internal/src/version/index.ts @@ -0,0 +1,12 @@ +/* + * 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 { encodeVersion } from './encode_version'; +export { encodeHitVersion } from './encode_hit_version'; +export { decodeVersion } from './decode_version'; +export { decodeRequestVersion } from './decode_request_version'; diff --git a/packages/core/saved-objects/core-saved-objects-base-server-internal/tsconfig.json b/packages/core/saved-objects/core-saved-objects-base-server-internal/tsconfig.json new file mode 100644 index 0000000000000..39d3c7097814a --- /dev/null +++ b/packages/core/saved-objects/core-saved-objects-base-server-internal/tsconfig.json @@ -0,0 +1,18 @@ +{ + "extends": "../../../../tsconfig.bazel.json", + "compilerOptions": { + "declaration": true, + "declarationMap": true, + "emitDeclarationOnly": true, + "outDir": "target_types", + "rootDir": "src", + "stripInternal": false, + "types": [ + "jest", + "node" + ] + }, + "include": [ + "src/**/*" + ] +} diff --git a/packages/core/saved-objects/core-saved-objects-base-server-mocks/BUILD.bazel b/packages/core/saved-objects/core-saved-objects-base-server-mocks/BUILD.bazel new file mode 100644 index 0000000000000..9f3538c20a752 --- /dev/null +++ b/packages/core/saved-objects/core-saved-objects-base-server-mocks/BUILD.bazel @@ -0,0 +1,100 @@ +load("@npm//@bazel/typescript:index.bzl", "ts_config") +load("@build_bazel_rules_nodejs//:index.bzl", "js_library") +load("//src/dev/bazel:index.bzl", "jsts_transpiler", "pkg_npm", "pkg_npm_types", "ts_project") + +PKG_DIRNAME = "core-saved-objects-base-server-mocks" +PKG_REQUIRE_NAME = "@kbn/core-saved-objects-base-server-mocks" + +SOURCE_FILES = glob( + [ + "src/**/*.ts", + ], + exclude = [ + "**/*.test.*", + "**/*.stories.*", + ], +) + +SRCS = SOURCE_FILES + +filegroup( + name = "srcs", + srcs = SRCS, +) + +NPM_MODULE_EXTRA_FILES = [ + "package.json", +] + +RUNTIME_DEPS = [ +] + +TYPES_DEPS = [ + "@npm//@types/node", + "@npm//@types/jest", + "//packages/core/saved-objects/core-saved-objects-server:npm_module_types", + "//packages/core/saved-objects/core-saved-objects-base-server-internal:npm_module_types", +] + +jsts_transpiler( + name = "target_node", + srcs = SRCS, + build_pkg_name = package_name(), + root_input_dir = "src", +) + +ts_config( + name = "tsconfig", + src = "tsconfig.json", + deps = [ + "//:tsconfig.base.json", + "//:tsconfig.bazel.json", + ], +) + +ts_project( + name = "tsc_types", + args = ['--pretty'], + srcs = SRCS, + deps = TYPES_DEPS, + declaration = True, + declaration_map = True, + emit_declaration_only = True, + out_dir = "target_types", + root_dir = "src", + tsconfig = ":tsconfig", +) + +js_library( + name = PKG_DIRNAME, + srcs = NPM_MODULE_EXTRA_FILES, + deps = RUNTIME_DEPS + [":target_node"], + package_name = PKG_REQUIRE_NAME, + visibility = ["//visibility:public"], +) + +pkg_npm( + name = "npm_module", + deps = [":" + PKG_DIRNAME], +) + +filegroup( + name = "build", + srcs = [":npm_module"], + visibility = ["//visibility:public"], +) + +pkg_npm_types( + name = "npm_module_types", + srcs = SRCS, + deps = [":tsc_types"], + package_name = PKG_REQUIRE_NAME, + tsconfig = ":tsconfig", + visibility = ["//visibility:public"], +) + +filegroup( + name = "build_types", + srcs = [":npm_module_types"], + visibility = ["//visibility:public"], +) diff --git a/packages/core/saved-objects/core-saved-objects-base-server-mocks/README.md b/packages/core/saved-objects/core-saved-objects-base-server-mocks/README.md new file mode 100644 index 0000000000000..5da5264ce9eed --- /dev/null +++ b/packages/core/saved-objects/core-saved-objects-base-server-mocks/README.md @@ -0,0 +1,5 @@ +# @kbn/core-saved-objects-base-server-mocks + +This package contains the mocks for the base server-side savedObjects sub-domain: +- `SavedObjectTypeRegistry` mock +- `SavedObjectsSerializer` mock diff --git a/packages/core/saved-objects/core-saved-objects-base-server-mocks/jest.config.js b/packages/core/saved-objects/core-saved-objects-base-server-mocks/jest.config.js new file mode 100644 index 0000000000000..fee774e787693 --- /dev/null +++ b/packages/core/saved-objects/core-saved-objects-base-server-mocks/jest.config.js @@ -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/jest_node', + rootDir: '../../../..', + roots: ['/packages/core/saved-objects/core-saved-objects-base-server-mocks'], +}; diff --git a/packages/core/saved-objects/core-saved-objects-base-server-mocks/package.json b/packages/core/saved-objects/core-saved-objects-base-server-mocks/package.json new file mode 100644 index 0000000000000..e119e704c7ace --- /dev/null +++ b/packages/core/saved-objects/core-saved-objects-base-server-mocks/package.json @@ -0,0 +1,7 @@ +{ + "name": "@kbn/core-saved-objects-base-server-mocks", + "private": true, + "version": "1.0.0", + "main": "./target_node/index.js", + "license": "SSPL-1.0 OR Elastic License 2.0" +} diff --git a/packages/core/saved-objects/core-saved-objects-base-server-mocks/src/index.ts b/packages/core/saved-objects/core-saved-objects-base-server-mocks/src/index.ts new file mode 100644 index 0000000000000..62657cf81ea61 --- /dev/null +++ b/packages/core/saved-objects/core-saved-objects-base-server-mocks/src/index.ts @@ -0,0 +1,10 @@ +/* + * 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 { typeRegistryMock } from './saved_objects_type_registry.mock'; +export { serializerMock } from './serializer.mock'; diff --git a/src/core/server/saved_objects/saved_objects_type_registry.mock.ts b/packages/core/saved-objects/core-saved-objects-base-server-mocks/src/saved_objects_type_registry.mock.ts similarity index 94% rename from src/core/server/saved_objects/saved_objects_type_registry.mock.ts rename to packages/core/saved-objects/core-saved-objects-base-server-mocks/src/saved_objects_type_registry.mock.ts index 70d05a0f7b0ab..8f792f177b5fc 100644 --- a/src/core/server/saved_objects/saved_objects_type_registry.mock.ts +++ b/packages/core/saved-objects/core-saved-objects-base-server-mocks/src/saved_objects_type_registry.mock.ts @@ -7,7 +7,7 @@ */ import type { ISavedObjectTypeRegistry } from '@kbn/core-saved-objects-server'; -import type { SavedObjectTypeRegistry } from './saved_objects_type_registry'; +import type { SavedObjectTypeRegistry } from '@kbn/core-saved-objects-base-server-internal'; const createRegistryMock = (): jest.Mocked< ISavedObjectTypeRegistry & Pick diff --git a/packages/core/saved-objects/core-saved-objects-base-server-mocks/src/serializer.mock.ts b/packages/core/saved-objects/core-saved-objects-base-server-mocks/src/serializer.mock.ts new file mode 100644 index 0000000000000..6bdac2e20c1f9 --- /dev/null +++ b/packages/core/saved-objects/core-saved-objects-base-server-mocks/src/serializer.mock.ts @@ -0,0 +1,24 @@ +/* + * 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 { ISavedObjectsSerializer } from '@kbn/core-saved-objects-server'; + +const createSerializerMock = () => { + const mock: jest.Mocked = { + isRawSavedObject: jest.fn(), + rawToSavedObject: jest.fn(), + savedObjectToRaw: jest.fn(), + generateRawId: jest.fn(), + generateRawLegacyUrlAliasId: jest.fn(), + }; + return mock; +}; + +export const serializerMock = { + create: createSerializerMock, +}; diff --git a/packages/core/saved-objects/core-saved-objects-base-server-mocks/tsconfig.json b/packages/core/saved-objects/core-saved-objects-base-server-mocks/tsconfig.json new file mode 100644 index 0000000000000..39d3c7097814a --- /dev/null +++ b/packages/core/saved-objects/core-saved-objects-base-server-mocks/tsconfig.json @@ -0,0 +1,18 @@ +{ + "extends": "../../../../tsconfig.bazel.json", + "compilerOptions": { + "declaration": true, + "declarationMap": true, + "emitDeclarationOnly": true, + "outDir": "target_types", + "rootDir": "src", + "stripInternal": false, + "types": [ + "jest", + "node" + ] + }, + "include": [ + "src/**/*" + ] +} diff --git a/packages/core/saved-objects/core-saved-objects-utils-server/BUILD.bazel b/packages/core/saved-objects/core-saved-objects-utils-server/BUILD.bazel new file mode 100644 index 0000000000000..71a61799ee46a --- /dev/null +++ b/packages/core/saved-objects/core-saved-objects-utils-server/BUILD.bazel @@ -0,0 +1,106 @@ +load("@npm//@bazel/typescript:index.bzl", "ts_config") +load("@build_bazel_rules_nodejs//:index.bzl", "js_library") +load("//src/dev/bazel:index.bzl", "jsts_transpiler", "pkg_npm", "pkg_npm_types", "ts_project") + +PKG_DIRNAME = "core-saved-objects-utils-server" +PKG_REQUIRE_NAME = "@kbn/core-saved-objects-utils-server" + +SOURCE_FILES = glob( + [ + "src/**/*.ts", + ], + exclude = [ + "**/*.test.*", + "**/*.stories.*", + ], +) + +SRCS = SOURCE_FILES + +filegroup( + name = "srcs", + srcs = SRCS, +) + +NPM_MODULE_EXTRA_FILES = [ + "package.json", +] + +RUNTIME_DEPS = [ + "@npm//lodash", + "@npm//uuid", + "@npm//@hapi/boom", +] + + +TYPES_DEPS = [ + "@npm//@types/node", + "@npm//@types/jest", + "@npm//@types/lodash", + "@npm//@types/uuid", + "@npm//@hapi/boom", + "//packages/core/saved-objects/core-saved-objects-server:npm_module_types", +] + +jsts_transpiler( + name = "target_node", + srcs = SRCS, + build_pkg_name = package_name(), + root_input_dir = "src", +) + +ts_config( + name = "tsconfig", + src = "tsconfig.json", + deps = [ + "//:tsconfig.base.json", + "//:tsconfig.bazel.json", + ], +) + +ts_project( + name = "tsc_types", + args = ['--pretty'], + srcs = SRCS, + deps = TYPES_DEPS, + declaration = True, + declaration_map = True, + emit_declaration_only = True, + out_dir = "target_types", + root_dir = "src", + tsconfig = ":tsconfig", +) + +js_library( + name = PKG_DIRNAME, + srcs = NPM_MODULE_EXTRA_FILES, + deps = RUNTIME_DEPS + [":target_node"], + package_name = PKG_REQUIRE_NAME, + visibility = ["//visibility:public"], +) + +pkg_npm( + name = "npm_module", + deps = [":" + PKG_DIRNAME], +) + +filegroup( + name = "build", + srcs = [":npm_module"], + visibility = ["//visibility:public"], +) + +pkg_npm_types( + name = "npm_module_types", + srcs = SRCS, + deps = [":tsc_types"], + package_name = PKG_REQUIRE_NAME, + tsconfig = ":tsconfig", + visibility = ["//visibility:public"], +) + +filegroup( + name = "build_types", + srcs = [":npm_module_types"], + visibility = ["//visibility:public"], +) diff --git a/packages/core/saved-objects/core-saved-objects-utils-server/README.md b/packages/core/saved-objects/core-saved-objects-utils-server/README.md new file mode 100644 index 0000000000000..ecbfa469575ae --- /dev/null +++ b/packages/core/saved-objects/core-saved-objects-utils-server/README.md @@ -0,0 +1,5 @@ +# @kbn/core-saved-objects-utils-server + +This package contains public utilities for Core's server-side `savedObjects` domain. + + diff --git a/packages/core/saved-objects/core-saved-objects-utils-server/jest.config.js b/packages/core/saved-objects/core-saved-objects-utils-server/jest.config.js new file mode 100644 index 0000000000000..5458bf05b6767 --- /dev/null +++ b/packages/core/saved-objects/core-saved-objects-utils-server/jest.config.js @@ -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/jest_node', + rootDir: '../../../..', + roots: ['/packages/core/saved-objects/core-saved-objects-utils-server'], +}; diff --git a/packages/core/saved-objects/core-saved-objects-utils-server/package.json b/packages/core/saved-objects/core-saved-objects-utils-server/package.json new file mode 100644 index 0000000000000..13220da373261 --- /dev/null +++ b/packages/core/saved-objects/core-saved-objects-utils-server/package.json @@ -0,0 +1,7 @@ +{ + "name": "@kbn/core-saved-objects-utils-server", + "private": true, + "version": "1.0.0", + "main": "./target_node/index.js", + "license": "SSPL-1.0 OR Elastic License 2.0" +} diff --git a/packages/core/saved-objects/core-saved-objects-utils-server/src/index.ts b/packages/core/saved-objects/core-saved-objects-utils-server/src/index.ts new file mode 100644 index 0000000000000..3704cebf08398 --- /dev/null +++ b/packages/core/saved-objects/core-saved-objects-utils-server/src/index.ts @@ -0,0 +1,17 @@ +/* + * 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 { mergeSavedObjectMigrationMaps } from './merge_migration_maps'; +export { SavedObjectsErrorHelpers, type DecoratedError } from './saved_objects_error_helpers'; +export { + SavedObjectsUtils, + ALL_NAMESPACES_STRING, + DEFAULT_NAMESPACE_STRING, + FIND_DEFAULT_PAGE, + FIND_DEFAULT_PER_PAGE, +} from './saved_objects_utils'; diff --git a/src/core/server/saved_objects/migrations/utils.test.ts b/packages/core/saved-objects/core-saved-objects-utils-server/src/merge_migration_maps.test.ts similarity index 96% rename from src/core/server/saved_objects/migrations/utils.test.ts rename to packages/core/saved-objects/core-saved-objects-utils-server/src/merge_migration_maps.test.ts index e3378c3fb9e78..28b3ebd3735b4 100644 --- a/src/core/server/saved_objects/migrations/utils.test.ts +++ b/packages/core/saved-objects/core-saved-objects-utils-server/src/merge_migration_maps.test.ts @@ -11,7 +11,7 @@ import type { SavedObjectMigrationMap, SavedObjectUnsanitizedDoc, } from '@kbn/core-saved-objects-server'; -import { mergeSavedObjectMigrationMaps } from './utils'; +import { mergeSavedObjectMigrationMaps } from './merge_migration_maps'; describe('mergeSavedObjectMigrationMaps', () => { const obj1: SavedObjectMigrationMap = { diff --git a/src/core/server/saved_objects/migrations/utils.ts b/packages/core/saved-objects/core-saved-objects-utils-server/src/merge_migration_maps.ts similarity index 96% rename from src/core/server/saved_objects/migrations/utils.ts rename to packages/core/saved-objects/core-saved-objects-utils-server/src/merge_migration_maps.ts index 108317fc6698b..e5f2f1d74a7cf 100644 --- a/src/core/server/saved_objects/migrations/utils.ts +++ b/packages/core/saved-objects/core-saved-objects-utils-server/src/merge_migration_maps.ts @@ -7,12 +7,12 @@ */ import { mergeWith } from 'lodash'; -import { +import type { SavedObjectMigrationContext, SavedObjectMigrationFn, SavedObjectMigrationMap, SavedObjectUnsanitizedDoc, -} from '../..'; +} from '@kbn/core-saved-objects-server'; /** * Merges two saved object migration maps. diff --git a/src/core/server/saved_objects/service/lib/errors.test.ts b/packages/core/saved-objects/core-saved-objects-utils-server/src/saved_objects_error_helpers.test.ts similarity index 99% rename from src/core/server/saved_objects/service/lib/errors.test.ts rename to packages/core/saved-objects/core-saved-objects-utils-server/src/saved_objects_error_helpers.test.ts index 3bea693429254..6f312a09a56e9 100644 --- a/src/core/server/saved_objects/service/lib/errors.test.ts +++ b/packages/core/saved-objects/core-saved-objects-utils-server/src/saved_objects_error_helpers.test.ts @@ -7,8 +7,7 @@ */ import Boom from '@hapi/boom'; - -import { SavedObjectsErrorHelpers } from './errors'; +import { SavedObjectsErrorHelpers } from './saved_objects_error_helpers'; describe('savedObjectsClient/errorTypes', () => { describe('BadRequest error', () => { diff --git a/src/core/server/saved_objects/service/lib/errors.ts b/packages/core/saved-objects/core-saved-objects-utils-server/src/saved_objects_error_helpers.ts similarity index 100% rename from src/core/server/saved_objects/service/lib/errors.ts rename to packages/core/saved-objects/core-saved-objects-utils-server/src/saved_objects_error_helpers.ts diff --git a/src/core/server/saved_objects/service/lib/utils.test.mock.ts b/packages/core/saved-objects/core-saved-objects-utils-server/src/saved_objects_utils.test.mock.ts similarity index 100% rename from src/core/server/saved_objects/service/lib/utils.test.mock.ts rename to packages/core/saved-objects/core-saved-objects-utils-server/src/saved_objects_utils.test.mock.ts diff --git a/src/core/server/saved_objects/service/lib/utils.test.ts b/packages/core/saved-objects/core-saved-objects-utils-server/src/saved_objects_utils.test.ts similarity index 94% rename from src/core/server/saved_objects/service/lib/utils.test.ts rename to packages/core/saved-objects/core-saved-objects-utils-server/src/saved_objects_utils.test.ts index 8c836afd087d3..717b52ef248ca 100644 --- a/src/core/server/saved_objects/service/lib/utils.test.ts +++ b/packages/core/saved-objects/core-saved-objects-utils-server/src/saved_objects_utils.test.ts @@ -6,10 +6,10 @@ * Side Public License, v 1. */ -import { mockUuidv1, mockUuidv5 } from './utils.test.mock'; +import { mockUuidv1, mockUuidv5 } from './saved_objects_utils.test.mock'; -import { SavedObjectsFindOptions } from '@kbn/core-saved-objects-api-server'; -import { SavedObjectsUtils } from './utils'; +import type { SavedObjectsFindOptions } from '@kbn/core-saved-objects-api-server'; +import { SavedObjectsUtils } from './saved_objects_utils'; describe('SavedObjectsUtils', () => { const { diff --git a/src/core/server/saved_objects/service/lib/utils.ts b/packages/core/saved-objects/core-saved-objects-utils-server/src/saved_objects_utils.ts similarity index 100% rename from src/core/server/saved_objects/service/lib/utils.ts rename to packages/core/saved-objects/core-saved-objects-utils-server/src/saved_objects_utils.ts diff --git a/packages/core/saved-objects/core-saved-objects-utils-server/tsconfig.json b/packages/core/saved-objects/core-saved-objects-utils-server/tsconfig.json new file mode 100644 index 0000000000000..39d3c7097814a --- /dev/null +++ b/packages/core/saved-objects/core-saved-objects-utils-server/tsconfig.json @@ -0,0 +1,18 @@ +{ + "extends": "../../../../tsconfig.bazel.json", + "compilerOptions": { + "declaration": true, + "declarationMap": true, + "emitDeclarationOnly": true, + "outDir": "target_types", + "rootDir": "src", + "stripInternal": false, + "types": [ + "jest", + "node" + ] + }, + "include": [ + "src/**/*" + ] +} diff --git a/src/core/server/core_usage_data/core_usage_data_service.test.ts b/src/core/server/core_usage_data/core_usage_data_service.test.ts index c45b3fdb0a125..5ac2863745ee7 100644 --- a/src/core/server/core_usage_data/core_usage_data_service.test.ts +++ b/src/core/server/core_usage_data/core_usage_data_service.test.ts @@ -18,14 +18,14 @@ import { mockCoreContext } from '@kbn/core-base-server-mocks'; import { config as RawLoggingConfig } from '@kbn/core-logging-server-internal'; import { config as RawElasticsearchConfig } from '@kbn/core-elasticsearch-server-internal'; import { config as RawHttpConfig } from '@kbn/core-http-server-internal'; -import { savedObjectsConfig as RawSavedObjectsConfig } from '../saved_objects/saved_objects_config'; +import { savedObjectsConfig as RawSavedObjectsConfig } from '@kbn/core-saved-objects-base-server-internal'; import { httpServiceMock } from '@kbn/core-http-server-mocks'; import { metricsServiceMock } from '@kbn/core-metrics-server-mocks'; import { savedObjectsServiceMock } from '../saved_objects/saved_objects_service.mock'; import { CoreUsageDataService } from './core_usage_data_service'; import { elasticsearchServiceMock } from '@kbn/core-elasticsearch-server-mocks'; -import { typeRegistryMock } from '../saved_objects/saved_objects_type_registry.mock'; +import { typeRegistryMock } from '@kbn/core-saved-objects-base-server-mocks'; import { CORE_USAGE_STATS_TYPE } from './constants'; import { CoreUsageStatsClient } from './core_usage_stats_client'; diff --git a/src/core/server/core_usage_data/core_usage_data_service.ts b/src/core/server/core_usage_data/core_usage_data_service.ts index f1e51a7e5f5aa..c5f2335e333e4 100644 --- a/src/core/server/core_usage_data/core_usage_data_service.ts +++ b/src/core/server/core_usage_data/core_usage_data_service.ts @@ -23,9 +23,12 @@ import type { HttpConfigType, InternalHttpServiceSetup } from '@kbn/core-http-se import type { ElasticsearchServiceStart } from '@kbn/core-elasticsearch-server'; import type { ElasticsearchConfigType } from '@kbn/core-elasticsearch-server-internal'; import type { MetricsServiceSetup, OpsMetrics } from '@kbn/core-metrics-server'; -import { SavedObjectsServiceStart, SavedObjectTypeRegistry } from '..'; +import { + LEGACY_URL_ALIAS_TYPE, + type SavedObjectsConfigType, +} from '@kbn/core-saved-objects-base-server-internal'; -import { SavedObjectsConfigType } from '../saved_objects/saved_objects_config'; +import { SavedObjectsServiceStart, SavedObjectTypeRegistry } from '..'; import type { CoreServicesUsageData, CoreUsageData, @@ -36,7 +39,6 @@ import type { } from './types'; import { isConfigured } from './is_configured'; import { coreUsageStatsType } from './core_usage_stats'; -import { LEGACY_URL_ALIAS_TYPE } from '../saved_objects/object_types'; import { CORE_USAGE_STATS_TYPE } from './constants'; import { CoreUsageStatsClient } from './core_usage_stats_client'; import { CoreIncrementUsageCounter } from './types'; diff --git a/src/core/server/core_usage_data/core_usage_stats_client.test.ts b/src/core/server/core_usage_data/core_usage_stats_client.test.ts index 6bcaa38bd0062..9a6984f6b5785 100644 --- a/src/core/server/core_usage_data/core_usage_stats_client.test.ts +++ b/src/core/server/core_usage_data/core_usage_stats_client.test.ts @@ -29,8 +29,8 @@ import { LEGACY_DASHBOARDS_EXPORT_STATS_PREFIX, BULK_RESOLVE_STATS_PREFIX, } from './core_usage_stats_client'; +import { DEFAULT_NAMESPACE_STRING } from '@kbn/core-saved-objects-utils-server'; import { CoreUsageStatsClient } from '.'; -import { DEFAULT_NAMESPACE_STRING } from '../saved_objects/service/lib/utils'; describe('CoreUsageStatsClient', () => { const setup = (namespace?: string) => { diff --git a/src/core/server/core_usage_data/core_usage_stats_client.ts b/src/core/server/core_usage_data/core_usage_stats_client.ts index 2dd8c77fd1876..c14776ff7ed81 100644 --- a/src/core/server/core_usage_data/core_usage_stats_client.ts +++ b/src/core/server/core_usage_data/core_usage_stats_client.ts @@ -6,9 +6,9 @@ * Side Public License, v 1. */ +import { DEFAULT_NAMESPACE_STRING } from '@kbn/core-saved-objects-utils-server'; import { CORE_USAGE_STATS_TYPE, CORE_USAGE_STATS_ID } from './constants'; import { CoreUsageStats } from './types'; -import { DEFAULT_NAMESPACE_STRING } from '../saved_objects/service/lib/utils'; import { ISavedObjectsRepository, SavedObjectsImportOptions, diff --git a/src/core/server/index.ts b/src/core/server/index.ts index 0f365366206d2..3327340c91a8c 100644 --- a/src/core/server/index.ts +++ b/src/core/server/index.ts @@ -388,6 +388,12 @@ export type { ISavedObjectsSerializer, SavedObjectsRequestHandlerContext, } from '@kbn/core-saved-objects-server'; +export { + SavedObjectsErrorHelpers, + SavedObjectsUtils, + mergeSavedObjectMigrationMaps, +} from '@kbn/core-saved-objects-utils-server'; +export { SavedObjectTypeRegistry } from '@kbn/core-saved-objects-base-server-internal'; export type { SavedObjectsRepository, @@ -396,14 +402,7 @@ export type { SavedObjectsImporter, SavedObjectsImportError, } from './saved_objects'; -export { - SavedObjectsClient, - SavedObjectsErrorHelpers, - SavedObjectsSerializer, - SavedObjectTypeRegistry, - SavedObjectsUtils, - mergeSavedObjectMigrationMaps, -} from './saved_objects'; +export { SavedObjectsClient } from './saved_objects'; export type { IUiSettingsClient, diff --git a/src/core/server/integration_tests/saved_objects/routes/delete_unknown_types.test.ts b/src/core/server/integration_tests/saved_objects/routes/delete_unknown_types.test.ts index 4a13921750d1f..b4a215169a376 100644 --- a/src/core/server/integration_tests/saved_objects/routes/delete_unknown_types.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/delete_unknown_types.test.ts @@ -8,8 +8,8 @@ import supertest from 'supertest'; import { elasticsearchServiceMock } from '@kbn/core-elasticsearch-server-mocks'; +import { typeRegistryMock } from '@kbn/core-saved-objects-base-server-mocks'; import { registerDeleteUnknownTypesRoute } from '../../../saved_objects/routes/deprecations'; -import { typeRegistryMock } from '../../../saved_objects/saved_objects_type_registry.mock'; import { setupServer } from '../../../saved_objects/routes/test_utils'; import { SavedObjectsType } from '../../..'; import type { InternalSavedObjectsRequestHandlerContext } from '../../../saved_objects/internal_types'; diff --git a/src/core/server/integration_tests/saved_objects/routes/export.test.ts b/src/core/server/integration_tests/saved_objects/routes/export.test.ts index 358a23902d5e1..b107d1266fe3c 100644 --- a/src/core/server/integration_tests/saved_objects/routes/export.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/export.test.ts @@ -16,7 +16,7 @@ import { CoreUsageStatsClient } from '../../../core_usage_data'; import { coreUsageStatsClientMock } from '../../../core_usage_data/core_usage_stats_client.mock'; import { coreUsageDataServiceMock } from '../../../core_usage_data/core_usage_data_service.mock'; import { savedObjectsExporterMock } from '../../../saved_objects/export/saved_objects_exporter.mock'; -import { SavedObjectConfig } from '../../../saved_objects/saved_objects_config'; +import type { SavedObjectConfig } from '@kbn/core-saved-objects-base-server-internal'; import { registerExportRoute } from '../../../saved_objects/routes/export'; import { setupServer, createExportableType } from '../../../saved_objects/routes/test_utils'; import type { InternalSavedObjectsRequestHandlerContext } from '../../../saved_objects/internal_types'; diff --git a/src/core/server/integration_tests/saved_objects/routes/import.test.ts b/src/core/server/integration_tests/saved_objects/routes/import.test.ts index a9062b8d07919..ec6a483e8ae1f 100644 --- a/src/core/server/integration_tests/saved_objects/routes/import.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/import.test.ts @@ -9,14 +9,15 @@ jest.mock('uuid'); import supertest from 'supertest'; +import { SavedObjectsErrorHelpers } from '@kbn/core-saved-objects-utils-server'; import { registerImportRoute } from '../../../saved_objects/routes/import'; import { savedObjectsClientMock } from '../../../mocks'; import { CoreUsageStatsClient } from '../../../core_usage_data'; import { coreUsageStatsClientMock } from '../../../core_usage_data/core_usage_stats_client.mock'; import { coreUsageDataServiceMock } from '../../../core_usage_data/core_usage_data_service.mock'; -import { SavedObjectConfig } from '../../../saved_objects/saved_objects_config'; +import { SavedObjectConfig } from '@kbn/core-saved-objects-base-server-internal'; import { setupServer, createExportableType } from '../../../saved_objects/routes/test_utils'; -import { SavedObjectsErrorHelpers, SavedObjectsImporter } from '../../../saved_objects'; +import { SavedObjectsImporter } from '../../../saved_objects'; import type { InternalSavedObjectsRequestHandlerContext } from '../../../saved_objects/internal_types'; type SetupServerReturn = Awaited>; diff --git a/src/core/server/integration_tests/saved_objects/routes/resolve_import_errors.test.ts b/src/core/server/integration_tests/saved_objects/routes/resolve_import_errors.test.ts index defdbc5cfc1d6..5d26fde36fae4 100644 --- a/src/core/server/integration_tests/saved_objects/routes/resolve_import_errors.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/resolve_import_errors.test.ts @@ -15,7 +15,7 @@ import { CoreUsageStatsClient } from '../../../core_usage_data'; import { coreUsageStatsClientMock } from '../../../core_usage_data/core_usage_stats_client.mock'; import { coreUsageDataServiceMock } from '../../../core_usage_data/core_usage_data_service.mock'; import { setupServer, createExportableType } from '../../../saved_objects/routes/test_utils'; -import { SavedObjectConfig } from '../../../saved_objects/saved_objects_config'; +import { SavedObjectConfig } from '@kbn/core-saved-objects-base-server-internal'; import { SavedObjectsImporter } from '../../../saved_objects/import'; import type { InternalSavedObjectsRequestHandlerContext } from '../../../saved_objects/internal_types'; diff --git a/src/core/server/mocks.ts b/src/core/server/mocks.ts index a98eaf50554f2..e2ae9a96b716d 100644 --- a/src/core/server/mocks.ts +++ b/src/core/server/mocks.ts @@ -23,6 +23,7 @@ import { httpServiceMock } from '@kbn/core-http-server-mocks'; import { elasticsearchServiceMock } from '@kbn/core-elasticsearch-server-mocks'; import { metricsServiceMock } from '@kbn/core-metrics-server-mocks'; import { capabilitiesServiceMock } from '@kbn/core-capabilities-server-mocks'; +import { typeRegistryMock as savedObjectsTypeRegistryMock } from '@kbn/core-saved-objects-base-server-mocks'; import type { PluginInitializerContext, CoreSetup, @@ -34,7 +35,6 @@ import type { import { httpResourcesMock } from './http_resources/http_resources_service.mock'; import { savedObjectsServiceMock } from './saved_objects/saved_objects_service.mock'; import { savedObjectsClientMock } from './saved_objects/service/saved_objects_client.mock'; -import { typeRegistryMock as savedObjectsTypeRegistryMock } from './saved_objects/saved_objects_type_registry.mock'; import { renderingMock } from './rendering/rendering_service.mock'; import { uiSettingsServiceMock } from './ui_settings/ui_settings_service.mock'; import { SharedGlobalConfig } from './plugins'; @@ -47,12 +47,12 @@ export { configServiceMock, configDeprecationsMock } from '@kbn/config-mocks'; export { loggingSystemMock } from '@kbn/core-logging-server-mocks'; export { httpServerMock, sessionStorageMock, httpServiceMock } from '@kbn/core-http-server-mocks'; export { elasticsearchServiceMock } from '@kbn/core-elasticsearch-server-mocks'; +export { typeRegistryMock as savedObjectsTypeRegistryMock } from '@kbn/core-saved-objects-base-server-mocks'; export { httpResourcesMock } from './http_resources/http_resources_service.mock'; export { savedObjectsRepositoryMock } from './saved_objects/service/lib/repository.mock'; export { savedObjectsServiceMock } from './saved_objects/saved_objects_service.mock'; export { savedObjectsClientMock } from './saved_objects/service/saved_objects_client.mock'; export { migrationMocks } from './saved_objects/migrations/mocks'; -export { typeRegistryMock as savedObjectsTypeRegistryMock } from './saved_objects/saved_objects_type_registry.mock'; export { uiSettingsServiceMock } from './ui_settings/ui_settings_service.mock'; export { metricsServiceMock } from '@kbn/core-metrics-server-mocks'; export { renderingMock } from './rendering/rendering_service.mock'; diff --git a/src/core/server/plugins/legacy_config.ts b/src/core/server/plugins/legacy_config.ts index 4bee00d615748..de86345c5b7ba 100644 --- a/src/core/server/plugins/legacy_config.ts +++ b/src/core/server/plugins/legacy_config.ts @@ -16,8 +16,11 @@ import { ElasticsearchConfigType, config as elasticsearchConfig, } from '@kbn/core-elasticsearch-server-internal'; +import { + type SavedObjectsConfigType, + savedObjectsConfig, +} from '@kbn/core-saved-objects-base-server-internal'; import { SharedGlobalConfig, SharedGlobalConfigKeys } from './types'; -import { SavedObjectsConfigType, savedObjectsConfig } from '../saved_objects/saved_objects_config'; const createGlobalConfig = ({ elasticsearch, diff --git a/src/core/server/plugins/types.ts b/src/core/server/plugins/types.ts index d41be740018a7..f8b20b66f5069 100644 --- a/src/core/server/plugins/types.ts +++ b/src/core/server/plugins/types.ts @@ -20,8 +20,7 @@ import type { import type { PluginName, PluginOpaqueId, PluginType } from '@kbn/core-base-common'; import type { NodeInfo } from '@kbn/core-node-server'; import type { ElasticsearchConfigType } from '@kbn/core-elasticsearch-server-internal'; - -import { SavedObjectsConfigType } from '../saved_objects/saved_objects_config'; +import type { SavedObjectsConfigType } from '@kbn/core-saved-objects-base-server-internal'; import { CorePreboot, CoreSetup, CoreStart } from '..'; type Maybe = T | undefined; diff --git a/src/core/server/saved_objects/deprecations/deprecation_factory.ts b/src/core/server/saved_objects/deprecations/deprecation_factory.ts index dea29cb7690ec..d330577151a52 100644 --- a/src/core/server/saved_objects/deprecations/deprecation_factory.ts +++ b/src/core/server/saved_objects/deprecations/deprecation_factory.ts @@ -7,8 +7,8 @@ */ import type { ISavedObjectTypeRegistry } from '@kbn/core-saved-objects-server'; +import type { SavedObjectConfig } from '@kbn/core-saved-objects-base-server-internal'; import type { RegisterDeprecationsConfig } from '../../deprecations'; -import type { SavedObjectConfig } from '../saved_objects_config'; import { getUnknownTypesDeprecations } from './unknown_object_types'; interface GetDeprecationProviderOptions { diff --git a/src/core/server/saved_objects/deprecations/unknown_object_types.test.ts b/src/core/server/saved_objects/deprecations/unknown_object_types.test.ts index 51f228f46438b..7e02f3343050d 100644 --- a/src/core/server/saved_objects/deprecations/unknown_object_types.test.ts +++ b/src/core/server/saved_objects/deprecations/unknown_object_types.test.ts @@ -9,7 +9,7 @@ import { getIndexForTypeMock } from './unknown_object_types.test.mocks'; import { deleteUnknownTypeObjects, getUnknownTypesDeprecations } from './unknown_object_types'; -import { typeRegistryMock } from '../saved_objects_type_registry.mock'; +import { typeRegistryMock } from '@kbn/core-saved-objects-base-server-mocks'; import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks'; import { SavedObjectsType } from '../..'; import { createAggregateTypesSearchResponse } from '../migrations/actions/check_for_unknown_docs.mocks'; diff --git a/src/core/server/saved_objects/export/collect_exported_objects.test.ts b/src/core/server/saved_objects/export/collect_exported_objects.test.ts index 8aedffdd3745b..480a80e23cc97 100644 --- a/src/core/server/saved_objects/export/collect_exported_objects.test.ts +++ b/src/core/server/saved_objects/export/collect_exported_objects.test.ts @@ -15,7 +15,7 @@ import type { import { applyExportTransformsMock } from './collect_exported_objects.test.mocks'; import { savedObjectsClientMock } from '../../mocks'; import { loggerMock } from '@kbn/logging-mocks'; -import { SavedObjectTypeRegistry } from '../saved_objects_type_registry'; +import { SavedObjectTypeRegistry } from '@kbn/core-saved-objects-base-server-internal'; import { collectExportedObjects, ExclusionReason } from './collect_exported_objects'; const createObject = (parts: Partial): SavedObject => ({ diff --git a/src/core/server/saved_objects/export/saved_objects_exporter.test.ts b/src/core/server/saved_objects/export/saved_objects_exporter.test.ts index 8b4604087141c..55ee7642388ba 100644 --- a/src/core/server/saved_objects/export/saved_objects_exporter.test.ts +++ b/src/core/server/saved_objects/export/saved_objects_exporter.test.ts @@ -8,9 +8,9 @@ import { httpServerMock } from '@kbn/core-http-server-mocks'; import type { SavedObject } from '@kbn/core-saved-objects-common'; +import { SavedObjectTypeRegistry } from '@kbn/core-saved-objects-base-server-internal'; import { SavedObjectsExporter } from './saved_objects_exporter'; import { savedObjectsClientMock } from '../service/saved_objects_client.mock'; -import { SavedObjectTypeRegistry } from '../saved_objects_type_registry'; import { loggerMock, MockedLogger } from '@kbn/logging-mocks'; import { Readable } from 'stream'; import { createPromiseFromStreams, createConcatStream } from '@kbn/utils'; diff --git a/src/core/server/saved_objects/import/import_saved_objects.test.ts b/src/core/server/saved_objects/import/import_saved_objects.test.ts index 71990a8438ef3..9a086537c4761 100644 --- a/src/core/server/saved_objects/import/import_saved_objects.test.ts +++ b/src/core/server/saved_objects/import/import_saved_objects.test.ts @@ -30,8 +30,8 @@ import type { ISavedObjectTypeRegistry, SavedObjectsImportHook, } from '@kbn/core-saved-objects-server'; +import { typeRegistryMock } from '@kbn/core-saved-objects-base-server-mocks'; import { savedObjectsClientMock } from '../../mocks'; -import { typeRegistryMock } from '../saved_objects_type_registry.mock'; import { importSavedObjectsFromStream, ImportSavedObjectsOptions } from './import_saved_objects'; import type { ImportStateMap } from './lib'; diff --git a/src/core/server/saved_objects/import/lib/check_conflicts.test.ts b/src/core/server/saved_objects/import/lib/check_conflicts.test.ts index 3dcbeacae1a2d..35be4e245086c 100644 --- a/src/core/server/saved_objects/import/lib/check_conflicts.test.ts +++ b/src/core/server/saved_objects/import/lib/check_conflicts.test.ts @@ -13,7 +13,7 @@ import type { SavedObjectsImportRetry, } from '@kbn/core-saved-objects-common'; import type { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server'; -import { SavedObjectsErrorHelpers } from '../../service'; +import { SavedObjectsErrorHelpers } from '@kbn/core-saved-objects-utils-server'; import { checkConflicts } from './check_conflicts'; jest.mock('uuid', () => ({ diff --git a/src/core/server/saved_objects/import/lib/check_origin_conflicts.test.ts b/src/core/server/saved_objects/import/lib/check_origin_conflicts.test.ts index ed80c7cdf0751..756214e2ddc03 100644 --- a/src/core/server/saved_objects/import/lib/check_origin_conflicts.test.ts +++ b/src/core/server/saved_objects/import/lib/check_origin_conflicts.test.ts @@ -16,9 +16,9 @@ import type { } from '@kbn/core-saved-objects-common'; import type { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server'; import type { ISavedObjectTypeRegistry } from '@kbn/core-saved-objects-server'; +import { typeRegistryMock } from '@kbn/core-saved-objects-base-server-mocks'; import { checkOriginConflicts } from './check_origin_conflicts'; import { savedObjectsClientMock } from '../../../mocks'; -import { typeRegistryMock } from '../../saved_objects_type_registry.mock'; import type { ImportStateMap } from './types'; jest.mock('uuid', () => ({ diff --git a/src/core/server/saved_objects/import/lib/check_reference_origins.test.ts b/src/core/server/saved_objects/import/lib/check_reference_origins.test.ts index cff3a4d5540a0..fce677ec6ea46 100644 --- a/src/core/server/saved_objects/import/lib/check_reference_origins.test.ts +++ b/src/core/server/saved_objects/import/lib/check_reference_origins.test.ts @@ -15,7 +15,7 @@ import type { import type { ISavedObjectTypeRegistry } from '@kbn/core-saved-objects-server'; import { checkReferenceOrigins, CheckReferenceOriginsParams } from './check_reference_origins'; import { savedObjectsClientMock } from '../../../mocks'; -import { typeRegistryMock } from '../../saved_objects_type_registry.mock'; +import { typeRegistryMock } from '@kbn/core-saved-objects-base-server-mocks'; import type { ImportStateMap } from './types'; const MULTI_NS_TYPE = 'multi'; diff --git a/src/core/server/saved_objects/import/lib/create_saved_objects.test.ts b/src/core/server/saved_objects/import/lib/create_saved_objects.test.ts index a29765849c364..363d2bee5899e 100644 --- a/src/core/server/saved_objects/import/lib/create_saved_objects.test.ts +++ b/src/core/server/saved_objects/import/lib/create_saved_objects.test.ts @@ -9,8 +9,8 @@ import { savedObjectsClientMock } from '../../../mocks'; import type { SavedObject, SavedObjectsImportFailure } from '@kbn/core-saved-objects-common'; import { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server'; +import { SavedObjectsErrorHelpers } from '@kbn/core-saved-objects-utils-server'; import { createSavedObjects } from './create_saved_objects'; -import { SavedObjectsErrorHelpers } from '../../service'; import { extractErrors } from './extract_errors'; type CreateSavedObjectsParams = Parameters[0]; diff --git a/src/core/server/saved_objects/import/lib/extract_errors.test.ts b/src/core/server/saved_objects/import/lib/extract_errors.test.ts index 20a8d40b62a70..c4d3d0e4c2722 100644 --- a/src/core/server/saved_objects/import/lib/extract_errors.test.ts +++ b/src/core/server/saved_objects/import/lib/extract_errors.test.ts @@ -8,8 +8,8 @@ import type { SavedObject } from '@kbn/core-saved-objects-common'; import type { CreatedObject } from '@kbn/core-saved-objects-server'; +import { SavedObjectsErrorHelpers } from '@kbn/core-saved-objects-utils-server'; import { extractErrors } from './extract_errors'; -import { SavedObjectsErrorHelpers } from '../../service'; describe('extractErrors()', () => { test('returns empty array when no errors exist', () => { diff --git a/src/core/server/saved_objects/import/lib/validate_references.test.ts b/src/core/server/saved_objects/import/lib/validate_references.test.ts index 2e6f1a5e0a9a2..2a8095ef78ce8 100644 --- a/src/core/server/saved_objects/import/lib/validate_references.test.ts +++ b/src/core/server/saved_objects/import/lib/validate_references.test.ts @@ -6,10 +6,10 @@ * Side Public License, v 1. */ +import { SavedObjectsErrorHelpers } from '@kbn/core-saved-objects-utils-server'; import type { ValidateReferencesParams } from './validate_references'; import { validateReferences } from './validate_references'; import { savedObjectsClientMock } from '../../../mocks'; -import { SavedObjectsErrorHelpers } from '../../service'; function setup({ objects = [], diff --git a/src/core/server/saved_objects/import/resolve_import_errors.test.ts b/src/core/server/saved_objects/import/resolve_import_errors.test.ts index bc297182b281d..288e58aabb4c2 100644 --- a/src/core/server/saved_objects/import/resolve_import_errors.test.ts +++ b/src/core/server/saved_objects/import/resolve_import_errors.test.ts @@ -36,8 +36,8 @@ import type { ISavedObjectTypeRegistry, SavedObjectsImportHook, } from '@kbn/core-saved-objects-server'; +import { typeRegistryMock } from '@kbn/core-saved-objects-base-server-mocks'; import { savedObjectsClientMock } from '../../mocks'; -import { typeRegistryMock } from '../saved_objects_type_registry.mock'; import { resolveSavedObjectsImportErrors, ResolveSavedObjectsImportErrorsOptions, diff --git a/src/core/server/saved_objects/index.ts b/src/core/server/saved_objects/index.ts index 4a7a14b45b665..4ccc4f1bcdb30 100644 --- a/src/core/server/saved_objects/index.ts +++ b/src/core/server/saved_objects/index.ts @@ -14,8 +14,6 @@ export type { SavedObjectsImportError } from './import'; export type { SavedObjectsExporter, SavedObjectsExportError } from './export'; -export { SavedObjectsSerializer } from './serialization'; - export { SavedObjectsService } from './saved_objects_service'; export type { @@ -23,10 +21,4 @@ export type { InternalSavedObjectsServiceSetup, } from './saved_objects_service'; -export type { SavedObjectsTypeMappingDefinitions } from './mappings'; - -export { mergeSavedObjectMigrationMaps } from './migrations'; - -export { savedObjectsConfig, savedObjectsMigrationConfig } from './saved_objects_config'; -export { SavedObjectTypeRegistry } from './saved_objects_type_registry'; export { CoreSavedObjectsRouteHandlerContext } from './saved_objects_route_handler_context'; diff --git a/src/core/server/saved_objects/migrations/actions/create_index.ts b/src/core/server/saved_objects/migrations/actions/create_index.ts index 0f6b062a42163..f48918d679624 100644 --- a/src/core/server/saved_objects/migrations/actions/create_index.ts +++ b/src/core/server/saved_objects/migrations/actions/create_index.ts @@ -11,8 +11,8 @@ import * as TaskEither from 'fp-ts/lib/TaskEither'; import { pipe } from 'fp-ts/lib/pipeable'; import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server'; +import type { IndexMapping } from '@kbn/core-saved-objects-base-server-internal'; import { AcknowledgeResponse } from '.'; -import { IndexMapping } from '../../mappings'; import { catchRetryableEsClientErrors, RetryableEsClientError, diff --git a/src/core/server/saved_objects/migrations/actions/fetch_indices.ts b/src/core/server/saved_objects/migrations/actions/fetch_indices.ts index 922797f2ba268..0eb43380a6990 100644 --- a/src/core/server/saved_objects/migrations/actions/fetch_indices.ts +++ b/src/core/server/saved_objects/migrations/actions/fetch_indices.ts @@ -5,10 +5,11 @@ * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ + import * as TaskEither from 'fp-ts/lib/TaskEither'; import * as Either from 'fp-ts/lib/Either'; import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server'; -import { IndexMapping } from '../../mappings'; +import type { IndexMapping } from '@kbn/core-saved-objects-base-server-internal'; import { catchRetryableEsClientErrors, RetryableEsClientError, diff --git a/src/core/server/saved_objects/migrations/actions/update_and_pickup_mappings.ts b/src/core/server/saved_objects/migrations/actions/update_and_pickup_mappings.ts index bd1c2d6ff7614..a5fe33e9bbcf5 100644 --- a/src/core/server/saved_objects/migrations/actions/update_and_pickup_mappings.ts +++ b/src/core/server/saved_objects/migrations/actions/update_and_pickup_mappings.ts @@ -10,7 +10,7 @@ import * as Either from 'fp-ts/lib/Either'; import * as TaskEither from 'fp-ts/lib/TaskEither'; import { pipe } from 'fp-ts/lib/pipeable'; import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server'; -import { IndexMapping } from '../../mappings'; +import type { IndexMapping } from '@kbn/core-saved-objects-base-server-internal'; import { catchRetryableEsClientErrors, RetryableEsClientError, diff --git a/src/core/server/saved_objects/migrations/core/build_active_mappings.test.ts b/src/core/server/saved_objects/migrations/core/build_active_mappings.test.ts index 7a57a7a8a08d3..7f1542ffc6008 100644 --- a/src/core/server/saved_objects/migrations/core/build_active_mappings.test.ts +++ b/src/core/server/saved_objects/migrations/core/build_active_mappings.test.ts @@ -6,7 +6,10 @@ * Side Public License, v 1. */ -import { IndexMapping, SavedObjectsTypeMappingDefinitions } from '../../mappings'; +import type { + IndexMapping, + SavedObjectsTypeMappingDefinitions, +} from '@kbn/core-saved-objects-base-server-internal'; import { buildActiveMappings, diffMappings } from './build_active_mappings'; describe('buildActiveMappings', () => { diff --git a/src/core/server/saved_objects/migrations/core/build_active_mappings.ts b/src/core/server/saved_objects/migrations/core/build_active_mappings.ts index 62f5bd1454419..1a0a502f655bd 100644 --- a/src/core/server/saved_objects/migrations/core/build_active_mappings.ts +++ b/src/core/server/saved_objects/migrations/core/build_active_mappings.ts @@ -13,7 +13,10 @@ import crypto from 'crypto'; import { cloneDeep, mapValues } from 'lodash'; import type { SavedObjectsMappingProperties } from '@kbn/core-saved-objects-server'; -import { IndexMapping, SavedObjectsTypeMappingDefinitions } from '../../mappings'; +import type { + IndexMapping, + SavedObjectsTypeMappingDefinitions, +} from '@kbn/core-saved-objects-base-server-internal'; /** * Creates an index mapping with the core properties required by saved object diff --git a/src/core/server/saved_objects/migrations/core/build_index_map.test.ts b/src/core/server/saved_objects/migrations/core/build_index_map.test.ts index 5f5d587eec359..ec82b0ac2c92f 100644 --- a/src/core/server/saved_objects/migrations/core/build_index_map.test.ts +++ b/src/core/server/saved_objects/migrations/core/build_index_map.test.ts @@ -7,8 +7,8 @@ */ import type { SavedObjectsType } from '@kbn/core-saved-objects-server'; +import { SavedObjectTypeRegistry } from '@kbn/core-saved-objects-base-server-internal'; import { createIndexMap } from './build_index_map'; -import { SavedObjectTypeRegistry } from '../../saved_objects_type_registry'; const createRegistry = (...types: Array>) => { const registry = new SavedObjectTypeRegistry(); diff --git a/src/core/server/saved_objects/migrations/core/build_index_map.ts b/src/core/server/saved_objects/migrations/core/build_index_map.ts index 1e1adcf0dcbc8..225b3bb422925 100644 --- a/src/core/server/saved_objects/migrations/core/build_index_map.ts +++ b/src/core/server/saved_objects/migrations/core/build_index_map.ts @@ -7,7 +7,7 @@ */ import type { ISavedObjectTypeRegistry } from '@kbn/core-saved-objects-server'; -import type { SavedObjectsTypeMappingDefinitions } from '../../mappings'; +import type { SavedObjectsTypeMappingDefinitions } from '@kbn/core-saved-objects-base-server-internal'; export interface CreateIndexMapOptions { kibanaIndexName: string; diff --git a/src/core/server/saved_objects/migrations/core/disable_unknown_type_mapping_fields.ts b/src/core/server/saved_objects/migrations/core/disable_unknown_type_mapping_fields.ts index b1e25e6e024fb..8b1eccbe09d78 100644 --- a/src/core/server/saved_objects/migrations/core/disable_unknown_type_mapping_fields.ts +++ b/src/core/server/saved_objects/migrations/core/disable_unknown_type_mapping_fields.ts @@ -7,7 +7,7 @@ */ import type { SavedObjectsMappingProperties } from '@kbn/core-saved-objects-server'; -import { IndexMapping } from '../../mappings'; +import type { IndexMapping } from '@kbn/core-saved-objects-base-server-internal'; /** * Merges the active mappings and the source mappings while disabling the diff --git a/src/core/server/saved_objects/migrations/core/document_migrator.test.mock.ts b/src/core/server/saved_objects/migrations/core/document_migrator.test.mock.ts index ee0b18af5ac0d..df7914a55876f 100644 --- a/src/core/server/saved_objects/migrations/core/document_migrator.test.mock.ts +++ b/src/core/server/saved_objects/migrations/core/document_migrator.test.mock.ts @@ -7,8 +7,9 @@ */ const mockGetConvertedObjectId = jest.fn().mockReturnValue('uuidv5'); -jest.mock('../../service/lib/utils', () => { - const actual = jest.requireActual('../../service/lib/utils'); + +jest.mock('@kbn/core-saved-objects-utils-server', () => { + const actual = jest.requireActual('@kbn/core-saved-objects-utils-server'); return { ...actual, SavedObjectsUtils: { diff --git a/src/core/server/saved_objects/migrations/core/document_migrator.test.ts b/src/core/server/saved_objects/migrations/core/document_migrator.test.ts index 1d12d2062be93..a0dd1cfddc3a4 100644 --- a/src/core/server/saved_objects/migrations/core/document_migrator.test.ts +++ b/src/core/server/saved_objects/migrations/core/document_migrator.test.ts @@ -10,11 +10,13 @@ import { mockGetConvertedObjectId } from './document_migrator.test.mock'; import { set } from '@kbn/safer-lodash-set'; import _ from 'lodash'; import type { SavedObjectUnsanitizedDoc, SavedObjectsType } from '@kbn/core-saved-objects-server'; +import { + SavedObjectTypeRegistry, + LEGACY_URL_ALIAS_TYPE, +} from '@kbn/core-saved-objects-base-server-internal'; import { DocumentMigrator } from './document_migrator'; import { TransformSavedObjectDocumentError } from './transform_saved_object_document_error'; import { loggingSystemMock } from '@kbn/core-logging-server-mocks'; -import { SavedObjectTypeRegistry } from '../../saved_objects_type_registry'; -import { LEGACY_URL_ALIAS_TYPE } from '../../object_types'; const mockLoggerFactory = loggingSystemMock.create(); const mockLogger = mockLoggerFactory.get('mock logger'); diff --git a/src/core/server/saved_objects/migrations/core/document_migrator.ts b/src/core/server/saved_objects/migrations/core/document_migrator.ts index 677b2a685f64e..1040699a99e9d 100644 --- a/src/core/server/saved_objects/migrations/core/document_migrator.ts +++ b/src/core/server/saved_objects/migrations/core/document_migrator.ts @@ -58,10 +58,13 @@ import type { SavedObjectMigrationFn, SavedObjectMigrationMap, } from '@kbn/core-saved-objects-server'; +import { DEFAULT_NAMESPACE_STRING, SavedObjectsUtils } from '@kbn/core-saved-objects-utils-server'; +import { + type LegacyUrlAlias, + LEGACY_URL_ALIAS_TYPE, +} from '@kbn/core-saved-objects-base-server-internal'; import { MigrationLogger } from './migration_logger'; import { TransformSavedObjectDocumentError } from '.'; -import { DEFAULT_NAMESPACE_STRING, SavedObjectsUtils } from '../../service/lib/utils'; -import { LegacyUrlAlias, LEGACY_URL_ALIAS_TYPE } from '../../object_types'; const DEFAULT_MINIMUM_CONVERT_VERSION = '8.0.0'; diff --git a/src/core/server/saved_objects/migrations/core/migrate_raw_docs.test.ts b/src/core/server/saved_objects/migrations/core/migrate_raw_docs.test.ts index 09ec13bcae05b..c9d7b78953e28 100644 --- a/src/core/server/saved_objects/migrations/core/migrate_raw_docs.test.ts +++ b/src/core/server/saved_objects/migrations/core/migrate_raw_docs.test.ts @@ -9,8 +9,10 @@ import { set } from '@kbn/safer-lodash-set'; import * as Either from 'fp-ts/lib/Either'; import _ from 'lodash'; -import { SavedObjectTypeRegistry } from '../../saved_objects_type_registry'; -import { SavedObjectsSerializer } from '../../serialization'; +import { + SavedObjectTypeRegistry, + SavedObjectsSerializer, +} from '@kbn/core-saved-objects-base-server-internal'; import { DocumentsTransformFailed, DocumentsTransformSuccess, diff --git a/src/core/server/saved_objects/migrations/core/migrate_raw_docs.ts b/src/core/server/saved_objects/migrations/core/migrate_raw_docs.ts index 8534d7e497be0..d1ca65f1dd103 100644 --- a/src/core/server/saved_objects/migrations/core/migrate_raw_docs.ts +++ b/src/core/server/saved_objects/migrations/core/migrate_raw_docs.ts @@ -16,7 +16,7 @@ import type { SavedObjectsRawDoc, SavedObjectUnsanitizedDoc, } from '@kbn/core-saved-objects-server'; -import { SavedObjectsSerializer } from '../../serialization'; +import { SavedObjectsSerializer } from '@kbn/core-saved-objects-base-server-internal'; import { MigrateAndConvertFn } from './document_migrator'; import { TransformSavedObjectDocumentError } from '.'; diff --git a/src/core/server/saved_objects/migrations/index.ts b/src/core/server/saved_objects/migrations/index.ts index 54416f423a79a..707b777330ec3 100644 --- a/src/core/server/saved_objects/migrations/index.ts +++ b/src/core/server/saved_objects/migrations/index.ts @@ -9,4 +9,3 @@ export type { MigrationResult } from './core'; export { KibanaMigrator } from './kibana_migrator'; export type { IKibanaMigrator, KibanaMigratorStatus } from './kibana_migrator'; -export { mergeSavedObjectMigrationMaps } from './utils'; diff --git a/src/core/server/saved_objects/migrations/initial_state.test.ts b/src/core/server/saved_objects/migrations/initial_state.test.ts index 32e3b9f50f4a3..6d49b17d4fa80 100644 --- a/src/core/server/saved_objects/migrations/initial_state.test.ts +++ b/src/core/server/saved_objects/migrations/initial_state.test.ts @@ -10,9 +10,11 @@ import { ByteSizeValue } from '@kbn/config-schema'; import * as Option from 'fp-ts/Option'; import type { DocLinksServiceSetup } from '@kbn/core-doc-links-server'; import { docLinksServiceMock } from '@kbn/core-doc-links-server-mocks'; +import { + type SavedObjectsMigrationConfigType, + SavedObjectTypeRegistry, +} from '@kbn/core-saved-objects-base-server-internal'; import { loggingSystemMock } from '../../mocks'; -import { SavedObjectsMigrationConfigType } from '../saved_objects_config'; -import { SavedObjectTypeRegistry } from '../saved_objects_type_registry'; import { createInitialState } from './initial_state'; const mockLogger = loggingSystemMock.create(); diff --git a/src/core/server/saved_objects/migrations/initial_state.ts b/src/core/server/saved_objects/migrations/initial_state.ts index 861ec75e2d875..1843227934bcd 100644 --- a/src/core/server/saved_objects/migrations/initial_state.ts +++ b/src/core/server/saved_objects/migrations/initial_state.ts @@ -11,8 +11,10 @@ import type { DocLinksServiceStart } from '@kbn/core-doc-links-server'; import type { Logger } from '@kbn/logging'; import type { SavedObjectsMigrationVersion } from '@kbn/core-saved-objects-common'; import type { ISavedObjectTypeRegistry } from '@kbn/core-saved-objects-server'; -import type { IndexMapping } from '../mappings'; -import type { SavedObjectsMigrationConfigType } from '../saved_objects_config'; +import type { + IndexMapping, + SavedObjectsMigrationConfigType, +} from '@kbn/core-saved-objects-base-server-internal'; import type { InitState } from './state'; import { excludeUnusedTypesQuery } from './core'; diff --git a/src/core/server/saved_objects/migrations/kibana_migrator.test.ts b/src/core/server/saved_objects/migrations/kibana_migrator.test.ts index 6806e5a9c80a1..5d1cb32eca6d2 100644 --- a/src/core/server/saved_objects/migrations/kibana_migrator.test.ts +++ b/src/core/server/saved_objects/migrations/kibana_migrator.test.ts @@ -12,8 +12,8 @@ import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import { loggingSystemMock } from '@kbn/core-logging-server-mocks'; import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks'; import type { SavedObjectsType } from '@kbn/core-saved-objects-server'; +import { SavedObjectTypeRegistry } from '@kbn/core-saved-objects-base-server-internal'; import { KibanaMigratorOptions, KibanaMigrator } from './kibana_migrator'; -import { SavedObjectTypeRegistry } from '../saved_objects_type_registry'; import { DocumentMigrator } from './core/document_migrator'; import { ByteSizeValue } from '@kbn/config-schema'; import { docLinksServiceMock } from '@kbn/core-doc-links-server-mocks'; diff --git a/src/core/server/saved_objects/migrations/kibana_migrator.ts b/src/core/server/saved_objects/migrations/kibana_migrator.ts index 146dd600ab4d0..2a8f9a9c3ee0f 100644 --- a/src/core/server/saved_objects/migrations/kibana_migrator.ts +++ b/src/core/server/saved_objects/migrations/kibana_migrator.ts @@ -22,12 +22,15 @@ import type { SavedObjectsRawDoc, ISavedObjectTypeRegistry, } from '@kbn/core-saved-objects-server'; -import { IndexMapping, SavedObjectsTypeMappingDefinitions } from '../mappings'; -import { SavedObjectsSerializer } from '../serialization'; +import { + SavedObjectsSerializer, + type IndexMapping, + type SavedObjectsTypeMappingDefinitions, + type SavedObjectsMigrationConfigType, +} from '@kbn/core-saved-objects-base-server-internal'; import { buildActiveMappings, MigrationResult, MigrationStatus } from './core'; import { DocumentMigrator, VersionedTransformer } from './core/document_migrator'; import { createIndexMap } from './core/build_index_map'; -import { SavedObjectsMigrationConfigType } from '../saved_objects_config'; import { runResilientMigrator } from './run_resilient_migrator'; import { migrateRawDocsSafely } from './core/migrate_raw_docs'; diff --git a/src/core/server/saved_objects/migrations/migrations_state_action_machine.test.ts b/src/core/server/saved_objects/migrations/migrations_state_action_machine.test.ts index db319c63e216f..1c4644fb43325 100644 --- a/src/core/server/saved_objects/migrations/migrations_state_action_machine.test.ts +++ b/src/core/server/saved_objects/migrations/migrations_state_action_machine.test.ts @@ -11,8 +11,8 @@ import { migrationStateActionMachine } from './migrations_state_action_machine'; import { docLinksServiceMock } from '@kbn/core-doc-links-server-mocks'; import { loggingSystemMock } from '@kbn/core-logging-server-mocks'; import { LoggerAdapter } from '@kbn/core-logging-server-internal'; +import { typeRegistryMock } from '@kbn/core-saved-objects-base-server-mocks'; import { elasticsearchServiceMock } from '../../mocks'; -import { typeRegistryMock } from '../saved_objects_type_registry.mock'; import * as Either from 'fp-ts/lib/Either'; import * as Option from 'fp-ts/lib/Option'; import { errors } from '@elastic/elasticsearch'; diff --git a/src/core/server/saved_objects/migrations/model/helpers.ts b/src/core/server/saved_objects/migrations/model/helpers.ts index ea28c14f9a5f0..5f84dc01af008 100644 --- a/src/core/server/saved_objects/migrations/model/helpers.ts +++ b/src/core/server/saved_objects/migrations/model/helpers.ts @@ -12,8 +12,8 @@ import type { QueryDslQueryContainer, } from '@elastic/elasticsearch/lib/api/types'; import * as Either from 'fp-ts/lib/Either'; +import type { IndexMapping } from '@kbn/core-saved-objects-base-server-internal'; import type { State } from '../state'; -import type { IndexMapping } from '../../mappings'; import type { FetchIndexResponse } from '../actions'; /** diff --git a/src/core/server/saved_objects/migrations/run_resilient_migrator.ts b/src/core/server/saved_objects/migrations/run_resilient_migrator.ts index 9ca3d3dbaaa60..6a6153b997146 100644 --- a/src/core/server/saved_objects/migrations/run_resilient_migrator.ts +++ b/src/core/server/saved_objects/migrations/run_resilient_migrator.ts @@ -11,14 +11,16 @@ import type { DocLinksServiceStart } from '@kbn/core-doc-links-server'; import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server'; import type { SavedObjectsMigrationVersion } from '@kbn/core-saved-objects-common'; import type { ISavedObjectTypeRegistry } from '@kbn/core-saved-objects-server'; -import { IndexMapping } from '../mappings'; +import type { + IndexMapping, + SavedObjectsMigrationConfigType, +} from '@kbn/core-saved-objects-base-server-internal'; import type { TransformRawDocs } from './types'; import { MigrationResult } from './core'; import { next } from './next'; import { model } from './model'; import { createInitialState } from './initial_state'; import { migrationStateActionMachine } from './migrations_state_action_machine'; -import { SavedObjectsMigrationConfigType } from '../saved_objects_config'; /** * To avoid the Elasticsearch-js client aborting our requests before we diff --git a/src/core/server/saved_objects/migrations/state.ts b/src/core/server/saved_objects/migrations/state.ts index d94d49ecec7aa..eb8d2e2fbb05b 100644 --- a/src/core/server/saved_objects/migrations/state.ts +++ b/src/core/server/saved_objects/migrations/state.ts @@ -13,9 +13,9 @@ import type { SavedObjectsRawDoc, SavedObjectTypeExcludeFromUpgradeFilterHook, } from '@kbn/core-saved-objects-server'; +import type { IndexMapping } from '@kbn/core-saved-objects-base-server-internal'; import type { ControlState } from './state_action_machine'; import type { AliasAction } from './actions'; -import type { IndexMapping } from '../mappings'; import type { TransformErrorObjects } from './core'; import type { MigrationLog, Progress } from './types'; diff --git a/src/core/server/saved_objects/object_types/index.ts b/src/core/server/saved_objects/object_types/index.ts index 11a2c1973b09a..55c0db7ffcdbc 100644 --- a/src/core/server/saved_objects/object_types/index.ts +++ b/src/core/server/saved_objects/object_types/index.ts @@ -6,6 +6,4 @@ * Side Public License, v 1. */ -export { LEGACY_URL_ALIAS_TYPE } from './constants'; -export type { LegacyUrlAlias } from './types'; export { registerCoreObjectTypes } from './registration'; diff --git a/src/core/server/saved_objects/object_types/registration.test.ts b/src/core/server/saved_objects/object_types/registration.test.ts index 724b9baababef..2c8a467e32842 100644 --- a/src/core/server/saved_objects/object_types/registration.test.ts +++ b/src/core/server/saved_objects/object_types/registration.test.ts @@ -6,8 +6,8 @@ * Side Public License, v 1. */ -import { typeRegistryMock } from '../saved_objects_type_registry.mock'; -import { LEGACY_URL_ALIAS_TYPE } from './constants'; +import { typeRegistryMock } from '@kbn/core-saved-objects-base-server-mocks'; +import { LEGACY_URL_ALIAS_TYPE } from '@kbn/core-saved-objects-base-server-internal'; import { registerCoreObjectTypes } from './registration'; describe('Core saved object types registration', () => { diff --git a/src/core/server/saved_objects/object_types/registration.ts b/src/core/server/saved_objects/object_types/registration.ts index d93b1cc2e2a23..5d31cb1e03077 100644 --- a/src/core/server/saved_objects/object_types/registration.ts +++ b/src/core/server/saved_objects/object_types/registration.ts @@ -7,9 +7,11 @@ */ import type { ISavedObjectTypeRegistry, SavedObjectsType } from '@kbn/core-saved-objects-server'; -import { LEGACY_URL_ALIAS_TYPE } from './constants'; -import { SavedObjectTypeRegistry } from '..'; -import type { LegacyUrlAlias } from './types'; +import { + SavedObjectTypeRegistry, + LEGACY_URL_ALIAS_TYPE, + type LegacyUrlAlias, +} from '@kbn/core-saved-objects-base-server-internal'; const legacyUrlAliasType: SavedObjectsType = { name: LEGACY_URL_ALIAS_TYPE, diff --git a/src/core/server/saved_objects/routes/export.ts b/src/core/server/saved_objects/routes/export.ts index bd89a2845626a..0ab75a3c7101d 100644 --- a/src/core/server/saved_objects/routes/export.ts +++ b/src/core/server/saved_objects/routes/export.ts @@ -15,8 +15,8 @@ import type { SavedObjectsExportByTypeOptions, SavedObjectsExportByObjectOptions, } from '@kbn/core-saved-objects-server'; +import type { SavedObjectConfig } from '@kbn/core-saved-objects-base-server-internal'; import { InternalCoreUsageDataSetup } from '../../core_usage_data'; -import { SavedObjectConfig } from '../saved_objects_config'; import { SavedObjectsExportError } from '../export'; import type { InternalSavedObjectRouter } from '../internal_types'; import { validateTypes, validateObjects, catchAndReturnBoomErrors } from './utils'; diff --git a/src/core/server/saved_objects/routes/import.ts b/src/core/server/saved_objects/routes/import.ts index 0c56acf9e2d68..717cc50a13e60 100644 --- a/src/core/server/saved_objects/routes/import.ts +++ b/src/core/server/saved_objects/routes/import.ts @@ -9,8 +9,8 @@ import { Readable } from 'stream'; import { extname } from 'path'; import { schema } from '@kbn/config-schema'; +import type { SavedObjectConfig } from '@kbn/core-saved-objects-base-server-internal'; import { InternalCoreUsageDataSetup } from '../../core_usage_data'; -import { SavedObjectConfig } from '../saved_objects_config'; import { SavedObjectsImportError } from '../import'; import type { InternalSavedObjectRouter } from '../internal_types'; import { catchAndReturnBoomErrors, createSavedObjectsStreamFromNdJson } from './utils'; diff --git a/src/core/server/saved_objects/routes/index.ts b/src/core/server/saved_objects/routes/index.ts index edc52efdeaef8..f49c604a37c0c 100644 --- a/src/core/server/saved_objects/routes/index.ts +++ b/src/core/server/saved_objects/routes/index.ts @@ -8,8 +8,8 @@ import type { Logger } from '@kbn/logging'; import type { InternalHttpServiceSetup } from '@kbn/core-http-server-internal'; +import type { SavedObjectConfig } from '@kbn/core-saved-objects-base-server-internal'; import { InternalCoreUsageDataSetup } from '../../core_usage_data'; -import { SavedObjectConfig } from '../saved_objects_config'; import { IKibanaMigrator } from '../migrations'; import type { InternalSavedObjectsRequestHandlerContext } from '../internal_types'; import { registerGetRoute } from './get'; diff --git a/src/core/server/saved_objects/routes/resolve_import_errors.ts b/src/core/server/saved_objects/routes/resolve_import_errors.ts index 4bedec1715a4f..ed919693e1b86 100644 --- a/src/core/server/saved_objects/routes/resolve_import_errors.ts +++ b/src/core/server/saved_objects/routes/resolve_import_errors.ts @@ -8,10 +8,10 @@ import { extname } from 'path'; import { Readable } from 'stream'; -import { schema } from '@kbn/config-schema'; import { chain } from 'lodash'; +import { schema } from '@kbn/config-schema'; +import type { SavedObjectConfig } from '@kbn/core-saved-objects-base-server-internal'; import { InternalCoreUsageDataSetup } from '../../core_usage_data'; -import { SavedObjectConfig } from '../saved_objects_config'; import { SavedObjectsImportError } from '../import'; import type { InternalSavedObjectRouter } from '../internal_types'; import { catchAndReturnBoomErrors, createSavedObjectsStreamFromNdJson } from './utils'; diff --git a/src/core/server/saved_objects/saved_objects_service.mock.ts b/src/core/server/saved_objects/saved_objects_service.mock.ts index 292e39b0c199d..f1a1ce6c091b6 100644 --- a/src/core/server/saved_objects/saved_objects_service.mock.ts +++ b/src/core/server/saved_objects/saved_objects_service.mock.ts @@ -21,7 +21,7 @@ import type { import { savedObjectsRepositoryMock } from './service/lib/repository.mock'; import { savedObjectsClientMock } from './service/saved_objects_client.mock'; -import { typeRegistryMock } from './saved_objects_type_registry.mock'; +import { typeRegistryMock, serializerMock } from '@kbn/core-saved-objects-base-server-mocks'; import { savedObjectsExporterMock } from './export/saved_objects_exporter.mock'; import { savedObjectsImporterMock } from './import/saved_objects_importer.mock'; import { migrationMocks } from './migrations/mocks'; @@ -105,4 +105,5 @@ export const savedObjectsServiceMock = { createTypeRegistryMock: typeRegistryMock.create, createExporter: savedObjectsExporterMock.create, createImporter: savedObjectsImporterMock.create, + createSerializer: serializerMock.create, }; diff --git a/src/core/server/saved_objects/saved_objects_service.test.mocks.ts b/src/core/server/saved_objects/saved_objects_service.test.mocks.ts index f4b58fd12d8ba..4b66f5865def5 100644 --- a/src/core/server/saved_objects/saved_objects_service.test.mocks.ts +++ b/src/core/server/saved_objects/saved_objects_service.test.mocks.ts @@ -8,7 +8,7 @@ import { mockKibanaMigrator } from './migrations/kibana_migrator.mock'; import { savedObjectsClientProviderMock } from './service/lib/scoped_client_provider.mock'; -import { typeRegistryMock } from './saved_objects_type_registry.mock'; +import { typeRegistryMock } from '@kbn/core-saved-objects-base-server-mocks'; export const migratorInstanceMock = mockKibanaMigrator.create(); export const KibanaMigratorMock = jest.fn().mockImplementation(() => migratorInstanceMock); @@ -22,15 +22,15 @@ jest.doMock('./service/lib/scoped_client_provider', () => ({ })); export const typeRegistryInstanceMock = typeRegistryMock.create(); -jest.doMock('./saved_objects_type_registry', () => ({ - SavedObjectTypeRegistry: jest.fn().mockImplementation(() => typeRegistryInstanceMock), -})); +jest.doMock('@kbn/core-saved-objects-base-server-internal', () => { + const actual = jest.requireActual('@kbn/core-saved-objects-base-server-internal'); + return { + ...actual, + SavedObjectTypeRegistry: jest.fn().mockImplementation(() => typeRegistryInstanceMock), + }; +}); export const registerRoutesMock = jest.fn(); jest.doMock('./routes', () => ({ registerRoutes: registerRoutesMock, })); - -// The SavedObjectsSerializer imports SavedObjectUtils from the '../service' module, and that somehow breaks unit tests for the -// SavedObjectsService. To avoid this, we mock the entire './serialization' module, since we don't need it for these tests. -jest.mock('./serialization'); diff --git a/src/core/server/saved_objects/saved_objects_service.ts b/src/core/server/saved_objects/saved_objects_service.ts index 53eb376cc37b7..542a13e3a4cc0 100644 --- a/src/core/server/saved_objects/saved_objects_service.ts +++ b/src/core/server/saved_objects/saved_objects_service.ts @@ -27,18 +27,18 @@ import type { SavedObjectsClientWrapperFactory, ISavedObjectTypeRegistry, } from '@kbn/core-saved-objects-server'; +import { + SavedObjectConfig, + SavedObjectsSerializer, + SavedObjectTypeRegistry, + type SavedObjectsConfigType, + type SavedObjectsMigrationConfigType, +} from '@kbn/core-saved-objects-base-server-internal'; import { SavedObjectsClient, SavedObjectsClientProvider } from './service'; import { KibanaMigrator, IKibanaMigrator } from './migrations'; import { InternalCoreUsageDataSetup } from '../core_usage_data'; import { InternalDeprecationsServiceSetup } from '../deprecations'; -import { - SavedObjectsConfigType, - SavedObjectsMigrationConfigType, - SavedObjectConfig, -} from './saved_objects_config'; import { SavedObjectsRepository } from './service/lib/repository'; -import { SavedObjectTypeRegistry } from './saved_objects_type_registry'; -import { SavedObjectsSerializer } from './serialization'; import { SavedObjectsExporter } from './export'; import { SavedObjectsImporter } from './import'; import { registerRoutes } from './routes'; diff --git a/src/core/server/saved_objects/service/index.ts b/src/core/server/saved_objects/service/index.ts index 1ce638c4c0188..0737fc725d1a4 100644 --- a/src/core/server/saved_objects/service/index.ts +++ b/src/core/server/saved_objects/service/index.ts @@ -5,6 +5,7 @@ * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ -export { SavedObjectsErrorHelpers, SavedObjectsClientProvider, SavedObjectsUtils } from './lib'; + +export { SavedObjectsClientProvider } from './lib'; export type { SavedObjectsRepository, ISavedObjectsClientProvider } from './lib'; export { SavedObjectsClient } from './saved_objects_client'; diff --git a/src/core/server/saved_objects/service/lib/aggregations/validation.ts b/src/core/server/saved_objects/service/lib/aggregations/validation.ts index 76098d73306af..b3a6bbae5e956 100644 --- a/src/core/server/saved_objects/service/lib/aggregations/validation.ts +++ b/src/core/server/saved_objects/service/lib/aggregations/validation.ts @@ -10,7 +10,7 @@ import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import { ObjectType } from '@kbn/config-schema'; import { isPlainObject, isArray } from 'lodash'; -import { IndexMapping } from '../../../mappings'; +import type { IndexMapping } from '@kbn/core-saved-objects-base-server-internal'; import { isObjectTypeAttribute, rewriteObjectTypeAttribute, diff --git a/src/core/server/saved_objects/service/lib/aggregations/validation_utils.ts b/src/core/server/saved_objects/service/lib/aggregations/validation_utils.ts index 0b2cc8e235c9c..5548ad4d57a5d 100644 --- a/src/core/server/saved_objects/service/lib/aggregations/validation_utils.ts +++ b/src/core/server/saved_objects/service/lib/aggregations/validation_utils.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import { IndexMapping } from '../../../mappings'; +import type { IndexMapping } from '@kbn/core-saved-objects-base-server-internal'; import { fieldDefined, hasFilterKeyError } from '../filter_utils'; /** diff --git a/src/core/server/saved_objects/service/lib/collect_multi_namespace_references.test.ts b/src/core/server/saved_objects/service/lib/collect_multi_namespace_references.test.ts index d3cf76716e598..86e1e82d12a6f 100644 --- a/src/core/server/saved_objects/service/lib/collect_multi_namespace_references.test.ts +++ b/src/core/server/saved_objects/service/lib/collect_multi_namespace_references.test.ts @@ -17,15 +17,15 @@ import type { SavedObjectsCollectMultiNamespaceReferencesObject, SavedObjectsCollectMultiNamespaceReferencesOptions, } from '@kbn/core-saved-objects-api-server'; -import { typeRegistryMock } from '../../saved_objects_type_registry.mock'; -import { SavedObjectsSerializer } from '../../serialization'; +import { SavedObjectsErrorHelpers } from '@kbn/core-saved-objects-utils-server'; +import { SavedObjectsSerializer } from '@kbn/core-saved-objects-base-server-internal'; +import { typeRegistryMock } from '@kbn/core-saved-objects-base-server-mocks'; import { ALIAS_OR_SHARED_ORIGIN_SEARCH_PER_PAGE, CollectMultiNamespaceReferencesParams, } from './collect_multi_namespace_references'; import { collectMultiNamespaceReferences } from './collect_multi_namespace_references'; import type { CreatePointInTimeFinderFn } from './point_in_time_finder'; -import { SavedObjectsErrorHelpers } from './errors'; const SPACES = ['default', 'another-space']; const VERSION_PROPS = { _seq_no: 1, _primary_term: 1 }; diff --git a/src/core/server/saved_objects/service/lib/collect_multi_namespace_references.ts b/src/core/server/saved_objects/service/lib/collect_multi_namespace_references.ts index b31f817e4c4d2..222b58d3a03e0 100644 --- a/src/core/server/saved_objects/service/lib/collect_multi_namespace_references.ts +++ b/src/core/server/saved_objects/service/lib/collect_multi_namespace_references.ts @@ -15,8 +15,8 @@ import type { SavedObjectReferenceWithContext, } from '@kbn/core-saved-objects-api-server'; import type { ISavedObjectTypeRegistry } from '@kbn/core-saved-objects-server'; -import type { SavedObjectsSerializer } from '../../serialization'; -import { SavedObjectsErrorHelpers } from './errors'; +import { SavedObjectsErrorHelpers } from '@kbn/core-saved-objects-utils-server'; +import type { SavedObjectsSerializer } from '@kbn/core-saved-objects-base-server-internal'; import { findLegacyUrlAliases } from './legacy_url_aliases'; import { getRootFields } from './included_fields'; import { diff --git a/src/core/server/saved_objects/service/lib/decorate_es_error.test.ts b/src/core/server/saved_objects/service/lib/decorate_es_error.test.ts index a7aa52f7a0f5a..8290f7345190d 100644 --- a/src/core/server/saved_objects/service/lib/decorate_es_error.test.ts +++ b/src/core/server/saved_objects/service/lib/decorate_es_error.test.ts @@ -8,8 +8,8 @@ import { errors as esErrors } from '@elastic/elasticsearch'; import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks'; +import { SavedObjectsErrorHelpers } from '@kbn/core-saved-objects-utils-server'; import { decorateEsError } from './decorate_es_error'; -import { SavedObjectsErrorHelpers } from './errors'; describe('savedObjectsClient/decorateEsError', () => { it('always returns the same error it receives', () => { diff --git a/src/core/server/saved_objects/service/lib/decorate_es_error.ts b/src/core/server/saved_objects/service/lib/decorate_es_error.ts index 40eda7a854a25..9cfdffc13a5dd 100644 --- a/src/core/server/saved_objects/service/lib/decorate_es_error.ts +++ b/src/core/server/saved_objects/service/lib/decorate_es_error.ts @@ -10,6 +10,7 @@ import { get } from 'lodash'; import { errors as esErrors } from '@elastic/elasticsearch'; import type { ElasticsearchErrorDetails } from '@kbn/es-errors'; import { isSupportedEsServer } from '@kbn/core-elasticsearch-server-internal'; +import { SavedObjectsErrorHelpers } from '@kbn/core-saved-objects-utils-server'; const responseErrors = { isServiceUnavailable: (statusCode?: number) => statusCode === 503, @@ -25,8 +26,6 @@ const { ConnectionError, NoLivingConnectionsError, TimeoutError } = esErrors; const SCRIPT_CONTEXT_DISABLED_REGEX = /(?:cannot execute scripts using \[)([a-z]*)(?:\] context)/; const INLINE_SCRIPTS_DISABLED_MESSAGE = 'cannot execute [inline] scripts'; -import { SavedObjectsErrorHelpers } from './errors'; - type EsErrors = | esErrors.ConnectionError | esErrors.NoLivingConnectionsError diff --git a/src/core/server/saved_objects/service/lib/filter_utils.ts b/src/core/server/saved_objects/service/lib/filter_utils.ts index 30880368d096d..ae7bb08039850 100644 --- a/src/core/server/saved_objects/service/lib/filter_utils.ts +++ b/src/core/server/saved_objects/service/lib/filter_utils.ts @@ -9,8 +9,8 @@ import { set } from '@kbn/safer-lodash-set'; import { get, cloneDeep } from 'lodash'; import * as esKuery from '@kbn/es-query'; -import { SavedObjectsErrorHelpers } from './errors'; -import { IndexMapping } from '../../mappings'; +import { SavedObjectsErrorHelpers } from '@kbn/core-saved-objects-utils-server'; +import type { IndexMapping } from '@kbn/core-saved-objects-base-server-internal'; type KueryNode = any; diff --git a/src/core/server/saved_objects/service/lib/find_shared_origin_objects.ts b/src/core/server/saved_objects/service/lib/find_shared_origin_objects.ts index 229e0c6f90a66..34aff0b11d6d0 100644 --- a/src/core/server/saved_objects/service/lib/find_shared_origin_objects.ts +++ b/src/core/server/saved_objects/service/lib/find_shared_origin_objects.ts @@ -7,9 +7,9 @@ */ import * as esKuery from '@kbn/es-query'; +import { ALL_NAMESPACES_STRING } from '@kbn/core-saved-objects-utils-server'; import { getObjectKey } from './internal_utils'; import type { CreatePointInTimeFinderFn } from './point_in_time_finder'; -import { ALL_NAMESPACES_STRING } from './utils'; interface ObjectOrigin { /** The object's type. */ diff --git a/src/core/server/saved_objects/service/lib/get_index_for_type.test.ts b/src/core/server/saved_objects/service/lib/get_index_for_type.test.ts index 16e3ba9495f04..01bb3174cc56b 100644 --- a/src/core/server/saved_objects/service/lib/get_index_for_type.test.ts +++ b/src/core/server/saved_objects/service/lib/get_index_for_type.test.ts @@ -6,8 +6,8 @@ * Side Public License, v 1. */ +import { typeRegistryMock } from '@kbn/core-saved-objects-base-server-mocks'; import { getIndexForType } from './get_index_for_type'; -import { typeRegistryMock } from '../../saved_objects_type_registry.mock'; describe('getIndexForType', () => { const kibanaVersion = '8.0.0'; diff --git a/src/core/server/saved_objects/service/lib/index.ts b/src/core/server/saved_objects/service/lib/index.ts index 8fdb8301ce101..a43750608bf95 100644 --- a/src/core/server/saved_objects/service/lib/index.ts +++ b/src/core/server/saved_objects/service/lib/index.ts @@ -11,8 +11,4 @@ export { SavedObjectsClientProvider } from './scoped_client_provider'; export type { ISavedObjectsClientProvider } from './scoped_client_provider'; -export { SavedObjectsErrorHelpers } from './errors'; - -export { SavedObjectsUtils } from './utils'; - export { getIndexForType } from './get_index_for_type'; diff --git a/src/core/server/saved_objects/service/lib/internal_bulk_resolve.test.ts b/src/core/server/saved_objects/service/lib/internal_bulk_resolve.test.ts index ec55ea7725718..119b3ac85b698 100644 --- a/src/core/server/saved_objects/service/lib/internal_bulk_resolve.test.ts +++ b/src/core/server/saved_objects/service/lib/internal_bulk_resolve.test.ts @@ -18,12 +18,13 @@ import type { SavedObjectsBulkResolveObject, SavedObjectsBaseOptions, } from '@kbn/core-saved-objects-api-server'; -import { LEGACY_URL_ALIAS_TYPE } from '../../object_types'; -import { typeRegistryMock } from '../../saved_objects_type_registry.mock'; -import { SavedObjectsSerializer } from '../../serialization'; -import { SavedObjectsErrorHelpers } from './errors'; +import { SavedObjectsErrorHelpers, SavedObjectsUtils } from '@kbn/core-saved-objects-utils-server'; +import { + SavedObjectsSerializer, + LEGACY_URL_ALIAS_TYPE, +} from '@kbn/core-saved-objects-base-server-internal'; +import { typeRegistryMock } from '@kbn/core-saved-objects-base-server-mocks'; import { internalBulkResolve, InternalBulkResolveParams } from './internal_bulk_resolve'; -import { SavedObjectsUtils } from './utils'; import { normalizeNamespace } from './internal_utils'; const VERSION_PROPS = { _seq_no: 1, _primary_term: 1 }; diff --git a/src/core/server/saved_objects/service/lib/internal_bulk_resolve.ts b/src/core/server/saved_objects/service/lib/internal_bulk_resolve.ts index ebe94e4e95b4d..b15fc56e2f3c0 100644 --- a/src/core/server/saved_objects/service/lib/internal_bulk_resolve.ts +++ b/src/core/server/saved_objects/service/lib/internal_bulk_resolve.ts @@ -21,14 +21,20 @@ import type { ISavedObjectTypeRegistry, SavedObjectsRawDocSource, } from '@kbn/core-saved-objects-server'; +import { + SavedObjectsErrorHelpers, + type DecoratedError, +} from '@kbn/core-saved-objects-utils-server'; +import { + LEGACY_URL_ALIAS_TYPE, + type LegacyUrlAlias, + type SavedObjectsSerializer, +} from '@kbn/core-saved-objects-base-server-internal'; import { CORE_USAGE_STATS_ID, CORE_USAGE_STATS_TYPE, REPOSITORY_RESOLVE_OUTCOME_STATS, } from '../../../core_usage_data'; -import { LegacyUrlAlias, LEGACY_URL_ALIAS_TYPE } from '../../object_types'; -import type { SavedObjectsSerializer } from '../../serialization'; -import { DecoratedError, SavedObjectsErrorHelpers } from './errors'; import { getCurrentTime, getSavedObjectFromSource, diff --git a/src/core/server/saved_objects/service/lib/internal_utils.test.ts b/src/core/server/saved_objects/service/lib/internal_utils.test.ts index 65cb83d3e8a77..96ca3949a4775 100644 --- a/src/core/server/saved_objects/service/lib/internal_utils.test.ts +++ b/src/core/server/saved_objects/service/lib/internal_utils.test.ts @@ -7,8 +7,9 @@ */ import type { SavedObjectsRawDoc } from '@kbn/core-saved-objects-server'; -import { typeRegistryMock } from '../../saved_objects_type_registry.mock'; -import { encodeHitVersion } from '../../version'; +import { ALL_NAMESPACES_STRING } from '@kbn/core-saved-objects-utils-server'; +import { encodeHitVersion } from '@kbn/core-saved-objects-base-server-internal'; +import { typeRegistryMock } from '@kbn/core-saved-objects-base-server-mocks'; import { getBulkOperationError, getCurrentTime, @@ -19,7 +20,6 @@ import { rawDocExistsInNamespace, rawDocExistsInNamespaces, } from './internal_utils'; -import { ALL_NAMESPACES_STRING } from './utils'; describe('#getBulkOperationError', () => { const type = 'obj-type'; diff --git a/src/core/server/saved_objects/service/lib/internal_utils.ts b/src/core/server/saved_objects/service/lib/internal_utils.ts index 5f20a2bc3c842..84539510504a2 100644 --- a/src/core/server/saved_objects/service/lib/internal_utils.ts +++ b/src/core/server/saved_objects/service/lib/internal_utils.ts @@ -13,9 +13,15 @@ import type { SavedObjectsRawDoc, SavedObjectsRawDocSource, } from '@kbn/core-saved-objects-server'; -import { decodeRequestVersion, encodeHitVersion } from '../../version'; -import { SavedObjectsErrorHelpers } from './errors'; -import { ALL_NAMESPACES_STRING, SavedObjectsUtils } from './utils'; +import { + SavedObjectsErrorHelpers, + SavedObjectsUtils, + ALL_NAMESPACES_STRING, +} from '@kbn/core-saved-objects-utils-server'; +import { + decodeRequestVersion, + encodeHitVersion, +} from '@kbn/core-saved-objects-base-server-internal'; /** * Discriminated union (TypeScript approximation of an algebraic data type); this design pattern is used for internal repository operations. diff --git a/src/core/server/saved_objects/service/lib/legacy_url_aliases/delete_legacy_url_aliases.test.ts b/src/core/server/saved_objects/service/lib/legacy_url_aliases/delete_legacy_url_aliases.test.ts index dc261ee23aafb..77a538672ff19 100644 --- a/src/core/server/saved_objects/service/lib/legacy_url_aliases/delete_legacy_url_aliases.test.ts +++ b/src/core/server/saved_objects/service/lib/legacy_url_aliases/delete_legacy_url_aliases.test.ts @@ -11,8 +11,8 @@ import { mockGetEsErrorMessage } from './delete_legacy_url_aliases.test.mock'; / import { errors as EsErrors } from '@elastic/elasticsearch'; import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks'; -import { typeRegistryMock } from '../../../saved_objects_type_registry.mock'; -import { ALL_NAMESPACES_STRING } from '../utils'; +import { ALL_NAMESPACES_STRING } from '@kbn/core-saved-objects-utils-server'; +import { typeRegistryMock } from '@kbn/core-saved-objects-base-server-mocks'; import { deleteLegacyUrlAliases } from './delete_legacy_url_aliases'; import type { DeleteLegacyUrlAliasesParams } from './delete_legacy_url_aliases'; diff --git a/src/core/server/saved_objects/service/lib/legacy_url_aliases/delete_legacy_url_aliases.ts b/src/core/server/saved_objects/service/lib/legacy_url_aliases/delete_legacy_url_aliases.ts index 873f4ab9b6c9c..73489308f59af 100644 --- a/src/core/server/saved_objects/service/lib/legacy_url_aliases/delete_legacy_url_aliases.ts +++ b/src/core/server/saved_objects/service/lib/legacy_url_aliases/delete_legacy_url_aliases.ts @@ -10,11 +10,13 @@ import * as esKuery from '@kbn/es-query'; import { getErrorMessage as getEsErrorMessage } from '@kbn/core-elasticsearch-client-server-internal'; import type { ISavedObjectTypeRegistry } from '@kbn/core-saved-objects-server'; -import type { IndexMapping } from '../../../mappings'; -import { LEGACY_URL_ALIAS_TYPE } from '../../../object_types'; +import { ALL_NAMESPACES_STRING } from '@kbn/core-saved-objects-utils-server'; +import { + LEGACY_URL_ALIAS_TYPE, + type IndexMapping, +} from '@kbn/core-saved-objects-base-server-internal'; import type { RepositoryEsClient } from '../repository_es_client'; import { getSearchDsl } from '../search_dsl'; -import { ALL_NAMESPACES_STRING } from '../utils'; /** @internal */ export interface DeleteLegacyUrlAliasesParams { diff --git a/src/core/server/saved_objects/service/lib/legacy_url_aliases/find_legacy_url_aliases.test.ts b/src/core/server/saved_objects/service/lib/legacy_url_aliases/find_legacy_url_aliases.test.ts index 8200c7502fec6..36435b9828be4 100644 --- a/src/core/server/saved_objects/service/lib/legacy_url_aliases/find_legacy_url_aliases.test.ts +++ b/src/core/server/saved_objects/service/lib/legacy_url_aliases/find_legacy_url_aliases.test.ts @@ -9,7 +9,10 @@ import type { DeeplyMockedKeys } from '@kbn/utility-types-jest'; import type { ISavedObjectsRepository } from '@kbn/core-saved-objects-api-server'; -import { LegacyUrlAlias, LEGACY_URL_ALIAS_TYPE } from '../../../object_types'; +import { + type LegacyUrlAlias, + LEGACY_URL_ALIAS_TYPE, +} from '@kbn/core-saved-objects-base-server-internal'; import type { CreatePointInTimeFinderFn, PointInTimeFinder } from '../point_in_time_finder'; import { savedObjectsPointInTimeFinderMock } from '../point_in_time_finder.mock'; import { savedObjectsRepositoryMock } from '../repository.mock'; diff --git a/src/core/server/saved_objects/service/lib/legacy_url_aliases/find_legacy_url_aliases.ts b/src/core/server/saved_objects/service/lib/legacy_url_aliases/find_legacy_url_aliases.ts index 70b1730ec8f48..5a90a2e70d073 100644 --- a/src/core/server/saved_objects/service/lib/legacy_url_aliases/find_legacy_url_aliases.ts +++ b/src/core/server/saved_objects/service/lib/legacy_url_aliases/find_legacy_url_aliases.ts @@ -7,7 +7,10 @@ */ import * as esKuery from '@kbn/es-query'; -import { LegacyUrlAlias, LEGACY_URL_ALIAS_TYPE } from '../../../object_types'; +import { + type LegacyUrlAlias, + LEGACY_URL_ALIAS_TYPE, +} from '@kbn/core-saved-objects-base-server-internal'; import { getObjectKey } from '../internal_utils'; import type { CreatePointInTimeFinderFn } from '../point_in_time_finder'; diff --git a/src/core/server/saved_objects/service/lib/preflight_check_for_create.test.ts b/src/core/server/saved_objects/service/lib/preflight_check_for_create.test.ts index 9563ebd51344f..d23d2cf5e804e 100644 --- a/src/core/server/saved_objects/service/lib/preflight_check_for_create.test.ts +++ b/src/core/server/saved_objects/service/lib/preflight_check_for_create.test.ts @@ -15,9 +15,11 @@ import type { DeeplyMockedKeys } from '@kbn/utility-types-jest'; import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server'; import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks'; -import { LEGACY_URL_ALIAS_TYPE } from '../../object_types'; -import { typeRegistryMock } from '../../saved_objects_type_registry.mock'; -import { SavedObjectsSerializer } from '../../serialization'; +import { + SavedObjectsSerializer, + LEGACY_URL_ALIAS_TYPE, +} from '@kbn/core-saved-objects-base-server-internal'; +import { typeRegistryMock } from '@kbn/core-saved-objects-base-server-mocks'; import type { CreatePointInTimeFinderFn } from './point_in_time_finder'; import { ALIAS_SEARCH_PER_PAGE, diff --git a/src/core/server/saved_objects/service/lib/preflight_check_for_create.ts b/src/core/server/saved_objects/service/lib/preflight_check_for_create.ts index b94302b2b990f..a3fd4218c3eeb 100644 --- a/src/core/server/saved_objects/service/lib/preflight_check_for_create.ts +++ b/src/core/server/saved_objects/service/lib/preflight_check_for_create.ts @@ -13,15 +13,20 @@ import type { SavedObjectsRawDoc, SavedObjectsRawDocSource, } from '@kbn/core-saved-objects-server'; -import { LegacyUrlAlias, LEGACY_URL_ALIAS_TYPE } from '../../object_types'; -import type { SavedObjectsSerializer } from '../../serialization'; +import { + SavedObjectsErrorHelpers, + ALL_NAMESPACES_STRING, +} from '@kbn/core-saved-objects-utils-server'; +import { + LEGACY_URL_ALIAS_TYPE, + type LegacyUrlAlias, + type SavedObjectsSerializer, +} from '@kbn/core-saved-objects-base-server-internal'; import { findLegacyUrlAliases } from './legacy_url_aliases'; import { Either, rawDocExistsInNamespaces } from './internal_utils'; import { getObjectKey, isLeft, isRight } from './internal_utils'; import type { CreatePointInTimeFinderFn } from './point_in_time_finder'; import type { RepositoryEsClient } from './repository_es_client'; -import { ALL_NAMESPACES_STRING } from './utils'; -import { SavedObjectsErrorHelpers } from './errors'; /** * If the object will be created in this many spaces (or "*" all current and future spaces), we use find to fetch all aliases. diff --git a/src/core/server/saved_objects/service/lib/repository.test.ts b/src/core/server/saved_objects/service/lib/repository.test.ts index 9af620101ab94..30a6b1ab36151 100644 --- a/src/core/server/saved_objects/service/lib/repository.test.ts +++ b/src/core/server/saved_objects/service/lib/repository.test.ts @@ -55,17 +55,21 @@ import type { SavedObjectsMappingProperties, SavedObjectsTypeMappingDefinition, } from '@kbn/core-saved-objects-server'; +import { + SavedObjectsErrorHelpers, + ALL_NAMESPACES_STRING, +} from '@kbn/core-saved-objects-utils-server'; import { SavedObjectsRepository } from './repository'; -import { SavedObjectsErrorHelpers } from './errors'; import { PointInTimeFinder } from './point_in_time_finder'; -import { ALL_NAMESPACES_STRING } from './utils'; import { loggerMock } from '@kbn/logging-mocks'; -import { SavedObjectsSerializer } from '../../serialization'; -import { encodeHitVersion } from '../../version'; -import { SavedObjectTypeRegistry } from '../../saved_objects_type_registry'; +import { + SavedObjectTypeRegistry, + SavedObjectsSerializer, + encodeHitVersion, + LEGACY_URL_ALIAS_TYPE, +} from '@kbn/core-saved-objects-base-server-internal'; import { DocumentMigrator } from '../../migrations/core/document_migrator'; import { mockKibanaMigrator } from '../../migrations/kibana_migrator.mock'; -import { LEGACY_URL_ALIAS_TYPE } from '../../object_types'; import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks'; import * as esKuery from '@kbn/es-query'; import { errors as EsErrors } from '@elastic/elasticsearch'; diff --git a/src/core/server/saved_objects/service/lib/repository.ts b/src/core/server/saved_objects/service/lib/repository.ts index 1ede13e1142b2..524fe5f7eb966 100644 --- a/src/core/server/saved_objects/service/lib/repository.ts +++ b/src/core/server/saved_objects/service/lib/repository.ts @@ -60,17 +60,31 @@ import type { SavedObjectsRawDocSource, ISavedObjectTypeRegistry, } from '@kbn/core-saved-objects-server'; -import { getRootPropertiesObjects, IndexMapping } from '../../mappings'; +import { + SavedObjectsErrorHelpers, + type DecoratedError, +} from '@kbn/core-saved-objects-utils-server'; +import { + ALL_NAMESPACES_STRING, + FIND_DEFAULT_PAGE, + FIND_DEFAULT_PER_PAGE, + SavedObjectsUtils, +} from '@kbn/core-saved-objects-utils-server'; +import { + SavedObjectsSerializer, + SavedObjectsTypeValidator, + decodeRequestVersion, + encodeVersion, + encodeHitVersion, + getRootPropertiesObjects, + LEGACY_URL_ALIAS_TYPE, + type IndexMapping, +} from '@kbn/core-saved-objects-base-server-internal'; import { PointInTimeFinder } from './point_in_time_finder'; import { createRepositoryEsClient, RepositoryEsClient } from './repository_es_client'; import { getSearchDsl } from './search_dsl'; import { includedFields } from './included_fields'; -import { SavedObjectsErrorHelpers, DecoratedError } from './errors'; -import { decodeRequestVersion, encodeVersion, encodeHitVersion } from '../../version'; import { IKibanaMigrator } from '../../migrations'; -import { SavedObjectsSerializer } from '../../serialization'; -import { LEGACY_URL_ALIAS_TYPE } from '../../object_types'; -import { SavedObjectsTypeValidator } from '../../validation'; import { internalBulkResolve, InternalBulkResolveError } from './internal_bulk_resolve'; import { validateConvertFilterToKueryNode } from './filter_utils'; import { validateAndConvertAggregations } from './aggregations'; @@ -86,12 +100,6 @@ import { isLeft, isRight, } from './internal_utils'; -import { - ALL_NAMESPACES_STRING, - FIND_DEFAULT_PAGE, - FIND_DEFAULT_PER_PAGE, - SavedObjectsUtils, -} from './utils'; import { collectMultiNamespaceReferences } from './collect_multi_namespace_references'; import { updateObjectsSpaces } from './update_objects_spaces'; import { getIndexForType } from './get_index_for_type'; diff --git a/src/core/server/saved_objects/service/lib/repository_create_repository.test.ts b/src/core/server/saved_objects/service/lib/repository_create_repository.test.ts index b1033012a4beb..9a2d56cdaaa89 100644 --- a/src/core/server/saved_objects/service/lib/repository_create_repository.test.ts +++ b/src/core/server/saved_objects/service/lib/repository_create_repository.test.ts @@ -6,10 +6,10 @@ * Side Public License, v 1. */ +import { SavedObjectTypeRegistry } from '@kbn/core-saved-objects-base-server-internal'; import { SavedObjectsRepository } from './repository'; import { mockKibanaMigrator } from '../../migrations/kibana_migrator.mock'; import { KibanaMigrator } from '../../migrations'; -import { SavedObjectTypeRegistry } from '../../saved_objects_type_registry'; import { loggerMock, MockedLogger } from '@kbn/logging-mocks'; jest.mock('./repository'); diff --git a/src/core/server/saved_objects/service/lib/repository_es_client.test.ts b/src/core/server/saved_objects/service/lib/repository_es_client.test.ts index f465ffb6a3dab..cbd8f81bfc0f5 100644 --- a/src/core/server/saved_objects/service/lib/repository_es_client.test.ts +++ b/src/core/server/saved_objects/service/lib/repository_es_client.test.ts @@ -10,7 +10,7 @@ import { retryCallClusterMock } from './repository_es_client.test.mock'; import { createRepositoryEsClient, RepositoryEsClient } from './repository_es_client'; import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks'; -import { SavedObjectsErrorHelpers } from './errors'; +import { SavedObjectsErrorHelpers } from '@kbn/core-saved-objects-utils-server'; describe('RepositoryEsClient', () => { let client: ReturnType; diff --git a/src/core/server/saved_objects/service/lib/scoped_client_provider.test.ts b/src/core/server/saved_objects/service/lib/scoped_client_provider.test.ts index efc04f69e6ecf..2641ecfb1cec6 100644 --- a/src/core/server/saved_objects/service/lib/scoped_client_provider.test.ts +++ b/src/core/server/saved_objects/service/lib/scoped_client_provider.test.ts @@ -7,8 +7,8 @@ */ import { httpServerMock } from '@kbn/core-http-server-mocks'; +import { typeRegistryMock } from '@kbn/core-saved-objects-base-server-mocks'; import { SavedObjectsClientProvider } from './scoped_client_provider'; -import { typeRegistryMock } from '../../saved_objects_type_registry.mock'; test(`uses default client factory when one isn't set`, () => { const returnValue = Symbol(); diff --git a/src/core/server/saved_objects/service/lib/search_dsl/query_params.test.ts b/src/core/server/saved_objects/service/lib/search_dsl/query_params.test.ts index 3f27bef5c68af..c502665468e6c 100644 --- a/src/core/server/saved_objects/service/lib/search_dsl/query_params.test.ts +++ b/src/core/server/saved_objects/service/lib/search_dsl/query_params.test.ts @@ -12,8 +12,11 @@ import * as esKuery from '@kbn/es-query'; type KueryNode = any; -import { ALL_NAMESPACES_STRING, DEFAULT_NAMESPACE_STRING } from '../utils'; -import { SavedObjectTypeRegistry } from '../../../saved_objects_type_registry'; +import { + ALL_NAMESPACES_STRING, + DEFAULT_NAMESPACE_STRING, +} from '@kbn/core-saved-objects-utils-server'; +import { SavedObjectTypeRegistry } from '@kbn/core-saved-objects-base-server-internal'; import { getQueryParams } from './query_params'; const registerTypes = (registry: SavedObjectTypeRegistry) => { diff --git a/src/core/server/saved_objects/service/lib/search_dsl/query_params.ts b/src/core/server/saved_objects/service/lib/search_dsl/query_params.ts index 1c21a7177faf4..669f2a273569b 100644 --- a/src/core/server/saved_objects/service/lib/search_dsl/query_params.ts +++ b/src/core/server/saved_objects/service/lib/search_dsl/query_params.ts @@ -11,7 +11,10 @@ import * as esKuery from '@kbn/es-query'; type KueryNode = any; import type { ISavedObjectTypeRegistry } from '@kbn/core-saved-objects-server'; -import { ALL_NAMESPACES_STRING, DEFAULT_NAMESPACE_STRING } from '../utils'; +import { + ALL_NAMESPACES_STRING, + DEFAULT_NAMESPACE_STRING, +} from '@kbn/core-saved-objects-utils-server'; import { getReferencesFilter } from './references_filter'; /** diff --git a/src/core/server/saved_objects/service/lib/search_dsl/search_dsl.test.ts b/src/core/server/saved_objects/service/lib/search_dsl/search_dsl.test.ts index b15560b82ab31..d1ed7251b2414 100644 --- a/src/core/server/saved_objects/service/lib/search_dsl/search_dsl.test.ts +++ b/src/core/server/saved_objects/service/lib/search_dsl/search_dsl.test.ts @@ -10,7 +10,7 @@ jest.mock('./pit_params'); jest.mock('./query_params'); jest.mock('./sorting_params'); -import { typeRegistryMock } from '../../../saved_objects_type_registry.mock'; +import { typeRegistryMock } from '@kbn/core-saved-objects-base-server-mocks'; import * as pitParamsNS from './pit_params'; import * as queryParamsNS from './query_params'; import { getSearchDsl } from './search_dsl'; diff --git a/src/core/server/saved_objects/service/lib/search_dsl/search_dsl.ts b/src/core/server/saved_objects/service/lib/search_dsl/search_dsl.ts index 7d6d31949739c..980bf800755b9 100644 --- a/src/core/server/saved_objects/service/lib/search_dsl/search_dsl.ts +++ b/src/core/server/saved_objects/service/lib/search_dsl/search_dsl.ts @@ -11,7 +11,7 @@ import Boom from '@hapi/boom'; import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import type { SavedObjectsPitParams } from '@kbn/core-saved-objects-api-server'; import type { ISavedObjectTypeRegistry } from '@kbn/core-saved-objects-server'; -import { IndexMapping } from '../../../mappings'; +import type { IndexMapping } from '@kbn/core-saved-objects-base-server-internal'; import { getQueryParams, HasReferenceQueryParams, SearchOperator } from './query_params'; import { getPitParams } from './pit_params'; import { getSortingParams } from './sorting_params'; diff --git a/src/core/server/saved_objects/service/lib/search_dsl/sorting_params.ts b/src/core/server/saved_objects/service/lib/search_dsl/sorting_params.ts index 030219b4ba5b1..d2308736b5dc2 100644 --- a/src/core/server/saved_objects/service/lib/search_dsl/sorting_params.ts +++ b/src/core/server/saved_objects/service/lib/search_dsl/sorting_params.ts @@ -8,7 +8,7 @@ import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import Boom from '@hapi/boom'; -import { getProperty, IndexMapping } from '../../../mappings'; +import { getProperty, type IndexMapping } from '@kbn/core-saved-objects-base-server-internal'; const TOP_LEVEL_FIELDS = ['_id', '_score']; diff --git a/src/core/server/saved_objects/service/lib/update_objects_spaces.test.ts b/src/core/server/saved_objects/service/lib/update_objects_spaces.test.ts index dfd1600e6d218..6e6c241965056 100644 --- a/src/core/server/saved_objects/service/lib/update_objects_spaces.test.ts +++ b/src/core/server/saved_objects/service/lib/update_objects_spaces.test.ts @@ -17,12 +17,14 @@ import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-m import { loggerMock } from '@kbn/logging-mocks'; import type { SavedObjectsUpdateObjectsSpacesObject } from '@kbn/core-saved-objects-api-server'; -import { typeRegistryMock } from '../../saved_objects_type_registry.mock'; -import { SavedObjectsSerializer } from '../../serialization'; +import { + SavedObjectsErrorHelpers, + ALL_NAMESPACES_STRING, +} from '@kbn/core-saved-objects-utils-server'; +import { SavedObjectsSerializer } from '@kbn/core-saved-objects-base-server-internal'; +import { typeRegistryMock } from '@kbn/core-saved-objects-base-server-mocks'; import type { UpdateObjectsSpacesParams } from './update_objects_spaces'; import { updateObjectsSpaces } from './update_objects_spaces'; -import { ALL_NAMESPACES_STRING } from './utils'; -import { SavedObjectsErrorHelpers } from './errors'; type SetupParams = Partial< Pick diff --git a/src/core/server/saved_objects/service/lib/update_objects_spaces.ts b/src/core/server/saved_objects/service/lib/update_objects_spaces.ts index a92f9a952af18..4053fcff4a8ea 100644 --- a/src/core/server/saved_objects/service/lib/update_objects_spaces.ts +++ b/src/core/server/saved_objects/service/lib/update_objects_spaces.ts @@ -22,10 +22,15 @@ import type { ISavedObjectTypeRegistry, SavedObjectsRawDocSource, } from '@kbn/core-saved-objects-server'; -import type { IndexMapping } from '../../mappings'; -import type { SavedObjectsSerializer } from '../../serialization'; -import type { DecoratedError } from './errors'; -import { SavedObjectsErrorHelpers } from './errors'; +import { + SavedObjectsErrorHelpers, + ALL_NAMESPACES_STRING, + type DecoratedError, +} from '@kbn/core-saved-objects-utils-server'; +import type { + IndexMapping, + SavedObjectsSerializer, +} from '@kbn/core-saved-objects-base-server-internal'; import { getBulkOperationError, getExpectedVersionProperties, @@ -36,7 +41,6 @@ import { } from './internal_utils'; import { DEFAULT_REFRESH_SETTING } from './repository'; import type { RepositoryEsClient } from './repository_es_client'; -import { ALL_NAMESPACES_STRING } from './utils'; import type { DeleteLegacyUrlAliasesParams } from './legacy_url_aliases'; import { deleteLegacyUrlAliases } from './legacy_url_aliases'; diff --git a/src/core/server/saved_objects/service/saved_objects_client.mock.ts b/src/core/server/saved_objects/service/saved_objects_client.mock.ts index fe5ea92ed0766..55a96ea3cecfc 100644 --- a/src/core/server/saved_objects/service/saved_objects_client.mock.ts +++ b/src/core/server/saved_objects/service/saved_objects_client.mock.ts @@ -7,7 +7,7 @@ */ import type { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server'; -import { SavedObjectsErrorHelpers } from './lib/errors'; +import { SavedObjectsErrorHelpers } from '@kbn/core-saved-objects-utils-server'; import { savedObjectsPointInTimeFinderMock } from './lib/point_in_time_finder.mock'; const create = () => { diff --git a/src/core/server/saved_objects/service/saved_objects_client.ts b/src/core/server/saved_objects/service/saved_objects_client.ts index c9cfd9e720056..7c2b3a205b76d 100644 --- a/src/core/server/saved_objects/service/saved_objects_client.ts +++ b/src/core/server/saved_objects/service/saved_objects_client.ts @@ -40,7 +40,7 @@ import type { SavedObjectsCreatePointInTimeFinderOptions, SavedObjectsFindOptions, } from '@kbn/core-saved-objects-api-server'; -import { SavedObjectsErrorHelpers } from './lib/errors'; +import { SavedObjectsErrorHelpers } from '@kbn/core-saved-objects-utils-server'; /** * Core internal implementation of {@link SavedObjectsClientContract} diff --git a/src/core/server/server.ts b/src/core/server/server.ts index 42878ca66e614..82705f2428e5c 100644 --- a/src/core/server/server.ts +++ b/src/core/server/server.ts @@ -45,6 +45,10 @@ import { import { MetricsService, opsConfig } from '@kbn/core-metrics-server-internal'; import { CapabilitiesService } from '@kbn/core-capabilities-server-internal'; import type { SavedObjectsServiceStart } from '@kbn/core-saved-objects-server'; +import { + savedObjectsConfig, + savedObjectsMigrationConfig, +} from '@kbn/core-saved-objects-base-server-internal'; import { CoreApp } from './core_app'; import { I18nService } from './i18n'; import { HttpResourcesService } from './http_resources'; @@ -53,9 +57,8 @@ import { UiSettingsService } from './ui_settings'; import { PluginsService, config as pluginsConfig } from './plugins'; import { SavedObjectsService } from './saved_objects'; // do not try to shorten the import to `./status`, it will break server test mocking -import { StatusService } from './status/status_service'; -import { savedObjectsConfig, savedObjectsMigrationConfig } from './saved_objects'; +import { StatusService } from './status/status_service'; import { config as uiSettingsConfig } from './ui_settings'; import { config as statusConfig } from './status'; import { config as i18nConfig } from './i18n'; diff --git a/src/core/server/ui_settings/create_or_upgrade_saved_config/create_or_upgrade_saved_config.test.ts b/src/core/server/ui_settings/create_or_upgrade_saved_config/create_or_upgrade_saved_config.test.ts index c5a9c9729b78a..6102ff6f7b1be 100644 --- a/src/core/server/ui_settings/create_or_upgrade_saved_config/create_or_upgrade_saved_config.test.ts +++ b/src/core/server/ui_settings/create_or_upgrade_saved_config/create_or_upgrade_saved_config.test.ts @@ -10,7 +10,7 @@ import { mockTransform, mockGetUpgradeableConfig, } from './create_or_upgrade_saved_config.test.mock'; -import { SavedObjectsErrorHelpers } from '../../saved_objects'; +import { SavedObjectsErrorHelpers } from '@kbn/core-saved-objects-utils-server'; import { savedObjectsClientMock } from '../../saved_objects/service/saved_objects_client.mock'; import { loggingSystemMock } from '@kbn/core-logging-server-mocks'; diff --git a/src/core/server/ui_settings/create_or_upgrade_saved_config/create_or_upgrade_saved_config.ts b/src/core/server/ui_settings/create_or_upgrade_saved_config/create_or_upgrade_saved_config.ts index def1b58784174..e453c9cf46f31 100644 --- a/src/core/server/ui_settings/create_or_upgrade_saved_config/create_or_upgrade_saved_config.ts +++ b/src/core/server/ui_settings/create_or_upgrade_saved_config/create_or_upgrade_saved_config.ts @@ -11,7 +11,7 @@ import { defaults } from 'lodash'; import type { Logger, LogMeta } from '@kbn/logging'; import { asyncForEach } from '@kbn/std'; import type { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server'; -import { SavedObjectsErrorHelpers } from '../../saved_objects'; +import { SavedObjectsErrorHelpers } from '@kbn/core-saved-objects-utils-server'; import { getUpgradeableConfig } from './get_upgradeable_config'; import { transforms } from '../saved_objects'; diff --git a/src/core/server/ui_settings/routes/delete.ts b/src/core/server/ui_settings/routes/delete.ts index 705a5319c1cf5..4147358d4e1ee 100644 --- a/src/core/server/ui_settings/routes/delete.ts +++ b/src/core/server/ui_settings/routes/delete.ts @@ -8,7 +8,7 @@ import { schema } from '@kbn/config-schema'; -import { SavedObjectsErrorHelpers } from '../../saved_objects'; +import { SavedObjectsErrorHelpers } from '@kbn/core-saved-objects-utils-server'; import type { InternalUiSettingsRouter } from '../internal_types'; import { CannotOverrideError } from '../ui_settings_errors'; diff --git a/src/core/server/ui_settings/routes/get.ts b/src/core/server/ui_settings/routes/get.ts index c940c2e1fe71e..2603526c37503 100644 --- a/src/core/server/ui_settings/routes/get.ts +++ b/src/core/server/ui_settings/routes/get.ts @@ -6,8 +6,8 @@ * Side Public License, v 1. */ +import { SavedObjectsErrorHelpers } from '@kbn/core-saved-objects-utils-server'; import type { InternalUiSettingsRouter } from '../internal_types'; -import { SavedObjectsErrorHelpers } from '../../saved_objects'; export function registerGetRoute(router: InternalUiSettingsRouter) { router.get( diff --git a/src/core/server/ui_settings/routes/set.ts b/src/core/server/ui_settings/routes/set.ts index af62fda0144b6..61493be876ad7 100644 --- a/src/core/server/ui_settings/routes/set.ts +++ b/src/core/server/ui_settings/routes/set.ts @@ -8,7 +8,7 @@ import { schema, ValidationError } from '@kbn/config-schema'; -import { SavedObjectsErrorHelpers } from '../../saved_objects'; +import { SavedObjectsErrorHelpers } from '@kbn/core-saved-objects-utils-server'; import type { InternalUiSettingsRouter } from '../internal_types'; import { CannotOverrideError } from '../ui_settings_errors'; diff --git a/src/core/server/ui_settings/routes/set_many.ts b/src/core/server/ui_settings/routes/set_many.ts index fe0ee1a0a721f..3bbe14c4a0076 100644 --- a/src/core/server/ui_settings/routes/set_many.ts +++ b/src/core/server/ui_settings/routes/set_many.ts @@ -8,7 +8,7 @@ import { schema, ValidationError } from '@kbn/config-schema'; -import { SavedObjectsErrorHelpers } from '../../saved_objects'; +import { SavedObjectsErrorHelpers } from '@kbn/core-saved-objects-utils-server'; import type { InternalUiSettingsRouter } from '../internal_types'; import { CannotOverrideError } from '../ui_settings_errors'; diff --git a/src/core/server/ui_settings/saved_objects/transforms.test.ts b/src/core/server/ui_settings/saved_objects/transforms.test.ts index afcd525673aa0..279dfd637b9e2 100644 --- a/src/core/server/ui_settings/saved_objects/transforms.test.ts +++ b/src/core/server/ui_settings/saved_objects/transforms.test.ts @@ -7,7 +7,7 @@ */ import { savedObjectsClientMock } from '../../mocks'; -import { SavedObjectsErrorHelpers } from '../../saved_objects'; +import { SavedObjectsErrorHelpers } from '@kbn/core-saved-objects-utils-server'; import { SavedObject } from '../../types'; import type { UpgradeableConfigAttributes } from '../create_or_upgrade_saved_config'; import { transformDefaultIndex } from './transforms'; diff --git a/src/core/server/ui_settings/saved_objects/transforms.ts b/src/core/server/ui_settings/saved_objects/transforms.ts index cabf14a2e6469..797b895f91556 100644 --- a/src/core/server/ui_settings/saved_objects/transforms.ts +++ b/src/core/server/ui_settings/saved_objects/transforms.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import { SavedObjectsErrorHelpers } from '../../saved_objects'; +import { SavedObjectsErrorHelpers } from '@kbn/core-saved-objects-utils-server'; import type { SavedObjectsClientContract } from '../../types'; import type { UpgradeableConfigAttributes } from '../create_or_upgrade_saved_config'; diff --git a/src/core/server/ui_settings/ui_settings_client.ts b/src/core/server/ui_settings/ui_settings_client.ts index 5175af54ffe3e..aa7d344881cf6 100644 --- a/src/core/server/ui_settings/ui_settings_client.ts +++ b/src/core/server/ui_settings/ui_settings_client.ts @@ -8,7 +8,7 @@ import type { Logger } from '@kbn/logging'; import type { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server'; -import { SavedObjectsErrorHelpers } from '../saved_objects'; +import { SavedObjectsErrorHelpers } from '@kbn/core-saved-objects-utils-server'; import { createOrUpgradeSavedConfig } from './create_or_upgrade_saved_config'; import { UiSettingsParams } from './types'; import { CannotOverrideError } from './ui_settings_errors'; diff --git a/x-pack/plugins/actions/server/actions_client.test.ts b/x-pack/plugins/actions/server/actions_client.test.ts index 4576a301a5f2f..44276a604896f 100644 --- a/x-pack/plugins/actions/server/actions_client.test.ts +++ b/x-pack/plugins/actions/server/actions_client.test.ts @@ -45,11 +45,15 @@ import { getOAuthJwtAccessToken } from './builtin_action_types/lib/get_oauth_jwt import { getOAuthClientCredentialsAccessToken } from './builtin_action_types/lib/get_oauth_client_credentials_access_token'; import { OAuthParams } from './routes/get_oauth_access_token'; -jest.mock('@kbn/core/server/saved_objects/service/lib/utils', () => ({ - SavedObjectsUtils: { - generateId: () => 'mock-saved-object-id', - }, -})); +jest.mock('@kbn/core-saved-objects-utils-server', () => { + const actual = jest.requireActual('@kbn/core-saved-objects-utils-server'); + return { + ...actual, + SavedObjectsUtils: { + generateId: () => 'mock-saved-object-id', + }, + }; +}); jest.mock('./lib/track_legacy_rbac_exemption', () => ({ trackLegacyRBACExemption: jest.fn(), diff --git a/x-pack/plugins/actions/server/builtin_action_types/lib/connector_token_client.test.ts b/x-pack/plugins/actions/server/builtin_action_types/lib/connector_token_client.test.ts index dfa307ca3cd91..1aa8bbb3da9a7 100644 --- a/x-pack/plugins/actions/server/builtin_action_types/lib/connector_token_client.test.ts +++ b/x-pack/plugins/actions/server/builtin_action_types/lib/connector_token_client.test.ts @@ -13,11 +13,15 @@ import { Logger } from '@kbn/core/server'; import { ConnectorToken } from '../../types'; const logger = loggingSystemMock.create().get() as jest.Mocked; -jest.mock('@kbn/core/server/saved_objects/service/lib/utils', () => ({ - SavedObjectsUtils: { - generateId: () => 'mock-saved-object-id', - }, -})); +jest.mock('@kbn/core-saved-objects-utils-server', () => { + const actual = jest.requireActual('@kbn/core-saved-objects-utils-server'); + return { + ...actual, + SavedObjectsUtils: { + generateId: () => 'mock-saved-object-id', + }, + }; +}); const unsecuredSavedObjectsClient = savedObjectsClientMock.create(); const encryptedSavedObjectsClient = encryptedSavedObjectsMock.createClient(); diff --git a/x-pack/plugins/alerting/server/rules_client/tests/create.test.ts b/x-pack/plugins/alerting/server/rules_client/tests/create.test.ts index 53f9c59545526..b29d41f183b73 100644 --- a/x-pack/plugins/alerting/server/rules_client/tests/create.test.ts +++ b/x-pack/plugins/alerting/server/rules_client/tests/create.test.ts @@ -26,11 +26,15 @@ jest.mock('../../invalidate_pending_api_keys/bulk_mark_api_keys_for_invalidation bulkMarkApiKeysForInvalidation: jest.fn(), })); -jest.mock('@kbn/core/server/saved_objects/service/lib/utils', () => ({ - SavedObjectsUtils: { - generateId: () => 'mock-saved-object-id', - }, -})); +jest.mock('@kbn/core-saved-objects-utils-server', () => { + const actual = jest.requireActual('@kbn/core-saved-objects-utils-server'); + return { + ...actual, + SavedObjectsUtils: { + generateId: () => 'mock-saved-object-id', + }, + }; +}); const taskManager = taskManagerMock.createStart(); const ruleTypeRegistry = ruleTypeRegistryMock.create(); diff --git a/x-pack/plugins/alerting/server/rules_client/tests/update.test.ts b/x-pack/plugins/alerting/server/rules_client/tests/update.test.ts index 219ee35756f07..9071099ed3aaf 100644 --- a/x-pack/plugins/alerting/server/rules_client/tests/update.test.ts +++ b/x-pack/plugins/alerting/server/rules_client/tests/update.test.ts @@ -23,11 +23,15 @@ import { auditLoggerMock } from '@kbn/security-plugin/server/audit/mocks'; import { getBeforeSetup, setGlobalDate } from './lib'; import { bulkMarkApiKeysForInvalidation } from '../../invalidate_pending_api_keys/bulk_mark_api_keys_for_invalidation'; -jest.mock('@kbn/core/server/saved_objects/service/lib/utils', () => ({ - SavedObjectsUtils: { - generateId: () => 'mock-saved-object-id', - }, -})); +jest.mock('@kbn/core-saved-objects-utils-server', () => { + const actual = jest.requireActual('@kbn/core-saved-objects-utils-server'); + return { + ...actual, + SavedObjectsUtils: { + generateId: () => 'mock-saved-object-id', + }, + }; +}); jest.mock('../../invalidate_pending_api_keys/bulk_mark_api_keys_for_invalidation', () => ({ bulkMarkApiKeysForInvalidation: jest.fn(), diff --git a/x-pack/plugins/encrypted_saved_objects/server/saved_objects/encrypted_saved_objects_client_wrapper.test.ts b/x-pack/plugins/encrypted_saved_objects/server/saved_objects/encrypted_saved_objects_client_wrapper.test.ts index 724178f9b7088..75dd3fdfe8dce 100644 --- a/x-pack/plugins/encrypted_saved_objects/server/saved_objects/encrypted_saved_objects_client_wrapper.test.ts +++ b/x-pack/plugins/encrypted_saved_objects/server/saved_objects/encrypted_saved_objects_client_wrapper.test.ts @@ -15,11 +15,12 @@ import { EncryptionErrorOperation } from '../crypto/encryption_error'; import { encryptedSavedObjectsServiceMock } from '../crypto/index.mock'; import { EncryptedSavedObjectsClientWrapper } from './encrypted_saved_objects_client_wrapper'; -jest.mock('@kbn/core/server/saved_objects/service/lib/utils', () => { - const { SavedObjectsUtils } = jest.requireActual( - '@kbn/core/server/saved_objects/service/lib/utils' +jest.mock('@kbn/core-saved-objects-utils-server', () => { + const { SavedObjectsUtils, ...actual } = jest.requireActual( + '@kbn/core-saved-objects-utils-server' ); return { + ...actual, SavedObjectsUtils: { namespaceStringToId: SavedObjectsUtils.namespaceStringToId, isRandomId: SavedObjectsUtils.isRandomId, @@ -699,6 +700,7 @@ describe('#bulkUpdate', () => { expectOptionsNamespaceInDescriptor: boolean; expectObjectNamespaceInDescriptor: boolean; } + const doTest = async ({ optionsNamespace, objectNamespace, diff --git a/x-pack/plugins/security/server/saved_objects/secure_saved_objects_client_wrapper.test.ts b/x-pack/plugins/security/server/saved_objects/secure_saved_objects_client_wrapper.test.ts index 96505d2b5f963..52702c014f0cb 100644 --- a/x-pack/plugins/security/server/saved_objects/secure_saved_objects_client_wrapper.test.ts +++ b/x-pack/plugins/security/server/saved_objects/secure_saved_objects_client_wrapper.test.ts @@ -23,11 +23,12 @@ import { Actions } from '../authorization'; import type { SavedObjectActions } from '../authorization/actions/saved_object'; import { SecureSavedObjectsClientWrapper } from './secure_saved_objects_client_wrapper'; -jest.mock('@kbn/core/server/saved_objects/service/lib/utils', () => { - const { SavedObjectsUtils } = jest.requireActual( - '@kbn/core/server/saved_objects/service/lib/utils' +jest.mock('@kbn/core-saved-objects-utils-server', () => { + const { SavedObjectsUtils, ...actual } = jest.requireActual( + '@kbn/core-saved-objects-utils-server' ); return { + ...actual, SavedObjectsUtils: { ...SavedObjectsUtils, createEmptyFindResponse: SavedObjectsUtils.createEmptyFindResponse, diff --git a/x-pack/plugins/security_solution/server/__mocks__/core.mock.ts b/x-pack/plugins/security_solution/server/__mocks__/core.mock.ts index 57feaedbc9487..1ae9b046dc636 100644 --- a/x-pack/plugins/security_solution/server/__mocks__/core.mock.ts +++ b/x-pack/plugins/security_solution/server/__mocks__/core.mock.ts @@ -8,8 +8,8 @@ // See: https://github.com/elastic/kibana/issues/117255, this creates mocks to avoid memory leaks from kibana core. // We _must_ import from the restricted path or we pull in _everything_ including memory leaks from Kibana core -import { SavedObjectsUtils } from '@kbn/core/server/saved_objects/service/lib/utils'; -import { SavedObjectsErrorHelpers } from '@kbn/core/server/saved_objects/service/lib/errors'; +import { SavedObjectsUtils, SavedObjectsErrorHelpers } from '@kbn/core-saved-objects-utils-server'; + module.exports = { SavedObjectsUtils, SavedObjectsErrorHelpers, diff --git a/x-pack/plugins/task_manager/server/task_store.test.ts b/x-pack/plugins/task_manager/server/task_store.test.ts index e7696102db8ca..561d4ac6a0989 100644 --- a/x-pack/plugins/task_manager/server/task_store.test.ts +++ b/x-pack/plugins/task_manager/server/task_store.test.ts @@ -15,20 +15,15 @@ import { TaskLifecycleResult, SerializedConcreteTaskInstance, } from './task'; -import { elasticsearchServiceMock } from '@kbn/core/server/mocks'; +import { elasticsearchServiceMock, savedObjectsServiceMock } from '@kbn/core/server/mocks'; import { TaskStore, SearchOpts, AggregationOpts } from './task_store'; import { savedObjectsRepositoryMock } from '@kbn/core/server/mocks'; -import { - SavedObjectsSerializer, - SavedObjectTypeRegistry, - SavedObjectAttributes, - SavedObjectsErrorHelpers, -} from '@kbn/core/server'; +import { SavedObjectAttributes, SavedObjectsErrorHelpers } from '@kbn/core/server'; import { TaskTypeDictionary } from './task_type_dictionary'; import { mockLogger } from './test_utils'; const savedObjectsClient = savedObjectsRepositoryMock.create(); -const serializer = new SavedObjectsSerializer(new SavedObjectTypeRegistry()); +const serializer = savedObjectsServiceMock.createSerializer(); beforeEach(() => jest.resetAllMocks()); diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/group2/tests/alerting/rbac_legacy.ts b/x-pack/test/alerting_api_integration/security_and_spaces/group2/tests/alerting/rbac_legacy.ts index 4f0f53383e206..7528c6e77acd3 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/group2/tests/alerting/rbac_legacy.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/group2/tests/alerting/rbac_legacy.ts @@ -6,7 +6,7 @@ */ import expect from '@kbn/expect'; -import { SavedObjectsUtils } from '@kbn/core/server/saved_objects'; +import { SavedObjectsUtils } from '@kbn/core/server'; import { UserAtSpaceScenarios, Superuser } from '../../../scenarios'; import { FtrProviderContext } from '../../../../common/ftr_provider_context'; import { ESTestIndexTool, getUrlPrefix, ObjectRemover, AlertUtils } from '../../../../common/lib'; diff --git a/x-pack/test/plugin_api_integration/test_suites/task_manager/migrations.ts b/x-pack/test/plugin_api_integration/test_suites/task_manager/migrations.ts index 644ed91410299..04f34ab50a133 100644 --- a/x-pack/test/plugin_api_integration/test_suites/task_manager/migrations.ts +++ b/x-pack/test/plugin_api_integration/test_suites/task_manager/migrations.ts @@ -13,7 +13,7 @@ import { TaskInstanceWithDeprecatedFields, TaskStatus, } from '@kbn/task-manager-plugin/server/task'; -import { SavedObjectsUtils } from '@kbn/core/server/saved_objects'; +import { SavedObjectsUtils } from '@kbn/core/server'; import { FtrProviderContext } from '../../../common/ftr_provider_context'; export default function createGetTests({ getService }: FtrProviderContext) { diff --git a/x-pack/test/spaces_api_integration/common/suites/disable_legacy_url_aliases.ts b/x-pack/test/spaces_api_integration/common/suites/disable_legacy_url_aliases.ts index f9d1fe6b97236..f95267a02ab3f 100644 --- a/x-pack/test/spaces_api_integration/common/suites/disable_legacy_url_aliases.ts +++ b/x-pack/test/spaces_api_integration/common/suites/disable_legacy_url_aliases.ts @@ -8,7 +8,7 @@ import expect from '@kbn/expect'; import { SuperTest } from 'supertest'; import type { Client } from '@elastic/elasticsearch'; -import { LegacyUrlAlias } from '@kbn/core/server/saved_objects/object_types'; +import type { LegacyUrlAlias } from '@kbn/core-saved-objects-base-server-internal'; import { SPACES } from '../lib/spaces'; import { getUrlPrefix } from '../../../saved_object_api_integration/common/lib/saved_object_test_utils'; import { diff --git a/yarn.lock b/yarn.lock index 83f67be271aa2..d390141ba0e8b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3377,6 +3377,14 @@ version "0.0.0" uid "" +"@kbn/core-saved-objects-base-server-internal@link:bazel-bin/packages/core/saved-objects/core-saved-objects-base-server-internal": + version "0.0.0" + uid "" + +"@kbn/core-saved-objects-base-server-mocks@link:bazel-bin/packages/core/saved-objects/core-saved-objects-base-server-mocks": + version "0.0.0" + uid "" + "@kbn/core-saved-objects-browser-internal@link:bazel-bin/packages/core/saved-objects/core-saved-objects-browser-internal": version "0.0.0" uid "" @@ -3397,6 +3405,10 @@ version "0.0.0" uid "" +"@kbn/core-saved-objects-utils-server@link:bazel-bin/packages/core/saved-objects/core-saved-objects-utils-server": + version "0.0.0" + uid "" + "@kbn/core-test-helpers-deprecations-getters@link:bazel-bin/packages/core/test-helpers/core-test-helpers-deprecations-getters": version "0.0.0" uid "" @@ -7347,6 +7359,14 @@ version "0.0.0" uid "" +"@types/kbn__core-saved-objects-base-server-internal@link:bazel-bin/packages/core/saved-objects/core-saved-objects-base-server-internal/npm_module_types": + version "0.0.0" + uid "" + +"@types/kbn__core-saved-objects-base-server-mocks@link:bazel-bin/packages/core/saved-objects/core-saved-objects-base-server-mocks/npm_module_types": + version "0.0.0" + uid "" + "@types/kbn__core-saved-objects-browser-internal@link:bazel-bin/packages/core/saved-objects/core-saved-objects-browser-internal/npm_module_types": version "0.0.0" uid "" @@ -7367,6 +7387,10 @@ version "0.0.0" uid "" +"@types/kbn__core-saved-objects-utils-server@link:bazel-bin/packages/core/saved-objects/core-saved-objects-utils-server/npm_module_types": + version "0.0.0" + uid "" + "@types/kbn__core-server-internal-base@link:bazel-bin/packages/core/server/internal-base/npm_module_types": version "0.0.0" uid ""