diff --git a/src/plugins/content_management/common/rpc/bulk_get.ts b/src/plugins/content_management/common/rpc/bulk_get.ts index c9d313b4473e..d9137567a51a 100644 --- a/src/plugins/content_management/common/rpc/bulk_get.ts +++ b/src/plugins/content_management/common/rpc/bulk_get.ts @@ -5,31 +5,8 @@ * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ -import { schema } from '@kbn/config-schema'; import type { Version } from '@kbn/object-versioning'; -import { versionSchema } from './constants'; -import { GetResult, getResultSchema } from './get'; - -import type { ProcedureSchemas } from './types'; - -export const bulkGetSchemas: ProcedureSchemas = { - in: schema.object( - { - contentTypeId: schema.string(), - version: versionSchema, - ids: schema.arrayOf(schema.string({ minLength: 1 }), { minSize: 1 }), - options: schema.maybe(schema.object({}, { unknowns: 'allow' })), - }, - { unknowns: 'forbid' } - ), - out: schema.object( - { - hits: schema.arrayOf(getResultSchema), - meta: schema.maybe(schema.object({}, { unknowns: 'allow' })), - }, - { unknowns: 'forbid' } - ), -}; +import { GetResult } from './get'; export interface BulkGetIn { contentTypeId: T; diff --git a/src/plugins/content_management/common/rpc/constants.ts b/src/plugins/content_management/common/rpc/constants.ts index 08bc8dcb4515..0361551f8732 100644 --- a/src/plugins/content_management/common/rpc/constants.ts +++ b/src/plugins/content_management/common/rpc/constants.ts @@ -5,9 +5,6 @@ * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ -import { schema } from '@kbn/config-schema'; -import { validateVersion } from '@kbn/object-versioning-utils'; - export const procedureNames = [ 'get', 'bulkGet', @@ -19,12 +16,3 @@ export const procedureNames = [ ] as const; export type ProcedureName = (typeof procedureNames)[number]; - -export const versionSchema = schema.number({ - validate: (value) => { - const { result } = validateVersion(value); - if (!result) { - return 'must be an integer'; - } - }, -}); diff --git a/src/plugins/content_management/common/rpc/create.ts b/src/plugins/content_management/common/rpc/create.ts index 42c4e299a05c..7336883a468c 100644 --- a/src/plugins/content_management/common/rpc/create.ts +++ b/src/plugins/content_management/common/rpc/create.ts @@ -5,32 +5,8 @@ * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ -import { schema } from '@kbn/config-schema'; import type { Version } from '@kbn/object-versioning'; -import { itemResultSchema } from './common'; -import { versionSchema } from './constants'; - -import type { ItemResult, ProcedureSchemas } from './types'; - -export const createSchemas: ProcedureSchemas = { - in: schema.object( - { - contentTypeId: schema.string(), - version: versionSchema, - // --> "data" to create a content will be defined by each content type - data: schema.recordOf(schema.string(), schema.any()), - options: schema.maybe(schema.object({}, { unknowns: 'allow' })), - }, - { unknowns: 'forbid' } - ), - out: schema.object( - { - contentTypeId: schema.string(), - result: itemResultSchema, - }, - { unknowns: 'forbid' } - ), -}; +import type { ItemResult } from './types'; export interface CreateIn< T extends string = string, diff --git a/src/plugins/content_management/common/rpc/delete.ts b/src/plugins/content_management/common/rpc/delete.ts index e9287e8964cc..e98f1366bf10 100644 --- a/src/plugins/content_management/common/rpc/delete.ts +++ b/src/plugins/content_management/common/rpc/delete.ts @@ -5,35 +5,7 @@ * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ -import { schema } from '@kbn/config-schema'; import type { Version } from '@kbn/object-versioning'; -import { versionSchema } from './constants'; - -import type { ProcedureSchemas } from './types'; - -export const deleteSchemas: ProcedureSchemas = { - in: schema.object( - { - contentTypeId: schema.string(), - id: schema.string({ minLength: 1 }), - version: versionSchema, - options: schema.maybe(schema.object({}, { unknowns: 'allow' })), - }, - { unknowns: 'forbid' } - ), - out: schema.object( - { - contentTypeId: schema.string(), - result: schema.object( - { - success: schema.boolean(), - }, - { unknowns: 'forbid' } - ), - }, - { unknowns: 'forbid' } - ), -}; export interface DeleteIn { contentTypeId: T; diff --git a/src/plugins/content_management/common/rpc/get.ts b/src/plugins/content_management/common/rpc/get.ts index e00838afde98..654bb0824f17 100644 --- a/src/plugins/content_management/common/rpc/get.ts +++ b/src/plugins/content_management/common/rpc/get.ts @@ -5,33 +5,8 @@ * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ -import { schema } from '@kbn/config-schema'; import type { Version } from '@kbn/object-versioning'; -import { itemResultSchema } from './common'; -import { versionSchema } from './constants'; - -import type { ItemResult, ProcedureSchemas } from './types'; - -export const getResultSchema = schema.object( - { - contentTypeId: schema.string(), - result: itemResultSchema, - }, - { unknowns: 'forbid' } -); - -export const getSchemas: ProcedureSchemas = { - in: schema.object( - { - contentTypeId: schema.string(), - id: schema.string({ minLength: 1 }), - version: versionSchema, - options: schema.maybe(schema.object({}, { unknowns: 'allow' })), - }, - { unknowns: 'forbid' } - ), - out: getResultSchema, -}; +import type { ItemResult } from './types'; export interface GetIn { id: string; diff --git a/src/plugins/content_management/common/rpc/index.ts b/src/plugins/content_management/common/rpc/index.ts index 3ab4e1919e74..6d13c62578b8 100644 --- a/src/plugins/content_management/common/rpc/index.ts +++ b/src/plugins/content_management/common/rpc/index.ts @@ -6,7 +6,6 @@ * Side Public License, v 1. */ -export { schemas } from './rpc'; export { procedureNames } from './constants'; export type { GetIn, GetResult } from './get'; diff --git a/src/plugins/content_management/common/rpc/msearch.ts b/src/plugins/content_management/common/rpc/msearch.ts index 9ba1fc81c65b..332596368070 100644 --- a/src/plugins/content_management/common/rpc/msearch.ts +++ b/src/plugins/content_management/common/rpc/msearch.ts @@ -5,36 +5,8 @@ * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ -import { schema } from '@kbn/config-schema'; import type { Version } from '@kbn/object-versioning'; -import { versionSchema } from './constants'; -import { searchQuerySchema, searchResultSchema, SearchQuery, SearchResult } from './search'; - -import type { ProcedureSchemas } from './types'; - -export const mSearchSchemas: ProcedureSchemas = { - in: schema.object( - { - contentTypes: schema.arrayOf( - schema.object({ contentTypeId: schema.string(), version: versionSchema }), - { - minSize: 1, - } - ), - query: searchQuerySchema, - }, - { unknowns: 'forbid' } - ), - out: schema.object( - { - contentTypes: schema.arrayOf( - schema.object({ contentTypeId: schema.string(), version: versionSchema }) - ), - result: searchResultSchema, - }, - { unknowns: 'forbid' } - ), -}; +import { SearchQuery, SearchResult } from './search'; export type MSearchQuery = SearchQuery; diff --git a/src/plugins/content_management/common/rpc/search.ts b/src/plugins/content_management/common/rpc/search.ts index 8958697df9c0..72d5d37796c0 100644 --- a/src/plugins/content_management/common/rpc/search.ts +++ b/src/plugins/content_management/common/rpc/search.ts @@ -5,58 +5,7 @@ * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ -import { schema } from '@kbn/config-schema'; import type { Version } from '@kbn/object-versioning'; -import { versionSchema } from './constants'; - -import type { ProcedureSchemas } from './types'; - -export const searchQuerySchema = schema.oneOf([ - schema.object( - { - text: schema.maybe(schema.string()), - tags: schema.maybe( - schema.object({ - included: schema.maybe(schema.arrayOf(schema.string())), - excluded: schema.maybe(schema.arrayOf(schema.string())), - }) - ), - limit: schema.maybe(schema.number()), - cursor: schema.maybe(schema.string()), - }, - { - unknowns: 'forbid', - } - ), -]); - -export const searchResultSchema = schema.object({ - hits: schema.arrayOf(schema.any()), - pagination: schema.object({ - total: schema.number(), - cursor: schema.maybe(schema.string()), - }), -}); - -export const searchSchemas: ProcedureSchemas = { - in: schema.object( - { - contentTypeId: schema.string(), - version: versionSchema, - query: searchQuerySchema, - options: schema.maybe(schema.object({}, { unknowns: 'allow' })), - }, - { unknowns: 'forbid' } - ), - out: schema.object( - { - contentTypeId: schema.string(), - result: searchResultSchema, - meta: schema.maybe(schema.object({}, { unknowns: 'allow' })), - }, - { unknowns: 'forbid' } - ), -}; export interface SearchQuery { /** The text to search for */ diff --git a/src/plugins/content_management/common/rpc/update.ts b/src/plugins/content_management/common/rpc/update.ts index 1b9afa15b636..cccb04c867aa 100644 --- a/src/plugins/content_management/common/rpc/update.ts +++ b/src/plugins/content_management/common/rpc/update.ts @@ -5,33 +5,8 @@ * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ -import { schema } from '@kbn/config-schema'; import type { Version } from '@kbn/object-versioning'; -import { itemResultSchema } from './common'; -import { versionSchema } from './constants'; - -import type { ItemResult, ProcedureSchemas } from './types'; - -export const updateSchemas: ProcedureSchemas = { - in: schema.object( - { - contentTypeId: schema.string(), - id: schema.string({ minLength: 1 }), - version: versionSchema, - // --> "data" to update a content will be defined by each content type - data: schema.recordOf(schema.string(), schema.any()), - options: schema.maybe(schema.object({}, { unknowns: 'allow' })), - }, - { unknowns: 'forbid' } - ), - out: schema.object( - { - contentTypeId: schema.string(), - result: itemResultSchema, - }, - { unknowns: 'forbid' } - ), -}; +import type { ItemResult } from './types'; export interface UpdateIn< T extends string = string, diff --git a/src/plugins/content_management/server/rpc/procedures/bulk_get.ts b/src/plugins/content_management/server/rpc/procedures/bulk_get.ts index 7ea19ebb4975..b9b20038dd71 100644 --- a/src/plugins/content_management/server/rpc/procedures/bulk_get.ts +++ b/src/plugins/content_management/server/rpc/procedures/bulk_get.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import { rpcSchemas } from '../../../common/schemas'; +import { rpcSchemas } from '../schemas'; import type { BulkGetIn } from '../../../common'; import type { ProcedureDefinition } from '../rpc_service'; import type { Context } from '../types'; diff --git a/src/plugins/content_management/server/rpc/procedures/create.ts b/src/plugins/content_management/server/rpc/procedures/create.ts index b8646e150597..ab7b0997e6c8 100644 --- a/src/plugins/content_management/server/rpc/procedures/create.ts +++ b/src/plugins/content_management/server/rpc/procedures/create.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import { rpcSchemas } from '../../../common/schemas'; +import { rpcSchemas } from '../schemas'; import type { CreateIn } from '../../../common'; import { getContentClientFactory } from '../../content_client'; import type { ProcedureDefinition } from '../rpc_service'; diff --git a/src/plugins/content_management/server/rpc/procedures/delete.ts b/src/plugins/content_management/server/rpc/procedures/delete.ts index 3e948730faba..3f42df5a6c4b 100644 --- a/src/plugins/content_management/server/rpc/procedures/delete.ts +++ b/src/plugins/content_management/server/rpc/procedures/delete.ts @@ -5,7 +5,7 @@ * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ -import { rpcSchemas } from '../../../common/schemas'; +import { rpcSchemas } from '../schemas'; import type { DeleteIn } from '../../../common'; import { getContentClientFactory } from '../../content_client'; import type { ProcedureDefinition } from '../rpc_service'; diff --git a/src/plugins/content_management/server/rpc/procedures/get.ts b/src/plugins/content_management/server/rpc/procedures/get.ts index a4e27847feed..57ff7fb034ff 100644 --- a/src/plugins/content_management/server/rpc/procedures/get.ts +++ b/src/plugins/content_management/server/rpc/procedures/get.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import { rpcSchemas } from '../../../common/schemas'; +import { rpcSchemas } from '../schemas'; import type { GetIn } from '../../../common'; import { getContentClientFactory } from '../../content_client'; import type { ProcedureDefinition } from '../rpc_service'; diff --git a/src/plugins/content_management/server/rpc/procedures/msearch.ts b/src/plugins/content_management/server/rpc/procedures/msearch.ts index dea79b1f5b0b..7c615bcfc277 100644 --- a/src/plugins/content_management/server/rpc/procedures/msearch.ts +++ b/src/plugins/content_management/server/rpc/procedures/msearch.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import { rpcSchemas } from '../../../common/schemas'; +import { rpcSchemas } from '../schemas'; import type { MSearchIn, MSearchOut } from '../../../common'; import type { ProcedureDefinition } from '../rpc_service'; import type { Context } from '../types'; diff --git a/src/plugins/content_management/server/rpc/procedures/search.ts b/src/plugins/content_management/server/rpc/procedures/search.ts index a726eb244f38..88443ec4afdc 100644 --- a/src/plugins/content_management/server/rpc/procedures/search.ts +++ b/src/plugins/content_management/server/rpc/procedures/search.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import { rpcSchemas } from '../../../common/schemas'; +import { rpcSchemas } from '../schemas'; import type { SearchIn } from '../../../common'; import { getContentClientFactory } from '../../content_client'; import type { ProcedureDefinition } from '../rpc_service'; diff --git a/src/plugins/content_management/server/rpc/procedures/update.ts b/src/plugins/content_management/server/rpc/procedures/update.ts index 99cd3d44c95e..a3a6eee45bf7 100644 --- a/src/plugins/content_management/server/rpc/procedures/update.ts +++ b/src/plugins/content_management/server/rpc/procedures/update.ts @@ -5,7 +5,7 @@ * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ -import { rpcSchemas } from '../../../common/schemas'; +import { rpcSchemas } from '../schemas'; import type { UpdateIn } from '../../../common'; import { getContentClientFactory } from '../../content_client'; import type { ProcedureDefinition } from '../rpc_service'; diff --git a/src/plugins/content_management/server/rpc/schemas/bulk_get.ts b/src/plugins/content_management/server/rpc/schemas/bulk_get.ts new file mode 100644 index 000000000000..28a36939f2cf --- /dev/null +++ b/src/plugins/content_management/server/rpc/schemas/bulk_get.ts @@ -0,0 +1,31 @@ +/* + * 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 { schema } from '@kbn/config-schema'; +import { getResultSchema } from './get'; +import { versionSchema } from './common'; + +import type { ProcedureSchemas } from '../../../common'; + +export const bulkGetSchemas: ProcedureSchemas = { + in: schema.object( + { + contentTypeId: schema.string(), + version: versionSchema, + ids: schema.arrayOf(schema.string({ minLength: 1 }), { minSize: 1 }), + options: schema.maybe(schema.object({}, { unknowns: 'allow' })), + }, + { unknowns: 'forbid' } + ), + out: schema.object( + { + hits: schema.arrayOf(getResultSchema), + meta: schema.maybe(schema.object({}, { unknowns: 'allow' })), + }, + { unknowns: 'forbid' } + ), +}; diff --git a/src/plugins/content_management/common/rpc/common.ts b/src/plugins/content_management/server/rpc/schemas/common.ts similarity index 70% rename from src/plugins/content_management/common/rpc/common.ts rename to src/plugins/content_management/server/rpc/schemas/common.ts index e1313aa6b16e..9aef89bd5301 100644 --- a/src/plugins/content_management/common/rpc/common.ts +++ b/src/plugins/content_management/server/rpc/schemas/common.ts @@ -6,6 +6,7 @@ * Side Public License, v 1. */ import { schema } from '@kbn/config-schema'; +import { validateVersion } from '@kbn/object-versioning-utils'; export const itemResultSchema = schema.object( { @@ -14,3 +15,12 @@ export const itemResultSchema = schema.object( }, { unknowns: 'forbid' } ); + +export const versionSchema = schema.number({ + validate: (value) => { + const { result } = validateVersion(value); + if (!result) { + return 'must be an integer'; + } + }, +}); diff --git a/src/plugins/content_management/server/rpc/schemas/create.ts b/src/plugins/content_management/server/rpc/schemas/create.ts new file mode 100644 index 000000000000..347898c54489 --- /dev/null +++ b/src/plugins/content_management/server/rpc/schemas/create.ts @@ -0,0 +1,31 @@ +/* + * 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 { schema } from '@kbn/config-schema'; +import { itemResultSchema, versionSchema } from './common'; + +import type { ProcedureSchemas } from '../../../common'; + +export const createSchemas: ProcedureSchemas = { + in: schema.object( + { + contentTypeId: schema.string(), + version: versionSchema, + // --> "data" to create a content will be defined by each content type + data: schema.recordOf(schema.string(), schema.any()), + options: schema.maybe(schema.object({}, { unknowns: 'allow' })), + }, + { unknowns: 'forbid' } + ), + out: schema.object( + { + contentTypeId: schema.string(), + result: itemResultSchema, + }, + { unknowns: 'forbid' } + ), +}; diff --git a/src/plugins/content_management/server/rpc/schemas/delete.ts b/src/plugins/content_management/server/rpc/schemas/delete.ts new file mode 100644 index 000000000000..1c64be60c8dc --- /dev/null +++ b/src/plugins/content_management/server/rpc/schemas/delete.ts @@ -0,0 +1,35 @@ +/* + * 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 { schema } from '@kbn/config-schema'; +import { versionSchema } from './common'; + +import type { ProcedureSchemas } from '../../../common'; + +export const deleteSchemas: ProcedureSchemas = { + in: schema.object( + { + contentTypeId: schema.string(), + id: schema.string({ minLength: 1 }), + version: versionSchema, + options: schema.maybe(schema.object({}, { unknowns: 'allow' })), + }, + { unknowns: 'forbid' } + ), + out: schema.object( + { + contentTypeId: schema.string(), + result: schema.object( + { + success: schema.boolean(), + }, + { unknowns: 'forbid' } + ), + }, + { unknowns: 'forbid' } + ), +}; diff --git a/src/plugins/content_management/server/rpc/schemas/get.ts b/src/plugins/content_management/server/rpc/schemas/get.ts new file mode 100644 index 000000000000..177e95364554 --- /dev/null +++ b/src/plugins/content_management/server/rpc/schemas/get.ts @@ -0,0 +1,32 @@ +/* + * 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 { schema } from '@kbn/config-schema'; +import { itemResultSchema, versionSchema } from './common'; + +import type { ProcedureSchemas } from '../../../common'; + +export const getResultSchema = schema.object( + { + contentTypeId: schema.string(), + result: itemResultSchema, + }, + { unknowns: 'forbid' } +); + +export const getSchemas: ProcedureSchemas = { + in: schema.object( + { + contentTypeId: schema.string(), + id: schema.string({ minLength: 1 }), + version: versionSchema, + options: schema.maybe(schema.object({}, { unknowns: 'allow' })), + }, + { unknowns: 'forbid' } + ), + out: getResultSchema, +}; diff --git a/src/plugins/content_management/common/schemas.ts b/src/plugins/content_management/server/rpc/schemas/index.ts similarity index 72% rename from src/plugins/content_management/common/schemas.ts rename to src/plugins/content_management/server/rpc/schemas/index.ts index 172e0f4b2866..99d9add54c39 100644 --- a/src/plugins/content_management/common/schemas.ts +++ b/src/plugins/content_management/server/rpc/schemas/index.ts @@ -6,6 +6,4 @@ * Side Public License, v 1. */ -// exporting schemas separately from the index.ts file to not include @kbn/schema in the public bundle -// should be only used server-side or in jest tests export { schemas as rpcSchemas } from './rpc'; diff --git a/src/plugins/content_management/server/rpc/schemas/msearch.ts b/src/plugins/content_management/server/rpc/schemas/msearch.ts new file mode 100644 index 000000000000..0022ad578fab --- /dev/null +++ b/src/plugins/content_management/server/rpc/schemas/msearch.ts @@ -0,0 +1,36 @@ +/* + * 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 { schema } from '@kbn/config-schema'; +import { versionSchema } from './common'; +import { searchQuerySchema, searchResultSchema } from './search'; + +import type { ProcedureSchemas } from '../../../common'; + +export const mSearchSchemas: ProcedureSchemas = { + in: schema.object( + { + contentTypes: schema.arrayOf( + schema.object({ contentTypeId: schema.string(), version: versionSchema }), + { + minSize: 1, + } + ), + query: searchQuerySchema, + }, + { unknowns: 'forbid' } + ), + out: schema.object( + { + contentTypes: schema.arrayOf( + schema.object({ contentTypeId: schema.string(), version: versionSchema }) + ), + result: searchResultSchema, + }, + { unknowns: 'forbid' } + ), +}; diff --git a/src/plugins/content_management/common/rpc/rpc.ts b/src/plugins/content_management/server/rpc/schemas/rpc.ts similarity index 90% rename from src/plugins/content_management/common/rpc/rpc.ts rename to src/plugins/content_management/server/rpc/schemas/rpc.ts index 0d9d472785a3..b0f06f24ad3c 100644 --- a/src/plugins/content_management/common/rpc/rpc.ts +++ b/src/plugins/content_management/server/rpc/schemas/rpc.ts @@ -6,8 +6,7 @@ * Side Public License, v 1. */ -import type { ProcedureName } from './constants'; -import type { ProcedureSchemas } from './types'; +import type { ProcedureName, ProcedureSchemas } from '../../../common'; import { getSchemas } from './get'; import { bulkGetSchemas } from './bulk_get'; import { createSchemas } from './create'; diff --git a/src/plugins/content_management/server/rpc/schemas/search.ts b/src/plugins/content_management/server/rpc/schemas/search.ts new file mode 100644 index 000000000000..97e2e9bd0307 --- /dev/null +++ b/src/plugins/content_management/server/rpc/schemas/search.ts @@ -0,0 +1,58 @@ +/* + * 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 { schema } from '@kbn/config-schema'; +import { versionSchema } from './common'; + +import type { ProcedureSchemas } from '../../../common'; + +export const searchQuerySchema = schema.oneOf([ + schema.object( + { + text: schema.maybe(schema.string()), + tags: schema.maybe( + schema.object({ + included: schema.maybe(schema.arrayOf(schema.string())), + excluded: schema.maybe(schema.arrayOf(schema.string())), + }) + ), + limit: schema.maybe(schema.number()), + cursor: schema.maybe(schema.string()), + }, + { + unknowns: 'forbid', + } + ), +]); + +export const searchResultSchema = schema.object({ + hits: schema.arrayOf(schema.any()), + pagination: schema.object({ + total: schema.number(), + cursor: schema.maybe(schema.string()), + }), +}); + +export const searchSchemas: ProcedureSchemas = { + in: schema.object( + { + contentTypeId: schema.string(), + version: versionSchema, + query: searchQuerySchema, + options: schema.maybe(schema.object({}, { unknowns: 'allow' })), + }, + { unknowns: 'forbid' } + ), + out: schema.object( + { + contentTypeId: schema.string(), + result: searchResultSchema, + meta: schema.maybe(schema.object({}, { unknowns: 'allow' })), + }, + { unknowns: 'forbid' } + ), +}; diff --git a/src/plugins/content_management/server/rpc/schemas/update.ts b/src/plugins/content_management/server/rpc/schemas/update.ts new file mode 100644 index 000000000000..6b27700ecd55 --- /dev/null +++ b/src/plugins/content_management/server/rpc/schemas/update.ts @@ -0,0 +1,32 @@ +/* + * 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 { schema } from '@kbn/config-schema'; +import { itemResultSchema, versionSchema } from './common'; + +import type { ProcedureSchemas } from '../../../common'; + +export const updateSchemas: ProcedureSchemas = { + in: schema.object( + { + contentTypeId: schema.string(), + id: schema.string({ minLength: 1 }), + version: versionSchema, + // --> "data" to update a content will be defined by each content type + data: schema.recordOf(schema.string(), schema.any()), + options: schema.maybe(schema.object({}, { unknowns: 'allow' })), + }, + { unknowns: 'forbid' } + ), + out: schema.object( + { + contentTypeId: schema.string(), + result: itemResultSchema, + }, + { unknowns: 'forbid' } + ), +};