@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,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Strapi custom scalar types
|
|
3
|
+
*/
|
|
4
|
+
import type { Attribute, Common } from '..';
|
|
5
|
+
/**
|
|
6
|
+
* Setters for the attributes options
|
|
7
|
+
*/
|
|
8
|
+
export type Required = {
|
|
9
|
+
required: true;
|
|
10
|
+
};
|
|
11
|
+
export type NonRequired = {
|
|
12
|
+
required: false;
|
|
13
|
+
};
|
|
14
|
+
export type Private = {
|
|
15
|
+
private: true;
|
|
16
|
+
};
|
|
17
|
+
export type NonPrivate = {
|
|
18
|
+
private: false;
|
|
19
|
+
};
|
|
20
|
+
export type Unique = {
|
|
21
|
+
unique: true;
|
|
22
|
+
};
|
|
23
|
+
export type NonUnique = {
|
|
24
|
+
unique: false;
|
|
25
|
+
};
|
|
26
|
+
export type Configurable = {
|
|
27
|
+
configurable: true;
|
|
28
|
+
};
|
|
29
|
+
export type NonConfigurable = {
|
|
30
|
+
configurable: false;
|
|
31
|
+
};
|
|
32
|
+
export type Writable = {
|
|
33
|
+
writable: true;
|
|
34
|
+
};
|
|
35
|
+
export type NonWritable = {
|
|
36
|
+
writable: false;
|
|
37
|
+
};
|
|
38
|
+
export type Visible = {
|
|
39
|
+
visible: true;
|
|
40
|
+
};
|
|
41
|
+
export type NonVisible = {
|
|
42
|
+
visible: false;
|
|
43
|
+
};
|
|
44
|
+
export type CustomField<TKind extends string, TOptions extends object | undefined = undefined> = {
|
|
45
|
+
customField: TKind;
|
|
46
|
+
options?: TOptions;
|
|
47
|
+
};
|
|
48
|
+
export type SetMinMax<TConfig extends Attribute.MinMaxOption<TType>, TType = number> = TConfig;
|
|
49
|
+
export type SetMinMaxLength<TConfig extends Attribute.MinMaxLengthOption> = TConfig;
|
|
50
|
+
export type SetPluginOptions<TConfig extends object = object> = {
|
|
51
|
+
pluginOptions?: TConfig;
|
|
52
|
+
};
|
|
53
|
+
export type DefaultTo<T> = {
|
|
54
|
+
default: T;
|
|
55
|
+
};
|
|
56
|
+
export type Any = Attribute.BigInteger | Attribute.Boolean | Attribute.Blocks | Attribute.Component<Common.UID.Component, boolean> | Attribute.DateTime | Attribute.Date | Attribute.Decimal | Attribute.DynamicZone | Attribute.Email | Attribute.Enumeration<string[]> | Attribute.Float | Attribute.Integer | Attribute.JSON | Attribute.Media<Attribute.MediaKind | undefined, boolean> | Attribute.Password | Attribute.Relation<Common.UID.Schema, Attribute.RelationKind.Any, Common.UID.Schema> | Attribute.RichText | Attribute.String | Attribute.Text | Attribute.Time | Attribute.Timestamp | Attribute.UID<Common.UID.Schema>;
|
|
57
|
+
export type PopulatableKind = Extract<Attribute.Kind, 'relation' | 'component' | 'dynamiczone' | 'media'>;
|
|
58
|
+
export type NonPopulatableKind = Exclude<Attribute.Kind, 'relation' | 'component' | 'dynamiczone' | 'media'>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Attribute, Common } from '..';
|
|
2
|
+
import type { Utils } from '../..';
|
|
3
|
+
export interface ComponentProperties<TComponentUID extends Common.UID.Component, TRepeatable extends Utils.Expression.BooleanValue = Utils.Expression.False> {
|
|
4
|
+
component: TComponentUID;
|
|
5
|
+
repeatable?: TRepeatable;
|
|
6
|
+
}
|
|
7
|
+
export type Component<TComponentUID extends Common.UID.Component = Common.UID.Component, TRepeatable extends Utils.Expression.BooleanValue = Utils.Expression.False> = Attribute.OfType<'component'> & ComponentProperties<TComponentUID, TRepeatable> & Attribute.ConfigurableOption & Attribute.MinMaxOption & Attribute.PrivateOption & Attribute.RequiredOption & Attribute.WritableOption & Attribute.VisibleOption;
|
|
8
|
+
export type ComponentValue<TComponentUID extends Common.UID.Component, TRepeatable extends Utils.Expression.BooleanValue> = Attribute.GetValues<TComponentUID> extends infer TValues ? Utils.Expression.If<TRepeatable, TValues[], TValues> : never;
|
|
9
|
+
export type GetComponentValue<TAttribute extends Attribute.Attribute> = TAttribute extends Component<infer TComponentUID, infer TRepeatable> ? ComponentValue<TComponentUID, TRepeatable> : never;
|
|
10
|
+
export type GetComponentTarget<TAttribute extends Attribute.Attribute> = TAttribute extends Component<infer TComponentUID, infer _TRepeatable> ? TComponentUID : never;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Attribute } from '..';
|
|
2
|
+
export type DateTime = Attribute.OfType<'datetime'> & Attribute.ConfigurableOption & Attribute.DefaultOption<DateTimeValue> & Attribute.PrivateOption & Attribute.RequiredOption & Attribute.UniqueOption & Attribute.WritableOption & Attribute.VisibleOption;
|
|
3
|
+
export type DateTimeValue = globalThis.Date | string;
|
|
4
|
+
export type GetDateTimeValue<T extends Attribute.Attribute> = T extends DateTime ? DateTimeValue : never;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Attribute } from '..';
|
|
2
|
+
export type Date = Attribute.OfType<'date'> & Attribute.ConfigurableOption & Attribute.DefaultOption<DateValue> & Attribute.PrivateOption & Attribute.RequiredOption & Attribute.UniqueOption & Attribute.WritableOption & Attribute.VisibleOption;
|
|
3
|
+
export type DateValue = globalThis.Date | string;
|
|
4
|
+
export type GetDateValue<T extends Attribute.Attribute> = T extends Date ? DateValue : never;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Attribute } from '..';
|
|
2
|
+
export type Decimal = Attribute.OfType<'decimal'> & Attribute.ConfigurableOption & Attribute.DefaultOption<DecimalValue> & Attribute.MinMaxOption & Attribute.PrivateOption & Attribute.RequiredOption & Attribute.WritableOption & Attribute.VisibleOption & Attribute.UniqueOption;
|
|
3
|
+
export type DecimalValue = number;
|
|
4
|
+
export type GetDecimalValue<T extends Attribute.Attribute> = T extends Decimal ? DecimalValue : never;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Attribute, Common } from '..';
|
|
2
|
+
import type { Utils } from '../..';
|
|
3
|
+
export interface DynamicZoneProperties<TComponentsUID extends Common.UID.Component[]> {
|
|
4
|
+
components: TComponentsUID;
|
|
5
|
+
}
|
|
6
|
+
export type DynamicZone<TComponentsUID extends Common.UID.Component[] = Common.UID.Component[]> = Attribute.OfType<'dynamiczone'> & DynamicZoneProperties<TComponentsUID> & Attribute.ConfigurableOption & Attribute.MinMaxOption & Attribute.RequiredOption & Attribute.WritableOption & Attribute.VisibleOption;
|
|
7
|
+
type DynamicZoneValue<TComponentsUID extends Common.UID.Component[]> = Array<Utils.Array.Values<TComponentsUID> extends infer TComponentUID ? TComponentUID extends Common.UID.Component ? Attribute.GetValues<TComponentUID> & {
|
|
8
|
+
__component: TComponentUID;
|
|
9
|
+
} : never : never>;
|
|
10
|
+
export type GetDynamicZoneValue<TAttribute extends Attribute.Attribute> = TAttribute extends DynamicZone<infer TComponentsUID> ? DynamicZoneValue<TComponentsUID> : never;
|
|
11
|
+
export type GetDynamicZoneTargets<TAttribute extends Attribute.Attribute> = TAttribute extends DynamicZone<infer TComponentsUID> ? Utils.Array.Values<TComponentsUID> : never;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Attribute } from '..';
|
|
2
|
+
export type Email = Attribute.OfType<'email'> & Attribute.ConfigurableOption & Attribute.DefaultOption<EmailValue> & Attribute.MinMaxLengthOption & Attribute.PrivateOption & Attribute.RequiredOption & Attribute.UniqueOption & Attribute.WritableOption & Attribute.VisibleOption;
|
|
3
|
+
export type EmailValue = string;
|
|
4
|
+
export type GetEmailValue<T extends Attribute.Attribute> = T extends Email ? EmailValue : never;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Attribute } from '..';
|
|
2
|
+
import type { Utils } from '../..';
|
|
3
|
+
export interface EnumerationProperties<TValues extends string[] = []> {
|
|
4
|
+
enum: TValues;
|
|
5
|
+
}
|
|
6
|
+
export type Enumeration<TValues extends string[] = []> = Attribute.OfType<'enumeration'> & EnumerationProperties<TValues> & Attribute.ConfigurableOption & Attribute.DefaultOption<TValues[number]> & Attribute.PrivateOption & Attribute.RequiredOption & Attribute.WritableOption & Attribute.VisibleOption;
|
|
7
|
+
export type EnumerationValue<TValues extends string[]> = Utils.Array.Values<TValues>;
|
|
8
|
+
export type GetEnumerationValue<TAttribute extends Attribute.Attribute> = TAttribute extends Enumeration<infer TValues> ? EnumerationValue<TValues> : never;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Attribute } from '..';
|
|
2
|
+
export type Float = Attribute.OfType<'float'> & Attribute.ConfigurableOption & Attribute.DefaultOption<FloatValue> & Attribute.MinMaxOption & Attribute.PrivateOption & Attribute.RequiredOption & Attribute.WritableOption & Attribute.VisibleOption & Attribute.UniqueOption;
|
|
3
|
+
export type FloatValue = number;
|
|
4
|
+
export type GetFloatValue<T extends Attribute.Attribute> = T extends Float ? FloatValue : never;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export * from './base';
|
|
2
|
+
export * from './biginteger';
|
|
3
|
+
export * from './boolean';
|
|
4
|
+
export * from './blocks';
|
|
5
|
+
export * from './component';
|
|
6
|
+
export * from './decimal';
|
|
7
|
+
export * from './dynamic-zone';
|
|
8
|
+
export * from './enumeration';
|
|
9
|
+
export * from './float';
|
|
10
|
+
export * from './integer';
|
|
11
|
+
export * from './json';
|
|
12
|
+
export * from './media';
|
|
13
|
+
export * from './password';
|
|
14
|
+
export * from './relation';
|
|
15
|
+
export * from './richtext';
|
|
16
|
+
export * from './string';
|
|
17
|
+
export * from './text';
|
|
18
|
+
export * from './uid';
|
|
19
|
+
export * from './email';
|
|
20
|
+
export * from './date';
|
|
21
|
+
export * from './date-time';
|
|
22
|
+
export * from './timestamp';
|
|
23
|
+
export * from './time';
|
|
24
|
+
export * from './common';
|
|
25
|
+
export * from './utils';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Attribute } from '..';
|
|
2
|
+
export type Integer = Attribute.OfType<'integer'> & Attribute.ConfigurableOption & Attribute.DefaultOption<IntegerValue> & Attribute.MinMaxOption & Attribute.PrivateOption & Attribute.RequiredOption & Attribute.WritableOption & Attribute.VisibleOption & Attribute.UniqueOption;
|
|
3
|
+
export type IntegerValue = number;
|
|
4
|
+
export type GetIntegerValue<T extends Attribute.Attribute> = T extends Integer ? IntegerValue : never;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Attribute } from '..';
|
|
2
|
+
export type JSON = Attribute.OfType<'json'> & Attribute.ConfigurableOption & Attribute.RequiredOption & Attribute.PrivateOption & Attribute.WritableOption & Attribute.VisibleOption & Attribute.DefaultOption<JsonValue>;
|
|
3
|
+
export type JsonValue<T extends object = object> = T;
|
|
4
|
+
export type GetJsonValue<T extends Attribute.Attribute> = T extends JSON ? JsonValue : never;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Attribute } from '..';
|
|
2
|
+
import type { Utils } from '../..';
|
|
3
|
+
export type MediaTarget = 'plugin::upload.file';
|
|
4
|
+
export type MediaKind = 'images' | 'videos' | 'files' | 'audios';
|
|
5
|
+
export interface MediaProperties<TKind extends MediaKind | undefined = undefined, TMultiple extends Utils.Expression.BooleanValue = Utils.Expression.False> {
|
|
6
|
+
allowedTypes?: TKind | TKind[];
|
|
7
|
+
multiple?: TMultiple;
|
|
8
|
+
}
|
|
9
|
+
export type Media<TKind extends MediaKind | undefined = undefined, TMultiple extends Utils.Expression.BooleanValue = Utils.Expression.False> = Attribute.OfType<'media'> & MediaProperties<TKind, TMultiple> & Attribute.ConfigurableOption & Attribute.RequiredOption & Attribute.PrivateOption & Attribute.WritableOption & Attribute.VisibleOption;
|
|
10
|
+
export type MediaValue<TMultiple extends Utils.Expression.BooleanValue = Utils.Expression.False> = Utils.Expression.If<TMultiple, any[], any>;
|
|
11
|
+
export type GetMediaValue<TAttribute extends Attribute.Attribute> = TAttribute extends Media<infer _TKind, infer TMultiple> ? MediaValue<TMultiple> : never;
|
|
12
|
+
export type GetMediaTarget<TAttribute extends Attribute.Attribute> = TAttribute extends Media<infer _TKind, infer _TMultiple> ? MediaTarget : never;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Attribute } from '..';
|
|
2
|
+
export type Password = Attribute.OfType<'password'> & Attribute.ConfigurableOption & Attribute.DefaultOption<PasswordValue> & Attribute.MinMaxLengthOption & Attribute.PrivateOption & Attribute.RequiredOption & Attribute.WritableOption & Attribute.VisibleOption;
|
|
3
|
+
export type PasswordValue = string;
|
|
4
|
+
export type GetPasswordValue<T extends Attribute.Attribute> = T extends Password ? PasswordValue : never;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { Attribute, Common } from '..';
|
|
2
|
+
import type { Utils } from '../..';
|
|
3
|
+
export type Relation<_TOrigin extends Common.UID.Schema = Common.UID.Schema, TRelationKind extends RelationKind.Any = RelationKind.Any, TTarget extends Common.UID.Schema = Common.UID.Schema> = Attribute.OfType<'relation'> & Utils.Guard.Never<RelationProperties<TRelationKind, TTarget>, AllRelationProperties<TTarget>> & Attribute.ConfigurableOption & Attribute.PrivateOption & Attribute.WritableOption & Attribute.VisibleOption & Attribute.RequiredOption;
|
|
4
|
+
export type RelationProperties<TRelationKind extends RelationKind.Any, TTarget extends Common.UID.Schema> = Utils.Expression.MatchFirst<[
|
|
5
|
+
[
|
|
6
|
+
Utils.Expression.Extends<TRelationKind, RelationKind.BiDirectional>,
|
|
7
|
+
BiDirectionalProperties<Utils.Cast<TRelationKind, RelationKind.BiDirectional>, TTarget>
|
|
8
|
+
],
|
|
9
|
+
[
|
|
10
|
+
Utils.Expression.Extends<TRelationKind, RelationKind.XWay>,
|
|
11
|
+
XWayProperties<Utils.Cast<TRelationKind, RelationKind.XWay>, TTarget>
|
|
12
|
+
],
|
|
13
|
+
[
|
|
14
|
+
Utils.Expression.Extends<TRelationKind, RelationKind.MorphReference>,
|
|
15
|
+
MorphReferenceProperties<Utils.Cast<TRelationKind, RelationKind.MorphReference>, TTarget>
|
|
16
|
+
],
|
|
17
|
+
[
|
|
18
|
+
Utils.Expression.Extends<TRelationKind, RelationKind.MorphOwner>,
|
|
19
|
+
MorphOwnerProperties<Utils.Cast<TRelationKind, RelationKind.MorphOwner>>
|
|
20
|
+
]
|
|
21
|
+
]>;
|
|
22
|
+
export type AllRelationProperties<TTarget extends Common.UID.Schema> = BiDirectionalProperties<RelationKind.BiDirectional, TTarget> | XWayProperties<RelationKind.XWay, TTarget> | MorphReferenceProperties<RelationKind.MorphReference, TTarget> | MorphOwnerProperties<'morphToOne'> | MorphOwnerProperties<'morphToMany'>;
|
|
23
|
+
type BiDirectionalProperties<TRelationKind extends RelationKind.BiDirectional, TTarget extends Common.UID.Schema> = {
|
|
24
|
+
relation: TRelationKind;
|
|
25
|
+
target: TTarget;
|
|
26
|
+
} & Utils.XOR<{
|
|
27
|
+
inversedBy?: string;
|
|
28
|
+
}, {
|
|
29
|
+
mappedBy?: string;
|
|
30
|
+
}>;
|
|
31
|
+
type XWayProperties<TRelationKind extends RelationKind.XWay, TTarget extends Common.UID.Schema> = {
|
|
32
|
+
relation: TRelationKind;
|
|
33
|
+
target: TTarget;
|
|
34
|
+
};
|
|
35
|
+
type MorphReferenceProperties<TRelationKind extends RelationKind.MorphReference, TTarget extends Common.UID.Schema> = {
|
|
36
|
+
relation: TRelationKind;
|
|
37
|
+
target: TTarget;
|
|
38
|
+
morphBy?: Utils.Guard.Never<Attribute.GetKeysByType<TTarget, 'relation', {
|
|
39
|
+
relation: RelationKind.MorphOwner;
|
|
40
|
+
}>, string>;
|
|
41
|
+
};
|
|
42
|
+
type MorphOwnerProperties<TRelationKind extends RelationKind.MorphOwner> = {
|
|
43
|
+
relation: TRelationKind;
|
|
44
|
+
};
|
|
45
|
+
export type RelationsKeysFromTo<TTarget extends Common.UID.Schema, TOrigin extends Common.UID.Schema> = Utils.Guard.Never<keyof PickRelationsFromTo<TTarget, TOrigin>, string>;
|
|
46
|
+
export type PickRelationsFromTo<TTarget extends Common.UID.Schema, TOrigin extends Common.UID.Schema> = Attribute.GetByType<TTarget, 'relation', {
|
|
47
|
+
target: TOrigin;
|
|
48
|
+
}>;
|
|
49
|
+
export type RelationPluralityModifier<TRelationKind extends RelationKind.Any, TValue> = TRelationKind extends Utils.String.Suffix<string, 'Many'> ? TValue[] : TValue;
|
|
50
|
+
export type RelationValue<TRelationKind extends RelationKind.Any, TTarget extends Common.UID.Schema> = RelationPluralityModifier<TRelationKind, Attribute.GetValues<TTarget>>;
|
|
51
|
+
export type GetRelationValue<TAttribute extends Attribute.Attribute> = TAttribute extends Relation<infer _TOrigin, infer TRelationKind, infer TTarget> ? RelationValue<TRelationKind, TTarget> : never;
|
|
52
|
+
export type GetRelationTarget<TAttribute extends Attribute.Attribute> = TAttribute extends Relation<infer _TOrigin, infer _TRelationKind, infer TTarget> ? TTarget : never;
|
|
53
|
+
export declare namespace RelationKind {
|
|
54
|
+
type GetOppositePlurality<TPlurality extends RelationKind.Left | RelationKind.Right> = {
|
|
55
|
+
one: 'many';
|
|
56
|
+
One: 'Many';
|
|
57
|
+
many: 'one';
|
|
58
|
+
Many: 'One';
|
|
59
|
+
}[TPlurality];
|
|
60
|
+
export type Plurality = 'one' | 'many';
|
|
61
|
+
export type Left = Lowercase<RelationKind.Plurality>;
|
|
62
|
+
export type Right = Capitalize<RelationKind.Plurality>;
|
|
63
|
+
export type MorphOwner = `morphTo${RelationKind.Right}`;
|
|
64
|
+
export type MorphReference = `morph${RelationKind.Right}`;
|
|
65
|
+
export type Morph = RelationKind.MorphOwner | RelationKind.MorphReference;
|
|
66
|
+
export type XWay = `${RelationKind.Left}Way`;
|
|
67
|
+
export type BiDirectional = `${RelationKind.Left}To${RelationKind.Right}`;
|
|
68
|
+
export type UniDirectional = RelationKind.MorphReference | RelationKind.XWay;
|
|
69
|
+
export type Any = RelationKind.BiDirectional | RelationKind.Morph | RelationKind.XWay;
|
|
70
|
+
export type WithTarget = RelationKind.BiDirectional | RelationKind.XWay | RelationKind.MorphReference;
|
|
71
|
+
export type WithoutTarget = RelationKind.MorphOwner;
|
|
72
|
+
export type Reverse<TRelationKind extends RelationKind.Any> = TRelationKind extends `${infer TLeft extends RelationKind.Left}To${infer TRight extends RelationKind.Right}` ? Utils.Expression.If<Utils.Expression.Extends<Uppercase<TLeft>, Uppercase<TRight>>, TRelationKind, `${GetOppositePlurality<TLeft>}To${GetOppositePlurality<TRight>}`> : TRelationKind;
|
|
73
|
+
export {};
|
|
74
|
+
}
|
|
75
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Attribute } from '..';
|
|
2
|
+
export type RichText = Attribute.OfType<'richtext'> & Attribute.ConfigurableOption & Attribute.DefaultOption<RichTextValue> & Attribute.MinMaxLengthOption & Attribute.PrivateOption & Attribute.RequiredOption & Attribute.WritableOption & Attribute.VisibleOption;
|
|
3
|
+
export type RichTextValue = string;
|
|
4
|
+
export type GetRichTextValue<T extends Attribute.Attribute> = T extends RichText ? RichTextValue : never;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Attribute } from '..';
|
|
2
|
+
export interface StringProperties {
|
|
3
|
+
regex?: RegExp;
|
|
4
|
+
}
|
|
5
|
+
type StringAttribute = Attribute.OfType<'string'> & StringProperties & Attribute.ConfigurableOption & Attribute.DefaultOption<StringValue> & Attribute.MinMaxLengthOption & Attribute.PrivateOption & Attribute.UniqueOption & Attribute.RequiredOption & Attribute.WritableOption & Attribute.VisibleOption;
|
|
6
|
+
export type StringValue = string;
|
|
7
|
+
export type GetStringValue<T extends Attribute.Attribute> = T extends StringAttribute ? StringValue : never;
|
|
8
|
+
export type String = StringAttribute;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Attribute } from '..';
|
|
2
|
+
export interface TextProperties {
|
|
3
|
+
regex?: RegExp;
|
|
4
|
+
}
|
|
5
|
+
export type Text = Attribute.OfType<'text'> & TextProperties & Attribute.ConfigurableOption & Attribute.DefaultOption<TextValue> & Attribute.MinMaxLengthOption & Attribute.PrivateOption & Attribute.UniqueOption & Attribute.RequiredOption & Attribute.WritableOption & Attribute.VisibleOption;
|
|
6
|
+
export type TextValue = string;
|
|
7
|
+
export type GetTextValue<T extends Attribute.Attribute> = T extends Text ? TextValue : never;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Attribute } from '..';
|
|
2
|
+
export type Time = Attribute.OfType<'time'> & Attribute.ConfigurableOption & Attribute.DefaultOption<TimeValue> & Attribute.PrivateOption & Attribute.RequiredOption & Attribute.UniqueOption & Attribute.WritableOption & Attribute.VisibleOption;
|
|
3
|
+
export type TimeValue = globalThis.Date | string;
|
|
4
|
+
export type GetTimeValue<T extends Attribute.Attribute> = T extends Time ? TimeValue : never;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Attribute } from '..';
|
|
2
|
+
export type Timestamp = Attribute.OfType<'timestamp'> & Attribute.ConfigurableOption & Attribute.DefaultOption<TimestampValue> & Attribute.PrivateOption & Attribute.RequiredOption & Attribute.UniqueOption & Attribute.WritableOption & Attribute.VisibleOption;
|
|
3
|
+
export type TimestampValue = globalThis.Date | number | string;
|
|
4
|
+
export type GetTimestampValue<T extends Attribute.Attribute> = T extends Timestamp ? TimestampValue : never;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Attribute, Common } from '..';
|
|
2
|
+
export interface UIDOptions {
|
|
3
|
+
separator?: string;
|
|
4
|
+
lowercase?: boolean;
|
|
5
|
+
decamelize?: boolean;
|
|
6
|
+
customReplacements?: Array<[string, string]>;
|
|
7
|
+
preserveLeadingUnderscore?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface UIDProperties<TTargetAttribute extends string = string, TOptions extends UIDOptions = UIDOptions> {
|
|
10
|
+
targetField?: TTargetAttribute;
|
|
11
|
+
options?: UIDOptions & TOptions;
|
|
12
|
+
}
|
|
13
|
+
export type UID<_TOrigin extends Common.UID.Schema = never, TTargetAttribute extends string = string, TOptions extends UIDOptions = UIDOptions> = Attribute.OfType<'uid'> & UIDProperties<TTargetAttribute, TOptions> & Attribute.ConfigurableOption & Attribute.DefaultOption<UIDValue> & Attribute.MinMaxLengthOption & Attribute.PrivateOption & Attribute.RequiredOption & Attribute.WritableOption & Attribute.VisibleOption;
|
|
14
|
+
export type UIDValue = string;
|
|
15
|
+
export type GetUIDValue<TAttribute extends Attribute.Attribute> = TAttribute extends UID<infer _TOrigin, infer _TTargetAttribute> ? UIDValue : never;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Attribute, Common } from '..';
|
|
2
|
+
import type { Utils } from '../..';
|
|
3
|
+
export type GetKeysByType<TSchemaUID extends Common.UID.Schema, TKind extends Attribute.Kind, TCondition = never> = Utils.Object.KeysBy<GetAll<TSchemaUID>, Attribute.OfType<TKind> & Utils.Guard.Never<TCondition, unknown>, string>;
|
|
4
|
+
export type GetByType<TSchemaUID extends Common.UID.Schema, TKind extends Attribute.Kind, TCondition = never> = Utils.Object.PickBy<GetAll<TSchemaUID>, Attribute.OfType<TKind> & Utils.Guard.Never<TCondition, unknown>>;
|
|
5
|
+
export type Get<TSchemaUID extends Common.UID.Schema, TKey extends GetKeys<TSchemaUID>> = Utils.Get<GetAll<TSchemaUID>, TKey>;
|
|
6
|
+
export type GetAll<TSchemaUID extends Common.UID.Schema> = Utils.Get<Common.Schemas[TSchemaUID], 'attributes'>;
|
|
7
|
+
export type GetTarget<TSchemaUID extends Common.UID.Schema, TKey extends GetKeys<TSchemaUID>> = Get<TSchemaUID, TKey> extends infer TAttribute extends Attribute.Attribute ? Attribute.GetRelationTarget<TAttribute> | Attribute.GetComponentTarget<TAttribute> | Attribute.GetMediaTarget<TAttribute> : never;
|
|
8
|
+
export type GetMorphTargets<TSchemaUID extends Common.UID.Schema, TKey extends GetKeys<TSchemaUID>> = Get<TSchemaUID, TKey> extends infer TAttribute extends Attribute.Attribute ? Attribute.GetDynamicZoneTargets<TAttribute> : never;
|
|
9
|
+
export type GetKeys<TSchemaUID extends Common.UID.Schema> = keyof GetAll<TSchemaUID> & string;
|
|
10
|
+
export type GetNonPopulatableKeys<TSchemaUID extends Common.UID.Schema> = GetKeysByType<TSchemaUID, Attribute.NonPopulatableKind>;
|
|
11
|
+
export type GetPopulatableKeys<TSchemaUID extends Common.UID.Schema> = GetKeysByType<TSchemaUID, Attribute.PopulatableKind>;
|
|
12
|
+
export type GetKeysWithTarget<TSchemaUID extends Common.UID.Schema> = keyof {
|
|
13
|
+
[key in GetKeys<TSchemaUID> as GetTarget<TSchemaUID, key> extends never ? never : key]: never;
|
|
14
|
+
} extends infer TKey extends GetKeys<TSchemaUID> ? TKey : never;
|
|
15
|
+
export type GetValue<TAttribute extends Attribute.Attribute, TGuard = unknown> = Utils.Guard.Never<Attribute.GetBigIntegerValue<TAttribute> | Attribute.GetBooleanValue<TAttribute> | Attribute.GetBlocksValue<TAttribute> | Attribute.GetComponentValue<TAttribute> | Attribute.GetDecimalValue<TAttribute> | Attribute.GetDynamicZoneValue<TAttribute> | Attribute.GetEnumerationValue<TAttribute> | Attribute.GetEmailValue<TAttribute> | Attribute.GetFloatValue<TAttribute> | Attribute.GetIntegerValue<TAttribute> | Attribute.GetJsonValue<TAttribute> | Attribute.GetMediaValue<TAttribute> | Attribute.GetPasswordValue<TAttribute> | Attribute.GetRelationValue<TAttribute> | Attribute.GetRichTextValue<TAttribute> | Attribute.GetStringValue<TAttribute> | Attribute.GetTextValue<TAttribute> | Attribute.GetUIDValue<TAttribute> | Attribute.GetDateValue<TAttribute> | Attribute.GetDateTimeValue<TAttribute> | Attribute.GetTimeValue<TAttribute> | Attribute.GetTimestampValue<TAttribute>, TGuard>;
|
|
16
|
+
export type GetValueByKey<TSchemaUID extends Common.UID.Schema, TKey extends GetKeys<TSchemaUID>> = Get<TSchemaUID, TKey> extends infer TAttribute extends Attribute.Attribute ? GetValue<TAttribute> : never;
|
|
17
|
+
export type GetValues<TSchemaUID extends Common.UID.Schema, TKey extends GetKeys<TSchemaUID> = GetKeys<TSchemaUID>> = {
|
|
18
|
+
id: number | `${number}`;
|
|
19
|
+
} & {
|
|
20
|
+
[key in GetRequiredKeys<TSchemaUID> as key extends TKey ? key : never]-?: GetValueByKey<TSchemaUID, key>;
|
|
21
|
+
} & {
|
|
22
|
+
[key in GetOptionalKeys<TSchemaUID> as key extends TKey ? key : never]?: GetValueByKey<TSchemaUID, key>;
|
|
23
|
+
};
|
|
24
|
+
export type GetRequiredKeys<TSchemaUID extends Common.UID.Schema> = Utils.Object.KeysBy<GetAll<TSchemaUID>, Attribute.Required, string>;
|
|
25
|
+
export type GetOptionalKeys<TSchemaUID extends Common.UID.Schema> = Utils.Object.KeysExcept<GetAll<TSchemaUID>, Attribute.Required, string>;
|
|
26
|
+
export type HasTarget<TSchemaUID extends Common.UID.Schema, TField extends Attribute.GetKeys<TSchemaUID>> = GetTarget<TSchemaUID, TField> extends infer TTarget ? Utils.Expression.And<Utils.Expression.IsNotNever<TTarget>, Utils.Expression.Extends<TTarget, Common.UID.Schema>> : Utils.Expression.False;
|
|
27
|
+
export type HasMorphTargets<TSchemaUID extends Common.UID.Schema, TField extends Attribute.GetKeys<TSchemaUID>> = GetMorphTargets<TSchemaUID, TField> extends infer TMaybeTargets ? Utils.Expression.And<Utils.Expression.IsNotNever<TMaybeTargets>, Utils.Expression.Extends<TMaybeTargets, Common.UID.Schema>> : Utils.Expression.False;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Utils, Attribute, Common } from '../..';
|
|
2
|
+
export * from './controller';
|
|
3
|
+
export * from './middleware';
|
|
4
|
+
export * from './policy';
|
|
5
|
+
export * from './service';
|
|
6
|
+
export * from './router';
|
|
7
|
+
export * from './schema';
|
|
8
|
+
export * as UID from './uid';
|
|
9
|
+
export * from './plugin';
|
|
10
|
+
export * from './module';
|
|
11
|
+
export * from './api';
|
|
12
|
+
/**
|
|
13
|
+
* Determines if the shared registries for components and content types have been extended or if they're still represented as loose mapped types
|
|
14
|
+
*
|
|
15
|
+
* Here we use the fact that once the registries are extended, Attribute.GetKeys<Common.UID.Schema> will resolve to either never or a more
|
|
16
|
+
* deterministic value rather than string | number which represent the keys of the initial mapped type (Component & ContentType's registries)
|
|
17
|
+
*/
|
|
18
|
+
export type AreSchemaRegistriesExtended = Utils.Expression.Not<Utils.Expression.Extends<string | number, Attribute.GetKeys<Common.UID.Schema>>>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type Koa from 'koa';
|
|
2
|
+
import type { Strapi } from '../../..';
|
|
3
|
+
export type MiddlewareFactory<T = any> = (config: T, ctx: {
|
|
4
|
+
strapi: Strapi;
|
|
5
|
+
}) => MiddlewareHandler | void;
|
|
6
|
+
export type MiddlewareHandler = Koa.Middleware;
|
|
7
|
+
export type Middleware = MiddlewareHandler | MiddlewareFactory;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Common, Schema } from '..';
|
|
2
|
+
import type { Strapi } from '../../..';
|
|
3
|
+
export interface Module {
|
|
4
|
+
bootstrap: ({ strapi }: {
|
|
5
|
+
strapi: Strapi;
|
|
6
|
+
}) => void | Promise<void>;
|
|
7
|
+
destroy: ({ strapi }: {
|
|
8
|
+
strapi: Strapi;
|
|
9
|
+
}) => void | Promise<void>;
|
|
10
|
+
register: ({ strapi }: {
|
|
11
|
+
strapi: Strapi;
|
|
12
|
+
}) => void | Promise<void>;
|
|
13
|
+
config<TDefault = unknown, TResult = unknown>(path: string, defaultValue?: TDefault): TResult;
|
|
14
|
+
routes: Record<string, Common.Router>;
|
|
15
|
+
controllers: Record<string, Common.Controller>;
|
|
16
|
+
services: Record<string, Common.Service>;
|
|
17
|
+
policies: Record<string, Common.Policy>;
|
|
18
|
+
middlewares: Record<string, Common.Middleware>;
|
|
19
|
+
contentTypes: Record<string, {
|
|
20
|
+
schema: Schema.ContentType;
|
|
21
|
+
}>;
|
|
22
|
+
controller<T extends Common.Controller>(name: string): T;
|
|
23
|
+
service<T extends Common.Service>(name: string): T;
|
|
24
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ExtendableContext } from 'koa';
|
|
2
|
+
import type { Strapi } from '../../..';
|
|
3
|
+
export type PolicyContext = Omit<ExtendableContext, 'is'> & {
|
|
4
|
+
type: string;
|
|
5
|
+
is(name: string): boolean;
|
|
6
|
+
};
|
|
7
|
+
export type Policy<T = unknown> = (ctx: PolicyContext, cfg: T, { strapi }: {
|
|
8
|
+
strapi: Strapi;
|
|
9
|
+
}) => boolean | undefined;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { MiddlewareHandler } from './middleware';
|
|
2
|
+
export type RouterType = 'admin' | 'content-api';
|
|
3
|
+
export type RouteInfo = {
|
|
4
|
+
apiName?: string;
|
|
5
|
+
pluginName?: string;
|
|
6
|
+
type?: string;
|
|
7
|
+
};
|
|
8
|
+
export type RouteConfig = {
|
|
9
|
+
prefix?: string;
|
|
10
|
+
middlewares?: Array<string | MiddlewareHandler>;
|
|
11
|
+
policies?: Array<string | {
|
|
12
|
+
name: string;
|
|
13
|
+
config: unknown;
|
|
14
|
+
}>;
|
|
15
|
+
auth?: false | {
|
|
16
|
+
scope?: string[];
|
|
17
|
+
strategies?: string[];
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export type Route = {
|
|
21
|
+
method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
22
|
+
path: string;
|
|
23
|
+
handler: string | MiddlewareHandler;
|
|
24
|
+
info: RouteInfo;
|
|
25
|
+
config?: RouteConfig;
|
|
26
|
+
};
|
|
27
|
+
export type RouteInput = Omit<Route, 'info'> & {
|
|
28
|
+
info?: Partial<RouteInfo>;
|
|
29
|
+
};
|
|
30
|
+
export type Router = {
|
|
31
|
+
type: RouterType;
|
|
32
|
+
prefix?: string;
|
|
33
|
+
routes: Route[];
|
|
34
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Shared, Schema as SchemaNamespace, Common, Registry, UID, Utils } from '../../..';
|
|
2
|
+
export type Service = Registry.Keys<Shared.Services, UID.Service>;
|
|
3
|
+
export type Controller = Registry.Keys<Shared.Controllers, UID.Controller>;
|
|
4
|
+
export type Policy = Registry.Keys<Shared.Policies, UID.Policy>;
|
|
5
|
+
export type Middleware = Registry.Keys<Shared.Middlewares, UID.Middleware>;
|
|
6
|
+
export type ContentType = Registry.Keys<Shared.ContentTypes, UID.ContentType>;
|
|
7
|
+
export type CollectionType = Utils.Guard.Never<Extract<Utils.Object.KeysBy<Shared.ContentTypes, SchemaNamespace.CollectionType>, ContentType>, ContentType>;
|
|
8
|
+
export type SingleType = Utils.Guard.Never<Extract<Utils.Object.KeysBy<Shared.ContentTypes, SchemaNamespace.SingleType>, ContentType>, ContentType>;
|
|
9
|
+
export type Component = Registry.Keys<Shared.Components, UID.Component>;
|
|
10
|
+
export type ComponentCategory = Component extends UID.Component<infer TCategory> ? TCategory : never;
|
|
11
|
+
export type Schema = Registry.Keys<Common.Schemas, UID.ContentType | UID.Component<ComponentCategory>>;
|
|
12
|
+
export type IsCollectionType<TSchemaUID extends Schema> = TSchemaUID extends CollectionType ? Utils.Expression.Extends<Shared.ContentTypes[TSchemaUID], SchemaNamespace.CollectionType> : Utils.Expression.False;
|
|
13
|
+
export type IsSingleType<TSchemaUID extends Schema> = TSchemaUID extends SingleType ? Utils.Expression.Extends<Shared.ContentTypes[TSchemaUID], SchemaNamespace.SingleType> : Utils.Expression.False;
|
|
14
|
+
export type IsComponent<TSchemaUID extends Schema> = TSchemaUID extends Component ? Utils.Expression.Extends<Shared.Components[TSchemaUID], SchemaNamespace.Component> : Utils.Expression.False;
|
|
15
|
+
export type IsContentType<TSchemaUID extends Schema> = TSchemaUID extends ContentType ? Utils.Expression.Or<IsCollectionType<TSchemaUID>, IsSingleType<TSchemaUID>> : Utils.Expression.False;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Note: linting will erroneously raise errors if a namespaced type has the same name as on exported by Strapi
|
|
3
|
+
* To work around it, use a pattern such as:
|
|
4
|
+
*
|
|
5
|
+
* import * as PluginImport from './plugins'
|
|
6
|
+
* export type Plugin = typeof PluginImport
|
|
7
|
+
*
|
|
8
|
+
* which causes linting to see the namespaces correctly.
|
|
9
|
+
*/
|
|
10
|
+
export * as Attribute from './attributes';
|
|
11
|
+
export * as Schema from './schemas';
|
|
12
|
+
export * as Plugin from './plugins';
|
|
13
|
+
export * from './strapi';
|
|
14
|
+
export * as Common from './common';
|
|
15
|
+
export * as Namespace from './namespace';
|
|
16
|
+
export * as UID from './uid';
|
|
17
|
+
export * as Registry from './registry';
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type * as Utils from '../utils';
|
|
2
|
+
/**
|
|
3
|
+
* Namespace for admin resources
|
|
4
|
+
*/
|
|
5
|
+
export type Admin = 'admin';
|
|
6
|
+
/**
|
|
7
|
+
* Namespace for strapi internal resources
|
|
8
|
+
*/
|
|
9
|
+
export type Strapi = 'strapi';
|
|
10
|
+
/**
|
|
11
|
+
* Namespace for scoped APIs resources
|
|
12
|
+
*/
|
|
13
|
+
export type API<T extends string = string> = `api${ColonsSeparator}${T}`;
|
|
14
|
+
/**
|
|
15
|
+
* Namespace for scoped plugins resources
|
|
16
|
+
*/
|
|
17
|
+
export type Plugin<T extends string = string> = `plugin${ColonsSeparator}${T}`;
|
|
18
|
+
/**
|
|
19
|
+
* Namespace for global resources
|
|
20
|
+
*/
|
|
21
|
+
export type Global = 'global';
|
|
22
|
+
/**
|
|
23
|
+
* Represents any namespace
|
|
24
|
+
*/
|
|
25
|
+
export type Any = API | Plugin | Admin | Strapi | Global;
|
|
26
|
+
/**
|
|
27
|
+
* Return a {@link Separator} based on the given {@link Any} ({@link DotSeparator} for {@link Scoped} and {@link ColonsSeparator} for regular ones)
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* type S = GetSeparator<Admin>
|
|
31
|
+
* // ^ '::'
|
|
32
|
+
*
|
|
33
|
+
* type S = GetSeparator<API>
|
|
34
|
+
* // ^ '.'
|
|
35
|
+
*
|
|
36
|
+
* type S = GetSeparator<Admin | API>
|
|
37
|
+
* // ^ '.' | '::'
|
|
38
|
+
*/
|
|
39
|
+
export type GetSeparator<TNamespace extends Any = Any> = TNamespace extends Scoped ? DotSeparator : ColonsSeparator;
|
|
40
|
+
/**
|
|
41
|
+
* Adds the corresponding separator (using {@link GetSeparator}) at the end of a namespace
|
|
42
|
+
*
|
|
43
|
+
* Warning: Using WithSeparator with a union type might produce undesired results as it'll distribute every matching suffix to every union member
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* type T = WithSeparator<Admin>
|
|
47
|
+
* // ^ 'admin::'
|
|
48
|
+
*
|
|
49
|
+
* type T = WithSeparator<API>
|
|
50
|
+
* // ^ 'api::{string}.'
|
|
51
|
+
*
|
|
52
|
+
* type T = WithSeparator<Admin | API>
|
|
53
|
+
* // ^ 'admin::' | 'admin.' | 'api::{string}.' | 'api::{string}::'
|
|
54
|
+
*
|
|
55
|
+
* type T = WithSeparator<Admin> | WithSeparator<API>
|
|
56
|
+
* // ^ 'admin::' | 'api::{string}.'
|
|
57
|
+
*/
|
|
58
|
+
export type WithSeparator<TNamespace extends Any> = Utils.String.Suffix<TNamespace, GetSeparator<TNamespace>>;
|
|
59
|
+
/**
|
|
60
|
+
* Represents namespaces composed of an origin and a scope, separated by colons
|
|
61
|
+
*/
|
|
62
|
+
export type Scoped<TOrigin extends string = string, TScope extends string = string> = Any & `${TOrigin}${ColonsSeparator}${TScope}`;
|
|
63
|
+
/**
|
|
64
|
+
* Extract the scope from the given scoped namespace
|
|
65
|
+
*/
|
|
66
|
+
export type ExtractScope<TNamespace> = TNamespace extends `${string}${ColonsSeparator}${infer TScope}` ? TScope : never;
|
|
67
|
+
/**
|
|
68
|
+
* Extract the origin from the given scoped namespace
|
|
69
|
+
*/
|
|
70
|
+
export type ExtractOrigin<TNamespace> = TNamespace extends `${infer TOrigin}${ColonsSeparator}${string}` ? TOrigin : never;
|
|
71
|
+
/**
|
|
72
|
+
* Separators used to join the different parts of a namespace (e.g. building a uid)
|
|
73
|
+
*/
|
|
74
|
+
export type Separator = ColonsSeparator | DotSeparator;
|
|
75
|
+
type ColonsSeparator = '::';
|
|
76
|
+
type DotSeparator = '.';
|
|
77
|
+
export {};
|