import type { AttributeNamesByType, Attribute } from '../..'; import type { ContentType } from '../../../data'; import type { Guard, String, Extends, If, Intersect } from '../../../utils'; import type * as UID from '../../../uid'; /** * Represents a relation Strapi attribute along with its options */ export type Relation = RelationWithTarget, TTargetUID> | RelationWithoutTarget>; export type RelationWithTarget = { oneToOne: OneToOne; oneToMany: OneToMany; manyToOne: ManyToOne; manyToMany: ManyToMany; oneWay: OneWay; manyWay: ManyWay; morphOne: MorphOne; morphMany: MorphMany; }[TRelationKind]; export type RelationWithoutTarget = { morphToOne: MorphToOne; morphToMany: MorphToMany; }[TRelationKind]; export type Bidirectional = Relation; export type XWay = Relation; export type MorphReference = Relation; export type MorphOwner = Relation; export type RelationOptions = Intersect<[ Attribute.ConfigurableOption, Attribute.PrivateOption, Attribute.WritableOption, Attribute.VisibleOption, Attribute.RequiredOption, { useJoinTable?: boolean; } ]>; export type CommonBidirectionalProperties = { target: TTargetUID; inversedBy?: string; mappedBy?: string; }; export type OneToOne = Intersect<[ Attribute.OfType<'relation'>, CommonBidirectionalProperties, RelationOptions, { relation: 'oneToOne'; } ]>; export type OneToMany = Intersect<[ Attribute.OfType<'relation'>, CommonBidirectionalProperties, RelationOptions, { relation: 'oneToMany'; } ]>; export type ManyToOne = Intersect<[ Attribute.OfType<'relation'>, CommonBidirectionalProperties, RelationOptions, { relation: 'manyToOne'; } ]>; export type ManyToMany = Intersect<[ Attribute.OfType<'relation'>, CommonBidirectionalProperties, RelationOptions, { relation: 'manyToMany'; } ]>; export type XWayCommonProperties = { target: TTargetUID; }; export type OneWay = Intersect<[ Attribute.OfType<'relation'>, XWayCommonProperties, RelationOptions, { relation: 'oneWay'; } ]>; export type ManyWay = Intersect<[ Attribute.OfType<'relation'>, XWayCommonProperties, RelationOptions, { relation: 'manyWay'; } ]>; export type MorphReferenceCommonProperties = { target: TTargetUID; morphBy?: Guard.Never, string>; }; export type MorphOne = Intersect<[ Attribute.OfType<'relation'>, MorphReferenceCommonProperties, RelationOptions, { relation: 'morphOne'; } ]>; export type MorphMany = Intersect<[ Attribute.OfType<'relation'>, MorphReferenceCommonProperties, RelationOptions, { relation: 'morphMany'; } ]>; export type MorphToOne = Intersect<[ Attribute.OfType<'relation'>, RelationOptions, { relation: 'morphToOne'; } ]>; export type MorphToMany = Intersect<[ Attribute.OfType<'relation'>, RelationOptions, { relation: 'morphToMany'; } ]>; export type RelationPluralityModifier = If, TValue[], TValue>; export type IsManyRelation = String.EndsWith; export type RelationTarget = TAttribute extends Relation ? TTarget : never; export type RelationValue = { oneToOne: ContentType; oneToMany: ContentType[]; manyToOne: ContentType; manyToMany: ContentType[]; oneWay: ContentType; manyWay: ContentType[]; morphOne: ContentType; morphMany: ContentType[]; morphToOne: ContentType; morphToMany: ContentType[]; }[TRelationKind]; export type GetRelationValue = TAttribute extends Relation ? RelationValue : TAttribute extends Relation ? RelationValue : never; export declare namespace RelationKind { type GetOppositePlurality = { one: 'many'; One: 'Many'; many: 'one'; Many: 'One'; }[TPlurality]; export type Plurality = 'one' | 'many'; export type Left = Lowercase; export type Right = Capitalize; export type MorphOwner = `morphTo${RelationKind.Right}`; export type MorphReference = `morph${RelationKind.Right}`; export type Morph = RelationKind.MorphOwner | RelationKind.MorphReference; export type XWay = `${RelationKind.Left}Way`; export type BiDirectional = `${RelationKind.Left}To${RelationKind.Right}`; export type UniDirectional = RelationKind.MorphReference | RelationKind.XWay; export type Any = RelationKind.BiDirectional | RelationKind.Morph | RelationKind.XWay; export type WithTarget = RelationKind.BiDirectional | RelationKind.XWay | RelationKind.MorphReference; export type WithoutTarget = RelationKind.MorphOwner; export type Reverse = TRelationKind extends `${infer TLeft extends RelationKind.Left}To${infer TRight extends RelationKind.Right}` ? If, Uppercase>, TRelationKind, `${GetOppositePlurality}To${GetOppositePlurality}`> : TRelationKind; export {}; } //# sourceMappingURL=relation.d.ts.map