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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 1 addition & 24 deletions src/plugins/content_management/common/rpc/bulk_get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends string = string, Options extends void | object = object> {
contentTypeId: T;
Expand Down
12 changes: 0 additions & 12 deletions src/plugins/content_management/common/rpc/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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';
}
},
});
26 changes: 1 addition & 25 deletions src/plugins/content_management/common/rpc/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
28 changes: 0 additions & 28 deletions src/plugins/content_management/common/rpc/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends string = string, Options extends void | object = object> {
contentTypeId: T;
Expand Down
27 changes: 1 addition & 26 deletions src/plugins/content_management/common/rpc/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends string = string, Options extends void | object = object> {
id: string;
Expand Down
1 change: 0 additions & 1 deletion src/plugins/content_management/common/rpc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* Side Public License, v 1.
*/

export { schemas } from './rpc';
export { procedureNames } from './constants';

export type { GetIn, GetResult } from './get';
Expand Down
30 changes: 1 addition & 29 deletions src/plugins/content_management/common/rpc/msearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
51 changes: 0 additions & 51 deletions src/plugins/content_management/common/rpc/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
27 changes: 1 addition & 26 deletions src/plugins/content_management/common/rpc/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
31 changes: 31 additions & 0 deletions src/plugins/content_management/server/rpc/schemas/bulk_get.ts
Original file line number Diff line number Diff line change
@@ -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' }
),
};
Loading