Skip to content

Commit

Permalink
chore: Export empty node & edge schemas for convenience
Browse files Browse the repository at this point in the history
  • Loading branch information
janjakubnanista committed Nov 24, 2023
1 parent 1796690 commit 0c9f974
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions packages/ua-utils/src/omnigraph/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ export const OmniVectorSchema: z.ZodSchema<OmniVector, z.ZodTypeDef, unknown> =
to: OmniPointSchema,
})

export const EmptyOmniNodeSchema = z.object({
point: OmniPointSchema,
config: z.unknown(),
})

export const EmptyOmniEdgeSchema = z.object({
vector: OmniVectorSchema,
config: z.unknown(),
})

/**
* Factory for OmniNode schemas
*
Expand All @@ -28,8 +38,7 @@ export const OmniVectorSchema: z.ZodSchema<OmniVector, z.ZodTypeDef, unknown> =
export const createOmniNodeSchema = <TConfig = unknown>(
configSchema: z.ZodSchema<TConfig, z.ZodTypeDef, unknown>
): z.ZodSchema<OmniNode<TConfig>, z.ZodTypeDef, unknown> =>
z.object({
point: OmniPointSchema,
EmptyOmniNodeSchema.extend({
config: configSchema,
}) as z.ZodSchema<OmniNode<TConfig>, z.ZodTypeDef, unknown>

Expand All @@ -43,7 +52,6 @@ export const createOmniNodeSchema = <TConfig = unknown>(
export const createOmniEdgeSchema = <TConfig = unknown>(
configSchema: z.ZodSchema<TConfig, z.ZodTypeDef, unknown>
): z.ZodSchema<OmniEdge<TConfig>, z.ZodTypeDef, unknown> =>
z.object({
vector: OmniVectorSchema,
EmptyOmniEdgeSchema.extend({
config: configSchema,
}) as z.ZodSchema<OmniEdge<TConfig>, z.ZodTypeDef, unknown>

0 comments on commit 0c9f974

Please sign in to comment.