@strapi/strapi 4.11.0-exp.push-transfer-push-stuck → 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 (65) 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/core/domain/content-type/index.js +1 -7
  5. package/lib/factories.d.ts +21 -0
  6. package/lib/global.d.ts +0 -44
  7. package/lib/index.d.ts +2 -1
  8. package/lib/services/entity-service/index.d.ts +1 -3
  9. package/lib/services/entity-service/index.js +60 -20
  10. package/lib/services/webhook-store.js +32 -4
  11. package/lib/types/core/attributes/base.d.ts +8 -5
  12. package/lib/types/core/attributes/biginteger.d.ts +8 -15
  13. package/lib/types/core/attributes/boolean.d.ts +7 -13
  14. package/lib/types/core/attributes/common.d.ts +46 -20
  15. package/lib/types/core/attributes/component.d.ts +24 -29
  16. package/lib/types/core/attributes/date-time.d.ts +8 -15
  17. package/lib/types/core/attributes/date.d.ts +8 -17
  18. package/lib/types/core/attributes/decimal.d.ts +8 -15
  19. package/lib/types/core/attributes/dynamic-zone.d.ts +18 -21
  20. package/lib/types/core/attributes/email.d.ts +9 -19
  21. package/lib/types/core/attributes/enumeration.d.ts +12 -22
  22. package/lib/types/core/attributes/float.d.ts +8 -17
  23. package/lib/types/core/attributes/integer.d.ts +8 -15
  24. package/lib/types/core/attributes/json.d.ts +8 -11
  25. package/lib/types/core/attributes/media.d.ts +23 -25
  26. package/lib/types/core/attributes/password.d.ts +8 -15
  27. package/lib/types/core/attributes/relation.d.ts +96 -48
  28. package/lib/types/core/attributes/richtext.d.ts +8 -15
  29. package/lib/types/core/attributes/string.d.ts +11 -21
  30. package/lib/types/core/attributes/text.d.ts +11 -21
  31. package/lib/types/core/attributes/time.d.ts +8 -17
  32. package/lib/types/core/attributes/timestamp.d.ts +8 -15
  33. package/lib/types/core/attributes/uid.d.ts +35 -39
  34. package/lib/types/core/attributes/utils.d.ts +69 -79
  35. package/lib/types/core/common/controller.d.ts +8 -0
  36. package/lib/types/core/common/index.d.ts +4 -0
  37. package/lib/types/core/common/schema.d.ts +3 -0
  38. package/lib/types/core/common/service.d.ts +3 -0
  39. package/lib/types/core/common/uid.d.ts +62 -0
  40. package/lib/types/core/index.d.ts +7 -2
  41. package/lib/types/core/namespace.d.ts +99 -0
  42. package/lib/types/core/registry.d.ts +68 -0
  43. package/lib/types/core/schemas/index.d.ts +16 -15
  44. package/lib/types/core/strapi/index.d.ts +7 -11
  45. package/lib/types/core/uid.d.ts +167 -0
  46. package/lib/types/core-api/controller.d.ts +52 -0
  47. package/lib/types/core-api/index.d.ts +3 -0
  48. package/lib/types/core-api/router.d.ts +65 -0
  49. package/lib/types/core-api/service.d.ts +48 -0
  50. package/lib/types/index.d.ts +4 -2
  51. package/lib/types/shared/index.d.ts +1 -0
  52. package/lib/types/shared/registries.d.ts +45 -0
  53. package/lib/types/utils/array.d.ts +25 -0
  54. package/lib/types/utils/expression.d.ts +68 -0
  55. package/lib/types/utils/guard.d.ts +14 -0
  56. package/lib/types/utils/index.d.ts +19 -0
  57. package/lib/types/utils/object.d.ts +29 -0
  58. package/lib/types/utils/string.d.ts +41 -0
  59. package/lib/types/utils/tuple.d.ts +13 -0
  60. package/package.json +17 -17
  61. package/lib/core/registries/services.d.ts +0 -7
  62. package/lib/core-api/controller/index.d.ts +0 -27
  63. package/lib/core-api/service/index.d.ts +0 -25
  64. package/lib/types/factories.d.ts +0 -60
  65. package/lib/types/utils.d.ts +0 -95
@@ -0,0 +1,68 @@
1
+ import type * as UID from './uid';
2
+
3
+ /**
4
+ * Extract valid keys from a given registry.
5
+ *
6
+ * It looks for {@link UID.Any} by default but the search can be narrowed to any UID subset using the `TUidFormat` generic.
7
+ *
8
+ * @example
9
+ * interface Registry {
10
+ * 'foo': unknown;
11
+ * 'default.foo': 'unknown';
12
+ * 'global::foo': unknown;
13
+ * 'api::foo.bar': unknown;
14
+ * }
15
+ *
16
+ * type T = Keys<Registry>;
17
+ * // ^ 'default.foo' | 'global::foo' | 'api::foo.bar'
18
+ * type T = Keys<Registry, UID.Policy>;
19
+ * // ^ 'global::foo' | 'api::foo.bar'
20
+ * type T = Keys<Registry, UID.Service>
21
+ * // ^ 'api::foo.bar'
22
+ */
23
+ export type Keys<TRegistry, TUidFormat extends UID.Any = UID.Any> = Extract<
24
+ keyof TRegistry,
25
+ TUidFormat
26
+ >;
27
+
28
+ /**
29
+ * Performs a `TQuery` filtering operation on the given `TRegistry` registry.
30
+ *
31
+ * `TQuery` needs to be a partial representation of a {@link UID.Parsed}
32
+ *
33
+ * Note: For additional filtering, the registry keys' type can be passed as the third parameter.
34
+ *
35
+ * @example
36
+ * interface Registry {
37
+ * 'admin::foo': unknown;
38
+ * 'admin::bar': unknown;
39
+ * 'api::foo.bar': unknown;
40
+ * 'api::foo.baz': unknown;
41
+ * 'api::bar.foo': unknown;
42
+ * 'plugin::foo.bar': unknown;
43
+ * }
44
+ *
45
+ * type T = keyof WhereKeys<Registry, { namespace: Namespace.API }>;
46
+ * // ^ "api::foo.bar" | "api::foo.baz" | "api::bar.foo"
47
+ *
48
+ * type T = keyof WhereKeys<Registry, { name: 'bar' }>;
49
+ * // ^ "admin::bar" | "api::foo.bar" | "plugin::foo.bar"
50
+ *
51
+ * type T = keyof WhereKeys<Registry, { separator: '.' }>;
52
+ * // ^ "api::foo.bar" | "api::foo.baz" | "api::bar.foo" | 'plugin::foo.bar"
53
+ *
54
+ * type T = keyof WhereKeys<Registry, { namespace: Namespace.Plugin | Namespace.Admin }>;
55
+ * // ^ "plugin::foo.bar" | "admin::foo" | "admin::bar"
56
+ *
57
+ * type T = keyof WhereKeys<Registry, { namespace: Namespace.API; name: Utils.Includes<'b'> }>;
58
+ * // ^ "api::foo.bar" | "api::foo.baz"
59
+ */
60
+ export type WhereKeys<
61
+ TRegistry,
62
+ TQuery extends Partial<UID.Parsed>,
63
+ TUidFormat extends UID.Any = UID.Any
64
+ > = {
65
+ [uid in Keys<TRegistry, TUidFormat> as UID.Parse<uid> extends TQuery
66
+ ? uid
67
+ : never]: TRegistry[uid];
68
+ };
@@ -1,5 +1,4 @@
1
- import { Attribute, ComponentAttribute } from '../attributes';
2
- import { KeysBy, SchemaUID, StringRecord } from '../../utils';
1
+ import type { Attribute, Utils, Common } from '@strapi/strapi';
3
2
 
4
3
  /**
5
4
  * Literal union type representing the possible natures of a content type
@@ -9,7 +8,7 @@ export type ContentTypeKind = 'singleType' | 'collectionType';
9
8
  /**
10
9
  * Literal union type representing the possible types of a model
11
10
  */
12
- export type SchemaModelType = 'contentType' | 'component';
11
+ export type ModelType = 'contentType' | 'component';
13
12
 
14
13
  /**
15
14
  * Data structure that can either represent a content type or a component
@@ -18,17 +17,17 @@ export interface Schema {
18
17
  /**
19
18
  * The type of the model. Useful to discriminate content-types from component
20
19
  */
21
- modelType: SchemaModelType;
20
+ modelType: ModelType;
22
21
 
23
22
  /**
24
23
  * Informations about schema naming and display
25
24
  */
26
- info: SchemaInfo;
25
+ info: Info;
27
26
 
28
27
  /**
29
28
  * Map of all the attributes with their name and definition
30
29
  */
31
- attributes: SchemaAttributes;
30
+ attributes: Attributes;
32
31
 
33
32
  /**
34
33
  * Options declared and read by the plugins
@@ -38,7 +37,7 @@ export interface Schema {
38
37
  /**
39
38
  * Options object dedicated to Strapi core features
40
39
  */
41
- options?: SchemaOptions;
40
+ options?: Options;
42
41
 
43
42
  /**
44
43
  * Custom table name for the schema
@@ -49,7 +48,7 @@ export interface Schema {
49
48
  /**
50
49
  * Data structure containing naming and display information for a Schema
51
50
  */
52
- export interface SchemaInfo {
51
+ export interface Info {
53
52
  /**
54
53
  * Default name to use in the admin panel
55
54
  */
@@ -79,12 +78,14 @@ export interface SchemaInfo {
79
78
  /**
80
79
  * Low level data structure referencing every schema attribute and its name
81
80
  */
82
- export interface SchemaAttributes extends StringRecord<Attribute> {}
81
+ export interface Attributes {
82
+ [key: string]: Attribute.Any;
83
+ }
83
84
 
84
85
  /**
85
86
  * Structure containing every core schema options and their associated value
86
87
  */
87
- export interface SchemaOptions {
88
+ export interface Options {
88
89
  draftAndPublish?: boolean;
89
90
  populateCreatorFields?: boolean;
90
91
  comment?: string;
@@ -95,13 +96,13 @@ export interface PluginOptions {}
95
96
  /**
96
97
  * Schema for a content type
97
98
  */
98
- export interface ContentTypeSchema extends Schema {
99
+ export interface ContentType extends Schema {
99
100
  modelType: 'contentType';
100
101
 
101
102
  /**
102
103
  * Unique identifier of the schema
103
104
  */
104
- uid: SchemaUID;
105
+ uid: Common.UID.ContentType;
105
106
 
106
107
  /**
107
108
  * Determine the type of the content type (single-type or collection-type)
@@ -112,20 +113,20 @@ export interface ContentTypeSchema extends Schema {
112
113
  /**
113
114
  * Schema for a collection type
114
115
  */
115
- export interface CollectionTypeSchema extends ContentTypeSchema {
116
+ export interface CollectionType extends ContentType {
116
117
  kind: 'collectionType';
117
118
  }
118
119
 
119
120
  /**
120
121
  * Schema for a single type
121
122
  */
122
- export interface SingleTypeSchema extends ContentTypeSchema {
123
+ export interface SingleType extends ContentType {
123
124
  kind: 'singleType';
124
125
  }
125
126
 
126
127
  /**
127
128
  * Schema for a component
128
129
  */
129
- export interface ComponentSchema extends Schema {
130
+ export interface Component extends Schema {
130
131
  modelType: 'component';
131
132
  }
@@ -1,9 +1,5 @@
1
- import type Koa from 'koa';
2
- import { Database } from '@strapi/database';
3
-
4
- import type { StringMap } from './utils';
5
- import type { GenericController } from '../../../core-api/controller';
6
- import type { GenericService } from '../../../core-api/service';
1
+ import type { Database } from '@strapi/database';
2
+ import type { Shared, Common } from '@strapi/strapi';
7
3
 
8
4
  // TODO move custom fields types to a separate file
9
5
  interface CustomFieldServerOptions {
@@ -21,7 +17,7 @@ interface CustomFieldServerOptions {
21
17
  * The existing Strapi data type the custom field uses
22
18
  */
23
19
  type: string;
24
-
20
+
25
21
  /**
26
22
  * Settings for the input size in the Admin UI
27
23
  */
@@ -69,24 +65,24 @@ export interface Strapi {
69
65
  *
70
66
  * It returns all the registered services
71
67
  */
72
- readonly services: StringMap<GenericService>;
68
+ readonly services: Shared.Services;
73
69
 
74
70
  /**
75
71
  * Find a service using its unique identifier
76
72
  */
77
- service<T extends GenericService = GenericService>(uid: string): T | undefined;
73
+ service<TService extends Common.Service = Common.Service>(uid: string): TService | undefined;
78
74
 
79
75
  /**
80
76
  * Getter for the Strapi controllers container
81
77
  *
82
78
  * It returns all the registered controllers
83
79
  */
84
- readonly controllers: StringMap<GenericController>;
80
+ readonly controllers: Shared.Controllers;
85
81
 
86
82
  /**
87
83
  * Find a controller using its unique identifier
88
84
  */
89
- controller(uid: string): GenericController | undefined;
85
+ controller<TContentTypeUID extends Common.UID.Controller>(uid: TContentTypeUID): Shared.Controllers[TContentTypeUID];
90
86
 
91
87
  /**
92
88
  * Getter for the Strapi content types container
@@ -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
+ >;