Skip to content

Commit

Permalink
feat: add catalog schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
juliannemarik committed Sep 24, 2024
1 parent 78c4669 commit 657d9ae
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 12 deletions.
70 changes: 70 additions & 0 deletions packages/common/src/core/schemas/shared/CatalogSchema.ts
Original file line number Diff line number Diff line change
@@ -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<EntityType, any>, targetEntity: EntityType) => {
acc[targetEntity] = QuerySchema;
return acc;
},
{} as Record<EntityType, any>
),
},
collections: {
type: "array",
items: CollectionSchema,
},
},
};
1 change: 1 addition & 0 deletions packages/common/src/core/schemas/shared/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./subschemas";
export * from "./CatalogSchema";
25 changes: 13 additions & 12 deletions packages/common/src/search/types/IHubCatalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 657d9ae

Please sign in to comment.