@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
@@ -0,0 +1,167 @@
1
+ import type * as Namespace from './namespace';
2
+ import type * as Utils from '../utils';
3
+
4
+ type StringSuffix<T extends string> = Utils.String.Suffix<T, string>;
5
+
6
+ /**
7
+ * Template for services' unique identifier
8
+ */
9
+ export type Service = StringSuffix<
10
+ | Namespace.WithSeparator<Namespace.Admin>
11
+ | Namespace.WithSeparator<Namespace.API>
12
+ | Namespace.WithSeparator<Namespace.Plugin>
13
+ >;
14
+
15
+ /**
16
+ * Template for controllers' unique identifier
17
+ */
18
+ export type Controller = StringSuffix<
19
+ | Namespace.WithSeparator<Namespace.Admin>
20
+ | Namespace.WithSeparator<Namespace.API>
21
+ | Namespace.WithSeparator<Namespace.Plugin>
22
+ >;
23
+
24
+ /**
25
+ * Template for policies' unique identifier
26
+ */
27
+ export type Policy = StringSuffix<
28
+ | Namespace.WithSeparator<Namespace.Admin>
29
+ | Namespace.WithSeparator<Namespace.Strapi>
30
+ | Namespace.WithSeparator<Namespace.Global>
31
+ | Namespace.WithSeparator<Namespace.API>
32
+ | Namespace.WithSeparator<Namespace.Plugin>
33
+ >;
34
+
35
+ /**
36
+ * Template for middlewares' unique identifier
37
+ */
38
+ export type Middleware = StringSuffix<
39
+ | Namespace.WithSeparator<Namespace.Admin>
40
+ | Namespace.WithSeparator<Namespace.Strapi>
41
+ | Namespace.WithSeparator<Namespace.Global>
42
+ | Namespace.WithSeparator<Namespace.API>
43
+ | Namespace.WithSeparator<Namespace.Plugin>
44
+ >;
45
+
46
+ /**
47
+ * Template for content-types' unique identifier
48
+ */
49
+ export type ContentType = StringSuffix<
50
+ | Namespace.WithSeparator<Namespace.Admin>
51
+ | Namespace.WithSeparator<Namespace.Strapi>
52
+ | Namespace.WithSeparator<Namespace.API>
53
+ | Namespace.WithSeparator<Namespace.Plugin>
54
+ >;
55
+
56
+ /**
57
+ * Template for components' unique identifier
58
+ *
59
+ * @example
60
+ * 'default.foo' extends Component => true (T = 'default', N = 'foo')
61
+ *
62
+ * @example
63
+ * // /!\ Warning: Can cause overlap with other UID formats:
64
+ * // 'api::foo.bar' both extends ContentType and Component
65
+ * 'api::foo.bar' extends ContentType => true (N = 'api', S='::', T='foo')
66
+ * 'api::foo.bar' extends Component => true (T = 'api::foo', N = 'bar')
67
+ */
68
+ export type Component<
69
+ TCategory extends string = string,
70
+ TName extends string = string
71
+ > = `${TCategory}.${TName}`;
72
+
73
+ /**
74
+ * Represents any UID
75
+ */
76
+ export type Any = Service | Controller | Policy | Middleware | ContentType | Component;
77
+
78
+ /**
79
+ * Type representation of every UID component.
80
+ *
81
+ * The separator type is automatically inferred from the given namespace
82
+ */
83
+ export interface Parsed<
84
+ TNamespace extends Namespace.Any = Namespace.Any,
85
+ TName extends string = string
86
+ > {
87
+ raw: `${TNamespace}${Namespace.GetSeparator<TNamespace>}${TName}`;
88
+ namespace: TNamespace;
89
+ origin: TNamespace extends Namespace.Scoped ? Namespace.ExtractOrigin<TNamespace> : TNamespace;
90
+ scope: TNamespace extends Namespace.Scoped ? Namespace.ExtractScope<TNamespace> : never;
91
+ separator: Namespace.GetSeparator<TNamespace>;
92
+ name: TName;
93
+ }
94
+
95
+ /**
96
+ * Parse a UID literal and returns a {@link Parsed} type.
97
+ *
98
+ * Warning: Using ParseUID with a union type might produce undesired results as it'll distribute every matching namespace parsing to every union member
99
+ *
100
+ * @example
101
+ * type T = Parse<'admin::foo'>
102
+ * // ^ { namespace: 'admin'; separator: '::'; name: 'foo'; }
103
+ *
104
+ * type T = Parse<'api::foo.bar'>
105
+ * // ^ { namespace: 'api::foo'; separator: '.'; name: 'bar'; }
106
+ *
107
+ * type T = Parse<'admin::foo' | 'api::foo.bar'>
108
+ * // ^ { namespace: 'admin' | 'api::foo' ; separator: '.' | '::'; name: 'foo' | 'bar' | 'foo.bar'; }
109
+ */
110
+ export type Parse<TUid extends Any> =
111
+ ExtractNamespace<TUid> extends infer TExtractedNamespace extends Namespace.Any
112
+ ? Namespace.GetSeparator<TExtractedNamespace> extends infer TSeparator extends Namespace.Separator
113
+ ? TUid extends `${infer TInferredNamespace extends TExtractedNamespace}${TSeparator}${infer TName extends string}`
114
+ ? Parsed<TInferredNamespace, TName>
115
+ : never
116
+ : never
117
+ : never;
118
+
119
+ /**
120
+ * Determines if the UID's namespace matches the given one.
121
+ *
122
+ * It returns TNamespace (the {@link Namespace.Any} literal) if there is a match, never otherwise.
123
+ *
124
+ * @example
125
+ * type T = EnsureNamespaceMatches<'admin::foo', Namespace.Admin>
126
+ * // ^ Namespace.Admin
127
+ * @example
128
+ * type T = EnsureNamespaceMatches<'foo.bar', Namespace.API>
129
+ * // ^ never
130
+ * @example
131
+ * type T = EnsureNamespaceMatches<'api::foo.bar', Namespace.Plugin>
132
+ * // ^ never
133
+ */
134
+ export type EnsureNamespaceMatches<
135
+ TUid extends Any,
136
+ TNamespace extends Namespace.Any
137
+ > = TUid extends StringSuffix<Namespace.WithSeparator<TNamespace>> ? TNamespace : never;
138
+
139
+ /**
140
+ * Get parsed properties from a given raw UID
141
+ */
142
+ export type Get<TUid extends Any, TKey extends keyof Parsed> = Parse<TUid>[TKey];
143
+
144
+ /**
145
+ * Pick parsed properties from a given raw UID
146
+ */
147
+ export type Select<TUid extends Any, TKey extends keyof Parse<TUid>> = Pick<Parse<TUid>, TKey>;
148
+
149
+ /**
150
+ * Extract the namespace literal from a given UID.
151
+ *
152
+ * @example
153
+ * type T = ExtractNamespace<'admin::foo'>
154
+ * // ^ Namespace.Admin
155
+ * @example
156
+ * type T = ExtractNamespace<'api::foo.bar'>
157
+ * // ^ Namespace.API
158
+ * @example
159
+ * type T = ExtractNamespace<'admin::foo' | 'api::foo.bar'>
160
+ * // ^ Namespace.Admin | Namespace.API
161
+ */
162
+ export type ExtractNamespace<TUid extends Any> =
163
+ | EnsureNamespaceMatches<TUid, Namespace.Global>
164
+ | EnsureNamespaceMatches<TUid, Namespace.Admin>
165
+ | EnsureNamespaceMatches<TUid, Namespace.Strapi>
166
+ | EnsureNamespaceMatches<TUid, Namespace.API>
167
+ | EnsureNamespaceMatches<TUid, Namespace.Plugin>;
@@ -0,0 +1,52 @@
1
+ import type { Common, CoreApi, Utils } from '@strapi/strapi';
2
+ import type { ExtendableContext } from 'koa';
3
+
4
+ /**
5
+ * Base Core-API controller type
6
+ *
7
+ * TODO: Make use of the T generic to type the other methods based on the given content type
8
+ */
9
+ export interface Base {
10
+ // TODO: Use actual entities instead of regular object
11
+ transformResponse<TData, TResponse>(data: TData, meta: object): TResponse;
12
+ sanitizeOutput<TData>(data: TData, ctx: ExtendableContext): Promise<TData>;
13
+ sanitizeInput<TData>(data: TData, ctx: ExtendableContext): Promise<TData>;
14
+ sanitizeQuery<TData>(data: TData, ctx: ExtendableContext): Promise<TData>;
15
+ }
16
+
17
+ /**
18
+ * Generic controller structure
19
+ */
20
+ export type Generic = {
21
+ [name: string]: Common.ControllerHandler<unknown>;
22
+ };
23
+
24
+ /**
25
+ * Core-API collection type controller
26
+ */
27
+ export interface CollectionType extends Base {
28
+ find?: Common.ControllerHandler<unknown>;
29
+ findOne?: Common.ControllerHandler<unknown>;
30
+ create?: Common.ControllerHandler<unknown>;
31
+ update?: Common.ControllerHandler<unknown>;
32
+ delete?: Common.ControllerHandler<unknown>;
33
+ }
34
+
35
+ /**
36
+ * Core-API single type controller
37
+ */
38
+ export interface SingleType extends Base {
39
+ find?: Common.ControllerHandler<unknown>;
40
+ update?: Common.ControllerHandler<unknown>;
41
+ delete?: Common.ControllerHandler<unknown>;
42
+ }
43
+
44
+ export type ContentType<T extends Common.UID.ContentType> = Utils.Expression.MatchFirst<
45
+ [
46
+ Utils.Expression.Test<Common.UID.IsCollectionType<T>, CollectionType>,
47
+ Utils.Expression.Test<Common.UID.IsSingleType<T>, SingleType>
48
+ ],
49
+ Base
50
+ >;
51
+
52
+ export type Extendable<T extends Common.UID.ContentType> = ContentType<T> & Generic;
@@ -0,0 +1,3 @@
1
+ export * as Controller from './controller';
2
+ export * as Service from './service';
3
+ export * as Router from './router';
@@ -0,0 +1,65 @@
1
+ import type { Common, Strapi, Utils } from '@strapi/strapi';
2
+
3
+ import { ExtendableContext } from 'koa';
4
+ import { Middleware as KoaMiddleware } from 'koa';
5
+
6
+ export type MiddlewareFactory = (config: any, ctx: { strapi: Strapi }) => Middleware | null;
7
+
8
+ export type Middleware = KoaMiddleware | MiddlewareFactory;
9
+
10
+ export interface PolicyContext extends ExtendableContext {
11
+ type: string;
12
+ }
13
+
14
+ export type PolicyImplementation<TCfg = unknown> = (
15
+ ctx: PolicyContext,
16
+ cfg: TCfg,
17
+ { strapi }: { strapi: Strapi }
18
+ ) => boolean | undefined;
19
+
20
+ type HandlerConfig = {
21
+ auth?: false | { scope: string[] };
22
+ policies?: Array<string | PolicyImplementation | { name: string; config: object }>;
23
+ middlewares?: Array<string | Middleware | { name: string; config: object }>;
24
+ };
25
+
26
+ export type Generic = {
27
+ [method: string | number | symbol]: HandlerConfig;
28
+ };
29
+
30
+ export interface SingleTypeRouterConfig extends Generic {
31
+ find?: HandlerConfig;
32
+ update?: HandlerConfig;
33
+ delete?: HandlerConfig;
34
+ }
35
+
36
+ export interface CollectionTypeRouterConfig extends Generic {
37
+ find?: HandlerConfig;
38
+ findOne?: HandlerConfig;
39
+ create?: HandlerConfig;
40
+ update?: HandlerConfig;
41
+ delete?: HandlerConfig;
42
+ }
43
+
44
+ export type RouterConfig<TContentTypeUID extends Common.UID.ContentType> = {
45
+ prefix?: string;
46
+ // TODO Refactor when we have a controller registry
47
+ only?: string[];
48
+ except?: string[];
49
+ config: Utils.Expression.MatchFirst<
50
+ [
51
+ Utils.Expression.Test<Common.UID.IsCollectionType<TContentTypeUID>, CollectionTypeRouterConfig>,
52
+ Utils.Expression.Test<Common.UID.IsSingleType<TContentTypeUID>, SingleTypeRouterConfig>
53
+ ],
54
+ Generic
55
+ >;
56
+ };
57
+
58
+ export type Route = {
59
+ method: string;
60
+ path: string;
61
+ };
62
+ export type Router = {
63
+ prefix: string;
64
+ routes: Route[];
65
+ };
@@ -0,0 +1,48 @@
1
+ import type { Common, Utils } from '@strapi/strapi';
2
+
3
+ // TODO Use actual entities instead of regular object
4
+ type Entity = object;
5
+
6
+ /**
7
+ * Base Core-API service type
8
+ */
9
+ export interface Base {
10
+ getFetchParams?(params: object): object;
11
+ }
12
+
13
+ /**
14
+ * Generic service structure
15
+ */
16
+ export type Generic = {
17
+ [method: string | number | symbol]: (...args: any) => any;
18
+ };
19
+
20
+ /**
21
+ * Core-API collection type service
22
+ */
23
+ export interface CollectionType extends Base {
24
+ find?(params: object): Promise<Entity[]> | Entity;
25
+ findOne?(entityId: string, params: object): Promise<Entity> | Entity;
26
+ create?(params: object): Promise<Entity> | Entity;
27
+ update?(entityId: string, params: object): Promise<Entity> | Entity;
28
+ delete?(entityId: string, params: object): Promise<Entity> | Entity;
29
+ }
30
+
31
+ /**
32
+ * Core-API single type service
33
+ */
34
+ export interface SingleType extends Base {
35
+ find?(params: object): Promise<Entity> | Entity;
36
+ createOrUpdate?(params: object): Promise<Entity> | Entity;
37
+ delete?(params: object): Promise<Entity> | Entity;
38
+ }
39
+
40
+ export type ContentType<TContentTypeUID extends Common.UID.ContentType> = Utils.Expression.MatchFirst<
41
+ [
42
+ Utils.Expression.Test<Common.UID.IsCollectionType<TContentTypeUID>, CollectionType>,
43
+ Utils.Expression.Test<Common.UID.IsSingleType<TContentTypeUID>, SingleType>
44
+ ],
45
+ Base
46
+ >;
47
+
48
+ export type Extendable<TContentTypeUID extends Common.UID.ContentType> = ContentType<TContentTypeUID> & Generic;
@@ -1,4 +1,6 @@
1
+ // Exports from core should already be modules
1
2
  export * from './core';
2
3
 
3
- export * as utils from './utils';
4
- export * as factories from './factories';
4
+ export * as CoreApi from './core-api';
5
+ export * as Utils from './utils';
6
+ export * as Shared from './shared';
@@ -0,0 +1 @@
1
+ export * from './registries';
@@ -0,0 +1,45 @@
1
+ import type { Common, Schema, UID } from '@strapi/strapi';
2
+
3
+ /**
4
+ * Shared service registry
5
+ */
6
+ export interface Services {
7
+ [uid: UID.Service]: Common.Service;
8
+ }
9
+
10
+ /**
11
+ * Shared controller registry
12
+ */
13
+ export interface Controllers {
14
+ [uid: UID.Controller]: Common.Controller;
15
+ }
16
+
17
+ /**
18
+ * Shared policy registry
19
+ */
20
+ export interface Policies {
21
+ // TODO: Create generic policy type
22
+ [uid: UID.Policy]: unknown;
23
+ }
24
+
25
+ /**
26
+ * Shared middleware registry
27
+ */
28
+ export interface Middlewares {
29
+ // TODO: Create generic middleware type
30
+ [uid: UID.Middleware]: unknown;
31
+ }
32
+
33
+ /**
34
+ * Shared content-types registry
35
+ */
36
+ export interface ContentTypes {
37
+ [key: UID.ContentType]: Schema.ContentType;
38
+ }
39
+
40
+ /**
41
+ * Shared component registry
42
+ */
43
+ export interface Components {
44
+ [key: UID.Component]: Schema.Component;
45
+ }
@@ -0,0 +1,25 @@
1
+ import type { Utils } from '@strapi/strapi';
2
+
3
+ /**
4
+ * Extract the array values into an union type
5
+ **/
6
+ export type Values<TCollection extends Array<unknown>> = TCollection extends Array<infer TValues>
7
+ ? TValues
8
+ : never;
9
+
10
+ /**
11
+ * Checks if the size of the given collection equals 0
12
+ */
13
+ export type IsEmpty<TCollection extends Array<unknown>> = Utils.Expression.Extends<
14
+ TCollection['length'],
15
+ 0
16
+ >;
17
+
18
+ /**
19
+ * Checks if the size of the given collection is not 0
20
+ *
21
+ * Returns a {@link Utils.Expression.Boolean} expression
22
+ */
23
+ export type IsNotEmpty<TCollection extends Array<unknown>> = Utils.Expression.Not<
24
+ IsEmpty<TCollection>
25
+ >;
@@ -0,0 +1,68 @@
1
+ import type { Utils } from '@strapi/strapi';
2
+
3
+ export type True = true;
4
+ export type False = false;
5
+ export type BooleanValue = True | False;
6
+
7
+ export type Extends<TLeft, TRight> = [TLeft] extends [TRight] ? True : False;
8
+
9
+ export type Not<TExpression extends BooleanValue> = If<TExpression, False, True>;
10
+
11
+ export type If<TExpression extends BooleanValue, TOnTrue, TOnFalse = never> = [
12
+ TExpression
13
+ ] extends [True]
14
+ ? TOnTrue
15
+ : TOnFalse;
16
+
17
+ export type MatchFirst<TTests extends Test[], TDefault = never> = TTests extends [
18
+ infer THead extends Test,
19
+ ...infer TTail extends Test[]
20
+ ]
21
+ ? THead extends Test<infer TExpression, infer TValue>
22
+ ? If<
23
+ TExpression,
24
+ TValue,
25
+ If<Utils.Array.IsNotEmpty<TTail>, MatchFirst<TTail, TDefault>, TDefault>
26
+ >
27
+ : never
28
+ : never;
29
+
30
+ export type MatchAll<TTests extends Test[], TDefault = never> = TTests extends [
31
+ infer THead extends Test,
32
+ ...infer TTail extends Test[]
33
+ ]
34
+ ? THead extends Test<infer TExpression, infer TValue>
35
+ ? Utils.Guard.Never<
36
+ If<TExpression, TValue> | If<Utils.Array.IsNotEmpty<TTail>, MatchAll<TTail, TDefault>>,
37
+ TDefault
38
+ >
39
+ : never
40
+ : never;
41
+
42
+ export type Test<TExpression extends BooleanValue = BooleanValue, TValue = unknown> = [
43
+ TExpression,
44
+ TValue
45
+ ];
46
+
47
+ export type Some<TExpressions extends BooleanValue[]> = TExpressions extends [
48
+ infer THead extends BooleanValue,
49
+ ...infer TTail extends BooleanValue[]
50
+ ]
51
+ ? If<Utils.Array.IsNotEmpty<TTail>, Or<THead, Some<TTail>>, Or<THead, false>>
52
+ : never;
53
+
54
+ export type Every<TExpressions extends BooleanValue[]> = TExpressions extends [
55
+ infer THead extends BooleanValue,
56
+ ...infer TTail extends BooleanValue[]
57
+ ]
58
+ ? If<Utils.Array.IsNotEmpty<TTail>, And<THead, Every<TTail>>, And<THead, True>>
59
+ : never;
60
+
61
+ export type And<TLeft extends BooleanValue, TRight extends BooleanValue> = Extends<
62
+ Extends<TLeft, True> | Extends<TRight, True>,
63
+ True
64
+ >;
65
+
66
+ export type Or<TLeft extends BooleanValue, TRight extends BooleanValue> = Not<
67
+ Extends<Extends<TLeft, True> | Extends<TRight, True>, False>
68
+ >;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Assign a default value `TDefault` to `TValue` if `TValue` is of type `never`
3
+ *
4
+ * @example
5
+ * type X = Never<{ foo: 'bar' }, string>
6
+ * // { foo: 'bar' }
7
+ *
8
+ * type X = Never<never>
9
+ * // unknown
10
+ *
11
+ * type X = Never<never, string>
12
+ * // string
13
+ */
14
+ export type Never<TValue, TDefault = unknown> = [TValue] extends [never] ? TDefault : TValue;
@@ -0,0 +1,19 @@
1
+ export * as Array from './array';
2
+ export * as Guard from './guard';
3
+ export * as Object from './object';
4
+ export * as String from './string';
5
+ export * as Tuple from './tuple';
6
+ export * as Expression from './expression';
7
+
8
+ /**
9
+ * Get the type of a specific key `TKey` in `TValue`
10
+ *
11
+ * @example
12
+ *
13
+ * type X = Get<{ foo: 'bar', 'bar': 'foo' }, 'foo'>
14
+ * // 'bar'
15
+ *
16
+ * type X = Get<{ foo: 'bar', 'bar': 'foo' }, 'bar'>
17
+ * // 'foo'
18
+ */
19
+ export type Get<TValue, TKey extends keyof TValue> = TValue[TKey];
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Retrieve object's (`TValue`) keys if they extends the given `TTest` type.
3
+ *
4
+ * @example
5
+ * type X = KeysBy<{ foo: 'bar', bar: 'foo', foobar: 2 }, string>
6
+ * // 'foo' | 'bar'
7
+ *
8
+ * type Base = { x: 'foo' | 'bar' };
9
+ * type Obj = { foo: { x: 'foo' }, bar: { x: 'bar' }, other: { x: '42' } };
10
+ * type X = KeysBy<Obj, Base>
11
+ * // 'foo' | 'bar'
12
+ */
13
+ export type KeysBy<TValue, TTest> = {
14
+ [key in keyof TValue]: TValue[key] extends TTest ? key : never;
15
+ }[keyof TValue];
16
+
17
+ /**
18
+ * Retrieve object's (`TValue`) properties if their value extends the given `TTest` type.
19
+ *
20
+ * @example
21
+ * type X = KeysBy<{ foo: 'bar', bar: 'foo', foobar: 2 }, string>
22
+ * // { foo: 'bar', bar: 'foo' }
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
+ * // { foo: { x: 'foo' }, bar: { x: 'bar' } }
28
+ */
29
+ export type PickBy<TValue, TTest> = Pick<TValue, KeysBy<TValue, TTest>>;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Alias for any literal type (useful for template string parameters)
3
+ */
4
+ export type Literal = string | number | bigint | boolean;
5
+
6
+ /**
7
+ * Used to check if a string includes a given literal
8
+ */
9
+ export type Includes<T extends Literal> = `${string}${T}${string}`;
10
+
11
+ /**
12
+ * Used to make sure the given string is not empty
13
+ */
14
+ export type NonEmpty<T extends string> = T extends '' ? never : T;
15
+
16
+ /**
17
+ * Split the given string into a tuple using the given `TSeparator` literal
18
+ */
19
+ export type Split<
20
+ TValue extends string,
21
+ TSeparator extends Literal
22
+ > = TValue extends `${infer TLeft}${TSeparator}${infer TRight}`
23
+ ? [TLeft, ...Split<TRight, TSeparator>]
24
+ : TValue extends ''
25
+ ? []
26
+ : [TValue];
27
+
28
+ /**
29
+ * Add a literal suffix (`TSuffix`) at the end of the given string
30
+ */
31
+ export type Suffix<TValue extends string, TSuffix extends Literal> = `${TValue}${TSuffix}`;
32
+
33
+ /**
34
+ * Add a literal prefix (`TPrefix`) at the beginning of the given string
35
+ */
36
+ export type Prefix<TValue extends string, TPrefix extends Literal> = `${TPrefix}${TValue}`;
37
+
38
+ /**
39
+ * Creates a record where every key is a string and every value is `T`
40
+ */
41
+ export type Dict<T> = Record<string, T>;
@@ -0,0 +1,13 @@
1
+ import type { Literal } from './string';
2
+
3
+ /**
4
+ * Aggregate the given tuple into a string, separated by the given `TSeparator` literal
5
+ */
6
+ export type Join<TCollection extends unknown[], TSeparator extends Literal> = TCollection extends [
7
+ infer THead extends Literal,
8
+ ...infer TTail
9
+ ]
10
+ ? TTail['length'] extends 0
11
+ ? THead
12
+ : `${THead}${TSeparator}${Join<TTail, TSeparator>}`
13
+ : never;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/strapi",
3
- "version": "4.11.0",
3
+ "version": "4.11.1-beta.0",
4
4
  "description": "An open source headless CMS solution to create and manage your own API. It provides a powerful dashboard and features to make your life easier. Databases supported: MySQL, MariaDB, PostgreSQL, SQLite",
5
5
  "keywords": [
6
6
  "strapi",
@@ -81,19 +81,19 @@
81
81
  "dependencies": {
82
82
  "@koa/cors": "3.4.3",
83
83
  "@koa/router": "10.1.1",
84
- "@strapi/admin": "4.11.0",
85
- "@strapi/data-transfer": "4.11.0",
86
- "@strapi/database": "4.11.0",
87
- "@strapi/generate-new": "4.11.0",
88
- "@strapi/generators": "4.11.0",
89
- "@strapi/logger": "4.11.0",
90
- "@strapi/permissions": "4.11.0",
91
- "@strapi/plugin-content-manager": "4.11.0",
92
- "@strapi/plugin-content-type-builder": "4.11.0",
93
- "@strapi/plugin-email": "4.11.0",
94
- "@strapi/plugin-upload": "4.11.0",
95
- "@strapi/typescript-utils": "4.11.0",
96
- "@strapi/utils": "4.11.0",
84
+ "@strapi/admin": "4.11.1-beta.0",
85
+ "@strapi/data-transfer": "4.11.1-beta.0",
86
+ "@strapi/database": "4.11.1-beta.0",
87
+ "@strapi/generate-new": "4.11.1-beta.0",
88
+ "@strapi/generators": "4.11.1-beta.0",
89
+ "@strapi/logger": "4.11.1-beta.0",
90
+ "@strapi/permissions": "4.11.1-beta.0",
91
+ "@strapi/plugin-content-manager": "4.11.1-beta.0",
92
+ "@strapi/plugin-content-type-builder": "4.11.1-beta.0",
93
+ "@strapi/plugin-email": "4.11.1-beta.0",
94
+ "@strapi/plugin-upload": "4.11.1-beta.0",
95
+ "@strapi/typescript-utils": "4.11.1-beta.0",
96
+ "@strapi/utils": "4.11.1-beta.0",
97
97
  "bcryptjs": "2.4.3",
98
98
  "boxen": "5.1.2",
99
99
  "chalk": "4.1.2",
@@ -131,7 +131,7 @@
131
131
  "package-json": "7.0.0",
132
132
  "qs": "6.11.1",
133
133
  "resolve-cwd": "3.0.0",
134
- "semver": "7.3.8",
134
+ "semver": "7.5.1",
135
135
  "statuses": "2.0.1"
136
136
  },
137
137
  "devDependencies": {
@@ -142,5 +142,5 @@
142
142
  "node": ">=14.19.1 <=18.x.x",
143
143
  "npm": ">=6.0.0"
144
144
  },
145
- "gitHead": "0de06a008d1dfbe67ebfee3562cc8ca0603d2255"
145
+ "gitHead": "30e56b8376b9cb52c39ecd1c3b7d8706688a1685"
146
146
  }
@@ -1,7 +0,0 @@
1
- import { Strapi } from '../../';
2
-
3
- export type Service = {
4
- [key: string]: (...args: any) => any;
5
- };
6
-
7
- export type ServiceFactory = ({ strapi: Strapi }) => Service;