@strapi/strapi 4.13.0-beta.0 → 4.13.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.
- package/README.md +13 -5
- package/lib/Strapi.js +11 -0
- package/lib/commands/actions/import/action.js +4 -4
- package/lib/commands/actions/import/command.js +1 -1
- package/lib/commands/actions/transfer/action.js +3 -6
- package/lib/commands/actions/transfer/command.js +1 -1
- package/lib/commands/actions/watch-admin/action.js +1 -1
- package/lib/commands/builders/admin.js +1 -1
- package/lib/commands/utils/data-transfer.js +39 -1
- package/lib/core/loaders/index.js +1 -0
- package/lib/core/loaders/plugins/get-enabled-plugins.js +40 -13
- package/lib/core/loaders/sanitizers.js +1 -1
- package/lib/core/loaders/validators.js +5 -0
- package/lib/core/registries/validators.js +26 -0
- package/lib/core-api/controller/collection-type.js +14 -8
- package/lib/core-api/controller/index.js +15 -3
- package/lib/core-api/controller/single-type.js +2 -0
- package/lib/factories.d.ts +10 -13
- package/lib/factories.js +12 -2
- package/lib/services/entity-service/index.d.ts +1 -100
- package/lib/services/entity-service/index.js +1 -0
- package/lib/services/entity-service/types/index.d.ts +228 -0
- package/lib/services/entity-service/types/params/attributes.d.ts +146 -0
- package/lib/services/entity-service/types/params/data.d.ts +4 -0
- package/lib/services/entity-service/types/params/fields.d.ts +74 -0
- package/lib/services/entity-service/types/params/filters/index.d.ts +75 -0
- package/lib/services/entity-service/types/params/filters/operators.d.ts +30 -0
- package/lib/services/entity-service/types/params/index.d.ts +79 -0
- package/lib/services/entity-service/types/params/pagination.d.ts +13 -0
- package/lib/services/entity-service/types/params/populate.d.ts +130 -0
- package/lib/services/entity-service/types/params/publication-state.d.ts +38 -0
- package/lib/services/entity-service/types/params/search.d.ts +1 -0
- package/lib/services/entity-service/types/params/sort.d.ts +106 -0
- package/lib/services/entity-service/types/plugin.d.ts +11 -0
- package/lib/services/entity-service/types/result.d.ts +205 -0
- package/lib/types/core/attributes/common.d.ts +13 -10
- package/lib/types/core/attributes/component.d.ts +3 -0
- package/lib/types/core/attributes/date-time.d.ts +2 -1
- package/lib/types/core/attributes/dynamic-zone.d.ts +10 -7
- package/lib/types/core/attributes/media.d.ts +8 -0
- package/lib/types/core/attributes/relation.d.ts +69 -28
- package/lib/types/core/attributes/time.d.ts +1 -1
- package/lib/types/core/attributes/timestamp.d.ts +1 -1
- package/lib/types/core/attributes/uid.d.ts +7 -17
- package/lib/types/core/attributes/utils.d.ts +61 -6
- package/lib/types/core/common/index.d.ts +12 -0
- package/lib/types/core/common/uid.d.ts +12 -16
- package/lib/types/core/index.d.ts +1 -0
- package/lib/types/core/plugins/index.d.ts +16 -0
- package/lib/types/core/schemas/index.d.ts +1 -0
- package/lib/types/core/strapi/index.d.ts +7 -2
- package/lib/types/core-api/controller.d.ts +12 -10
- package/lib/types/index.d.ts +2 -0
- package/lib/types/shared/entity-service.d.ts +1 -0
- package/lib/types/shared/index.d.ts +2 -0
- package/lib/types/shared/plugins.d.ts +3 -0
- package/lib/types/utils/expression.d.ts +29 -6
- package/lib/types/utils/guard.d.ts +14 -1
- package/lib/types/utils/index.d.ts +8 -0
- package/lib/types/utils/object.d.ts +35 -1
- package/lib/types/utils/string.d.ts +18 -0
- package/package.json +17 -16
|
@@ -5,53 +5,79 @@ export type Relation<
|
|
|
5
5
|
// on TTarget -> TOrigin relations. Due to errors because of Attribute.Any [relation] very generic
|
|
6
6
|
// representation, type mismatches were encountered and mappedBy/inversedBy are now regular strings.
|
|
7
7
|
// It is kept to allow for future iterations without breaking the current type API
|
|
8
|
-
|
|
8
|
+
_TOrigin extends Common.UID.Schema = Common.UID.Schema,
|
|
9
9
|
TRelationKind extends RelationKind.Any = RelationKind.Any,
|
|
10
10
|
TTarget extends Common.UID.Schema = never
|
|
11
11
|
> = Attribute.OfType<'relation'> &
|
|
12
12
|
// Properties
|
|
13
|
-
RelationProperties<
|
|
13
|
+
Utils.Guard.Never<RelationProperties<TRelationKind, TTarget>, AllRelationProperties<TTarget>> &
|
|
14
14
|
// Options
|
|
15
15
|
Attribute.ConfigurableOption &
|
|
16
16
|
Attribute.PrivateOption;
|
|
17
17
|
|
|
18
18
|
export type RelationProperties<
|
|
19
|
-
_TOrigin extends Common.UID.Schema,
|
|
20
19
|
TRelationKind extends RelationKind.Any,
|
|
21
20
|
TTarget extends Common.UID.Schema
|
|
22
21
|
> = Utils.Expression.MatchFirst<
|
|
23
22
|
[
|
|
24
|
-
|
|
23
|
+
[
|
|
25
24
|
Utils.Expression.Extends<TRelationKind, RelationKind.BiDirectional>,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
Utils.Expression.Test<
|
|
34
|
-
Utils.Expression.Extends<TRelationKind, RelationKind.UniDirectional>,
|
|
35
|
-
{ relation: TRelationKind }
|
|
36
|
-
>,
|
|
37
|
-
Utils.Expression.Test<
|
|
25
|
+
BiDirectionalProperties<Utils.Cast<TRelationKind, RelationKind.BiDirectional>, TTarget>
|
|
26
|
+
],
|
|
27
|
+
[
|
|
28
|
+
Utils.Expression.Extends<TRelationKind, RelationKind.XWay>,
|
|
29
|
+
XWayProperties<Utils.Cast<TRelationKind, RelationKind.XWay>, TTarget>
|
|
30
|
+
],
|
|
31
|
+
[
|
|
38
32
|
Utils.Expression.Extends<TRelationKind, RelationKind.MorphReference>,
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
>;
|
|
46
|
-
}
|
|
47
|
-
>
|
|
33
|
+
MorphReferenceProperties<Utils.Cast<TRelationKind, RelationKind.MorphReference>, TTarget>
|
|
34
|
+
],
|
|
35
|
+
[
|
|
36
|
+
Utils.Expression.Extends<TRelationKind, RelationKind.MorphOwner>,
|
|
37
|
+
MorphOwnerProperties<Utils.Cast<TRelationKind, RelationKind.MorphOwner>>
|
|
38
|
+
]
|
|
48
39
|
]
|
|
49
40
|
>;
|
|
50
41
|
|
|
42
|
+
export type AllRelationProperties<TTarget extends Common.UID.Schema> =
|
|
43
|
+
| BiDirectionalProperties<RelationKind.BiDirectional, TTarget>
|
|
44
|
+
| XWayProperties<RelationKind.XWay, TTarget>
|
|
45
|
+
| MorphReferenceProperties<RelationKind.MorphReference, TTarget>
|
|
46
|
+
| MorphOwnerProperties<RelationKind.MorphOwner>;
|
|
47
|
+
|
|
48
|
+
type BiDirectionalProperties<
|
|
49
|
+
TRelationKind extends RelationKind.BiDirectional,
|
|
50
|
+
TTarget extends Common.UID.Schema
|
|
51
|
+
> = {
|
|
52
|
+
relation: TRelationKind;
|
|
53
|
+
target: TTarget;
|
|
54
|
+
} & Utils.XOR<{ inversedBy?: string }, { mappedBy?: string }>;
|
|
55
|
+
|
|
56
|
+
type XWayProperties<TRelationKind extends RelationKind.XWay, TTarget extends Common.UID.Schema> = {
|
|
57
|
+
relation: TRelationKind;
|
|
58
|
+
target: TTarget;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
type MorphReferenceProperties<
|
|
62
|
+
TRelationKind extends RelationKind.MorphReference,
|
|
63
|
+
TTarget extends Common.UID.Schema
|
|
64
|
+
> = {
|
|
65
|
+
relation: TRelationKind;
|
|
66
|
+
target: TTarget;
|
|
67
|
+
morphBy?: Utils.Guard.Never<
|
|
68
|
+
Attribute.GetKeysByType<TTarget, 'relation', { relation: RelationKind.MorphOwner }>,
|
|
69
|
+
string
|
|
70
|
+
>;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
type MorphOwnerProperties<TRelationKind extends RelationKind.MorphOwner> = {
|
|
74
|
+
relation: TRelationKind;
|
|
75
|
+
};
|
|
76
|
+
|
|
51
77
|
export type RelationsKeysFromTo<
|
|
52
78
|
TTarget extends Common.UID.Schema,
|
|
53
79
|
TOrigin extends Common.UID.Schema
|
|
54
|
-
> = keyof PickRelationsFromTo<TTarget, TOrigin>;
|
|
80
|
+
> = Utils.Guard.Never<keyof PickRelationsFromTo<TTarget, TOrigin>, string>;
|
|
55
81
|
|
|
56
82
|
export type PickRelationsFromTo<
|
|
57
83
|
TTarget extends Common.UID.Schema,
|
|
@@ -76,6 +102,14 @@ export type GetRelationValue<TAttribute extends Attribute.Attribute> = TAttribut
|
|
|
76
102
|
? RelationValue<TRelationKind, TTarget>
|
|
77
103
|
: never;
|
|
78
104
|
|
|
105
|
+
export type GetRelationTarget<TAttribute extends Attribute.Attribute> = TAttribute extends Relation<
|
|
106
|
+
infer _TOrigin,
|
|
107
|
+
infer _TRelationKind,
|
|
108
|
+
infer TTarget
|
|
109
|
+
>
|
|
110
|
+
? TTarget
|
|
111
|
+
: never;
|
|
112
|
+
|
|
79
113
|
export module RelationKind {
|
|
80
114
|
type GetOppositePlurality<TPlurality extends RelationKind.Left | RelationKind.Right> = {
|
|
81
115
|
one: 'many';
|
|
@@ -96,9 +130,16 @@ export module RelationKind {
|
|
|
96
130
|
export type XWay = `${RelationKind.Left}Way`;
|
|
97
131
|
|
|
98
132
|
export type BiDirectional = `${RelationKind.Left}To${RelationKind.Right}`;
|
|
99
|
-
export type UniDirectional = RelationKind.
|
|
133
|
+
export type UniDirectional = RelationKind.MorphReference | RelationKind.XWay;
|
|
134
|
+
|
|
135
|
+
export type Any = RelationKind.BiDirectional | RelationKind.Morph | RelationKind.XWay;
|
|
136
|
+
|
|
137
|
+
export type WithTarget =
|
|
138
|
+
| RelationKind.BiDirectional
|
|
139
|
+
| RelationKind.XWay
|
|
140
|
+
| RelationKind.MorphReference;
|
|
100
141
|
|
|
101
|
-
export type
|
|
142
|
+
export type WithoutTarget = RelationKind.MorphOwner;
|
|
102
143
|
|
|
103
144
|
export type Reverse<TRelationKind extends RelationKind.Any> =
|
|
104
145
|
TRelationKind extends `${infer TLeft extends RelationKind.Left}To${infer TRight extends RelationKind.Right}`
|
|
@@ -8,6 +8,6 @@ export type Time = Attribute.OfType<'time'> &
|
|
|
8
8
|
Attribute.RequiredOption &
|
|
9
9
|
Attribute.UniqueOption;
|
|
10
10
|
|
|
11
|
-
export type TimeValue = string;
|
|
11
|
+
export type TimeValue = globalThis.Date | string;
|
|
12
12
|
|
|
13
13
|
export type GetTimeValue<T extends Attribute.Attribute> = T extends Time ? TimeValue : never;
|
|
@@ -8,7 +8,7 @@ export type Timestamp = Attribute.OfType<'timestamp'> &
|
|
|
8
8
|
Attribute.RequiredOption &
|
|
9
9
|
Attribute.UniqueOption;
|
|
10
10
|
|
|
11
|
-
export type TimestampValue = string;
|
|
11
|
+
export type TimestampValue = globalThis.Date | number | string;
|
|
12
12
|
|
|
13
13
|
export type GetTimestampValue<T extends Attribute.Attribute> = T extends Timestamp
|
|
14
14
|
? TimestampValue
|
|
@@ -9,28 +9,23 @@ export interface UIDOptions {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export interface UIDProperties<
|
|
12
|
-
|
|
13
|
-
TTargetAttribute extends AllowedTargetAttributes<TOrigin>,
|
|
12
|
+
TTargetAttribute extends string = string,
|
|
14
13
|
TOptions extends UIDOptions = UIDOptions
|
|
15
14
|
> {
|
|
16
15
|
targetField: TTargetAttribute;
|
|
17
16
|
options: UIDOptions & TOptions;
|
|
18
17
|
}
|
|
19
18
|
|
|
20
|
-
export interface GenericUIDProperties<TOptions extends UIDOptions = UIDOptions> {
|
|
21
|
-
targetField?: string;
|
|
22
|
-
options: TOptions & UIDOptions;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
19
|
export type UID<
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
// TODO: V5:
|
|
21
|
+
// The TOrigin was used to narrow down the list of possible target attribute for a
|
|
22
|
+
// UID, but was removed due to circular dependency issues and will be removed in V5
|
|
23
|
+
_TOrigin extends Common.UID.Schema = never,
|
|
24
|
+
TTargetAttribute extends string = string,
|
|
28
25
|
TOptions extends UIDOptions = UIDOptions
|
|
29
26
|
> = Attribute.OfType<'uid'> &
|
|
30
27
|
// Properties
|
|
31
|
-
|
|
32
|
-
? UIDProperties<TOrigin, TTargetAttribute, TOptions>
|
|
33
|
-
: GenericUIDProperties<TOptions>) &
|
|
28
|
+
UIDProperties<TTargetAttribute, TOptions> &
|
|
34
29
|
// Options
|
|
35
30
|
Attribute.ConfigurableOption &
|
|
36
31
|
Attribute.DefaultOption<UIDValue> &
|
|
@@ -38,11 +33,6 @@ export type UID<
|
|
|
38
33
|
Attribute.PrivateOption &
|
|
39
34
|
Attribute.RequiredOption;
|
|
40
35
|
|
|
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;
|
|
45
|
-
|
|
46
36
|
export type UIDValue = string;
|
|
47
37
|
|
|
48
38
|
export type GetUIDValue<TAttribute extends Attribute.Attribute> = TAttribute extends UID<
|
|
@@ -28,9 +28,42 @@ export type GetAll<TSchemaUID extends Common.UID.Schema> = Utils.Get<
|
|
|
28
28
|
'attributes'
|
|
29
29
|
>;
|
|
30
30
|
|
|
31
|
+
export type GetTarget<TSchemaUID extends Common.UID.Schema, TKey extends GetKeys<TSchemaUID>> = Get<
|
|
32
|
+
TSchemaUID,
|
|
33
|
+
TKey
|
|
34
|
+
> extends infer TAttribute extends Attribute.Attribute
|
|
35
|
+
?
|
|
36
|
+
| Attribute.GetRelationTarget<TAttribute>
|
|
37
|
+
| Attribute.GetComponentTarget<TAttribute>
|
|
38
|
+
| Attribute.GetMediaTarget<TAttribute>
|
|
39
|
+
: never;
|
|
40
|
+
|
|
41
|
+
export type GetMorphTargets<
|
|
42
|
+
TSchemaUID extends Common.UID.Schema,
|
|
43
|
+
TKey extends GetKeys<TSchemaUID>
|
|
44
|
+
> = Get<TSchemaUID, TKey> extends infer TAttribute extends Attribute.Attribute
|
|
45
|
+
? Attribute.GetDynamicZoneTargets<TAttribute>
|
|
46
|
+
: never;
|
|
47
|
+
|
|
31
48
|
export type GetKeys<TSchemaUID extends Common.UID.Schema> = keyof GetAll<TSchemaUID>;
|
|
32
49
|
|
|
33
|
-
export type
|
|
50
|
+
export type GetNonPopulatableKeys<TSchemaUID extends Common.UID.Schema> = GetKeysByType<
|
|
51
|
+
TSchemaUID,
|
|
52
|
+
Attribute.NonPopulatableKind
|
|
53
|
+
>;
|
|
54
|
+
|
|
55
|
+
export type GetPopulatableKeys<TSchemaUID extends Common.UID.Schema> = GetKeysByType<
|
|
56
|
+
TSchemaUID,
|
|
57
|
+
Attribute.PopulatableKind
|
|
58
|
+
>;
|
|
59
|
+
|
|
60
|
+
export type GetKeysWithTarget<TSchemaUID extends Common.UID.Schema> = keyof {
|
|
61
|
+
[key in GetKeys<TSchemaUID> as GetTarget<TSchemaUID, key> extends never ? never : key]: never;
|
|
62
|
+
} extends infer TKey extends GetKeys<TSchemaUID>
|
|
63
|
+
? TKey
|
|
64
|
+
: never;
|
|
65
|
+
|
|
66
|
+
export type GetValue<TAttribute extends Attribute.Attribute, TGuard = unknown> = Utils.Guard.Never<
|
|
34
67
|
| Attribute.GetBigIntegerValue<TAttribute>
|
|
35
68
|
| Attribute.GetBooleanValue<TAttribute>
|
|
36
69
|
| Attribute.GetComponentValue<TAttribute>
|
|
@@ -51,7 +84,9 @@ export type GetValue<TAttribute extends Attribute.Attribute> =
|
|
|
51
84
|
| Attribute.GetDateValue<TAttribute>
|
|
52
85
|
| Attribute.GetDateTimeValue<TAttribute>
|
|
53
86
|
| Attribute.GetTimeValue<TAttribute>
|
|
54
|
-
| Attribute.GetTimestampValue<TAttribute
|
|
87
|
+
| Attribute.GetTimestampValue<TAttribute>,
|
|
88
|
+
TGuard
|
|
89
|
+
>;
|
|
55
90
|
|
|
56
91
|
export type GetValueByKey<
|
|
57
92
|
TSchemaUID extends Common.UID.Schema,
|
|
@@ -63,7 +98,7 @@ export type GetValueByKey<
|
|
|
63
98
|
export type GetValues<
|
|
64
99
|
TSchemaUID extends Common.UID.Schema,
|
|
65
100
|
TKey extends GetKeys<TSchemaUID> = GetKeys<TSchemaUID>
|
|
66
|
-
> = {
|
|
101
|
+
> = { id: number | `${number}` } & {
|
|
67
102
|
// Handle required attributes
|
|
68
103
|
[key in GetRequiredKeys<TSchemaUID> as key extends TKey ? key : never]-?: GetValueByKey<
|
|
69
104
|
TSchemaUID,
|
|
@@ -79,10 +114,30 @@ export type GetValues<
|
|
|
79
114
|
|
|
80
115
|
export type GetRequiredKeys<TSchemaUID extends Common.UID.Schema> = Utils.Object.KeysBy<
|
|
81
116
|
GetAll<TSchemaUID>,
|
|
82
|
-
|
|
117
|
+
Attribute.Required
|
|
83
118
|
>;
|
|
84
119
|
|
|
85
|
-
export type GetOptionalKeys<TSchemaUID extends Common.UID.Schema> =
|
|
120
|
+
export type GetOptionalKeys<TSchemaUID extends Common.UID.Schema> = Utils.Object.KeysExcept<
|
|
86
121
|
GetAll<TSchemaUID>,
|
|
87
|
-
|
|
122
|
+
Attribute.Required
|
|
88
123
|
>;
|
|
124
|
+
|
|
125
|
+
export type HasTarget<
|
|
126
|
+
TSchemaUID extends Common.UID.Schema,
|
|
127
|
+
TField extends Attribute.GetKeys<TSchemaUID>
|
|
128
|
+
> = GetTarget<TSchemaUID, TField> extends infer TTarget
|
|
129
|
+
? Utils.Expression.And<
|
|
130
|
+
Utils.Expression.IsNotNever<TTarget>,
|
|
131
|
+
Utils.Expression.Extends<TTarget, Common.UID.Schema>
|
|
132
|
+
>
|
|
133
|
+
: Utils.Expression.False;
|
|
134
|
+
|
|
135
|
+
export type HasMorphTargets<
|
|
136
|
+
TSchemaUID extends Common.UID.Schema,
|
|
137
|
+
TField extends Attribute.GetKeys<TSchemaUID>
|
|
138
|
+
> = GetMorphTargets<TSchemaUID, TField> extends infer TMaybeTargets
|
|
139
|
+
? Utils.Expression.And<
|
|
140
|
+
Utils.Expression.IsNotNever<TMaybeTargets>,
|
|
141
|
+
Utils.Expression.Extends<TMaybeTargets, Common.UID.Schema>
|
|
142
|
+
>
|
|
143
|
+
: Utils.Expression.False;
|
|
@@ -1,4 +1,16 @@
|
|
|
1
|
+
import type { Attribute, Common, Utils } from '@strapi/strapi';
|
|
2
|
+
|
|
1
3
|
export * from './controller';
|
|
2
4
|
export * from './service';
|
|
3
5
|
export * from './schema';
|
|
4
6
|
export * as UID from './uid';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Determines if the shared registries for components and content types have been extended or if they're still represented as loose mapped types
|
|
10
|
+
*
|
|
11
|
+
* Here we use the fact that once the registries are extended, Attribute.GetKeys<Common.UID.Schema> will resolve to either never or a more
|
|
12
|
+
* deterministic value rather than string | number which represent the keys of the initial mapped type (Component & ContentType's registries)
|
|
13
|
+
*/
|
|
14
|
+
export type AreSchemaRegistriesExtended = Utils.Expression.Not<
|
|
15
|
+
Utils.Expression.Extends<string | number, Attribute.GetKeys<Common.UID.Schema>>
|
|
16
|
+
>;
|
|
@@ -41,22 +41,18 @@ export type Schema = Registry.Keys<
|
|
|
41
41
|
UID.ContentType | UID.Component<ComponentCategory>
|
|
42
42
|
>;
|
|
43
43
|
|
|
44
|
-
export type IsCollectionType<
|
|
45
|
-
Shared.ContentTypes[
|
|
46
|
-
|
|
47
|
-
>;
|
|
44
|
+
export type IsCollectionType<TSchemaUID extends Schema> = TSchemaUID extends CollectionType
|
|
45
|
+
? Utils.Expression.Extends<Shared.ContentTypes[TSchemaUID], SchemaNamespace.CollectionType>
|
|
46
|
+
: Utils.Expression.False;
|
|
48
47
|
|
|
49
|
-
export type IsSingleType<
|
|
50
|
-
Shared.ContentTypes[
|
|
51
|
-
|
|
52
|
-
>;
|
|
48
|
+
export type IsSingleType<TSchemaUID extends Schema> = TSchemaUID extends SingleType
|
|
49
|
+
? Utils.Expression.Extends<Shared.ContentTypes[TSchemaUID], SchemaNamespace.SingleType>
|
|
50
|
+
: Utils.Expression.False;
|
|
53
51
|
|
|
54
|
-
export type IsComponent<
|
|
55
|
-
Shared.Components[
|
|
56
|
-
|
|
57
|
-
>;
|
|
52
|
+
export type IsComponent<TSchemaUID extends Schema> = TSchemaUID extends Component
|
|
53
|
+
? Utils.Expression.Extends<Shared.Components[TSchemaUID], SchemaNamespace.Component>
|
|
54
|
+
: Utils.Expression.False;
|
|
58
55
|
|
|
59
|
-
export type IsContentType<
|
|
60
|
-
IsCollectionType<
|
|
61
|
-
|
|
62
|
-
>;
|
|
56
|
+
export type IsContentType<TSchemaUID extends Schema> = TSchemaUID extends ContentType
|
|
57
|
+
? Utils.Expression.Or<IsCollectionType<TSchemaUID>, IsSingleType<TSchemaUID>>
|
|
58
|
+
: Utils.Expression.False;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Common, Shared, Utils } from '@strapi/strapi';
|
|
2
|
+
|
|
3
|
+
export type IsEnabled<
|
|
4
|
+
TName extends keyof any,
|
|
5
|
+
TSchemaUID extends Common.UID.Schema
|
|
6
|
+
> = TName extends keyof Shared.PluginActivation
|
|
7
|
+
? Shared.PluginActivation[TName] extends infer TRule
|
|
8
|
+
? Utils.Expression.Or<
|
|
9
|
+
Utils.Expression.Not<Common.AreSchemaRegistriesExtended>,
|
|
10
|
+
Utils.Expression.Extends<
|
|
11
|
+
Common.Schemas[TSchemaUID]['pluginOptions'],
|
|
12
|
+
{ [key in TName]: TRule }
|
|
13
|
+
>
|
|
14
|
+
>
|
|
15
|
+
: false
|
|
16
|
+
: false;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Database } from '@strapi/database';
|
|
2
|
-
import type {
|
|
2
|
+
import type { Comomn, EntityService, Shared } from '@strapi/strapi';
|
|
3
3
|
|
|
4
4
|
// TODO move custom fields types to a separate file
|
|
5
5
|
interface CustomFieldServerOptions {
|
|
@@ -65,6 +65,11 @@ export interface Strapi {
|
|
|
65
65
|
*/
|
|
66
66
|
readonly sanitizers: any;
|
|
67
67
|
|
|
68
|
+
/**
|
|
69
|
+
* Getter for the Strapi validators container
|
|
70
|
+
*/
|
|
71
|
+
readonly validators: any;
|
|
72
|
+
|
|
68
73
|
/**
|
|
69
74
|
* Getter for the Strapi services container
|
|
70
75
|
*
|
|
@@ -412,7 +417,7 @@ export interface Strapi {
|
|
|
412
417
|
/**
|
|
413
418
|
* Entity Service instance
|
|
414
419
|
*/
|
|
415
|
-
entityService:
|
|
420
|
+
entityService: EntityService.EntityService;
|
|
416
421
|
}
|
|
417
422
|
|
|
418
423
|
export interface Lifecycles {
|
|
@@ -11,34 +11,36 @@ export interface Base {
|
|
|
11
11
|
transformResponse<TData, TResponse>(data: TData, meta: object): TResponse;
|
|
12
12
|
sanitizeOutput<TData>(data: TData, ctx: ExtendableContext): Promise<TData>;
|
|
13
13
|
sanitizeInput<TData>(data: TData, ctx: ExtendableContext): Promise<TData>;
|
|
14
|
-
sanitizeQuery<TData>(
|
|
14
|
+
sanitizeQuery<TData>(ctx: ExtendableContext): Promise<TData>;
|
|
15
|
+
validateInput<TData>(data: TData, ctx: ExtendableContext): Promise<TData>;
|
|
16
|
+
validateQuery<TData>(ctx: ExtendableContext): Promise<TData>;
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
/**
|
|
18
20
|
* Generic controller structure
|
|
19
21
|
*/
|
|
20
22
|
export type Generic = {
|
|
21
|
-
[name: string]: Common.ControllerHandler
|
|
23
|
+
[name: string]: Common.ControllerHandler;
|
|
22
24
|
};
|
|
23
25
|
|
|
24
26
|
/**
|
|
25
27
|
* Core-API collection type controller
|
|
26
28
|
*/
|
|
27
29
|
export interface CollectionType extends Base {
|
|
28
|
-
find?: Common.ControllerHandler
|
|
29
|
-
findOne?: Common.ControllerHandler
|
|
30
|
-
create?: Common.ControllerHandler
|
|
31
|
-
update?: Common.ControllerHandler
|
|
32
|
-
delete?: Common.ControllerHandler
|
|
30
|
+
find?: Common.ControllerHandler;
|
|
31
|
+
findOne?: Common.ControllerHandler;
|
|
32
|
+
create?: Common.ControllerHandler;
|
|
33
|
+
update?: Common.ControllerHandler;
|
|
34
|
+
delete?: Common.ControllerHandler;
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
/**
|
|
36
38
|
* Core-API single type controller
|
|
37
39
|
*/
|
|
38
40
|
export interface SingleType extends Base {
|
|
39
|
-
find?: Common.ControllerHandler
|
|
40
|
-
update?: Common.ControllerHandler
|
|
41
|
-
delete?: Common.ControllerHandler
|
|
41
|
+
find?: Common.ControllerHandler;
|
|
42
|
+
update?: Common.ControllerHandler;
|
|
43
|
+
delete?: Common.ControllerHandler;
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
export type ContentType<T extends Common.UID.ContentType> = Utils.Expression.MatchFirst<
|
package/lib/types/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export interface EntityServicePluginParams {}
|
|
@@ -4,8 +4,20 @@ export type True = true;
|
|
|
4
4
|
export type False = false;
|
|
5
5
|
export type BooleanValue = True | False;
|
|
6
6
|
|
|
7
|
+
export type IsNever<TValue> = StrictEqual<TValue, never>;
|
|
8
|
+
|
|
9
|
+
export type IsNotNever<TValue> = Not<IsNever<TValue>>;
|
|
10
|
+
|
|
11
|
+
export type IsTrue<TValue> = [TValue] extends [True] ? True : False;
|
|
12
|
+
|
|
13
|
+
export type IsFalse<TValue> = [TValue] extends [False] ? True : False;
|
|
14
|
+
|
|
15
|
+
export type StrictEqual<TValue, TMatch> = And<Extends<TValue, TMatch>, Extends<TMatch, TValue>>;
|
|
16
|
+
|
|
7
17
|
export type Extends<TLeft, TRight> = [TLeft] extends [TRight] ? True : False;
|
|
8
18
|
|
|
19
|
+
export type DoesNotExtends<TLeft, TRight> = Not<Extends<TLeft, TRight>>;
|
|
20
|
+
|
|
9
21
|
export type Not<TExpression extends BooleanValue> = If<TExpression, False, True>;
|
|
10
22
|
|
|
11
23
|
export type If<TExpression extends BooleanValue, TOnTrue, TOnFalse = never> = [
|
|
@@ -27,18 +39,30 @@ export type MatchFirst<TTests extends Test[], TDefault = never> = TTests extends
|
|
|
27
39
|
: never
|
|
28
40
|
: never;
|
|
29
41
|
|
|
30
|
-
export type
|
|
42
|
+
export type MatchAllUnion<TTests extends Test[], TDefault = never> = TTests extends [
|
|
31
43
|
infer THead extends Test,
|
|
32
44
|
...infer TTail extends Test[]
|
|
33
45
|
]
|
|
34
46
|
? THead extends Test<infer TExpression, infer TValue>
|
|
35
47
|
? Utils.Guard.Never<
|
|
36
|
-
If<TExpression, TValue> | If<Utils.Array.IsNotEmpty<TTail>,
|
|
48
|
+
If<TExpression, TValue> | If<Utils.Array.IsNotEmpty<TTail>, MatchAllUnion<TTail, TDefault>>,
|
|
37
49
|
TDefault
|
|
38
50
|
>
|
|
39
51
|
: never
|
|
40
52
|
: never;
|
|
41
53
|
|
|
54
|
+
export type MatchAllIntersect<TTests extends Test[], TDefault = unknown> = TTests extends [
|
|
55
|
+
infer THead extends Test,
|
|
56
|
+
...infer TTail extends Test[]
|
|
57
|
+
]
|
|
58
|
+
? THead extends Test<infer TExpression, infer TValue>
|
|
59
|
+
? // Actual test case evaluation
|
|
60
|
+
If<TExpression, TValue, TDefault> &
|
|
61
|
+
// Recursion / End of recursion
|
|
62
|
+
If<Utils.Array.IsNotEmpty<TTail>, MatchAllIntersect<TTail, TDefault>, TDefault>
|
|
63
|
+
: TDefault
|
|
64
|
+
: TDefault;
|
|
65
|
+
|
|
42
66
|
export type Test<TExpression extends BooleanValue = BooleanValue, TValue = unknown> = [
|
|
43
67
|
TExpression,
|
|
44
68
|
TValue
|
|
@@ -58,11 +82,10 @@ export type Every<TExpressions extends BooleanValue[]> = TExpressions extends [
|
|
|
58
82
|
? If<Utils.Array.IsNotEmpty<TTail>, And<THead, Every<TTail>>, And<THead, True>>
|
|
59
83
|
: never;
|
|
60
84
|
|
|
61
|
-
export type And<TLeft extends BooleanValue, TRight extends BooleanValue> =
|
|
62
|
-
|
|
63
|
-
True
|
|
85
|
+
export type And<TLeft extends BooleanValue, TRight extends BooleanValue> = IsTrue<
|
|
86
|
+
IsTrue<TLeft> | IsTrue<TRight>
|
|
64
87
|
>;
|
|
65
88
|
|
|
66
89
|
export type Or<TLeft extends BooleanValue, TRight extends BooleanValue> = Not<
|
|
67
|
-
|
|
90
|
+
IsFalse<IsTrue<TLeft> | IsTrue<TRight>>
|
|
68
91
|
>;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { Utils } from '@strapi/strapi';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Assign a default value `TDefault` to `TValue` if `TValue` is of type `never`
|
|
3
5
|
*
|
|
@@ -11,4 +13,15 @@
|
|
|
11
13
|
* type X = Never<never, string>
|
|
12
14
|
* // string
|
|
13
15
|
*/
|
|
14
|
-
export type Never<TValue,
|
|
16
|
+
export type Never<TValue, TFallback = unknown> = OfTypes<[never], TValue, TFallback>;
|
|
17
|
+
|
|
18
|
+
export type OfTypes<TTypes extends unknown[], TValue, TFallback = unknown> = TTypes extends [
|
|
19
|
+
infer THead extends unknown,
|
|
20
|
+
...infer TTail extends unknown[]
|
|
21
|
+
]
|
|
22
|
+
? Utils.Expression.If<
|
|
23
|
+
Utils.Expression.StrictEqual<TValue, THead>,
|
|
24
|
+
TFallback,
|
|
25
|
+
Utils.Expression.If<Utils.Array.IsNotEmpty<TTail>, OfTypes<TTail, TValue, TFallback>, TValue>
|
|
26
|
+
>
|
|
27
|
+
: never;
|
|
@@ -17,3 +17,11 @@ export * as Expression from './expression';
|
|
|
17
17
|
* // 'foo'
|
|
18
18
|
*/
|
|
19
19
|
export type Get<TValue, TKey extends keyof TValue> = TValue[TKey];
|
|
20
|
+
|
|
21
|
+
export type Without<TLeft, TRight> = { [key in Exclude<keyof TLeft, keyof TRight>]?: never };
|
|
22
|
+
|
|
23
|
+
export type XOR<TLeft, TRight> = TLeft | TRight extends object
|
|
24
|
+
? (Without<TLeft, TRight> & TRight) | (Without<TRight, TLeft> & TLeft)
|
|
25
|
+
: TLeft | TRight;
|
|
26
|
+
|
|
27
|
+
export type Cast<TValue, TType> = TValue extends TType ? TValue : never;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Retrieve object's (`TValue`) keys if they
|
|
2
|
+
* Retrieve object's (`TValue`) keys if they extend the given `TTest` type.
|
|
3
3
|
*
|
|
4
4
|
* @example
|
|
5
5
|
* type X = KeysBy<{ foo: 'bar', bar: 'foo', foobar: 2 }, string>
|
|
@@ -14,6 +14,22 @@ export type KeysBy<TValue, TTest> = {
|
|
|
14
14
|
[key in keyof TValue]: TValue[key] extends TTest ? key : never;
|
|
15
15
|
}[keyof TValue];
|
|
16
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Retrieve object's (`TValue`) keys if they don't extend the given `TTest` type.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* type X = KeysExcept<{ foo: 'bar', bar: 'foo', foobar: 2 }, string>
|
|
22
|
+
* // foobar
|
|
23
|
+
*
|
|
24
|
+
* type Base = { x: 'foo' | 'bar' };
|
|
25
|
+
* type Obj = { foo: { x: 'foo' }, bar: { x: 'bar' }, other: { x: '42' } };
|
|
26
|
+
* type X = KeysBy<Obj, Base>
|
|
27
|
+
* // 'other'
|
|
28
|
+
*/
|
|
29
|
+
export type KeysExcept<TValue, TTest> = {
|
|
30
|
+
[key in keyof TValue]: TValue[key] extends TTest ? never : key;
|
|
31
|
+
}[keyof TValue];
|
|
32
|
+
|
|
17
33
|
/**
|
|
18
34
|
* Retrieve object's (`TValue`) properties if their value extends the given `TTest` type.
|
|
19
35
|
*
|
|
@@ -27,3 +43,21 @@ export type KeysBy<TValue, TTest> = {
|
|
|
27
43
|
* // { foo: { x: 'foo' }, bar: { x: 'bar' } }
|
|
28
44
|
*/
|
|
29
45
|
export type PickBy<TValue, TTest> = Pick<TValue, KeysBy<TValue, TTest>>;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Retrieve object's (`TObject`) values
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* type X = Values<{ foo: 'bar', bar: 'foo', foobar: 2 }>
|
|
52
|
+
* // 'bar' | 'foo' | 2
|
|
53
|
+
*
|
|
54
|
+
* type Y = Values<{ foo: { x: 'foo' }, bar: { x: 'bar' }, other: { x: '42' } }>
|
|
55
|
+
* // { x: 'foo' } | { x: 'bar' } | { x: '42' }
|
|
56
|
+
*/
|
|
57
|
+
export type Values<TObject extends object> = TObject[keyof TObject];
|
|
58
|
+
|
|
59
|
+
export type DeepPartial<TObject> = TObject extends object
|
|
60
|
+
? {
|
|
61
|
+
[TKey in keyof TObject]?: DeepPartial<TObject[TKey]>;
|
|
62
|
+
}
|
|
63
|
+
: TObject;
|