Skip to content

Commit

Permalink
more complete schema
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkime committed Apr 24, 2023
1 parent bd1ca70 commit 744c083
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions packages/kbn-content-management-utils/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,49 @@ export const objectTypeToGetResultSchema = (soSchema: ObjectType<any>) =>
);

export const createOptionsSchema = schema.object({
id: schema.maybe(schema.string()),
references: schema.maybe(referencesSchema),
overwrite: schema.maybe(schema.boolean()),
version: schema.maybe(schema.string()),
refresh: schema.maybe(schema.boolean()),
initialNamespaces: schema.maybe(schema.arrayOf(schema.string())),
});

export const schemaAndOr = schema.oneOf([schema.literal('AND'), schema.literal('OR')]);

export const searchOptionsSchema = schema.object({
page: schema.maybe(schema.number()),
perPage: schema.maybe(schema.number()),
sortField: schema.maybe(schema.string()),
sortOrder: schema.maybe(schema.oneOf([schema.literal('asc'), schema.literal('desc')])),
fields: schema.maybe(schema.arrayOf(schema.string())),
search: schema.maybe(schema.string()),
searchFields: schema.maybe(schema.oneOf([schema.string(), schema.arrayOf(schema.string())])),
rootSearchFields: schema.maybe(schema.arrayOf(schema.string())),

hasReference: schema.maybe(schema.oneOf([referenceSchema, schema.arrayOf(referenceSchema)])),
hasReferenceOperator: schema.maybe(schemaAndOr),
hasNoReference: schema.maybe(schema.oneOf([referenceSchema, schema.arrayOf(referenceSchema)])),
hasNoReferenceOperator: schema.maybe(schemaAndOr),
defaultSearchOperator: schema.maybe(schemaAndOr),
namespaces: schema.maybe(schema.arrayOf(schema.string())),
type: schema.maybe(schema.string()),

filter: schema.maybe(schema.string()),
pit: schema.maybe(
schema.object({ id: schema.string(), keepAlive: schema.maybe(schema.string()) })
),
});

export const updateOptionsSchema = (attributesSchema: ObjectType<any>) =>
schema.object({
references: schema.maybe(referencesSchema),
version: schema.maybe(schema.string()),
refresh: schema.maybe(schema.oneOf([schema.boolean(), schema.literal('wait_for')])),
upsert: schema.maybe(savedObjectSchema(attributesSchema)),
retryOnConflict: schema.maybe(schema.number()),
});

export const createResultSchema = (soSchema: ObjectType<any>) =>
schema.object(
{
Expand Down

0 comments on commit 744c083

Please sign in to comment.