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