@strapi/types 0.0.0 → 4.14.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/LICENSE +22 -0
- package/README.md +5 -0
- package/dist/container.d.ts +5 -0
- package/dist/index.d.ts +138 -0
- package/dist/modules/auth.d.ts +24 -0
- package/dist/modules/content-api.d.ts +29 -0
- package/dist/modules/core-store.d.ts +27 -0
- package/dist/modules/cron.d.ts +26 -0
- package/dist/modules/custom-fields.d.ts +24 -0
- package/dist/modules/entity-service/index.d.ts +73 -0
- package/dist/modules/entity-service/params/attributes.d.ts +74 -0
- package/dist/modules/entity-service/params/data.d.ts +3 -0
- package/dist/modules/entity-service/params/fields.d.ts +58 -0
- package/dist/modules/entity-service/params/filters/index.d.ts +53 -0
- package/dist/modules/entity-service/params/filters/operators.d.ts +8 -0
- package/dist/modules/entity-service/params/index.d.ts +132 -0
- package/dist/modules/entity-service/params/pagination.d.ts +10 -0
- package/dist/modules/entity-service/params/populate.d.ts +68 -0
- package/dist/modules/entity-service/params/publication-state.d.ts +15 -0
- package/dist/modules/entity-service/params/search.d.ts +1 -0
- package/dist/modules/entity-service/params/sort.d.ts +84 -0
- package/dist/modules/entity-service/plugin.d.ts +7 -0
- package/dist/modules/entity-service/result.d.ts +88 -0
- package/dist/modules/entity-validator.d.ts +18 -0
- package/dist/modules/event-hub.d.ts +14 -0
- package/dist/modules/fetch.d.ts +6 -0
- package/dist/modules/metrics.d.ts +7 -0
- package/dist/modules/request-context.d.ts +5 -0
- package/dist/modules/sanitizers.d.ts +8 -0
- package/dist/modules/server.d.ts +30 -0
- package/dist/modules/validators.d.ts +8 -0
- package/dist/modules/webhook-runner.d.ts +15 -0
- package/dist/modules/webhook-store.d.ts +20 -0
- package/dist/types/core/attributes/base.d.ts +51 -0
- package/dist/types/core/attributes/biginteger.d.ts +4 -0
- package/dist/types/core/attributes/blocks.d.ts +4 -0
- package/dist/types/core/attributes/boolean.d.ts +6 -0
- package/dist/types/core/attributes/common.d.ts +58 -0
- package/dist/types/core/attributes/component.d.ts +10 -0
- package/dist/types/core/attributes/date-time.d.ts +4 -0
- package/dist/types/core/attributes/date.d.ts +4 -0
- package/dist/types/core/attributes/decimal.d.ts +4 -0
- package/dist/types/core/attributes/dynamic-zone.d.ts +12 -0
- package/dist/types/core/attributes/email.d.ts +4 -0
- package/dist/types/core/attributes/enumeration.d.ts +8 -0
- package/dist/types/core/attributes/float.d.ts +4 -0
- package/dist/types/core/attributes/index.d.ts +25 -0
- package/dist/types/core/attributes/integer.d.ts +4 -0
- package/dist/types/core/attributes/json.d.ts +4 -0
- package/dist/types/core/attributes/media.d.ts +12 -0
- package/dist/types/core/attributes/password.d.ts +4 -0
- package/dist/types/core/attributes/relation.d.ts +75 -0
- package/dist/types/core/attributes/richtext.d.ts +4 -0
- package/dist/types/core/attributes/string.d.ts +9 -0
- package/dist/types/core/attributes/text.d.ts +7 -0
- package/dist/types/core/attributes/time.d.ts +4 -0
- package/dist/types/core/attributes/timestamp.d.ts +4 -0
- package/dist/types/core/attributes/uid.d.ts +15 -0
- package/dist/types/core/attributes/utils.d.ts +27 -0
- package/dist/types/core/commands/index.d.ts +5 -0
- package/dist/types/core/common/api.d.ts +3 -0
- package/dist/types/core/common/controller.d.ts +5 -0
- package/dist/types/core/common/index.d.ts +18 -0
- package/dist/types/core/common/middleware.d.ts +7 -0
- package/dist/types/core/common/module.d.ts +24 -0
- package/dist/types/core/common/plugin.d.ts +5 -0
- package/dist/types/core/common/policy.d.ts +9 -0
- package/dist/types/core/common/router.d.ts +34 -0
- package/dist/types/core/common/schema.d.ts +2 -0
- package/dist/types/core/common/service.d.ts +3 -0
- package/dist/types/core/common/uid.d.ts +15 -0
- package/dist/types/core/index.d.ts +17 -0
- package/dist/types/core/namespace.d.ts +77 -0
- package/dist/types/core/plugins/config/index.d.ts +2 -0
- package/dist/types/core/plugins/config/strapi-admin/index.d.ts +5 -0
- package/dist/types/core/plugins/config/strapi-server/config.d.ts +4 -0
- package/dist/types/core/plugins/config/strapi-server/content-types.d.ts +10 -0
- package/dist/types/core/plugins/config/strapi-server/controllers.d.ts +7 -0
- package/dist/types/core/plugins/config/strapi-server/index.d.ts +20 -0
- package/dist/types/core/plugins/config/strapi-server/lifecycle.d.ts +7 -0
- package/dist/types/core/plugins/config/strapi-server/routes.d.ts +10 -0
- package/dist/types/core/plugins/index.d.ts +5 -0
- package/dist/types/core/registry.d.ts +57 -0
- package/dist/types/core/schemas/index.d.ts +124 -0
- package/dist/types/core/strapi/index.d.ts +25 -0
- package/dist/types/core/uid.d.ts +108 -0
- package/dist/types/core-api/controller.d.ts +44 -0
- package/dist/types/core-api/index.d.ts +3 -0
- package/dist/types/core-api/router.d.ts +62 -0
- package/dist/types/core-api/service.d.ts +64 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/shared/index.d.ts +3 -0
- package/dist/types/shared/registries.d.ts +37 -0
- package/dist/types/utils/array.d.ts +15 -0
- package/dist/types/utils/expression.d.ts +42 -0
- package/dist/types/utils/function.d.ts +2 -0
- package/dist/types/utils/guard.d.ts +19 -0
- package/dist/types/utils/index.d.ts +25 -0
- package/dist/types/utils/object.d.ts +58 -0
- package/dist/types/utils/string.d.ts +39 -0
- package/dist/types/utils/tuple.d.ts +8 -0
- package/index.js +2 -0
- package/package.json +70 -5
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ContentType } from '../../../schemas';
|
|
2
|
+
export interface ContentTypes {
|
|
3
|
+
/**
|
|
4
|
+
* Only the schema property is used and available
|
|
5
|
+
* See loader in packages/core/strapi/src/core/loaders/plugins/index.ts
|
|
6
|
+
* */
|
|
7
|
+
[key: string]: {
|
|
8
|
+
schema: ContentType;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Config } from './config';
|
|
2
|
+
import type { Routes } from './routes';
|
|
3
|
+
import type { ContentTypes } from './content-types';
|
|
4
|
+
import type { Controllers } from './controllers';
|
|
5
|
+
import type { Register, Bootstrap, Destroy } from './lifecycle';
|
|
6
|
+
export interface ServerObject {
|
|
7
|
+
register: Register;
|
|
8
|
+
bootstrap: Bootstrap;
|
|
9
|
+
destroy: Destroy;
|
|
10
|
+
config: Config;
|
|
11
|
+
routes: Routes;
|
|
12
|
+
contentTypes: ContentTypes;
|
|
13
|
+
controllers: Controllers;
|
|
14
|
+
registerTrads: unknown;
|
|
15
|
+
services: unknown;
|
|
16
|
+
policies: unknown;
|
|
17
|
+
middlewares: unknown;
|
|
18
|
+
}
|
|
19
|
+
export type ServerFunction = () => ServerObject;
|
|
20
|
+
export type ServerInput = ServerObject | ServerFunction;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Strapi } from '../../../../..';
|
|
2
|
+
export type LifecycleMethod = ({ strapi }: {
|
|
3
|
+
strapi: Strapi;
|
|
4
|
+
}) => Promise<unknown> | unknown;
|
|
5
|
+
export type Register = LifecycleMethod;
|
|
6
|
+
export type Bootstrap = LifecycleMethod;
|
|
7
|
+
export type Destroy = LifecycleMethod;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Common } from '../../..';
|
|
2
|
+
export type ArrayNotation = Common.RouteInput[];
|
|
3
|
+
export interface ObjectNotation {
|
|
4
|
+
routes: Common.RouteInput[];
|
|
5
|
+
type?: Common.RouterType;
|
|
6
|
+
}
|
|
7
|
+
export interface NamedRoutes {
|
|
8
|
+
[key: string]: ObjectNotation;
|
|
9
|
+
}
|
|
10
|
+
export type Routes = ArrayNotation | NamedRoutes;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Common, Shared, Utils } from '../..';
|
|
2
|
+
export type IsEnabled<TName extends keyof any, TSchemaUID extends Common.UID.Schema> = TName extends keyof Shared.PluginActivation ? Shared.PluginActivation[TName] extends infer TRule ? Utils.Expression.Or<Utils.Expression.Not<Common.AreSchemaRegistriesExtended>, Utils.Expression.Extends<Common.Schemas[TSchemaUID]['pluginOptions'], {
|
|
3
|
+
[key in TName]: TRule;
|
|
4
|
+
}>> : false : false;
|
|
5
|
+
export * as Config from './config';
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type * as UID from './uid';
|
|
2
|
+
/**
|
|
3
|
+
* Extract valid keys from a given registry.
|
|
4
|
+
*
|
|
5
|
+
* It looks for {@link UID.Any} by default but the search can be narrowed to any UID subset using the `TUidFormat` generic.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* interface Registry {
|
|
9
|
+
* 'foo': unknown;
|
|
10
|
+
* 'default.foo': 'unknown';
|
|
11
|
+
* 'global::foo': unknown;
|
|
12
|
+
* 'api::foo.bar': unknown;
|
|
13
|
+
* }
|
|
14
|
+
*
|
|
15
|
+
* type T = Keys<Registry>;
|
|
16
|
+
* // ^ 'default.foo' | 'global::foo' | 'api::foo.bar'
|
|
17
|
+
* type T = Keys<Registry, UID.Policy>;
|
|
18
|
+
* // ^ 'global::foo' | 'api::foo.bar'
|
|
19
|
+
* type T = Keys<Registry, UID.Service>
|
|
20
|
+
* // ^ 'api::foo.bar'
|
|
21
|
+
*/
|
|
22
|
+
export type Keys<TRegistry, TUidFormat extends UID.Any = UID.Any> = Extract<keyof TRegistry, TUidFormat>;
|
|
23
|
+
/**
|
|
24
|
+
* Performs a `TQuery` filtering operation on the given `TRegistry` registry.
|
|
25
|
+
*
|
|
26
|
+
* `TQuery` needs to be a partial representation of a {@link UID.Parsed}
|
|
27
|
+
*
|
|
28
|
+
* Note: For additional filtering, the registry keys' type can be passed as the third parameter.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* interface Registry {
|
|
32
|
+
* 'admin::foo': unknown;
|
|
33
|
+
* 'admin::bar': unknown;
|
|
34
|
+
* 'api::foo.bar': unknown;
|
|
35
|
+
* 'api::foo.baz': unknown;
|
|
36
|
+
* 'api::bar.foo': unknown;
|
|
37
|
+
* 'plugin::foo.bar': unknown;
|
|
38
|
+
* }
|
|
39
|
+
*
|
|
40
|
+
* type T = keyof WhereKeys<Registry, { namespace: Namespace.API }>;
|
|
41
|
+
* // ^ "api::foo.bar" | "api::foo.baz" | "api::bar.foo"
|
|
42
|
+
*
|
|
43
|
+
* type T = keyof WhereKeys<Registry, { name: 'bar' }>;
|
|
44
|
+
* // ^ "admin::bar" | "api::foo.bar" | "plugin::foo.bar"
|
|
45
|
+
*
|
|
46
|
+
* type T = keyof WhereKeys<Registry, { separator: '.' }>;
|
|
47
|
+
* // ^ "api::foo.bar" | "api::foo.baz" | "api::bar.foo" | 'plugin::foo.bar"
|
|
48
|
+
*
|
|
49
|
+
* type T = keyof WhereKeys<Registry, { namespace: Namespace.Plugin | Namespace.Admin }>;
|
|
50
|
+
* // ^ "plugin::foo.bar" | "admin::foo" | "admin::bar"
|
|
51
|
+
*
|
|
52
|
+
* type T = keyof WhereKeys<Registry, { namespace: Namespace.API; name: Utils.Includes<'b'> }>;
|
|
53
|
+
* // ^ "api::foo.bar" | "api::foo.baz"
|
|
54
|
+
*/
|
|
55
|
+
export type WhereKeys<TRegistry, TQuery extends Partial<UID.Parsed>, TUidFormat extends UID.Any = UID.Any> = {
|
|
56
|
+
[uid in Keys<TRegistry, TUidFormat> as UID.Parse<uid> extends TQuery ? uid : never]: TRegistry[uid];
|
|
57
|
+
};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type { Attribute, Common } from '../..';
|
|
2
|
+
/**
|
|
3
|
+
* Literal union type representing the possible natures of a content type
|
|
4
|
+
*/
|
|
5
|
+
export type ContentTypeKind = 'singleType' | 'collectionType';
|
|
6
|
+
/**
|
|
7
|
+
* Literal union type representing the possible types of a model
|
|
8
|
+
*/
|
|
9
|
+
export type ModelType = 'contentType' | 'component';
|
|
10
|
+
/**
|
|
11
|
+
* Data structure that can either represent a content type or a component
|
|
12
|
+
*/
|
|
13
|
+
export interface Schema {
|
|
14
|
+
/**
|
|
15
|
+
* The type of the model. Useful to discriminate content-types from component
|
|
16
|
+
*/
|
|
17
|
+
modelType: ModelType;
|
|
18
|
+
/**
|
|
19
|
+
* Unique identifier of the schema
|
|
20
|
+
*/
|
|
21
|
+
modelName: string;
|
|
22
|
+
/**
|
|
23
|
+
* Unique identifier of the schema
|
|
24
|
+
*/
|
|
25
|
+
globalId: string;
|
|
26
|
+
/**
|
|
27
|
+
* Map of all the attributes with their name and definition
|
|
28
|
+
*/
|
|
29
|
+
attributes: Attributes;
|
|
30
|
+
/**
|
|
31
|
+
* Options declared and read by the plugins
|
|
32
|
+
*/
|
|
33
|
+
pluginOptions?: PluginOptions;
|
|
34
|
+
/**
|
|
35
|
+
* Options object dedicated to Strapi core features
|
|
36
|
+
*/
|
|
37
|
+
options?: Options;
|
|
38
|
+
/**
|
|
39
|
+
* Custom table name for the schema
|
|
40
|
+
*/
|
|
41
|
+
collectionName?: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Data structure containing naming and display information for a Schema
|
|
45
|
+
*/
|
|
46
|
+
export interface Info {
|
|
47
|
+
/**
|
|
48
|
+
* Default name to use in the admin panel
|
|
49
|
+
*/
|
|
50
|
+
displayName: string;
|
|
51
|
+
/**
|
|
52
|
+
* Description of the model
|
|
53
|
+
*/
|
|
54
|
+
description?: string;
|
|
55
|
+
/**
|
|
56
|
+
* FontAwesome (v5) icon name to use for the component's icon in the admin panel
|
|
57
|
+
*/
|
|
58
|
+
icon?: string;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Low level data structure referencing every schema attribute and its name
|
|
62
|
+
*/
|
|
63
|
+
export interface Attributes {
|
|
64
|
+
[key: string]: Attribute.Any;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Structure containing every core schema options and their associated value
|
|
68
|
+
*/
|
|
69
|
+
export interface Options {
|
|
70
|
+
draftAndPublish?: boolean;
|
|
71
|
+
populateCreatorFields?: boolean;
|
|
72
|
+
comment?: string;
|
|
73
|
+
version?: string;
|
|
74
|
+
}
|
|
75
|
+
export interface PluginOptions {
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Schema for a content type
|
|
79
|
+
*/
|
|
80
|
+
export interface ContentType extends Schema {
|
|
81
|
+
modelType: 'contentType';
|
|
82
|
+
/**
|
|
83
|
+
* Unique identifier of the schema
|
|
84
|
+
*/
|
|
85
|
+
uid: Common.UID.ContentType;
|
|
86
|
+
/**
|
|
87
|
+
* Determine the type of the content type (single-type or collection-type)
|
|
88
|
+
*/
|
|
89
|
+
kind: ContentTypeKind;
|
|
90
|
+
/**
|
|
91
|
+
* Informations about schema naming and display
|
|
92
|
+
*/
|
|
93
|
+
info: ContentTypeInfo;
|
|
94
|
+
}
|
|
95
|
+
export interface ContentTypeInfo extends Info {
|
|
96
|
+
/**
|
|
97
|
+
* Singular form of the content type name
|
|
98
|
+
*/
|
|
99
|
+
singularName: string;
|
|
100
|
+
/**
|
|
101
|
+
* Plural form of the collection type name
|
|
102
|
+
*/
|
|
103
|
+
pluralName: string;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Schema for a collection type
|
|
107
|
+
*/
|
|
108
|
+
export interface CollectionType extends ContentType {
|
|
109
|
+
kind: 'collectionType';
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Schema for a single type
|
|
113
|
+
*/
|
|
114
|
+
export interface SingleType extends ContentType {
|
|
115
|
+
kind: 'singleType';
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Schema for a component
|
|
119
|
+
*/
|
|
120
|
+
export interface Component extends Schema {
|
|
121
|
+
modelType: 'component';
|
|
122
|
+
uid: Common.UID.Component;
|
|
123
|
+
category: string;
|
|
124
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface StrapiDirectories {
|
|
2
|
+
static: {
|
|
3
|
+
public: string;
|
|
4
|
+
};
|
|
5
|
+
app: {
|
|
6
|
+
root: string;
|
|
7
|
+
src: string;
|
|
8
|
+
api: string;
|
|
9
|
+
components: string;
|
|
10
|
+
extensions: string;
|
|
11
|
+
policies: string;
|
|
12
|
+
middlewares: string;
|
|
13
|
+
config: string;
|
|
14
|
+
};
|
|
15
|
+
dist: {
|
|
16
|
+
root: string;
|
|
17
|
+
src: string;
|
|
18
|
+
api: string;
|
|
19
|
+
components: string;
|
|
20
|
+
extensions: string;
|
|
21
|
+
policies: string;
|
|
22
|
+
middlewares: string;
|
|
23
|
+
config: string;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type * as Namespace from './namespace';
|
|
2
|
+
import type * as Utils from '../utils';
|
|
3
|
+
type StringSuffix<T extends string> = Utils.String.Suffix<T, string>;
|
|
4
|
+
/**
|
|
5
|
+
* Template for services' unique identifier
|
|
6
|
+
*/
|
|
7
|
+
export type Service = StringSuffix<Namespace.WithSeparator<Namespace.Admin> | Namespace.WithSeparator<Namespace.API> | Namespace.WithSeparator<Namespace.Plugin>>;
|
|
8
|
+
/**
|
|
9
|
+
* Template for controllers' unique identifier
|
|
10
|
+
*/
|
|
11
|
+
export type Controller = StringSuffix<Namespace.WithSeparator<Namespace.Admin> | Namespace.WithSeparator<Namespace.API> | Namespace.WithSeparator<Namespace.Plugin>>;
|
|
12
|
+
/**
|
|
13
|
+
* Template for policies' unique identifier
|
|
14
|
+
*/
|
|
15
|
+
export type Policy = StringSuffix<Namespace.WithSeparator<Namespace.Admin> | Namespace.WithSeparator<Namespace.Strapi> | Namespace.WithSeparator<Namespace.Global> | Namespace.WithSeparator<Namespace.API> | Namespace.WithSeparator<Namespace.Plugin>>;
|
|
16
|
+
/**
|
|
17
|
+
* Template for middlewares' unique identifier
|
|
18
|
+
*/
|
|
19
|
+
export type Middleware = StringSuffix<Namespace.WithSeparator<Namespace.Admin> | Namespace.WithSeparator<Namespace.Strapi> | Namespace.WithSeparator<Namespace.Global> | Namespace.WithSeparator<Namespace.API> | Namespace.WithSeparator<Namespace.Plugin>>;
|
|
20
|
+
/**
|
|
21
|
+
* Template for content-types' unique identifier
|
|
22
|
+
*/
|
|
23
|
+
export type ContentType = StringSuffix<Namespace.WithSeparator<Namespace.Admin> | Namespace.WithSeparator<Namespace.Strapi> | Namespace.WithSeparator<Namespace.API> | Namespace.WithSeparator<Namespace.Plugin>>;
|
|
24
|
+
/**
|
|
25
|
+
* Template for components' unique identifier
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* 'default.foo' extends Component => true (T = 'default', N = 'foo')
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* // /!\ Warning: Can cause overlap with other UID formats:
|
|
32
|
+
* // 'api::foo.bar' both extends ContentType and Component
|
|
33
|
+
* 'api::foo.bar' extends ContentType => true (N = 'api', S='::', T='foo')
|
|
34
|
+
* 'api::foo.bar' extends Component => true (T = 'api::foo', N = 'bar')
|
|
35
|
+
*/
|
|
36
|
+
export type Component<TCategory extends string = string, TName extends string = string> = `${TCategory}.${TName}`;
|
|
37
|
+
/**
|
|
38
|
+
* Represents any UID
|
|
39
|
+
*/
|
|
40
|
+
export type Any = Service | Controller | Policy | Middleware | ContentType | Component;
|
|
41
|
+
/**
|
|
42
|
+
* Type representation of every UID component.
|
|
43
|
+
*
|
|
44
|
+
* The separator type is automatically inferred from the given namespace
|
|
45
|
+
*/
|
|
46
|
+
export interface Parsed<TNamespace extends Namespace.Any = Namespace.Any, TName extends string = string> {
|
|
47
|
+
raw: `${TNamespace}${Namespace.GetSeparator<TNamespace>}${TName}`;
|
|
48
|
+
namespace: TNamespace;
|
|
49
|
+
origin: TNamespace extends Namespace.Scoped ? Namespace.ExtractOrigin<TNamespace> : TNamespace;
|
|
50
|
+
scope: TNamespace extends Namespace.Scoped ? Namespace.ExtractScope<TNamespace> : never;
|
|
51
|
+
separator: Namespace.GetSeparator<TNamespace>;
|
|
52
|
+
name: TName;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Parse a UID literal and returns a {@link Parsed} type.
|
|
56
|
+
*
|
|
57
|
+
* Warning: Using ParseUID with a union type might produce undesired results as it'll distribute every matching namespace parsing to every union member
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* type T = Parse<'admin::foo'>
|
|
61
|
+
* // ^ { namespace: 'admin'; separator: '::'; name: 'foo'; }
|
|
62
|
+
*
|
|
63
|
+
* type T = Parse<'api::foo.bar'>
|
|
64
|
+
* // ^ { namespace: 'api::foo'; separator: '.'; name: 'bar'; }
|
|
65
|
+
*
|
|
66
|
+
* type T = Parse<'admin::foo' | 'api::foo.bar'>
|
|
67
|
+
* // ^ { namespace: 'admin' | 'api::foo' ; separator: '.' | '::'; name: 'foo' | 'bar' | 'foo.bar'; }
|
|
68
|
+
*/
|
|
69
|
+
export type Parse<TUid extends Any> = ExtractNamespace<TUid> extends infer TExtractedNamespace extends Namespace.Any ? Namespace.GetSeparator<TExtractedNamespace> extends infer TSeparator extends Namespace.Separator ? TUid extends `${infer TInferredNamespace extends TExtractedNamespace}${TSeparator}${infer TName extends string}` ? Parsed<TInferredNamespace, TName> : never : never : never;
|
|
70
|
+
/**
|
|
71
|
+
* Determines if the UID's namespace matches the given one.
|
|
72
|
+
*
|
|
73
|
+
* It returns TNamespace (the {@link Namespace.Any} literal) if there is a match, never otherwise.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* type T = EnsureNamespaceMatches<'admin::foo', Namespace.Admin>
|
|
77
|
+
* // ^ Namespace.Admin
|
|
78
|
+
* @example
|
|
79
|
+
* type T = EnsureNamespaceMatches<'foo.bar', Namespace.API>
|
|
80
|
+
* // ^ never
|
|
81
|
+
* @example
|
|
82
|
+
* type T = EnsureNamespaceMatches<'api::foo.bar', Namespace.Plugin>
|
|
83
|
+
* // ^ never
|
|
84
|
+
*/
|
|
85
|
+
export type EnsureNamespaceMatches<TUid extends Any, TNamespace extends Namespace.Any> = TUid extends StringSuffix<Namespace.WithSeparator<TNamespace>> ? TNamespace : never;
|
|
86
|
+
/**
|
|
87
|
+
* Get parsed properties from a given raw UID
|
|
88
|
+
*/
|
|
89
|
+
export type Get<TUid extends Any, TKey extends keyof Parsed> = Parse<TUid>[TKey];
|
|
90
|
+
/**
|
|
91
|
+
* Pick parsed properties from a given raw UID
|
|
92
|
+
*/
|
|
93
|
+
export type Select<TUid extends Any, TKey extends keyof Parse<TUid>> = Pick<Parse<TUid>, TKey>;
|
|
94
|
+
/**
|
|
95
|
+
* Extract the namespace literal from a given UID.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* type T = ExtractNamespace<'admin::foo'>
|
|
99
|
+
* // ^ Namespace.Admin
|
|
100
|
+
* @example
|
|
101
|
+
* type T = ExtractNamespace<'api::foo.bar'>
|
|
102
|
+
* // ^ Namespace.API
|
|
103
|
+
* @example
|
|
104
|
+
* type T = ExtractNamespace<'admin::foo' | 'api::foo.bar'>
|
|
105
|
+
* // ^ Namespace.Admin | Namespace.API
|
|
106
|
+
*/
|
|
107
|
+
export type ExtractNamespace<TUid extends Any> = EnsureNamespaceMatches<TUid, Namespace.Global> | EnsureNamespaceMatches<TUid, Namespace.Admin> | EnsureNamespaceMatches<TUid, Namespace.Strapi> | EnsureNamespaceMatches<TUid, Namespace.API> | EnsureNamespaceMatches<TUid, Namespace.Plugin>;
|
|
108
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Context } from 'koa';
|
|
2
|
+
import type { Common, Utils } from '..';
|
|
3
|
+
/**
|
|
4
|
+
* Base Core-API controller type
|
|
5
|
+
*
|
|
6
|
+
* TODO: Make use of the T generic to type the other methods based on the given content type
|
|
7
|
+
*/
|
|
8
|
+
export interface Base {
|
|
9
|
+
transformResponse<TData>(data: TData, meta?: object): unknown;
|
|
10
|
+
sanitizeOutput<TData>(data: TData, ctx: Context): Promise<unknown>;
|
|
11
|
+
sanitizeInput<TData>(data: TData, ctx: Context): Promise<unknown>;
|
|
12
|
+
sanitizeQuery(ctx: Context): Promise<Record<string, unknown>>;
|
|
13
|
+
validateInput<TData>(data: TData, ctx: Context): Promise<void>;
|
|
14
|
+
validateQuery(ctx: Context): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Generic controller structure
|
|
18
|
+
*/
|
|
19
|
+
export type Generic = {
|
|
20
|
+
[name: string]: Common.ControllerHandler<unknown>;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Core-API collection type controller
|
|
24
|
+
*/
|
|
25
|
+
export interface CollectionType extends Base {
|
|
26
|
+
find: Common.ControllerHandler<unknown>;
|
|
27
|
+
findOne: Common.ControllerHandler<unknown>;
|
|
28
|
+
create: Common.ControllerHandler<unknown>;
|
|
29
|
+
update: Common.ControllerHandler<unknown>;
|
|
30
|
+
delete: Common.ControllerHandler<unknown>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Core-API single type controller
|
|
34
|
+
*/
|
|
35
|
+
export interface SingleType extends Base {
|
|
36
|
+
find: Common.ControllerHandler<unknown>;
|
|
37
|
+
update: Common.ControllerHandler<unknown>;
|
|
38
|
+
delete: Common.ControllerHandler<unknown>;
|
|
39
|
+
}
|
|
40
|
+
export type ContentType<T extends Common.UID.ContentType> = Utils.Expression.MatchFirst<[
|
|
41
|
+
Utils.Expression.Test<Common.UID.IsCollectionType<T>, CollectionType>,
|
|
42
|
+
Utils.Expression.Test<Common.UID.IsSingleType<T>, SingleType>
|
|
43
|
+
], Base>;
|
|
44
|
+
export type Extendable<T extends Common.UID.ContentType> = Partial<ContentType<T>> & Generic;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { ExtendableContext, Middleware as KoaMiddleware } from 'koa';
|
|
2
|
+
import type { Strapi } from '../..';
|
|
3
|
+
import type { Common, Utils } from '..';
|
|
4
|
+
export type MiddlewareFactory = (config: any, ctx: {
|
|
5
|
+
strapi: Strapi;
|
|
6
|
+
}) => Middleware | null;
|
|
7
|
+
export type Middleware = KoaMiddleware | MiddlewareFactory;
|
|
8
|
+
export interface PolicyContext extends ExtendableContext {
|
|
9
|
+
type: string;
|
|
10
|
+
}
|
|
11
|
+
export type PolicyImplementation<TCfg = unknown> = (ctx: PolicyContext, cfg: TCfg, { strapi }: {
|
|
12
|
+
strapi: Strapi;
|
|
13
|
+
}) => boolean | undefined;
|
|
14
|
+
type HandlerConfig = {
|
|
15
|
+
auth?: false | {
|
|
16
|
+
scope: string[];
|
|
17
|
+
};
|
|
18
|
+
policies?: Array<string | PolicyImplementation | {
|
|
19
|
+
name: string;
|
|
20
|
+
config: object;
|
|
21
|
+
}>;
|
|
22
|
+
middlewares?: Array<string | Middleware | {
|
|
23
|
+
name: string;
|
|
24
|
+
config: object;
|
|
25
|
+
}>;
|
|
26
|
+
};
|
|
27
|
+
export type Generic = {
|
|
28
|
+
[method: string | number | symbol]: HandlerConfig | undefined;
|
|
29
|
+
};
|
|
30
|
+
export interface SingleTypeRouterConfig extends Generic {
|
|
31
|
+
find?: HandlerConfig;
|
|
32
|
+
update?: HandlerConfig;
|
|
33
|
+
delete?: HandlerConfig;
|
|
34
|
+
}
|
|
35
|
+
export interface CollectionTypeRouterConfig extends Generic {
|
|
36
|
+
find?: HandlerConfig;
|
|
37
|
+
findOne?: HandlerConfig;
|
|
38
|
+
create?: HandlerConfig;
|
|
39
|
+
update?: HandlerConfig;
|
|
40
|
+
delete?: HandlerConfig;
|
|
41
|
+
}
|
|
42
|
+
export type RouterConfig<TContentTypeUID extends Common.UID.ContentType> = {
|
|
43
|
+
prefix?: string;
|
|
44
|
+
only?: string[];
|
|
45
|
+
except?: string[];
|
|
46
|
+
config?: Utils.Expression.MatchFirst<[
|
|
47
|
+
Utils.Expression.Test<Common.UID.IsCollectionType<TContentTypeUID>, CollectionTypeRouterConfig>,
|
|
48
|
+
Utils.Expression.Test<Common.UID.IsSingleType<TContentTypeUID>, SingleTypeRouterConfig>
|
|
49
|
+
], Generic>;
|
|
50
|
+
type?: RouterType;
|
|
51
|
+
};
|
|
52
|
+
export type RouterType = 'admin' | 'content-api';
|
|
53
|
+
export type Route = {
|
|
54
|
+
method: string;
|
|
55
|
+
path: string;
|
|
56
|
+
};
|
|
57
|
+
export type Router = {
|
|
58
|
+
type: RouterType;
|
|
59
|
+
prefix?: string;
|
|
60
|
+
routes: Route[] | (() => Route[]);
|
|
61
|
+
};
|
|
62
|
+
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { Common, Utils } from '..';
|
|
2
|
+
type Entity = {
|
|
3
|
+
id: string | number;
|
|
4
|
+
} & Record<string, unknown>;
|
|
5
|
+
type PaginatedEntiies = {
|
|
6
|
+
results: Entity[];
|
|
7
|
+
pagination: {
|
|
8
|
+
page: number;
|
|
9
|
+
pageSize: number | null;
|
|
10
|
+
start?: undefined;
|
|
11
|
+
limit?: undefined;
|
|
12
|
+
} | {
|
|
13
|
+
start: number;
|
|
14
|
+
limit: number;
|
|
15
|
+
page?: undefined;
|
|
16
|
+
pageSize?: undefined;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
type Data = Record<string, unknown>;
|
|
20
|
+
/**
|
|
21
|
+
* Base Core-API service type
|
|
22
|
+
*/
|
|
23
|
+
export interface Base {
|
|
24
|
+
getFetchParams(params: object): object;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Generic core api service structure
|
|
28
|
+
*/
|
|
29
|
+
export type Generic = {
|
|
30
|
+
[key: keyof any]: unknown;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Core-API collection type service
|
|
34
|
+
*/
|
|
35
|
+
export interface CollectionType extends Base {
|
|
36
|
+
find(params: object): Promise<PaginatedEntiies>;
|
|
37
|
+
findOne(entityId: number | `${number}`, params: object): Promise<Entity | null>;
|
|
38
|
+
create(params: {
|
|
39
|
+
data: Data;
|
|
40
|
+
[key: string]: unknown;
|
|
41
|
+
}): Promise<Entity>;
|
|
42
|
+
update(entityId: number | `${number}`, params: {
|
|
43
|
+
data: Data;
|
|
44
|
+
[key: string]: unknown;
|
|
45
|
+
}): Promise<Entity> | Entity;
|
|
46
|
+
delete(entityId: number | `${number}`, params: object): Promise<Entity> | Entity;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Core-API single type service
|
|
50
|
+
*/
|
|
51
|
+
export interface SingleType extends Base {
|
|
52
|
+
find(params: object): Promise<Entity> | Entity;
|
|
53
|
+
createOrUpdate(params: {
|
|
54
|
+
data: Data;
|
|
55
|
+
[key: string]: unknown;
|
|
56
|
+
}): Promise<Entity> | Entity;
|
|
57
|
+
delete(params: object): Promise<Entity> | Entity;
|
|
58
|
+
}
|
|
59
|
+
export type ContentType<TContentTypeUID extends Common.UID.ContentType> = Utils.Expression.MatchFirst<[
|
|
60
|
+
Utils.Expression.Test<Common.UID.IsCollectionType<TContentTypeUID>, CollectionType>,
|
|
61
|
+
Utils.Expression.Test<Common.UID.IsSingleType<TContentTypeUID>, SingleType>
|
|
62
|
+
], Base>;
|
|
63
|
+
export type Extendable<TContentTypeUID extends Common.UID.ContentType> = Partial<ContentType<TContentTypeUID>> & Generic;
|
|
64
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Common, Schema, UID } from '..';
|
|
2
|
+
/**
|
|
3
|
+
* Shared service registry
|
|
4
|
+
*/
|
|
5
|
+
export interface Services {
|
|
6
|
+
[uid: UID.Service]: Common.Service;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Shared controller registry
|
|
10
|
+
*/
|
|
11
|
+
export interface Controllers {
|
|
12
|
+
[uid: UID.Controller]: Common.Controller;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Shared policy registry
|
|
16
|
+
*/
|
|
17
|
+
export interface Policies {
|
|
18
|
+
[uid: UID.Policy]: unknown;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Shared middleware registry
|
|
22
|
+
*/
|
|
23
|
+
export interface Middlewares {
|
|
24
|
+
[uid: UID.Middleware]: unknown;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Shared content-types registry
|
|
28
|
+
*/
|
|
29
|
+
export interface ContentTypes {
|
|
30
|
+
[key: UID.ContentType]: Schema.ContentType;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Shared component registry
|
|
34
|
+
*/
|
|
35
|
+
export interface Components {
|
|
36
|
+
[key: UID.Component]: Schema.Component;
|
|
37
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Utils } from '..';
|
|
2
|
+
/**
|
|
3
|
+
* Extract the array values into an union type
|
|
4
|
+
*/
|
|
5
|
+
export type Values<TCollection extends Array<unknown>> = TCollection extends Array<infer TValues> ? TValues : never;
|
|
6
|
+
/**
|
|
7
|
+
* Checks if the size of the given collection equals 0
|
|
8
|
+
*/
|
|
9
|
+
export type IsEmpty<TCollection extends Array<unknown>> = Utils.Expression.Extends<TCollection['length'], 0>;
|
|
10
|
+
/**
|
|
11
|
+
* Checks if the size of the given collection is not 0
|
|
12
|
+
*
|
|
13
|
+
* Returns a {@link Utils.Expression.Boolean} expression
|
|
14
|
+
*/
|
|
15
|
+
export type IsNotEmpty<TCollection extends Array<unknown>> = Utils.Expression.Not<IsEmpty<TCollection>>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Utils } from '..';
|
|
2
|
+
export type True = true;
|
|
3
|
+
export type False = false;
|
|
4
|
+
export type BooleanValue = True | False;
|
|
5
|
+
export type IsNever<TValue> = StrictEqual<TValue, never>;
|
|
6
|
+
export type IsNotNever<TValue> = Not<IsNever<TValue>>;
|
|
7
|
+
export type IsTrue<TValue> = [TValue] extends [True] ? True : False;
|
|
8
|
+
export type IsFalse<TValue> = [TValue] extends [False] ? True : False;
|
|
9
|
+
export type StrictEqual<TValue, TMatch> = And<Extends<TValue, TMatch>, Extends<TMatch, TValue>>;
|
|
10
|
+
export type Extends<TLeft, TRight> = [TLeft] extends [TRight] ? True : False;
|
|
11
|
+
export type DoesNotExtends<TLeft, TRight> = Not<Extends<TLeft, TRight>>;
|
|
12
|
+
export type Not<TExpression extends BooleanValue> = If<TExpression, False, True>;
|
|
13
|
+
export type If<TExpression extends BooleanValue, TOnTrue, TOnFalse = never> = [
|
|
14
|
+
TExpression
|
|
15
|
+
] extends [True] ? TOnTrue : TOnFalse;
|
|
16
|
+
export type MatchFirst<TTests extends Test[], TDefault = never> = TTests extends [
|
|
17
|
+
infer THead extends Test,
|
|
18
|
+
...infer TTail extends Test[]
|
|
19
|
+
] ? THead extends Test<infer TExpression, infer TValue> ? If<TExpression, TValue, If<Utils.Array.IsNotEmpty<TTail>, MatchFirst<TTail, TDefault>, TDefault>> : never : never;
|
|
20
|
+
export type MatchAllUnion<TTests extends Test[], TDefault = never> = TTests extends [
|
|
21
|
+
infer THead extends Test,
|
|
22
|
+
...infer TTail extends Test[]
|
|
23
|
+
] ? THead extends Test<infer TExpression, infer TValue> ? Utils.Guard.Never<If<TExpression, TValue> | If<Utils.Array.IsNotEmpty<TTail>, MatchAllUnion<TTail, TDefault>>, TDefault> : never : never;
|
|
24
|
+
export type MatchAllIntersect<TTests extends Test[], TDefault = unknown> = TTests extends [
|
|
25
|
+
infer THead extends Test,
|
|
26
|
+
...infer TTail extends Test[]
|
|
27
|
+
] ? THead extends Test<infer TExpression, infer TValue> ? // Actual test case evaluation
|
|
28
|
+
If<TExpression, TValue, TDefault> & If<Utils.Array.IsNotEmpty<TTail>, MatchAllIntersect<TTail, TDefault>, TDefault> : TDefault : TDefault;
|
|
29
|
+
export type Test<TExpression extends BooleanValue = BooleanValue, TValue = unknown> = [
|
|
30
|
+
TExpression,
|
|
31
|
+
TValue
|
|
32
|
+
];
|
|
33
|
+
export type Some<TExpressions extends BooleanValue[]> = TExpressions extends [
|
|
34
|
+
infer THead extends BooleanValue,
|
|
35
|
+
...infer TTail extends BooleanValue[]
|
|
36
|
+
] ? If<Utils.Array.IsNotEmpty<TTail>, Or<THead, Some<TTail>>, Or<THead, false>> : never;
|
|
37
|
+
export type Every<TExpressions extends BooleanValue[]> = TExpressions extends [
|
|
38
|
+
infer THead extends BooleanValue,
|
|
39
|
+
...infer TTail extends BooleanValue[]
|
|
40
|
+
] ? If<Utils.Array.IsNotEmpty<TTail>, And<THead, Every<TTail>>, And<THead, True>> : never;
|
|
41
|
+
export type And<TLeft extends BooleanValue, TRight extends BooleanValue> = IsTrue<IsTrue<TLeft> | IsTrue<TRight>>;
|
|
42
|
+
export type Or<TLeft extends BooleanValue, TRight extends BooleanValue> = Not<IsFalse<IsTrue<TLeft> | IsTrue<TRight>>>;
|