@strapi/strapi 4.13.0-beta.0 → 4.13.1

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 (62) hide show
  1. package/README.md +13 -5
  2. package/lib/Strapi.js +11 -0
  3. package/lib/commands/actions/import/action.js +4 -4
  4. package/lib/commands/actions/import/command.js +1 -1
  5. package/lib/commands/actions/transfer/action.js +3 -6
  6. package/lib/commands/actions/transfer/command.js +1 -1
  7. package/lib/commands/actions/watch-admin/action.js +1 -1
  8. package/lib/commands/builders/admin.js +1 -1
  9. package/lib/commands/utils/data-transfer.js +39 -1
  10. package/lib/core/loaders/index.js +1 -0
  11. package/lib/core/loaders/plugins/get-enabled-plugins.js +40 -13
  12. package/lib/core/loaders/sanitizers.js +1 -1
  13. package/lib/core/loaders/validators.js +5 -0
  14. package/lib/core/registries/validators.js +26 -0
  15. package/lib/core-api/controller/collection-type.js +14 -8
  16. package/lib/core-api/controller/index.js +15 -3
  17. package/lib/core-api/controller/single-type.js +2 -0
  18. package/lib/factories.d.ts +10 -13
  19. package/lib/factories.js +12 -2
  20. package/lib/services/entity-service/index.d.ts +1 -100
  21. package/lib/services/entity-service/index.js +1 -0
  22. package/lib/services/entity-service/types/index.d.ts +228 -0
  23. package/lib/services/entity-service/types/params/attributes.d.ts +146 -0
  24. package/lib/services/entity-service/types/params/data.d.ts +4 -0
  25. package/lib/services/entity-service/types/params/fields.d.ts +74 -0
  26. package/lib/services/entity-service/types/params/filters/index.d.ts +75 -0
  27. package/lib/services/entity-service/types/params/filters/operators.d.ts +30 -0
  28. package/lib/services/entity-service/types/params/index.d.ts +79 -0
  29. package/lib/services/entity-service/types/params/pagination.d.ts +13 -0
  30. package/lib/services/entity-service/types/params/populate.d.ts +130 -0
  31. package/lib/services/entity-service/types/params/publication-state.d.ts +38 -0
  32. package/lib/services/entity-service/types/params/search.d.ts +1 -0
  33. package/lib/services/entity-service/types/params/sort.d.ts +106 -0
  34. package/lib/services/entity-service/types/plugin.d.ts +11 -0
  35. package/lib/services/entity-service/types/result.d.ts +205 -0
  36. package/lib/types/core/attributes/common.d.ts +13 -10
  37. package/lib/types/core/attributes/component.d.ts +3 -0
  38. package/lib/types/core/attributes/date-time.d.ts +2 -1
  39. package/lib/types/core/attributes/dynamic-zone.d.ts +10 -7
  40. package/lib/types/core/attributes/media.d.ts +8 -0
  41. package/lib/types/core/attributes/relation.d.ts +69 -28
  42. package/lib/types/core/attributes/time.d.ts +1 -1
  43. package/lib/types/core/attributes/timestamp.d.ts +1 -1
  44. package/lib/types/core/attributes/uid.d.ts +7 -17
  45. package/lib/types/core/attributes/utils.d.ts +61 -6
  46. package/lib/types/core/common/index.d.ts +12 -0
  47. package/lib/types/core/common/uid.d.ts +12 -16
  48. package/lib/types/core/index.d.ts +1 -0
  49. package/lib/types/core/plugins/index.d.ts +16 -0
  50. package/lib/types/core/schemas/index.d.ts +1 -0
  51. package/lib/types/core/strapi/index.d.ts +7 -2
  52. package/lib/types/core-api/controller.d.ts +12 -10
  53. package/lib/types/index.d.ts +2 -0
  54. package/lib/types/shared/entity-service.d.ts +1 -0
  55. package/lib/types/shared/index.d.ts +2 -0
  56. package/lib/types/shared/plugins.d.ts +3 -0
  57. package/lib/types/utils/expression.d.ts +29 -6
  58. package/lib/types/utils/guard.d.ts +14 -1
  59. package/lib/types/utils/index.d.ts +8 -0
  60. package/lib/types/utils/object.d.ts +35 -1
  61. package/lib/types/utils/string.d.ts +18 -0
  62. package/package.json +17 -16
@@ -0,0 +1,130 @@
1
+ import type { Attribute, Common, EntityService, Utils } from '@strapi/strapi';
2
+ import type * as Params from './index';
3
+
4
+ /**
5
+ * Wildcard notation for populate
6
+ *
7
+ * To populate all the root level relations
8
+ */
9
+ export type WildcardNotation = '*';
10
+
11
+ /**
12
+ * Union of all possible string representation for populate
13
+ *
14
+ * @example
15
+ * type A = 'image'; // ✅
16
+ * type B = 'image,component'; // ✅
17
+ * type c = '*'; // ✅
18
+ * type D = 'populatableField'; // ✅
19
+ * type E = '<random_string>'; // ❌
20
+ */
21
+ export type StringNotation<TSchemaUID extends Common.UID.Schema> =
22
+ | WildcardNotation
23
+ // Populatable keys
24
+ | Utils.Guard.Never<Attribute.GetPopulatableKeys<TSchemaUID>, string>
25
+ // Other string notations
26
+ // Those are not computed as it would break the TS parser for schemas with lots of populatable attributes
27
+ | `${string},${string}`
28
+ | `${string}.${string}`;
29
+
30
+ /**
31
+ * Array notation for populate
32
+ *
33
+ * @example
34
+ * type A = ['image']; // ✅
35
+ * type B = ['image', 'component']; // ✅
36
+ * type C = ['populatableField']; // ✅
37
+ * type D = ['<random_string>']; // ❌
38
+ * type E = ['*']; // ❌
39
+ */
40
+ export type ArrayNotation<TSchemaUID extends Common.UID.Schema> = Exclude<
41
+ StringNotation<TSchemaUID>,
42
+ WildcardNotation
43
+ >[];
44
+
45
+ type GetPopulatableKeysWithTarget<TSchemaUID extends Common.UID.Schema> = Extract<
46
+ Attribute.GetPopulatableKeys<TSchemaUID>,
47
+ Attribute.GetKeysWithTarget<TSchemaUID>
48
+ >;
49
+
50
+ type GetPopulatableKeysWithoutTarget<TSchemaUID extends Common.UID.Schema> = Exclude<
51
+ Attribute.GetPopulatableKeys<TSchemaUID>,
52
+ GetPopulatableKeysWithTarget<TSchemaUID>
53
+ >;
54
+
55
+ /**
56
+ * Fragment populate notation for polymorphic attributes
57
+ */
58
+ export type Fragment<TMaybeTargets extends Common.UID.Schema> = {
59
+ on?: { [TSchemaUID in TMaybeTargets]?: boolean | NestedParams<TSchemaUID> };
60
+ };
61
+
62
+ type PopulateClause<
63
+ TSchemaUID extends Common.UID.Schema,
64
+ TKeys extends Attribute.GetPopulatableKeys<TSchemaUID>
65
+ > = {
66
+ [TKey in TKeys]?: boolean | NestedParams<Attribute.GetTarget<TSchemaUID, TKey>>;
67
+ };
68
+
69
+ /**
70
+ * Object notation for populate
71
+ *
72
+ * @example
73
+ * type A = { image: true }; // ✅
74
+ * type B = { image: { fields: ['url', 'provider'] } }; // ✅
75
+ * type C = { populatableField: { populate: { nestedPopulatableField: true } } }; // ✅
76
+ * type D = { dynamic_zone: { on: { comp_A: { fields: ['name', 'price_a'] }, comp_B: { fields: ['name', 'price_b'] } } } }; // ✅
77
+ */
78
+ export type ObjectNotation<TSchemaUID extends Common.UID.Schema> = [
79
+ GetPopulatableKeysWithTarget<TSchemaUID>,
80
+ GetPopulatableKeysWithoutTarget<TSchemaUID>
81
+ ] extends [
82
+ infer TKeysWithTarget extends Attribute.GetPopulatableKeys<TSchemaUID>,
83
+ infer TKeysWithoutTarget extends Attribute.GetPopulatableKeys<TSchemaUID>
84
+ ]
85
+ ? Utils.Expression.If<
86
+ Utils.Expression.And<
87
+ Common.AreSchemaRegistriesExtended,
88
+ // If TSchemaUID === Common.UID.Schema, then ignore it and move to loose types
89
+ // Note: Currently, this only ignores TSchemaUID when it is equal to Common.UID.Schema, it won't work if Common.UID.(ContentType|Component) is passed as parameter
90
+ Utils.Expression.DoesNotExtends<Common.UID.Schema, TSchemaUID>
91
+ >,
92
+ // Populatable keys with a target
93
+ | Utils.Expression.If<
94
+ Utils.Expression.IsNotNever<TKeysWithTarget>,
95
+ PopulateClause<TSchemaUID, TKeysWithTarget>
96
+ >
97
+ // Populatable keys with either zero or multiple target(s)
98
+ | Utils.Expression.If<
99
+ Utils.Expression.IsNotNever<TKeysWithoutTarget>,
100
+ {
101
+ [TKey in TKeysWithoutTarget]?:
102
+ | boolean
103
+ | Fragment<
104
+ Utils.Guard.Never<Attribute.GetMorphTargets<TSchemaUID, TKey>, Common.UID.Schema>
105
+ >
106
+ // TODO: V5: Remove root-level nested params for morph data structures and only allow fragments
107
+ | NestedParams<Common.UID.Schema>;
108
+ }
109
+ >,
110
+ // Loose fallback when registries are not extended
111
+ | { [TKey in string]?: boolean | NestedParams<Common.UID.Schema> }
112
+ | {
113
+ [TKey in string]?:
114
+ | boolean
115
+ | Fragment<Common.UID.Schema>
116
+ // TODO: V5: Remove root-level nested params for morph data structures and only allow fragments
117
+ | NestedParams<Common.UID.Schema>;
118
+ }
119
+ >
120
+ : never;
121
+
122
+ export type NestedParams<TSchemaUID extends Common.UID.Schema> = EntityService.Params.Pick<
123
+ TSchemaUID,
124
+ 'fields' | 'filters' | 'populate' | 'sort' | 'plugin' | 'publicationState'
125
+ >;
126
+
127
+ export type Any<TSchemaUID extends Common.UID.Schema> =
128
+ | StringNotation<TSchemaUID>
129
+ | ArrayNotation<TSchemaUID>
130
+ | ObjectNotation<TSchemaUID>;
@@ -0,0 +1,38 @@
1
+ import type { Common, Utils } from '@strapi/strapi';
2
+
3
+ export type Kind = 'preview' | 'live';
4
+
5
+ export type IsEnabled<TSchemaUID extends Common.UID.Schema> = Utils.Expression.MatchFirst<
6
+ [
7
+ [
8
+ Common.UID.IsContentType<TSchemaUID>,
9
+ Utils.Expression.IsTrue<Common.Schemas[TSchemaUID]['options']['draftAndPublish']>
10
+ ],
11
+ [
12
+ // Here, we're manually excluding potential overlap between Component and ContentTypes' UIDs and thus preventing false positives
13
+ // e.g. api::foo.bar extends a Component UID (`${string}.${string}`) but shouldn't be considered a component
14
+ Utils.Expression.And<
15
+ Utils.Expression.Not<Utils.Expression.Extends<TSchemaUID, Common.UID.ContentType>>,
16
+ Common.UID.IsComponent<TSchemaUID>
17
+ >,
18
+ Utils.Expression.False
19
+ ]
20
+ ],
21
+ Utils.Expression.BooleanValue
22
+ >;
23
+
24
+ export type For<TSchemaUID extends Common.UID.Schema> = IsEnabled<TSchemaUID> extends infer TEnabled
25
+ ? Utils.Expression.If<
26
+ Utils.Expression.Or<
27
+ // If publication state is enabled for the given content type
28
+ Utils.Expression.IsTrue<TEnabled>,
29
+ // Or if the content type is not resolved (IsEnabled is BooleanValue)
30
+ // NOTE: The parameters order is important here ([true/false] extends [boolean] but [boolean] don't extend [true/false])
31
+ Utils.Expression.Extends<Utils.Expression.BooleanValue, TEnabled>
32
+ >,
33
+ // Then add the publicationState param
34
+ { publicationState?: Kind },
35
+ // Else, don't do anything
36
+ {}
37
+ >
38
+ : never;
@@ -0,0 +1 @@
1
+ export type Q = string;
@@ -0,0 +1,106 @@
1
+ import type { Attribute, Common, Utils } from '@strapi/strapi';
2
+
3
+ export module OrderKind {
4
+ export type Asc = 'asc';
5
+ export type Desc = 'desc';
6
+
7
+ export type Any = Asc | Desc;
8
+ }
9
+
10
+ /**
11
+ * Single non-populatable attribute representation
12
+ *
13
+ * @example
14
+ * type A = 'title'; // ✅
15
+ * type B = 'description'; // ✅
16
+ * type C = 'title:asc'; // ❌
17
+ * type D = 'title,description'; // ❌
18
+ */
19
+ type SingleAttribute<TSchemaUID extends Common.UID.Schema> =
20
+ | 'id'
21
+ | Utils.Guard.Never<string & Attribute.GetNonPopulatableKeys<TSchemaUID>, string>;
22
+
23
+ /**
24
+ * Ordered single non-populatable attribute representation
25
+ *
26
+ * @example
27
+ * type A = 'title:asc'; // ✅
28
+ * type B = 'description:desc'; // ✅
29
+ * type C = 'title'; // ❌
30
+ * type D = 'title,description'; // ❌
31
+ */
32
+ type OrderedSingleAttribute<TSchemaUID extends Common.UID.Schema> =
33
+ `${SingleAttribute<TSchemaUID>}:${OrderKind.Any}`;
34
+
35
+ /**
36
+ * Union of all possible string representation for a sort
37
+ *
38
+ * @example
39
+ * type A = 'title:asc'; // ✅
40
+ * type B = 'description:desc'; // ✅
41
+ * type C = 'title'; // ✅
42
+ * type D = 'title,description:asc'; // ✅
43
+ * type E = [42]; // ❌
44
+ * type F = { title: 'asc' }; // ❌
45
+ */
46
+ export type StringNotation<TSchemaUID extends Common.UID.Schema> =
47
+ | SingleAttribute<TSchemaUID>
48
+ | OrderedSingleAttribute<TSchemaUID>
49
+ // TODO: Loose type checking to avoid circular dependencies & infinite recursion
50
+ | `${string},${string}`;
51
+
52
+ /**
53
+ * Array notation for a sort
54
+ *
55
+ * @example
56
+ * type A = ['title:asc', 'description']; // ✅
57
+ * type B = ['title']; // ✅
58
+ * type C = ['count', 'title,description:asc']; // ✅
59
+ * type D = { title: 'asc' }; // ❌
60
+ * type E = [42]; // ❌
61
+ * type F = 'title'; // ❌
62
+ */
63
+ export type ArrayNotation<TSchemaUID extends Common.UID.Schema> = Any<TSchemaUID>[];
64
+
65
+ /**
66
+ * Object notation for a sort
67
+ *
68
+ * @example
69
+ * type A = { title: 'asc' }; // ✅
70
+ * type B = { title: 'asc', description: 'desc' }; // ✅
71
+ * type C = { title: 'asc', author: { name: 'asc' } }; // ✅
72
+ * type D = { author: { email: 'asc', role: { name: 'desc' } } }; // ✅
73
+ * type E = ['title']; // ❌
74
+ * type F = 'title'; // ❌
75
+ */
76
+ export type ObjectNotation<TSchemaUID extends Common.UID.Schema> = {
77
+ // First level sort
78
+ [key in SingleAttribute<TSchemaUID>]?: OrderKind.Any;
79
+ } & {
80
+ // Deep sort, only add populatable keys that have a
81
+ // target (remove dynamic zones and other polymorphic links)
82
+ [key in Attribute.GetKeysWithTarget<TSchemaUID>]?: ObjectNotation<
83
+ Attribute.GetTarget<TSchemaUID, key>
84
+ >;
85
+ };
86
+
87
+ /**
88
+ * Represents any notation for a sort (string, array, object)
89
+ *
90
+ * @example
91
+ * type A = 'title:asc'; // ✅
92
+ * type B = 'description:desc'; // ✅
93
+ * type C = 'title'; // ✅
94
+ * type D = 'title,description:asc'; // ✅
95
+ * type E = ['title:asc', 'description']; // ✅
96
+ * type F = ['title']; // ✅
97
+ * type G = ['count', 'title,description:asc']; // ✅
98
+ * type H = { title: 'asc' }; // ✅
99
+ * type I = { title: 'asc', description: 'desc' }; // ✅
100
+ * type J = { title: 'asc', author: { name: 'asc' } }; // ✅
101
+ * type K = { author: { email: 'asc', role: { name: 'desc' } } }; // ✅
102
+ */
103
+ export type Any<TSchemaUID extends Common.UID.Schema> =
104
+ | StringNotation<TSchemaUID>
105
+ | ArrayNotation<TSchemaUID>
106
+ | ObjectNotation<TSchemaUID>;
@@ -0,0 +1,11 @@
1
+ import type { Common, Plugin, Utils, Shared } from '@strapi/strapi';
2
+
3
+ export type GetPluginParams<TSchemaUID extends Common.UID.Schema> = Utils.Guard.OfTypes<
4
+ [never, undefined],
5
+ Utils.Object.Values<{
6
+ [TPluginName in keyof Shared.EntityServicePluginParams]: Shared.EntityServicePluginParams[TPluginName] extends infer TParam
7
+ ? Utils.Expression.If<Plugin.IsEnabled<TPluginName, TSchemaUID>, TParam>
8
+ : never;
9
+ }>,
10
+ unknown
11
+ >;
@@ -0,0 +1,205 @@
1
+ import type { Attribute, Common, EntityService, Utils } from '@strapi/strapi';
2
+
3
+ type Pagination = { page: number; pageSize: number; pageCount: number; total: number };
4
+
5
+ type AnyEntity = { id: EntityService.Params.Attribute.ID } & { [key: string]: any };
6
+
7
+ export type Result<
8
+ TSchemaUID extends Common.UID.Schema,
9
+ TParams extends EntityService.Params.Pick<TSchemaUID, 'fields' | 'populate'> = never
10
+ > = Utils.Expression.If<
11
+ Common.AreSchemaRegistriesExtended,
12
+ GetValues<
13
+ TSchemaUID,
14
+ Utils.Guard.Never<
15
+ ExtractFields<TSchemaUID, TParams['fields']>,
16
+ Attribute.GetNonPopulatableKeys<TSchemaUID>
17
+ >,
18
+ ExtractPopulate<TSchemaUID, TParams['populate']>
19
+ >,
20
+ AnyEntity
21
+ >;
22
+
23
+ export type Entity<
24
+ TSchemaUID extends Common.UID.Schema,
25
+ TParams extends EntityService.Params.Pick<TSchemaUID, 'fields' | 'populate'> = never
26
+ > = Utils.Expression.If<
27
+ Common.AreSchemaRegistriesExtended,
28
+ GetValues<
29
+ TSchemaUID,
30
+ Utils.Guard.Never<
31
+ ExtractFields<TSchemaUID, TParams['fields']>,
32
+ Attribute.GetNonPopulatableKeys<TSchemaUID>
33
+ >,
34
+ Utils.Guard.Never<
35
+ ExtractPopulate<TSchemaUID, TParams['populate']>,
36
+ Attribute.GetPopulatableKeys<TSchemaUID>
37
+ >
38
+ >,
39
+ AnyEntity
40
+ >;
41
+
42
+ export type PartialEntity<
43
+ TSchemaUID extends Common.UID.Schema,
44
+ TParams extends EntityService.Params.Pick<TSchemaUID, 'fields' | 'populate'> = never
45
+ > = Partial<Entity<TSchemaUID, TParams>>;
46
+
47
+ export type PaginatedResult<
48
+ TSchemaUID extends Common.UID.Schema,
49
+ TParams extends EntityService.Params.Pick<TSchemaUID, 'fields' | 'populate'> = never
50
+ > = {
51
+ results: Entity<TSchemaUID, TParams>[];
52
+ pagination: Pagination;
53
+ };
54
+
55
+ /**
56
+ * Attribute.GetValues override with extended values
57
+ *
58
+ * TODO: Make it recursive for populatable fields
59
+ */
60
+ export type GetValues<
61
+ TSchemaUID extends Common.UID.Schema,
62
+ TFields extends Attribute.GetKeys<TSchemaUID>,
63
+ TPopulate extends Attribute.GetKeys<TSchemaUID>
64
+ > = Utils.Expression.If<
65
+ Common.AreSchemaRegistriesExtended,
66
+ Utils.Guard.Never<TFields | TPopulate, Attribute.GetKeys<TSchemaUID>> extends infer TKeys
67
+ ? Attribute.GetValues<TSchemaUID, TKeys>
68
+ : never,
69
+ AnyEntity
70
+ >;
71
+
72
+ type ExtractFields<
73
+ TSchemaUID extends Common.UID.Schema,
74
+ TFields extends EntityService.Params.Fields.Any<TSchemaUID>
75
+ > = Utils.Expression.MatchFirst<
76
+ [
77
+ // No fields provided
78
+ [
79
+ Utils.Expression.Or<
80
+ Utils.Expression.StrictEqual<TFields, EntityService.Params.Fields.Any<TSchemaUID>>,
81
+ Utils.Expression.IsNever<TFields>
82
+ >,
83
+ never
84
+ ],
85
+ // string
86
+ [
87
+ Utils.Expression.Extends<TFields, EntityService.Params.Fields.StringNotation<TSchemaUID>>,
88
+ ParseStringFields<
89
+ TSchemaUID,
90
+ Utils.Cast<TFields, EntityService.Params.Fields.StringNotation<TSchemaUID>>
91
+ >
92
+ ],
93
+ // string array
94
+ [
95
+ Utils.Expression.Extends<TFields, EntityService.Params.Fields.ArrayNotation<TSchemaUID>>,
96
+ ParseStringFields<
97
+ TSchemaUID,
98
+ Utils.Cast<
99
+ Utils.Array.Values<
100
+ Utils.Cast<TFields, EntityService.Params.Fields.ArrayNotation<TSchemaUID>>
101
+ >,
102
+ EntityService.Params.Fields.StringNotation<TSchemaUID>
103
+ >
104
+ >
105
+ ]
106
+ ]
107
+ >;
108
+
109
+ type ParseStringFields<
110
+ TSchemaUID extends Common.UID.Schema,
111
+ TFields extends EntityService.Params.Fields.StringNotation<TSchemaUID>
112
+ > = Utils.Expression.MatchFirst<
113
+ [
114
+ [
115
+ Utils.Expression.StrictEqual<TFields, EntityService.Params.Fields.WildcardNotation>,
116
+ Attribute.GetNonPopulatableKeys<TSchemaUID>
117
+ ],
118
+ [
119
+ Utils.Expression.Extends<TFields, EntityService.Params.Fields.SingleAttribute<TSchemaUID>>,
120
+ TFields
121
+ ],
122
+ [
123
+ Utils.Expression.Extends<TFields, `${string},${string}`>,
124
+ Utils.Array.Values<Utils.String.Split<Utils.Cast<TFields, string>, ','>>
125
+ ]
126
+ ]
127
+ >;
128
+
129
+ type ExtractPopulate<
130
+ TSchemaUID extends Common.UID.Schema,
131
+ TPopulate extends EntityService.Params.Populate.Any<TSchemaUID>
132
+ > = Utils.Expression.MatchFirst<
133
+ [
134
+ // No populate provided
135
+ [
136
+ Utils.Expression.Or<
137
+ Utils.Expression.StrictEqual<TPopulate, EntityService.Params.Populate.Any<TSchemaUID>>,
138
+ Utils.Expression.IsNever<TPopulate>
139
+ >,
140
+ never
141
+ ],
142
+ // string notation
143
+ [
144
+ Utils.Expression.Extends<TPopulate, EntityService.Params.Populate.StringNotation<TSchemaUID>>,
145
+ ParseStringPopulate<
146
+ TSchemaUID,
147
+ Utils.Cast<TPopulate, EntityService.Params.Populate.StringNotation<TSchemaUID>>
148
+ >
149
+ ],
150
+ // Array notation
151
+ [
152
+ Utils.Expression.Extends<TPopulate, EntityService.Params.Populate.ArrayNotation<TSchemaUID>>,
153
+ ParseStringPopulate<
154
+ TSchemaUID,
155
+ Utils.Cast<
156
+ Utils.Array.Values<
157
+ Utils.Cast<TPopulate, EntityService.Params.Populate.ArrayNotation<TSchemaUID>>
158
+ >,
159
+ EntityService.Params.Populate.StringNotation<TSchemaUID>
160
+ >
161
+ >
162
+ ],
163
+ // object notation
164
+ [
165
+ Utils.Expression.Extends<TPopulate, EntityService.Params.Populate.ObjectNotation<TSchemaUID>>,
166
+ ParseStringPopulate<
167
+ TSchemaUID,
168
+ // TODO: Handle relations set to false in object notation
169
+ Utils.Cast<keyof TPopulate, EntityService.Params.Populate.StringNotation<TSchemaUID>>
170
+ >
171
+ ]
172
+ ]
173
+ >;
174
+
175
+ type ParsePopulateDotNotation<
176
+ TSchemaUID extends Common.UID.Schema,
177
+ TPopulate extends EntityService.Params.Populate.StringNotation<TSchemaUID>
178
+ > = Utils.String.Split<Utils.Cast<TPopulate, string>, '.'>[0];
179
+
180
+ type ParseStringPopulate<
181
+ TSchemaUID extends Common.UID.Schema,
182
+ TPopulate extends EntityService.Params.Populate.StringNotation<TSchemaUID>
183
+ > = Utils.Expression.MatchFirst<
184
+ [
185
+ [
186
+ Utils.Expression.StrictEqual<EntityService.Params.Populate.WildcardNotation, TPopulate>,
187
+ Attribute.GetPopulatableKeys<TSchemaUID>
188
+ ],
189
+ [
190
+ Utils.Expression.Extends<TPopulate, `${string},${string}`>,
191
+ ParsePopulateDotNotation<
192
+ TSchemaUID,
193
+ Utils.Cast<
194
+ Utils.Array.Values<Utils.String.Split<Utils.Cast<TPopulate, string>, ','>>,
195
+ EntityService.Params.Populate.StringNotation<TSchemaUID>
196
+ >
197
+ >
198
+ ],
199
+ [
200
+ Utils.Expression.Extends<TPopulate, `${string}.${string}`>,
201
+ ParsePopulateDotNotation<TSchemaUID, TPopulate>
202
+ ]
203
+ ],
204
+ TPopulate
205
+ >;
@@ -2,7 +2,7 @@
2
2
  * Strapi custom scalar types
3
3
  */
4
4
 
5
- import { Attribute, Common } from '@strapi/strapi';
5
+ import type { Attribute, Common } from '@strapi/strapi';
6
6
 
7
7
  /**
8
8
  * Setters for the attributes options
@@ -58,17 +58,20 @@ export type Any =
58
58
  | Attribute.JSON
59
59
  | Attribute.Media<Attribute.MediaKind | undefined, boolean>
60
60
  | Attribute.Password
61
- | (
62
- | Attribute.Relation<
63
- Common.UID.Schema,
64
- Attribute.RelationKind.BiDirectional,
65
- Common.UID.Schema
66
- >
67
- | Attribute.Relation<Common.UID.Schema, Attribute.RelationKind.UniDirectional>
68
- )
61
+ | Attribute.Relation<Common.UID.Schema, Attribute.RelationKind.Any, Common.UID.Schema>
69
62
  | Attribute.RichText
70
63
  | Attribute.String
71
64
  | Attribute.Text
72
65
  | Attribute.Time
73
66
  | Attribute.Timestamp
74
- | Attribute.UID<Common.UID.Schema | undefined>;
67
+ | Attribute.UID<Common.UID.Schema>;
68
+
69
+ export type PopulatableKind = Extract<
70
+ Attribute.Kind,
71
+ 'relation' | 'component' | 'dynamiczone' | 'media'
72
+ >;
73
+
74
+ export type NonPopulatableKind = Exclude<
75
+ Attribute.Kind,
76
+ 'relation' | 'component' | 'dynamiczone' | 'media'
77
+ >;
@@ -31,3 +31,6 @@ export type GetComponentValue<TAttribute extends Attribute.Attribute> =
31
31
  TAttribute extends Component<infer TComponentUID, infer TRepeatable>
32
32
  ? ComponentValue<TComponentUID, TRepeatable>
33
33
  : never;
34
+
35
+ export type GetComponentTarget<TAttribute extends Attribute.Attribute> =
36
+ TAttribute extends Component<infer TComponentUID, infer _TRepeatable> ? TComponentUID : never;
@@ -8,7 +8,8 @@ export type DateTime = Attribute.OfType<'datetime'> &
8
8
  Attribute.RequiredOption &
9
9
  Attribute.UniqueOption;
10
10
 
11
- export type DateTimeValue = string;
11
+ // TODO: Use string templates for date formats
12
+ export type DateTimeValue = globalThis.Date | string;
12
13
 
13
14
  export type GetDateTimeValue<T extends Attribute.Attribute> = T extends DateTime
14
15
  ? DateTimeValue
@@ -1,21 +1,21 @@
1
1
  import type { Utils, Attribute, Common } from '@strapi/strapi';
2
2
 
3
- export interface DynamicZoneProperties<TComponentsUIDs extends Common.UID.Component[]> {
4
- components: TComponentsUIDs;
3
+ export interface DynamicZoneProperties<TComponentsUID extends Common.UID.Component[]> {
4
+ components: TComponentsUID;
5
5
  }
6
6
 
7
- export type DynamicZone<TComponentsUIDs extends Common.UID.Component[] = Common.UID.Component[]> =
7
+ export type DynamicZone<TComponentsUID extends Common.UID.Component[] = Common.UID.Component[]> =
8
8
  Attribute.OfType<'dynamiczone'> &
9
9
  // Properties
10
- DynamicZoneProperties<TComponentsUIDs> &
10
+ DynamicZoneProperties<TComponentsUID> &
11
11
  // Options
12
12
  Attribute.ConfigurableOption &
13
13
  Attribute.MinMaxOption &
14
14
  Attribute.RequiredOption;
15
15
 
16
- type DynamicZoneValue<TComponentsUIDs extends Common.UID.Component[]> = Array<
16
+ type DynamicZoneValue<TComponentsUID extends Common.UID.Component[]> = Array<
17
17
  // Extract tuple values to a component uid union type
18
- Utils.Array.Values<TComponentsUIDs> extends infer TComponentUID
18
+ Utils.Array.Values<TComponentsUID> extends infer TComponentUID
19
19
  ? TComponentUID extends Common.UID.Component
20
20
  ? Attribute.GetValues<TComponentUID> & { __component: TComponentUID }
21
21
  : never
@@ -23,4 +23,7 @@ type DynamicZoneValue<TComponentsUIDs extends Common.UID.Component[]> = Array<
23
23
  >;
24
24
 
25
25
  export type GetDynamicZoneValue<TAttribute extends Attribute.Attribute> =
26
- TAttribute extends DynamicZone<infer TComponentsUIDs> ? DynamicZoneValue<TComponentsUIDs> : never;
26
+ TAttribute extends DynamicZone<infer TComponentsUID> ? DynamicZoneValue<TComponentsUID> : never;
27
+
28
+ export type GetDynamicZoneTargets<TAttribute extends Attribute.Attribute> =
29
+ TAttribute extends DynamicZone<infer TComponentsUID> ? Utils.Array.Values<TComponentsUID> : never;
@@ -1,5 +1,6 @@
1
1
  import type { Attribute, Utils } from '@strapi/strapi';
2
2
 
3
+ export type MediaTarget = 'plugin::upload.file';
3
4
  export type MediaKind = 'images' | 'videos' | 'files' | 'audios';
4
5
 
5
6
  export interface MediaProperties<
@@ -32,3 +33,10 @@ export type GetMediaValue<TAttribute extends Attribute.Attribute> = TAttribute e
32
33
  >
33
34
  ? MediaValue<TMultiple>
34
35
  : never;
36
+
37
+ export type GetMediaTarget<TAttribute extends Attribute.Attribute> = TAttribute extends Media<
38
+ infer _TKind,
39
+ infer _TMultiple
40
+ >
41
+ ? MediaTarget
42
+ : never;