@strapi/strapi 4.11.0 → 4.11.1-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/lib/commands/actions/develop/action.js +5 -6
  2. package/lib/commands/actions/ts/generate-types/action.js +12 -9
  3. package/lib/commands/actions/ts/generate-types/command.js +4 -4
  4. package/lib/factories.d.ts +21 -0
  5. package/lib/global.d.ts +0 -44
  6. package/lib/index.d.ts +2 -1
  7. package/lib/types/core/attributes/base.d.ts +8 -5
  8. package/lib/types/core/attributes/biginteger.d.ts +8 -15
  9. package/lib/types/core/attributes/boolean.d.ts +7 -13
  10. package/lib/types/core/attributes/common.d.ts +46 -20
  11. package/lib/types/core/attributes/component.d.ts +24 -29
  12. package/lib/types/core/attributes/date-time.d.ts +8 -15
  13. package/lib/types/core/attributes/date.d.ts +8 -17
  14. package/lib/types/core/attributes/decimal.d.ts +8 -15
  15. package/lib/types/core/attributes/dynamic-zone.d.ts +18 -21
  16. package/lib/types/core/attributes/email.d.ts +9 -19
  17. package/lib/types/core/attributes/enumeration.d.ts +12 -22
  18. package/lib/types/core/attributes/float.d.ts +8 -17
  19. package/lib/types/core/attributes/integer.d.ts +8 -15
  20. package/lib/types/core/attributes/json.d.ts +8 -11
  21. package/lib/types/core/attributes/media.d.ts +23 -25
  22. package/lib/types/core/attributes/password.d.ts +8 -15
  23. package/lib/types/core/attributes/relation.d.ts +96 -48
  24. package/lib/types/core/attributes/richtext.d.ts +8 -15
  25. package/lib/types/core/attributes/string.d.ts +11 -21
  26. package/lib/types/core/attributes/text.d.ts +11 -21
  27. package/lib/types/core/attributes/time.d.ts +8 -17
  28. package/lib/types/core/attributes/timestamp.d.ts +8 -15
  29. package/lib/types/core/attributes/uid.d.ts +35 -39
  30. package/lib/types/core/attributes/utils.d.ts +69 -79
  31. package/lib/types/core/common/controller.d.ts +8 -0
  32. package/lib/types/core/common/index.d.ts +4 -0
  33. package/lib/types/core/common/schema.d.ts +3 -0
  34. package/lib/types/core/common/service.d.ts +3 -0
  35. package/lib/types/core/common/uid.d.ts +62 -0
  36. package/lib/types/core/index.d.ts +7 -2
  37. package/lib/types/core/namespace.d.ts +99 -0
  38. package/lib/types/core/registry.d.ts +68 -0
  39. package/lib/types/core/schemas/index.d.ts +16 -15
  40. package/lib/types/core/strapi/index.d.ts +6 -10
  41. package/lib/types/core/uid.d.ts +167 -0
  42. package/lib/types/core-api/controller.d.ts +52 -0
  43. package/lib/types/core-api/index.d.ts +3 -0
  44. package/lib/types/core-api/router.d.ts +65 -0
  45. package/lib/types/core-api/service.d.ts +48 -0
  46. package/lib/types/index.d.ts +4 -2
  47. package/lib/types/shared/index.d.ts +1 -0
  48. package/lib/types/shared/registries.d.ts +45 -0
  49. package/lib/types/utils/array.d.ts +25 -0
  50. package/lib/types/utils/expression.d.ts +68 -0
  51. package/lib/types/utils/guard.d.ts +14 -0
  52. package/lib/types/utils/index.d.ts +19 -0
  53. package/lib/types/utils/object.d.ts +29 -0
  54. package/lib/types/utils/string.d.ts +41 -0
  55. package/lib/types/utils/tuple.d.ts +13 -0
  56. package/package.json +16 -16
  57. package/lib/core/registries/services.d.ts +0 -7
  58. package/lib/core-api/controller/index.d.ts +0 -27
  59. package/lib/core-api/service/index.d.ts +0 -25
  60. package/lib/types/factories.d.ts +0 -60
  61. package/lib/types/utils.d.ts +0 -95
@@ -1,22 +1,13 @@
1
- import {
2
- Attribute,
3
- ConfigurableOption,
4
- DefaultOption,
5
- MinMaxOption,
6
- PrivateOption,
7
- RequiredOption,
8
- } from './base';
1
+ import type { Attribute } from '@strapi/strapi';
9
2
 
10
- export type FloatAttribute = Attribute<'float'> &
3
+ export type Float = Attribute.OfType<'float'> &
11
4
  // Options
12
- ConfigurableOption &
13
- DefaultOption<FloatValue> &
14
- MinMaxOption &
15
- PrivateOption &
16
- RequiredOption;
5
+ Attribute.ConfigurableOption &
6
+ Attribute.DefaultOption<FloatValue> &
7
+ Attribute.MinMaxOption &
8
+ Attribute.PrivateOption &
9
+ Attribute.RequiredOption;
17
10
 
18
11
  export type FloatValue = number;
19
12
 
20
- export type GetFloatAttributeValue<T extends Attribute> = T extends FloatAttribute
21
- ? FloatValue
22
- : never;
13
+ export type GetFloatValue<T extends Attribute.Attribute> = T extends Float ? FloatValue : never;
@@ -1,22 +1,15 @@
1
- import {
2
- Attribute,
3
- ConfigurableOption,
4
- DefaultOption,
5
- MinMaxOption,
6
- PrivateOption,
7
- RequiredOption,
8
- } from './base';
1
+ import type { Attribute } from '@strapi/strapi';
9
2
 
10
- export type IntegerAttribute = Attribute<'integer'> &
3
+ export type Integer = Attribute.OfType<'integer'> &
11
4
  // Options
12
- ConfigurableOption &
13
- DefaultOption<IntegerValue> &
14
- MinMaxOption &
15
- PrivateOption &
16
- RequiredOption;
5
+ Attribute.ConfigurableOption &
6
+ Attribute.DefaultOption<IntegerValue> &
7
+ Attribute.MinMaxOption &
8
+ Attribute.PrivateOption &
9
+ Attribute.RequiredOption;
17
10
 
18
11
  export type IntegerValue = number;
19
12
 
20
- export type GetIntegerAttributeValue<T extends Attribute> = T extends IntegerAttribute
13
+ export type GetIntegerValue<T extends Attribute.Attribute> = T extends Integer
21
14
  ? IntegerValue
22
15
  : never;
@@ -1,14 +1,11 @@
1
- import { Attribute, ConfigurableOption, PrivateOption, RequiredOption } from './base';
2
- import { JSON } from './common';
1
+ import type { Attribute } from '@strapi/strapi';
3
2
 
4
- export type JSONAttribute = Attribute<'json'> &
5
- //Options
6
- ConfigurableOption &
7
- RequiredOption &
8
- PrivateOption;
3
+ export type JSON = Attribute.OfType<'json'> &
4
+ // Options
5
+ Attribute.ConfigurableOption &
6
+ Attribute.RequiredOption &
7
+ Attribute.PrivateOption;
9
8
 
10
- export type JsonValue = JSON;
9
+ export type JsonValue<T extends object = object> = T;
11
10
 
12
- export type GetJsonAttributeValue<T extends Attribute> = T extends JSONAttribute
13
- ? JsonValue
14
- : never;
11
+ export type GetJsonValue<T extends Attribute.Attribute> = T extends JSON ? JsonValue : never;
@@ -1,36 +1,34 @@
1
- import { Attribute, ConfigurableOption, PrivateOption, RequiredOption } from './base';
2
- import { Media } from './common';
1
+ import type { Attribute, Utils } from '@strapi/strapi';
3
2
 
4
- export type AllowedMediaTypes = 'images' | 'videos' | 'files' | 'audios';
3
+ export type MediaKind = 'images' | 'videos' | 'files' | 'audios';
5
4
 
6
- export interface MediaAttributeProperties<
7
- // Media Type
8
- T extends AllowedMediaTypes = undefined,
9
- // Multiple
10
- U extends boolean = false
5
+ export interface MediaProperties<
6
+ TKind extends MediaKind | undefined = undefined,
7
+ TMultiple extends Utils.Expression.BooleanValue = Utils.Expression.False
11
8
  > {
12
- allowedTypes?: T;
13
- multiple?: U;
9
+ allowedTypes?: TKind;
10
+ multiple?: TMultiple;
14
11
  }
15
12
 
16
- export type MediaAttribute<
17
- // Media Type
18
- T extends AllowedMediaTypes = undefined,
19
- // Multiple
20
- U extends boolean = false
21
- > = Attribute<'media'> &
13
+ export type Media<
14
+ TKind extends MediaKind | undefined = undefined,
15
+ TMultiple extends Utils.Expression.BooleanValue = Utils.Expression.False
16
+ > = Attribute.OfType<'media'> &
22
17
  // Properties
23
- MediaAttributeProperties<T, U> &
18
+ MediaProperties<TKind, TMultiple> &
24
19
  // Options
25
- ConfigurableOption &
26
- RequiredOption &
27
- PrivateOption;
20
+ Attribute.ConfigurableOption &
21
+ Attribute.RequiredOption &
22
+ Attribute.PrivateOption;
28
23
 
29
- export type MediaValue<T extends boolean = false> = T extends true ? Media[] : Media;
24
+ // TODO: Introduce a real type for the media values
25
+ export type MediaValue<TMultiple extends Utils.Expression.BooleanValue = Utils.Expression.False> =
26
+ Utils.Expression.If<TMultiple, any[], any>;
30
27
 
31
- export type GetMediaAttributeValue<T extends Attribute> = T extends MediaAttribute<
32
- infer _U,
33
- infer S
28
+ export type GetMediaValue<TAttribute extends Attribute.Attribute> = TAttribute extends Media<
29
+ // Unused as long as the media value is any
30
+ infer _TKind,
31
+ infer TMultiple
34
32
  >
35
- ? MediaValue<S>
33
+ ? MediaValue<TMultiple>
36
34
  : never;
@@ -1,22 +1,15 @@
1
- import {
2
- Attribute,
3
- ConfigurableOption,
4
- DefaultOption,
5
- MinMaxLengthOption,
6
- PrivateOption,
7
- RequiredOption,
8
- } from './base';
1
+ import type { Attribute } from '@strapi/strapi';
9
2
 
10
- export type PasswordAttribute = Attribute<'password'> &
3
+ export type Password = Attribute.OfType<'password'> &
11
4
  // Options
12
- ConfigurableOption &
13
- DefaultOption<PasswordValue> &
14
- MinMaxLengthOption &
15
- PrivateOption &
16
- RequiredOption;
5
+ Attribute.ConfigurableOption &
6
+ Attribute.DefaultOption<PasswordValue> &
7
+ Attribute.MinMaxLengthOption &
8
+ Attribute.PrivateOption &
9
+ Attribute.RequiredOption;
17
10
 
18
11
  export type PasswordValue = string;
19
12
 
20
- export type GetPasswordAttributeValue<T extends Attribute> = T extends PasswordAttribute
13
+ export type GetPasswordValue<T extends Attribute.Attribute> = T extends Password
21
14
  ? PasswordValue
22
15
  : never;
@@ -1,63 +1,111 @@
1
- import { SchemaUID } from '../../utils';
2
- import { Attribute, ConfigurableOption, PrivateOption } from './base';
3
- import { GetAttributesByType, GetAttributesValues } from './utils';
4
-
5
- export type BasicRelationsType = 'oneToOne' | 'oneToMany' | 'manyToOne' | 'manyToMany';
6
- export type PolymorphicRelationsType = 'morphToOne' | 'morphToMany' | 'morphOne' | 'morphMany';
7
- export type RelationsType = BasicRelationsType | PolymorphicRelationsType;
8
-
9
- export interface BasicRelationAttributeProperties<
10
- S extends SchemaUID,
11
- R extends RelationsType,
12
- T extends SchemaUID
13
- > {
14
- relation: R;
15
- target: T;
16
- inversedBy?: RelationsKeysFromTo<T, S>;
17
- mappedBy?: RelationsKeysFromTo<T, S>;
18
- }
19
-
20
- export interface PolymorphicRelationAttributeProperties<R extends RelationsType> {
21
- relation: R;
22
- }
1
+ import type { Attribute, Common, Utils } from '@strapi/strapi';
23
2
 
24
- export type RelationAttribute<
25
- S extends SchemaUID,
26
- R extends RelationsType,
27
- T extends R extends PolymorphicRelationsType ? never : SchemaUID = never
28
- > = Attribute<'relation'> &
3
+ export type Relation<
4
+ // TODO: TOrigin was originally needed to infer precise attribute literal types by doing a reverse lookup
5
+ // on TTarget -> TOrigin relations. Due to errors because of Attribute.Any [relation] very generic
6
+ // representation, type mismatches were encountered and mappedBy/inversedBy are now regular strings.
7
+ // It is kept to allow for future iterations without breaking the current type API
8
+ TOrigin extends Common.UID.Schema = Common.UID.Schema,
9
+ TRelationKind extends RelationKind.Any = RelationKind.Any,
10
+ TTarget extends Common.UID.Schema = never
11
+ > = Attribute.OfType<'relation'> &
29
12
  // Properties
30
- (R extends BasicRelationsType
31
- ? BasicRelationAttributeProperties<S, R, T>
32
- : PolymorphicRelationAttributeProperties<R>) &
13
+ RelationProperties<TOrigin, TRelationKind, TTarget> &
33
14
  // Options
34
- ConfigurableOption &
35
- PrivateOption;
15
+ Attribute.ConfigurableOption &
16
+ Attribute.PrivateOption;
17
+
18
+ export type RelationProperties<
19
+ _TOrigin extends Common.UID.Schema,
20
+ TRelationKind extends RelationKind.Any,
21
+ TTarget extends Common.UID.Schema
22
+ > = Utils.Expression.MatchFirst<
23
+ [
24
+ Utils.Expression.Test<
25
+ Utils.Expression.Extends<TRelationKind, RelationKind.BiDirectional>,
26
+ {
27
+ relation: TRelationKind;
28
+ target: TTarget;
29
+ inversedBy?: string;
30
+ mappedBy?: string;
31
+ }
32
+ >,
33
+ Utils.Expression.Test<
34
+ Utils.Expression.Extends<TRelationKind, RelationKind.UniDirectional>,
35
+ { relation: TRelationKind }
36
+ >,
37
+ Utils.Expression.Test<
38
+ Utils.Expression.Extends<TRelationKind, RelationKind.MorphReference>,
39
+ {
40
+ relation: TRelationKind;
41
+ target: TTarget;
42
+ morphBy?: Utils.Guard.Never<
43
+ Attribute.GetKeysByType<TTarget, 'relation', { relation: RelationKind.MorphOwner }>,
44
+ string
45
+ >;
46
+ }
47
+ >
48
+ ]
49
+ >;
36
50
 
37
51
  export type RelationsKeysFromTo<
38
- TTarget extends SchemaUID,
39
- TSource extends SchemaUID
40
- > = keyof PickRelationsFromTo<TTarget, TSource>;
52
+ TTarget extends Common.UID.Schema,
53
+ TOrigin extends Common.UID.Schema
54
+ > = keyof PickRelationsFromTo<TTarget, TOrigin>;
41
55
 
42
56
  export type PickRelationsFromTo<
43
- TTarget extends SchemaUID,
44
- TSource extends SchemaUID
45
- > = GetAttributesByType<TTarget, 'relation', { target: TSource }>;
57
+ TTarget extends Common.UID.Schema,
58
+ TOrigin extends Common.UID.Schema
59
+ > = Attribute.GetByType<TTarget, 'relation', { target: TOrigin }>;
46
60
 
47
61
  export type RelationPluralityModifier<
48
- TRelation extends RelationsType,
49
- TValue extends Record<string, unknown>
50
- > = TRelation extends `${string}Many` ? TValue[] : TValue;
62
+ TRelationKind extends RelationKind.Any,
63
+ TValue
64
+ > = TRelationKind extends Utils.String.Suffix<string, 'Many'> ? TValue[] : TValue;
51
65
 
52
66
  export type RelationValue<
53
- TRelation extends RelationsType,
54
- TTarget extends SchemaUID
55
- > = RelationPluralityModifier<TRelation, GetAttributesValues<TTarget>>;
67
+ TRelationKind extends RelationKind.Any,
68
+ TTarget extends Common.UID.Schema
69
+ > = RelationPluralityModifier<TRelationKind, Attribute.GetValues<TTarget>>;
56
70
 
57
- export type GetRelationAttributeValue<T extends Attribute> = T extends RelationAttribute<
58
- infer _TSource,
59
- infer TRelation,
71
+ export type GetRelationValue<TAttribute extends Attribute.Attribute> = TAttribute extends Relation<
72
+ infer _TOrigin,
73
+ infer TRelationKind,
60
74
  infer TTarget
61
75
  >
62
- ? RelationValue<TRelation, TTarget>
76
+ ? RelationValue<TRelationKind, TTarget>
63
77
  : never;
78
+
79
+ export module RelationKind {
80
+ type GetOppositePlurality<TPlurality extends RelationKind.Left | RelationKind.Right> = {
81
+ one: 'many';
82
+ One: 'Many';
83
+ many: 'one';
84
+ Many: 'One';
85
+ }[TPlurality];
86
+
87
+ export type Plurality = 'one' | 'many';
88
+
89
+ export type Left = Lowercase<RelationKind.Plurality>;
90
+ export type Right = Capitalize<RelationKind.Plurality>;
91
+
92
+ export type MorphOwner = `morphTo${RelationKind.Right}`;
93
+ export type MorphReference = `morph${RelationKind.Right}`;
94
+ export type Morph = RelationKind.MorphOwner | RelationKind.MorphReference;
95
+
96
+ export type XWay = `${RelationKind.Left}Way`;
97
+
98
+ export type BiDirectional = `${RelationKind.Left}To${RelationKind.Right}`;
99
+ export type UniDirectional = RelationKind.Morph | RelationKind.XWay;
100
+
101
+ export type Any = RelationKind.BiDirectional | RelationKind.UniDirectional;
102
+
103
+ export type Reverse<TRelationKind extends RelationKind.Any> =
104
+ TRelationKind extends `${infer TLeft extends RelationKind.Left}To${infer TRight extends RelationKind.Right}`
105
+ ? Utils.Expression.If<
106
+ Utils.Expression.Extends<Uppercase<TLeft>, Uppercase<TRight>>,
107
+ TRelationKind,
108
+ `${GetOppositePlurality<TLeft>}To${GetOppositePlurality<TRight>}`
109
+ >
110
+ : TRelationKind;
111
+ }
@@ -1,22 +1,15 @@
1
- import {
2
- Attribute,
3
- ConfigurableOption,
4
- DefaultOption,
5
- MinMaxLengthOption,
6
- PrivateOption,
7
- RequiredOption,
8
- } from './base';
1
+ import type { Attribute } from '@strapi/strapi';
9
2
 
10
- export type RichTextAttribute = Attribute<'richtext'> &
3
+ export type RichText = Attribute.OfType<'richtext'> &
11
4
  // Options
12
- ConfigurableOption &
13
- DefaultOption<RichTextValue> &
14
- MinMaxLengthOption &
15
- PrivateOption &
16
- RequiredOption;
5
+ Attribute.ConfigurableOption &
6
+ Attribute.DefaultOption<RichTextValue> &
7
+ Attribute.MinMaxLengthOption &
8
+ Attribute.PrivateOption &
9
+ Attribute.RequiredOption;
17
10
 
18
11
  export type RichTextValue = string;
19
12
 
20
- export type GetRichTextAttributeValue<T extends Attribute> = T extends RichTextAttribute
13
+ export type GetRichTextValue<T extends Attribute.Attribute> = T extends RichText
21
14
  ? RichTextValue
22
15
  : never;
@@ -1,30 +1,20 @@
1
- import {
2
- Attribute,
3
- ConfigurableOption,
4
- DefaultOption,
5
- MinMaxLengthOption,
6
- PrivateOption,
7
- RequiredOption,
8
- UniqueOption,
9
- } from './base';
1
+ import type { Attribute } from '@strapi/strapi';
10
2
 
11
- export interface StringAttributeProperties {
3
+ export interface StringProperties {
12
4
  regex?: RegExp;
13
5
  }
14
6
 
15
- export type StringAttribute = Attribute<'string'> &
7
+ export type String = Attribute.OfType<'string'> &
16
8
  // Properties
17
- StringAttributeProperties &
9
+ StringProperties &
18
10
  // Options
19
- ConfigurableOption &
20
- DefaultOption<StringValue> &
21
- MinMaxLengthOption &
22
- PrivateOption &
23
- UniqueOption &
24
- RequiredOption;
11
+ Attribute.ConfigurableOption &
12
+ Attribute.DefaultOption<StringValue> &
13
+ Attribute.MinMaxLengthOption &
14
+ Attribute.PrivateOption &
15
+ Attribute.UniqueOption &
16
+ Attribute.RequiredOption;
25
17
 
26
18
  export type StringValue = string;
27
19
 
28
- export type GetStringAttributeValue<T extends Attribute> = T extends StringAttribute
29
- ? StringValue
30
- : never;
20
+ export type GetStringValue<T extends Attribute.Attribute> = T extends String ? StringValue : never;
@@ -1,30 +1,20 @@
1
- import {
2
- Attribute,
3
- ConfigurableOption,
4
- DefaultOption,
5
- MinMaxLengthOption,
6
- PrivateOption,
7
- RequiredOption,
8
- UniqueOption,
9
- } from './base';
1
+ import type { Attribute } from '@strapi/strapi';
10
2
 
11
- export interface TextAttributeProperties {
3
+ export interface TextProperties {
12
4
  regex?: RegExp;
13
5
  }
14
6
 
15
- export type TextAttribute = Attribute<'text'> &
7
+ export type Text = Attribute.OfType<'text'> &
16
8
  // Properties
17
- TextAttributeProperties &
9
+ TextProperties &
18
10
  // Options
19
- ConfigurableOption &
20
- DefaultOption<TextValue> &
21
- MinMaxLengthOption &
22
- PrivateOption &
23
- UniqueOption &
24
- RequiredOption;
11
+ Attribute.ConfigurableOption &
12
+ Attribute.DefaultOption<TextValue> &
13
+ Attribute.MinMaxLengthOption &
14
+ Attribute.PrivateOption &
15
+ Attribute.UniqueOption &
16
+ Attribute.RequiredOption;
25
17
 
26
18
  export type TextValue = string;
27
19
 
28
- export type GetTextAttributeValue<T extends Attribute> = T extends TextAttribute
29
- ? TextValue
30
- : never;
20
+ export type GetTextValue<T extends Attribute.Attribute> = T extends Text ? TextValue : never;
@@ -1,22 +1,13 @@
1
- import {
2
- Attribute,
3
- ConfigurableOption,
4
- DefaultOption,
5
- PrivateOption,
6
- RequiredOption,
7
- UniqueOption,
8
- } from './base';
1
+ import type { Attribute } from '@strapi/strapi';
9
2
 
10
- export type TimeAttribute = Attribute<'time'> &
3
+ export type Time = Attribute.OfType<'time'> &
11
4
  // Options
12
- ConfigurableOption &
13
- DefaultOption<TimeValue> &
14
- PrivateOption &
15
- RequiredOption &
16
- UniqueOption;
5
+ Attribute.ConfigurableOption &
6
+ Attribute.DefaultOption<TimeValue> &
7
+ Attribute.PrivateOption &
8
+ Attribute.RequiredOption &
9
+ Attribute.UniqueOption;
17
10
 
18
11
  export type TimeValue = string;
19
12
 
20
- export type GetTimeAttributeValue<T extends Attribute> = T extends TimeAttribute
21
- ? TimeValue
22
- : never;
13
+ export type GetTimeValue<T extends Attribute.Attribute> = T extends Time ? TimeValue : never;
@@ -1,22 +1,15 @@
1
- import {
2
- Attribute,
3
- ConfigurableOption,
4
- DefaultOption,
5
- PrivateOption,
6
- RequiredOption,
7
- UniqueOption,
8
- } from './base';
1
+ import type { Attribute } from '@strapi/strapi';
9
2
 
10
- export type TimestampAttribute = Attribute<'timestamp'> &
3
+ export type Timestamp = Attribute.OfType<'timestamp'> &
11
4
  // Options
12
- ConfigurableOption &
13
- DefaultOption<TimestampValue> &
14
- PrivateOption &
15
- RequiredOption &
16
- UniqueOption;
5
+ Attribute.ConfigurableOption &
6
+ Attribute.DefaultOption<TimestampValue> &
7
+ Attribute.PrivateOption &
8
+ Attribute.RequiredOption &
9
+ Attribute.UniqueOption;
17
10
 
18
11
  export type TimestampValue = string;
19
12
 
20
- export type GetTimestampAttributeValue<T extends Attribute> = T extends TimestampAttribute
13
+ export type GetTimestampValue<T extends Attribute.Attribute> = T extends Timestamp
21
14
  ? TimestampValue
22
15
  : never;
@@ -1,15 +1,6 @@
1
- import {
2
- Attribute,
3
- ConfigurableOption,
4
- DefaultOption,
5
- MinMaxLengthOption,
6
- PrivateOption,
7
- RequiredOption,
8
- } from './base';
9
- import { SchemaUID } from '../../utils';
10
- import { GetAttributesKeysByType } from './utils';
1
+ import type { Attribute, Common, Utils } from '@strapi/strapi';
11
2
 
12
- export interface UIDAttributeOptions {
3
+ export interface UIDOptions {
13
4
  separator?: string;
14
5
  lowercase?: boolean;
15
6
  decamelize?: boolean;
@@ -17,41 +8,46 @@ export interface UIDAttributeOptions {
17
8
  preserveLeadingUnderscore?: boolean;
18
9
  }
19
10
 
20
- export interface UIDAttributeProperties<
21
- // Own Schema Reference
22
- T extends SchemaUID | undefined = undefined,
23
- // Target attribute
24
- U extends T extends SchemaUID
25
- ? GetAttributesKeysByType<T, 'string' | 'text'>
26
- : undefined = undefined,
27
- // UID options
28
- S extends UIDAttributeOptions = UIDAttributeOptions
11
+ export interface UIDProperties<
12
+ TOrigin extends Common.UID.Schema,
13
+ TTargetAttribute extends AllowedTargetAttributes<TOrigin>,
14
+ TOptions extends UIDOptions = UIDOptions
29
15
  > {
30
- targetField?: U;
31
- options?: UIDAttributeOptions & S;
16
+ targetField: TTargetAttribute;
17
+ options: UIDOptions & TOptions;
32
18
  }
33
19
 
34
- export type UIDAttribute<
35
- // Own Schema Reference
36
- T extends SchemaUID | undefined = undefined,
37
- // Target attribute
38
- U extends T extends SchemaUID
39
- ? GetAttributesKeysByType<T, 'string' | 'text'>
40
- : undefined = undefined,
41
- // UID options
42
- S extends UIDAttributeOptions = UIDAttributeOptions
43
- > = Attribute<'uid'> &
20
+ export interface GenericUIDProperties<TOptions extends UIDOptions = UIDOptions> {
21
+ targetField?: string;
22
+ options: TOptions & UIDOptions;
23
+ }
24
+
25
+ export type UID<
26
+ TOrigin extends Common.UID.Schema | undefined = undefined,
27
+ TTargetAttribute extends AllowedTargetAttributes<TOrigin> = AllowedTargetAttributes<TOrigin>,
28
+ TOptions extends UIDOptions = UIDOptions
29
+ > = Attribute.OfType<'uid'> &
44
30
  // Properties
45
- UIDAttributeProperties<T, U, S> &
31
+ (TOrigin extends Common.UID.Schema
32
+ ? UIDProperties<TOrigin, TTargetAttribute, TOptions>
33
+ : GenericUIDProperties<TOptions>) &
46
34
  // Options
47
- ConfigurableOption &
48
- DefaultOption<UIDValue> &
49
- MinMaxLengthOption &
50
- PrivateOption &
51
- RequiredOption;
35
+ Attribute.ConfigurableOption &
36
+ Attribute.DefaultOption<UIDValue> &
37
+ Attribute.MinMaxLengthOption &
38
+ Attribute.PrivateOption &
39
+ Attribute.RequiredOption;
40
+
41
+ type AllowedTargetAttributes<TOrigin extends Common.UID.Schema | undefined> =
42
+ TOrigin extends Common.UID.Schema
43
+ ? Utils.Guard.Never<Attribute.GetKeysByType<TOrigin, 'string' | 'text'>, string>
44
+ : never;
52
45
 
53
46
  export type UIDValue = string;
54
47
 
55
- export type GetUIDAttributeValue<T extends Attribute> = T extends UIDAttribute<infer _U, infer _P>
48
+ export type GetUIDValue<TAttribute extends Attribute.Attribute> = TAttribute extends UID<
49
+ infer _TOrigin,
50
+ infer _TTargetAttribute
51
+ >
56
52
  ? UIDValue
57
53
  : never;