diff --git a/packages/core/strapi/lib/types/core/attributes/date-time.d.ts b/packages/core/strapi/lib/types/core/attributes/date-time.d.ts new file mode 100644 index 0000000000..96447508a3 --- /dev/null +++ b/packages/core/strapi/lib/types/core/attributes/date-time.d.ts @@ -0,0 +1,9 @@ +import { Attribute } from './base'; + +export interface DateTimeAttribute extends Attribute<'datetime'> {} + +export type DateTimeValue = string; + +export type GetDateTimeAttributeValue = T extends DateTimeAttribute + ? DateTimeValue + : never; diff --git a/packages/core/strapi/lib/types/core/attributes/date.d.ts b/packages/core/strapi/lib/types/core/attributes/date.d.ts new file mode 100644 index 0000000000..9d8a9d857f --- /dev/null +++ b/packages/core/strapi/lib/types/core/attributes/date.d.ts @@ -0,0 +1,9 @@ +import { Attribute } from './base'; + +export interface DateAttribute extends Attribute<'date'> {} + +export type DateValue = Date; + +export type GetDateAttributeValue = T extends DateAttribute + ? DateValue + : never; diff --git a/packages/core/strapi/lib/types/core/attributes/email.d.ts b/packages/core/strapi/lib/types/core/attributes/email.d.ts new file mode 100644 index 0000000000..d6642e4cd2 --- /dev/null +++ b/packages/core/strapi/lib/types/core/attributes/email.d.ts @@ -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 EmailAttribute + ? EmailValue + : never; diff --git a/packages/core/strapi/lib/types/core/attributes/index.d.ts b/packages/core/strapi/lib/types/core/attributes/index.d.ts index 790a99f7c8..27c40aae0f 100644 --- a/packages/core/strapi/lib/types/core/attributes/index.d.ts +++ b/packages/core/strapi/lib/types/core/attributes/index.d.ts @@ -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'; diff --git a/packages/core/strapi/lib/types/core/attributes/time.d.ts b/packages/core/strapi/lib/types/core/attributes/time.d.ts new file mode 100644 index 0000000000..a03420fb6b --- /dev/null +++ b/packages/core/strapi/lib/types/core/attributes/time.d.ts @@ -0,0 +1,7 @@ +import { Attribute } from './base'; + +export interface TimeAttribute extends Attribute<'time'> {} + +export type TimeValue = string; + +export type GetTimeAttributeValue = T extends TimeAttribute ? TimeValue : never; diff --git a/packages/core/strapi/lib/types/core/attributes/timestamp.d.ts b/packages/core/strapi/lib/types/core/attributes/timestamp.d.ts new file mode 100644 index 0000000000..af42724e71 --- /dev/null +++ b/packages/core/strapi/lib/types/core/attributes/timestamp.d.ts @@ -0,0 +1,9 @@ +import { Attribute } from './base'; + +export interface TimestampAttribute extends Attribute<'timestamp'> {} + +export type TimestampValue = string; + +export type GetTimestampAttributeValue = T extends TimestampAttribute + ? TimestampValue + : never; diff --git a/packages/core/strapi/lib/types/core/attributes/utils.d.ts b/packages/core/strapi/lib/types/core/attributes/utils.d.ts index 46f9a56153..1d79f5eed6 100644 --- a/packages/core/strapi/lib/types/core/attributes/utils.d.ts +++ b/packages/core/strapi/lib/types/core/attributes/utils.d.ts @@ -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; -export type GetAttributesKeysByType = KeysBy< - GetAttributes, - Attribute & NeverGuard ->; +export type GetAttributesKeysByType< + T extends SchemaUID, + U extends AttributeType, + P = never +> = KeysBy, Attribute & NeverGuard>; export type GetAttributesByType = PickBy< GetAttributes, Attribute & NeverGuard >; -export type GetAttribute> = Get, U>; +export type GetAttribute> = Get< + GetAttributes, + U +>; export type GetAttributes = Get; @@ -54,20 +62,35 @@ export type GetAttributeValue = | GetRichTextAttributeValue | GetStringAttributeValue | GetTextAttributeValue - | GetUIDAttributeValue; + | GetUIDAttributeValue + | GetMediaAttributeValue + | GetDateAttributeValue + | GetDateTimeAttributeValue + | GetTimeAttributeValue + | GetTimestampAttributeValue; -export type GetAttributeValueByKey> = GetAttribute extends infer P ? P extends Attribute ? GetAttributeValue

: never : never; +export type GetAttributeValueByKey< + T extends SchemaUID, + U extends GetAttributesKey +> = GetAttribute extends infer P + ? P extends Attribute + ? GetAttributeValue

+ : never + : never; export type GetAttributesValues = { // Handle required attributes [key in GetAttributesRequiredKeys]-?: GetAttributeValueByKey; -} & { +} & + { // Handle optional attributes [key in GetAttributesOptionalKeys]?: GetAttributeValueByKey; }; -export type GetAttributesRequiredKeys = KeysBy, { required: true }>; +export type GetAttributesRequiredKeys = KeysBy< + GetAttributes, + { required: true } +>; export type GetAttributesOptionalKeys = keyof Omit< GetAttributes, GetAttributesRequiredKeys