Fix circular dependencies breaking types resolution due to DefaultOption using GetAttributeValue

This commit is contained in:
Convly 2022-06-30 17:39:49 +02:00
parent 626875fef2
commit 40875d4866
18 changed files with 120 additions and 183 deletions

View File

@ -55,8 +55,8 @@ export interface UniqueOption {
unique?: boolean; unique?: boolean;
} }
export interface DefaultOption<T extends Attribute> { export interface DefaultOption<T> {
default?: GetAttributeValue<T>; default?: T;
} }
export interface ConfigurableOption { export interface ConfigurableOption {

View File

@ -7,17 +7,13 @@ import {
RequiredOption, RequiredOption,
} from './base'; } from './base';
export type BigIntegerAttribute = Attribute<'biginteger'> extends infer T export type BigIntegerAttribute = Attribute<'biginteger'> &
? T extends Attribute // Options
? T & ConfigurableOption &
// Options DefaultOption<BigIntegerValue> &
ConfigurableOption & MinMaxOption<string> &
DefaultOption<T> & PrivateOption &
MinMaxOption<string> & RequiredOption;
PrivateOption &
RequiredOption
: never
: never;
export type BigIntegerValue = string; export type BigIntegerValue = string;

View File

@ -6,16 +6,12 @@ import {
RequiredOption, RequiredOption,
} from './base'; } from './base';
export type BooleanAttribute = Attribute<'boolean'> extends infer T export type BooleanAttribute = Attribute<'boolean'> &
? T extends Attribute // Options
? T & ConfigurableOption &
// Options DefaultOption<BooleanValue> &
ConfigurableOption & PrivateOption &
DefaultOption<T> & RequiredOption;
PrivateOption &
RequiredOption
: never
: never;
export type BooleanValue = boolean; export type BooleanValue = boolean;

View File

@ -7,17 +7,13 @@ import {
UniqueOption, UniqueOption,
} from './base'; } from './base';
export type DateTimeAttribute = Attribute<'datetime'> extends infer T export type DateTimeAttribute = Attribute<'datetime'> &
? T extends Attribute // Options
? T & ConfigurableOption &
// Options DefaultOption<DateTimeValue> &
ConfigurableOption & PrivateOption &
DefaultOption<T> & RequiredOption &
PrivateOption & UniqueOption;
RequiredOption &
UniqueOption
: never
: never;
export type DateTimeValue = string; export type DateTimeValue = string;

View File

@ -7,17 +7,13 @@ import {
UniqueOption, UniqueOption,
} from './base'; } from './base';
export type DateAttribute = Attribute<'date'> extends infer T export type DateAttribute = Attribute<'date'> &
? T extends Attribute // Options
? T & ConfigurableOption &
// Options DefaultOption<DateValue> &
ConfigurableOption & PrivateOption &
DefaultOption<T> & RequiredOption &
PrivateOption & UniqueOption;
RequiredOption &
UniqueOption
: never
: never;
export type DateValue = Date; export type DateValue = Date;

View File

@ -7,17 +7,13 @@ import {
RequiredOption, RequiredOption,
} from './base'; } from './base';
export type DecimalAttribute = Attribute<'decimal'> extends infer T export type DecimalAttribute = Attribute<'decimal'> &
? T extends Attribute // Options
? T & ConfigurableOption &
// Options DefaultOption<DecimalValue> &
ConfigurableOption & MinMaxOption &
DefaultOption<T> & PrivateOption &
MinMaxOption & RequiredOption;
PrivateOption &
RequiredOption
: never
: never;
export type DecimalValue = number; export type DecimalValue = number;

View File

@ -8,18 +8,14 @@ import {
UniqueOption, UniqueOption,
} from './base'; } from './base';
export type EmailAttribute = Attribute<'email'> extends infer T export type EmailAttribute = Attribute<'email'> &
? T extends Attribute // Options
? T & ConfigurableOption &
// Options DefaultOption<EmailValue> &
ConfigurableOption & MinMaxLengthOption &
DefaultOption<T> & PrivateOption &
MinMaxLengthOption & RequiredOption &
PrivateOption & UniqueOption;
RequiredOption &
UniqueOption
: never
: never;
export type EmailValue = string; export type EmailValue = string;

View File

@ -12,16 +12,12 @@ export interface EnumerationAttributeProperties<T extends string[] = []> {
} }
export type EnumerationAttribute<T extends string[] = []> = Attribute<'enumeration'> & export type EnumerationAttribute<T extends string[] = []> = Attribute<'enumeration'> &
EnumerationAttributeProperties<T> extends infer U EnumerationAttributeProperties<T> &
? U extends Attribute // Options
? U & ConfigurableOption &
// Options DefaultOption<T> &
ConfigurableOption & PrivateOption &
DefaultOption<U> & RequiredOption;
PrivateOption &
RequiredOption
: never
: never;
export type EnumerationValue<T extends string[]> = GetArrayValues<T>; export type EnumerationValue<T extends string[]> = GetArrayValues<T>;

View File

@ -7,17 +7,13 @@ import {
RequiredOption, RequiredOption,
} from './base'; } from './base';
export type FloatAttribute = Attribute<'float'> extends infer T export type FloatAttribute = Attribute<'float'> &
? T extends Attribute // Options
? T & ConfigurableOption &
// Options DefaultOption<FloatValue> &
ConfigurableOption & MinMaxOption &
DefaultOption<T> & PrivateOption &
MinMaxOption & RequiredOption;
PrivateOption &
RequiredOption
: never
: never;
export type FloatValue = number; export type FloatValue = number;

View File

@ -7,17 +7,13 @@ import {
RequiredOption, RequiredOption,
} from './base'; } from './base';
export type IntegerAttribute = Attribute<'integer'> extends infer T export type IntegerAttribute = Attribute<'integer'> &
? T extends Attribute // Options
? T & ConfigurableOption &
// Options DefaultOption<IntegerValue> &
ConfigurableOption & MinMaxOption &
DefaultOption<T> & PrivateOption &
MinMaxOption & RequiredOption;
PrivateOption &
RequiredOption
: never
: never;
export type IntegerValue = number; export type IntegerValue = number;

View File

@ -7,19 +7,13 @@ import {
RequiredOption, RequiredOption,
} from './base'; } from './base';
// export interface PasswordAttribute extends BaseStringAttribute<'password'> {} export type PasswordAttribute = Attribute<'password'> &
// Options
export type PasswordAttribute = Attribute<'password'> extends infer T ConfigurableOption &
? T extends Attribute DefaultOption<PasswordValue> &
? T & MinMaxLengthOption &
// Options PrivateOption &
ConfigurableOption & RequiredOption;
DefaultOption<T> &
MinMaxLengthOption &
PrivateOption &
RequiredOption
: never
: never;
export type PasswordValue = string; export type PasswordValue = string;

View File

@ -7,17 +7,13 @@ import {
RequiredOption, RequiredOption,
} from './base'; } from './base';
export type RichTextAttribute = Attribute<'richtext'> extends infer T export type RichTextAttribute = Attribute<'richtext'> &
? T extends Attribute // Options
? T & ConfigurableOption &
// Options DefaultOption<RichTextValue> &
ConfigurableOption & MinMaxLengthOption &
DefaultOption<T> & PrivateOption &
MinMaxLengthOption & RequiredOption;
PrivateOption &
RequiredOption
: never
: never;
export type RichTextValue = string; export type RichTextValue = string;

View File

@ -14,18 +14,14 @@ export interface StringAttributeProperties {
export type StringAttribute = Attribute<'string'> & export type StringAttribute = Attribute<'string'> &
// Properties // Properties
StringAttributeProperties extends infer U StringAttributeProperties &
? U extends Attribute // Options
? U & ConfigurableOption &
// Options DefaultOption<StringValue> &
ConfigurableOption & MinMaxLengthOption &
DefaultOption<U> & PrivateOption &
MinMaxLengthOption & UniqueOption &
PrivateOption & RequiredOption;
UniqueOption &
RequiredOption
: never
: never;
export type StringValue = string; export type StringValue = string;

View File

@ -14,18 +14,14 @@ export interface TextAttributeProperties {
export type TextAttribute = Attribute<'text'> & export type TextAttribute = Attribute<'text'> &
// Properties // Properties
TextAttributeProperties extends infer U TextAttributeProperties &
? U extends Attribute // Options
? U & ConfigurableOption &
// Options DefaultOption<TextValue> &
ConfigurableOption & MinMaxLengthOption &
DefaultOption<U> & PrivateOption &
MinMaxLengthOption & UniqueOption &
PrivateOption & RequiredOption;
UniqueOption &
RequiredOption
: never
: never;
export type TextValue = string; export type TextValue = string;

View File

@ -7,17 +7,13 @@ import {
UniqueOption, UniqueOption,
} from './base'; } from './base';
export type TimeAttribute = Attribute<'time'> extends infer T export type TimeAttribute = Attribute<'time'> &
? T extends Attribute // Options
? T & ConfigurableOption &
// Options DefaultOption<TimeValue> &
ConfigurableOption & PrivateOption &
DefaultOption<T> & RequiredOption &
PrivateOption & UniqueOption;
RequiredOption &
UniqueOption
: never
: never;
export type TimeValue = string; export type TimeValue = string;

View File

@ -7,17 +7,13 @@ import {
UniqueOption, UniqueOption,
} from './base'; } from './base';
export type TimestampAttribute = Attribute<'timestamp'> extends infer T export type TimestampAttribute = Attribute<'timestamp'> &
? T extends Attribute // Options
? T & ConfigurableOption &
// Options DefaultOption<TimestampValue> &
ConfigurableOption & PrivateOption &
DefaultOption<T> & RequiredOption &
PrivateOption & UniqueOption;
RequiredOption &
UniqueOption
: never
: never;
export type TimestampValue = string; export type TimestampValue = string;

View File

@ -40,17 +40,15 @@ export type UIDAttribute<
U extends T extends SchemaUID U extends T extends SchemaUID
? GetAttributesKeysByType<T, 'string' | 'text'> ? GetAttributesKeysByType<T, 'string' | 'text'>
: undefined = undefined : undefined = undefined
> = Attribute<'uid'> & UIDAttributeProperties<S, T, U> extends infer P > = Attribute<'uid'> &
? P extends Attribute // Properties
? P & UIDAttributeProperties<S, T, U> &
// Options // Options
ConfigurableOption & ConfigurableOption &
DefaultOption<P> & DefaultOption<UIDValue> &
MinMaxLengthOption & MinMaxLengthOption &
PrivateOption & PrivateOption &
RequiredOption RequiredOption;
: never
: never;
export type UIDValue = string; export type UIDValue = string;

View File

@ -3,7 +3,6 @@ import {
Attribute, Attribute,
AttributeType, AttributeType,
GetBigIntegerAttributeValue, GetBigIntegerAttributeValue,
GetComponentAttributeValue,
GetBooleanAttributeValue, GetBooleanAttributeValue,
GetDecimalAttributeValue, GetDecimalAttributeValue,
GetDynamicZoneAttributeValue, GetDynamicZoneAttributeValue,
@ -18,7 +17,8 @@ import {
GetStringAttributeValue, GetStringAttributeValue,
GetTextAttributeValue, GetTextAttributeValue,
GetUIDAttributeValue, GetUIDAttributeValue,
BigIntegerAttribute, GetComponentAttributeValue,
GetEmailAttributeValue,
} from '.'; } from '.';
import { GetDateAttributeValue } from './date'; import { GetDateAttributeValue } from './date';
import { GetDateTimeAttributeValue } from './date-time'; import { GetDateTimeAttributeValue } from './date-time';
@ -54,6 +54,7 @@ export type GetAttributeValue<T extends Attribute> =
| GetDecimalAttributeValue<T> | GetDecimalAttributeValue<T>
| GetDynamicZoneAttributeValue<T> | GetDynamicZoneAttributeValue<T>
| GetEnumerationAttributeValue<T> | GetEnumerationAttributeValue<T>
| GetEmailAttributeValue<T>
| GetFloatAttributeValue<T> | GetFloatAttributeValue<T>
| GetIntegerAttributeValue<T> | GetIntegerAttributeValue<T>
| GetJsonAttributeValue<T> | GetJsonAttributeValue<T>