mirror of
https://github.com/strapi/strapi.git
synced 2025-11-01 18:33:55 +00:00
Fix Attribute.Any definition
This commit is contained in:
parent
e63e3bee81
commit
d2be844147
@ -2,7 +2,7 @@
|
||||
* Strapi custom scalar types
|
||||
*/
|
||||
|
||||
import type { Attribute } from '@strapi/strapi';
|
||||
import type { Attribute, Common } from '@strapi/strapi';
|
||||
|
||||
/**
|
||||
* Setters for the attributes options
|
||||
@ -46,16 +46,17 @@ export type DefaultTo<T> = { default: T };
|
||||
export type Any =
|
||||
| Attribute.BigInteger
|
||||
| Attribute.Boolean
|
||||
| Attribute.Component
|
||||
| Attribute.Component<Common.UID.Component, boolean>
|
||||
| Attribute.DateTime
|
||||
| Attribute.Date
|
||||
| Attribute.Decimal
|
||||
| Attribute.DynamicZone
|
||||
| Attribute.Email
|
||||
| Attribute.Enumeration
|
||||
| Attribute.Enumeration<string[]>
|
||||
| Attribute.Float
|
||||
| Attribute.Integer
|
||||
| Attribute.JSON
|
||||
| Attribute.Media
|
||||
| (Attribute.Media<undefined, boolean> | Attribute.Media<Attribute.AllowedMediaTypes, boolean>)
|
||||
| Attribute.Password
|
||||
| Attribute.Relation
|
||||
| Attribute.RichText
|
||||
@ -63,4 +64,4 @@ export type Any =
|
||||
| Attribute.Text
|
||||
| Attribute.Time
|
||||
| Attribute.Timestamp
|
||||
| Attribute.UID;
|
||||
| (Attribute.UID<undefined> | Attribute.UID<Common.UID.Schema>);
|
||||
|
||||
@ -4,7 +4,7 @@ export type AllowedMediaTypes = 'images' | 'videos' | 'files' | 'audios';
|
||||
|
||||
export interface MediaProperties<
|
||||
// Media Type
|
||||
T extends AllowedMediaTypes = undefined,
|
||||
T extends AllowedMediaTypes | undefined = undefined,
|
||||
// Multiple
|
||||
U extends boolean = false
|
||||
> {
|
||||
@ -14,7 +14,7 @@ export interface MediaProperties<
|
||||
|
||||
export type Media<
|
||||
// Media Type
|
||||
T extends AllowedMediaTypes = undefined,
|
||||
T extends AllowedMediaTypes | undefined = undefined,
|
||||
// Multiple
|
||||
U extends boolean = false
|
||||
> = Attribute.Attribute<'media'> &
|
||||
|
||||
@ -1,27 +1,41 @@
|
||||
import type { Attribute, Common } from '@strapi/strapi';
|
||||
import type { Attribute, Common, Utils } from '@strapi/strapi';
|
||||
|
||||
export type BasicRelationsType = 'oneToOne' | 'oneToMany' | 'manyToOne' | 'manyToMany';
|
||||
export type PolymorphicRelationsType = 'morphToOne' | 'morphToMany' | 'morphOne' | 'morphMany';
|
||||
export type BasicRelationsType =
|
||||
| 'oneToOne'
|
||||
| 'oneToMany'
|
||||
| 'manyToOne'
|
||||
| 'manyToMany'
|
||||
| 'morphOne'
|
||||
| 'morphMany';
|
||||
export type PolymorphicRelationsType = 'morphToOne' | 'morphToMany';
|
||||
export type RelationsType = BasicRelationsType | PolymorphicRelationsType;
|
||||
|
||||
export interface BasicRelationProperties<
|
||||
export type BasicRelationProperties<
|
||||
S extends Common.UID.Schema,
|
||||
R extends RelationsType,
|
||||
R extends BasicRelationsType,
|
||||
T extends Common.UID.Schema
|
||||
> {
|
||||
> = {
|
||||
relation: R;
|
||||
target: T;
|
||||
inversedBy?: RelationsKeysFromTo<T, S>;
|
||||
mappedBy?: RelationsKeysFromTo<T, S>;
|
||||
}
|
||||
} & R extends `morph${string}`
|
||||
? {
|
||||
morphBy?: Utils.KeysBy<
|
||||
Common.Schemas[T]['attributes'],
|
||||
Attribute.Relation<Common.UID.Schema, Attribute.PolymorphicRelationsType>
|
||||
>;
|
||||
}
|
||||
: {
|
||||
inversedBy?: RelationsKeysFromTo<T, S>;
|
||||
mappedBy?: RelationsKeysFromTo<T, S>;
|
||||
};
|
||||
|
||||
export interface PolymorphicRelationProperties<R extends RelationsType> {
|
||||
export interface PolymorphicRelationProperties<R extends PolymorphicRelationsType> {
|
||||
relation: R;
|
||||
}
|
||||
|
||||
export type Relation<
|
||||
S extends Common.UID.Schema,
|
||||
R extends RelationsType,
|
||||
S extends Common.UID.Schema = Common.UID.Schema,
|
||||
R extends RelationsType = RelationsType,
|
||||
T extends R extends PolymorphicRelationsType ? never : Common.UID.Schema = never
|
||||
> = Attribute.Attribute<'relation'> &
|
||||
// Properties
|
||||
|
||||
@ -10,25 +10,21 @@ export interface UIDOptions {
|
||||
|
||||
export interface UIDProperties<
|
||||
// Own Schema Reference
|
||||
T extends Common.UID.Schema | undefined = undefined,
|
||||
T extends Common.UID.Schema | undefined,
|
||||
// Target attribute
|
||||
U extends T extends Common.UID.Schema
|
||||
? Attribute.GetKeysByType<T, 'string' | 'text'>
|
||||
: undefined = undefined,
|
||||
U extends T extends Common.UID.Schema ? Attribute.GetKeysByType<T, 'string' | 'text'> : undefined,
|
||||
// UID options
|
||||
S extends UIDOptions = UIDOptions
|
||||
> {
|
||||
targetField?: U;
|
||||
options?: UIDOptions & S;
|
||||
targetField: U;
|
||||
options: UIDOptions & S;
|
||||
}
|
||||
|
||||
export type UID<
|
||||
// Own Schema Reference
|
||||
T extends Common.UID.Schema | undefined = undefined,
|
||||
// Target attribute
|
||||
U extends T extends Common.UID.Schema
|
||||
? Attribute.GetKeysByType<T, 'string' | 'text'>
|
||||
: undefined = undefined,
|
||||
U extends TargetAttributeByUID<T> = TargetAttributeByUID<T>,
|
||||
// UID options
|
||||
S extends UIDOptions = UIDOptions
|
||||
> = Attribute.Attribute<'uid'> &
|
||||
@ -41,6 +37,10 @@ export type UID<
|
||||
Attribute.PrivateOption &
|
||||
Attribute.RequiredOption;
|
||||
|
||||
type TargetAttributeByUID<T extends Common.UID.Schema | undefined> = T extends Common.UID.Schema
|
||||
? Attribute.GetKeysByType<T, 'string' | 'text'>
|
||||
: undefined;
|
||||
|
||||
export type UIDValue = string;
|
||||
|
||||
export type GetUIDValue<T extends Attribute.Attribute> = T extends UID<infer _U, infer _P>
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { Attribute, Common, Utils } from '@strapi/strapi';
|
||||
import type { Attribute, Common, Utils } from '@strapi/strapi';
|
||||
|
||||
export type PickTypes<T extends Attribute.Type> = T;
|
||||
|
||||
|
||||
@ -78,7 +78,7 @@ export interface Info {
|
||||
/**
|
||||
* Low level data structure referencing every schema attribute and its name
|
||||
*/
|
||||
export interface Attributes extends Utils.StringRecord<Attribute.Attribute> {}
|
||||
export interface Attributes extends Utils.StringRecord<Attribute.Any> {}
|
||||
|
||||
/**
|
||||
* Structure containing every core schema options and their associated value
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user