mirror of
https://github.com/strapi/strapi.git
synced 2025-08-08 08:46:42 +00:00
Add missing Strapi scalar types to attributes definitions
This commit is contained in:
parent
c2aba34289
commit
4329381635
9
packages/core/strapi/lib/types/core/attributes/date-time.d.ts
vendored
Normal file
9
packages/core/strapi/lib/types/core/attributes/date-time.d.ts
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
import { Attribute } from './base';
|
||||
|
||||
export interface DateTimeAttribute extends Attribute<'datetime'> {}
|
||||
|
||||
export type DateTimeValue = string;
|
||||
|
||||
export type GetDateTimeAttributeValue<T extends Attribute> = T extends DateTimeAttribute
|
||||
? DateTimeValue
|
||||
: never;
|
9
packages/core/strapi/lib/types/core/attributes/date.d.ts
vendored
Normal file
9
packages/core/strapi/lib/types/core/attributes/date.d.ts
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
import { Attribute } from './base';
|
||||
|
||||
export interface DateAttribute extends Attribute<'date'> {}
|
||||
|
||||
export type DateValue = Date;
|
||||
|
||||
export type GetDateAttributeValue<T extends Attribute> = T extends DateAttribute
|
||||
? DateValue
|
||||
: never;
|
10
packages/core/strapi/lib/types/core/attributes/email.d.ts
vendored
Normal file
10
packages/core/strapi/lib/types/core/attributes/email.d.ts
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
import { Attribute } from './base';
|
||||
import { BaseStringAttribute } from './common';
|
||||
|
||||
export interface EmailAttribute extends BaseStringAttribute<'email'> {}
|
||||
|
||||
export type EmailValue = string;
|
||||
|
||||
export type GetEmailAttributeValue<T extends Attribute> = T extends EmailAttribute
|
||||
? EmailValue
|
||||
: never;
|
@ -16,6 +16,11 @@ export * from './richtext';
|
||||
export * from './string';
|
||||
export * from './text';
|
||||
export * from './uid';
|
||||
export * from './email';
|
||||
export * from './date';
|
||||
export * from './date-time';
|
||||
export * from './timestamp';
|
||||
export * from './time';
|
||||
|
||||
export * from './common';
|
||||
export * from './utils';
|
||||
|
7
packages/core/strapi/lib/types/core/attributes/time.d.ts
vendored
Normal file
7
packages/core/strapi/lib/types/core/attributes/time.d.ts
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
import { Attribute } from './base';
|
||||
|
||||
export interface TimeAttribute extends Attribute<'time'> {}
|
||||
|
||||
export type TimeValue = string;
|
||||
|
||||
export type GetTimeAttributeValue<T extends Attibute> = T extends TimeAttribute ? TimeValue : never;
|
9
packages/core/strapi/lib/types/core/attributes/timestamp.d.ts
vendored
Normal file
9
packages/core/strapi/lib/types/core/attributes/timestamp.d.ts
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
import { Attribute } from './base';
|
||||
|
||||
export interface TimestampAttribute extends Attribute<'timestamp'> {}
|
||||
|
||||
export type TimestampValue = string;
|
||||
|
||||
export type GetTimestampAttributeValue<T extends Attribute> = T extends TimestampAttribute
|
||||
? TimestampValue
|
||||
: never;
|
@ -19,20 +19,28 @@ import {
|
||||
GetTextAttributeValue,
|
||||
GetUIDAttributeValue,
|
||||
} from '.';
|
||||
import { GetDateAttributeValue } from './date';
|
||||
import { GetDateTimeAttributeValue } from './date-time';
|
||||
import { GetTimeAttributeValue } from './time';
|
||||
import { GetTimestampAttributeValue } from './timestamp';
|
||||
|
||||
export type PickTypes<T extends AttributeType> = T;
|
||||
|
||||
export type GetAttributesKeysByType<T extends SchemaUID, U extends AttributeType, P = never> = KeysBy<
|
||||
GetAttributes<T>,
|
||||
Attribute<U> & NeverGuard<P, unknown>
|
||||
>;
|
||||
export type GetAttributesKeysByType<
|
||||
T extends SchemaUID,
|
||||
U extends AttributeType,
|
||||
P = never
|
||||
> = KeysBy<GetAttributes<T>, Attribute<U> & NeverGuard<P, unknown>>;
|
||||
|
||||
export type GetAttributesByType<T extends SchemaUID, U extends AttributeType, P = never> = PickBy<
|
||||
GetAttributes<T>,
|
||||
Attribute<U> & NeverGuard<P, unknown>
|
||||
>;
|
||||
|
||||
export type GetAttribute<T extends SchemaUID, U extends GetAttributesKey<T>> = Get<GetAttributes<T>, U>;
|
||||
export type GetAttribute<T extends SchemaUID, U extends GetAttributesKey<T>> = Get<
|
||||
GetAttributes<T>,
|
||||
U
|
||||
>;
|
||||
|
||||
export type GetAttributes<T extends SchemaUID> = Get<Strapi.Schemas[T], 'attributes'>;
|
||||
|
||||
@ -54,20 +62,35 @@ export type GetAttributeValue<T extends Attribute> =
|
||||
| GetRichTextAttributeValue<T>
|
||||
| GetStringAttributeValue<T>
|
||||
| GetTextAttributeValue<T>
|
||||
| GetUIDAttributeValue<T>;
|
||||
| GetUIDAttributeValue<T>
|
||||
| GetMediaAttributeValue<T>
|
||||
| GetDateAttributeValue<T>
|
||||
| GetDateTimeAttributeValue<T>
|
||||
| GetTimeAttributeValue<T>
|
||||
| GetTimestampAttributeValue<T>;
|
||||
|
||||
export type GetAttributeValueByKey<T extends SchemaUID, U extends GetAttributesKey<T>> = GetAttribute<T, U
|
||||
> extends infer P ? P extends Attribute ? GetAttributeValue<P> : never : never;
|
||||
export type GetAttributeValueByKey<
|
||||
T extends SchemaUID,
|
||||
U extends GetAttributesKey<T>
|
||||
> = GetAttribute<T, U> extends infer P
|
||||
? P extends Attribute
|
||||
? GetAttributeValue<P>
|
||||
: never
|
||||
: never;
|
||||
|
||||
export type GetAttributesValues<T extends SchemaUID> = {
|
||||
// Handle required attributes
|
||||
[key in GetAttributesRequiredKeys<T>]-?: GetAttributeValueByKey<T, key>;
|
||||
} & {
|
||||
} &
|
||||
{
|
||||
// Handle optional attributes
|
||||
[key in GetAttributesOptionalKeys<T>]?: GetAttributeValueByKey<T, key>;
|
||||
};
|
||||
|
||||
export type GetAttributesRequiredKeys<T extends SchemaUID> = KeysBy<GetAttributes<T>, { required: true }>;
|
||||
export type GetAttributesRequiredKeys<T extends SchemaUID> = KeysBy<
|
||||
GetAttributes<T>,
|
||||
{ required: true }
|
||||
>;
|
||||
export type GetAttributesOptionalKeys<T extends SchemaUID> = keyof Omit<
|
||||
GetAttributes<T>,
|
||||
GetAttributesRequiredKeys<T>
|
||||
|
Loading…
x
Reference in New Issue
Block a user