From 657d9ae43a2ddae321bc1e268d52823098a7228c Mon Sep 17 00:00:00 2001 From: juliannemarik Date: Tue, 24 Sep 2024 11:12:59 -0500 Subject: [PATCH] feat: add catalog schemas --- .../src/core/schemas/shared/CatalogSchema.ts | 70 +++++++++++++++++++ .../common/src/core/schemas/shared/index.ts | 1 + .../common/src/search/types/IHubCatalog.ts | 25 +++---- 3 files changed, 84 insertions(+), 12 deletions(-) create mode 100644 packages/common/src/core/schemas/shared/CatalogSchema.ts diff --git a/packages/common/src/core/schemas/shared/CatalogSchema.ts b/packages/common/src/core/schemas/shared/CatalogSchema.ts new file mode 100644 index 00000000000..2a7f3c7f41a --- /dev/null +++ b/packages/common/src/core/schemas/shared/CatalogSchema.ts @@ -0,0 +1,70 @@ +import { EntityType, targetEntities } from "../../../search/types/IHubCatalog"; +import { IConfigurationSchema } from "../types"; + +export const PredicateSchema: IConfigurationSchema = { + type: "object", +}; + +export const FilterSchema: IConfigurationSchema = { + type: "object", + required: ["predicates"], + properties: { + operation: { + type: "string", + enum: ["AND", "OR"], + }, + predicates: { + type: "array", + items: PredicateSchema, + }, + }, +}; + +export const QuerySchema: IConfigurationSchema = { + type: "object", + required: ["targetEntity"], + properties: { + targetEntity: { + type: "string", + enum: [...targetEntities], + }, + filters: { + type: "array", + items: FilterSchema, + }, + }, +}; + +export const CollectionSchema: IConfigurationSchema = { + type: "object", + required: ["label"], + properties: { + label: { + type: "string", + }, + scope: QuerySchema, + }, +}; + +export const CatalogSchema: IConfigurationSchema = { + type: "object", + properties: { + title: { + type: "string", + }, + scopes: { + type: "object", + properties: targetEntities.reduce( + (acc: Record, targetEntity: EntityType) => { + acc[targetEntity] = QuerySchema; + return acc; + }, + {} as Record + ), + }, + collections: { + type: "array", + items: CollectionSchema, + }, + }, +}; diff --git a/packages/common/src/core/schemas/shared/index.ts b/packages/common/src/core/schemas/shared/index.ts index 17363774418..7bae8323edb 100644 --- a/packages/common/src/core/schemas/shared/index.ts +++ b/packages/common/src/core/schemas/shared/index.ts @@ -1 +1,2 @@ export * from "./subschemas"; +export * from "./CatalogSchema"; diff --git a/packages/common/src/search/types/IHubCatalog.ts b/packages/common/src/search/types/IHubCatalog.ts index 108ad4eb58e..5b625508fb7 100644 --- a/packages/common/src/search/types/IHubCatalog.ts +++ b/packages/common/src/search/types/IHubCatalog.ts @@ -67,18 +67,19 @@ export interface IHubCollection { targetEntity: EntityType; } -export type EntityType = - | "item" - | "group" - | "user" - | "portalUser" - | "communityUser" - | "groupMember" - | "event" - | "channel" - | "discussionPost" - | "event" - | "eventAttendee"; +export const targetEntities = [ + "item", + "group", + "user", + "portalUser", + "communityUser", + "groupMember", + "event", + "channel", + "discussionPost", + "eventAttendee", +] as const; +export type EntityType = (typeof targetEntities)[number]; /** * @private