@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,132 @@
|
|
|
1
|
+
import type { Common, Utils } from '../../../types';
|
|
2
|
+
import type { GetPluginParams } from '..';
|
|
3
|
+
import type * as Sort from './sort';
|
|
4
|
+
import type * as Pagination from './pagination';
|
|
5
|
+
import type * as Fields from './fields';
|
|
6
|
+
import type * as Filters from './filters';
|
|
7
|
+
import type * as Populate from './populate';
|
|
8
|
+
import type * as PublicationState from './publication-state';
|
|
9
|
+
import type * as Data from './data';
|
|
10
|
+
import type * as Search from './search';
|
|
11
|
+
import type * as Attribute from './attributes';
|
|
12
|
+
export type Pick<TSchemaUID extends Common.UID.Schema, TKind extends Kind> = Utils.Expression.MatchAllIntersect<[
|
|
13
|
+
[
|
|
14
|
+
HasMember<TKind, 'sort'>,
|
|
15
|
+
{
|
|
16
|
+
sort?: Sort.Any<TSchemaUID>;
|
|
17
|
+
}
|
|
18
|
+
],
|
|
19
|
+
[
|
|
20
|
+
HasMember<TKind, 'sort:string'>,
|
|
21
|
+
{
|
|
22
|
+
sort?: Sort.StringNotation<TSchemaUID>;
|
|
23
|
+
}
|
|
24
|
+
],
|
|
25
|
+
[
|
|
26
|
+
HasMember<TKind, 'sort:array'>,
|
|
27
|
+
{
|
|
28
|
+
sort?: Sort.ArrayNotation<TSchemaUID>;
|
|
29
|
+
}
|
|
30
|
+
],
|
|
31
|
+
[
|
|
32
|
+
HasMember<TKind, 'sort:object'>,
|
|
33
|
+
{
|
|
34
|
+
sort?: Sort.ObjectNotation<TSchemaUID>;
|
|
35
|
+
}
|
|
36
|
+
],
|
|
37
|
+
[
|
|
38
|
+
HasMember<TKind, 'fields'>,
|
|
39
|
+
{
|
|
40
|
+
fields?: Fields.Any<TSchemaUID>;
|
|
41
|
+
}
|
|
42
|
+
],
|
|
43
|
+
[
|
|
44
|
+
HasMember<TKind, 'fields:string'>,
|
|
45
|
+
{
|
|
46
|
+
fields?: Fields.StringNotation<TSchemaUID>;
|
|
47
|
+
}
|
|
48
|
+
],
|
|
49
|
+
[
|
|
50
|
+
HasMember<TKind, 'fields:array'>,
|
|
51
|
+
{
|
|
52
|
+
fields?: Fields.ArrayNotation<TSchemaUID>;
|
|
53
|
+
}
|
|
54
|
+
],
|
|
55
|
+
[
|
|
56
|
+
HasMember<TKind, 'filters'>,
|
|
57
|
+
{
|
|
58
|
+
filters?: Filters.Any<TSchemaUID>;
|
|
59
|
+
}
|
|
60
|
+
],
|
|
61
|
+
[
|
|
62
|
+
HasMember<TKind, 'populate'>,
|
|
63
|
+
{
|
|
64
|
+
populate?: Populate.Any<TSchemaUID>;
|
|
65
|
+
}
|
|
66
|
+
],
|
|
67
|
+
[
|
|
68
|
+
HasMember<TKind, 'populate:string'>,
|
|
69
|
+
{
|
|
70
|
+
populate?: Populate.StringNotation<TSchemaUID>;
|
|
71
|
+
}
|
|
72
|
+
],
|
|
73
|
+
[
|
|
74
|
+
HasMember<TKind, 'populate:array'>,
|
|
75
|
+
{
|
|
76
|
+
populate?: Populate.ArrayNotation<TSchemaUID>;
|
|
77
|
+
}
|
|
78
|
+
],
|
|
79
|
+
[
|
|
80
|
+
HasMember<TKind, 'populate:object'>,
|
|
81
|
+
{
|
|
82
|
+
populate?: Populate.ObjectNotation<TSchemaUID>;
|
|
83
|
+
}
|
|
84
|
+
],
|
|
85
|
+
[
|
|
86
|
+
HasMember<TKind, 'pagination'>,
|
|
87
|
+
Pagination.Any
|
|
88
|
+
],
|
|
89
|
+
[
|
|
90
|
+
HasMember<TKind, 'pagination:offset'>,
|
|
91
|
+
Pagination.OffsetNotation
|
|
92
|
+
],
|
|
93
|
+
[
|
|
94
|
+
HasMember<TKind, 'pagination:page'>,
|
|
95
|
+
Pagination.PageNotation
|
|
96
|
+
],
|
|
97
|
+
[
|
|
98
|
+
HasMember<TKind, 'publicationState'>,
|
|
99
|
+
PublicationState.For<TSchemaUID>
|
|
100
|
+
],
|
|
101
|
+
[
|
|
102
|
+
HasMember<TKind, 'plugin'>,
|
|
103
|
+
GetPluginParams<TSchemaUID>
|
|
104
|
+
],
|
|
105
|
+
[
|
|
106
|
+
HasMember<TKind, 'data'>,
|
|
107
|
+
{
|
|
108
|
+
data?: Data.Input<TSchemaUID>;
|
|
109
|
+
}
|
|
110
|
+
],
|
|
111
|
+
[
|
|
112
|
+
HasMember<TKind, 'data:partial'>,
|
|
113
|
+
{
|
|
114
|
+
data?: Partial<Data.Input<TSchemaUID>>;
|
|
115
|
+
}
|
|
116
|
+
],
|
|
117
|
+
[
|
|
118
|
+
HasMember<TKind, 'files'>,
|
|
119
|
+
{
|
|
120
|
+
files?: Record<string, unknown>;
|
|
121
|
+
}
|
|
122
|
+
],
|
|
123
|
+
[
|
|
124
|
+
HasMember<TKind, '_q'>,
|
|
125
|
+
{
|
|
126
|
+
_q?: Search.Q;
|
|
127
|
+
}
|
|
128
|
+
]
|
|
129
|
+
]>;
|
|
130
|
+
export type Kind = 'sort' | 'sort:string' | 'sort:array' | 'sort:object' | 'fields' | 'fields:string' | 'fields:array' | 'filters' | 'populate' | 'populate:string' | 'populate:array' | 'populate:object' | 'pagination' | 'pagination:offset' | 'pagination:page' | 'publicationState' | 'plugin' | 'data' | 'data:partial' | 'files' | '_q';
|
|
131
|
+
type HasMember<TValue extends Kind, TTest extends Kind> = Utils.Expression.Extends<TTest, TValue>;
|
|
132
|
+
export type { Sort, Pagination, Fields, Filters, Populate, PublicationState, Data, Attribute };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { Attribute, Common, Utils } from '../../../types';
|
|
2
|
+
import type { Params } from '..';
|
|
3
|
+
/**
|
|
4
|
+
* Wildcard notation for populate
|
|
5
|
+
*
|
|
6
|
+
* To populate all the root level relations
|
|
7
|
+
*/
|
|
8
|
+
export type WildcardNotation = '*';
|
|
9
|
+
/**
|
|
10
|
+
* Union of all possible string representation for populate
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* type A = 'image'; // ✅
|
|
14
|
+
* type B = 'image,component'; // ✅
|
|
15
|
+
* type c = '*'; // ✅
|
|
16
|
+
* type D = 'populatableField'; // ✅
|
|
17
|
+
* type E = '<random_string>'; // ❌
|
|
18
|
+
*/
|
|
19
|
+
export type StringNotation<TSchemaUID extends Common.UID.Schema> = WildcardNotation | Utils.Guard.Never<Attribute.GetPopulatableKeys<TSchemaUID>, string> | `${string},${string}` | `${string}.${string}`;
|
|
20
|
+
/**
|
|
21
|
+
* Array notation for populate
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* type A = ['image']; // ✅
|
|
25
|
+
* type B = ['image', 'component']; // ✅
|
|
26
|
+
* type C = ['populatableField']; // ✅
|
|
27
|
+
* type D = ['<random_string>']; // ❌
|
|
28
|
+
* type E = ['*']; // ❌
|
|
29
|
+
*/
|
|
30
|
+
export type ArrayNotation<TSchemaUID extends Common.UID.Schema> = Exclude<StringNotation<TSchemaUID>, WildcardNotation>[];
|
|
31
|
+
type GetPopulatableKeysWithTarget<TSchemaUID extends Common.UID.Schema> = Extract<Attribute.GetPopulatableKeys<TSchemaUID>, Attribute.GetKeysWithTarget<TSchemaUID>>;
|
|
32
|
+
type GetPopulatableKeysWithoutTarget<TSchemaUID extends Common.UID.Schema> = Exclude<Attribute.GetPopulatableKeys<TSchemaUID>, GetPopulatableKeysWithTarget<TSchemaUID>>;
|
|
33
|
+
/**
|
|
34
|
+
* Fragment populate notation for polymorphic attributes
|
|
35
|
+
*/
|
|
36
|
+
export type Fragment<TMaybeTargets extends Common.UID.Schema> = {
|
|
37
|
+
on?: {
|
|
38
|
+
[TSchemaUID in TMaybeTargets]?: boolean | NestedParams<TSchemaUID>;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
type PopulateClause<TSchemaUID extends Common.UID.Schema, TKeys extends Attribute.GetPopulatableKeys<TSchemaUID>> = {
|
|
42
|
+
[TKey in TKeys]?: boolean | NestedParams<Attribute.GetTarget<TSchemaUID, TKey>>;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Object notation for populate
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* type A = { image: true }; // ✅
|
|
49
|
+
* type B = { image: { fields: ['url', 'provider'] } }; // ✅
|
|
50
|
+
* type C = { populatableField: { populate: { nestedPopulatableField: true } } }; // ✅
|
|
51
|
+
* type D = { dynamic_zone: { on: { comp_A: { fields: ['name', 'price_a'] }, comp_B: { fields: ['name', 'price_b'] } } } }; // ✅
|
|
52
|
+
*/
|
|
53
|
+
export type ObjectNotation<TSchemaUID extends Common.UID.Schema> = [
|
|
54
|
+
GetPopulatableKeysWithTarget<TSchemaUID>,
|
|
55
|
+
GetPopulatableKeysWithoutTarget<TSchemaUID>
|
|
56
|
+
] extends [
|
|
57
|
+
infer TKeysWithTarget extends Attribute.GetPopulatableKeys<TSchemaUID>,
|
|
58
|
+
infer TKeysWithoutTarget extends Attribute.GetPopulatableKeys<TSchemaUID>
|
|
59
|
+
] ? Utils.Expression.If<Utils.Expression.And<Common.AreSchemaRegistriesExtended, Utils.Expression.DoesNotExtends<Common.UID.Schema, TSchemaUID>>, Utils.Expression.If<Utils.Expression.IsNotNever<TKeysWithTarget>, PopulateClause<TSchemaUID, TKeysWithTarget>> | Utils.Expression.If<Utils.Expression.IsNotNever<TKeysWithoutTarget>, {
|
|
60
|
+
[TKey in TKeysWithoutTarget]?: boolean | Fragment<Utils.Guard.Never<Attribute.GetMorphTargets<TSchemaUID, TKey>, Common.UID.Schema>> | NestedParams<Common.UID.Schema>;
|
|
61
|
+
}>, {
|
|
62
|
+
[TKey in string]?: boolean | NestedParams<Common.UID.Schema>;
|
|
63
|
+
} | {
|
|
64
|
+
[TKey in string]?: boolean | Fragment<Common.UID.Schema> | NestedParams<Common.UID.Schema>;
|
|
65
|
+
}> : never;
|
|
66
|
+
export type NestedParams<TSchemaUID extends Common.UID.Schema> = Params.Pick<TSchemaUID, 'fields' | 'filters' | 'populate' | 'sort' | 'plugin' | 'publicationState'>;
|
|
67
|
+
export type Any<TSchemaUID extends Common.UID.Schema> = StringNotation<TSchemaUID> | ArrayNotation<TSchemaUID> | ObjectNotation<TSchemaUID>;
|
|
68
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Common, Utils } from '../../../types';
|
|
2
|
+
export type Kind = 'preview' | 'live';
|
|
3
|
+
export type IsEnabled<TSchemaUID extends Common.UID.Schema> = Utils.Expression.MatchFirst<[
|
|
4
|
+
[
|
|
5
|
+
Common.UID.IsContentType<TSchemaUID>,
|
|
6
|
+
Utils.Expression.IsTrue<NonNullable<Common.Schemas[TSchemaUID]['options']>['draftAndPublish']>
|
|
7
|
+
],
|
|
8
|
+
[
|
|
9
|
+
Utils.Expression.And<Utils.Expression.Not<Utils.Expression.Extends<TSchemaUID, Common.UID.ContentType>>, Common.UID.IsComponent<TSchemaUID>>,
|
|
10
|
+
Utils.Expression.False
|
|
11
|
+
]
|
|
12
|
+
], Utils.Expression.BooleanValue>;
|
|
13
|
+
export type For<TSchemaUID extends Common.UID.Schema> = IsEnabled<TSchemaUID> extends infer TEnabled ? Utils.Expression.If<Utils.Expression.Or<Utils.Expression.IsTrue<TEnabled>, Utils.Expression.Extends<Utils.Expression.BooleanValue, TEnabled>>, {
|
|
14
|
+
publicationState?: Kind;
|
|
15
|
+
}, unknown> : never;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Q = string;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { Attribute, Common, Utils } from '../../../types';
|
|
2
|
+
export declare namespace OrderKind {
|
|
3
|
+
type Asc = 'asc';
|
|
4
|
+
type Desc = 'desc';
|
|
5
|
+
type Any = Asc | Desc;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Single non-populatable attribute representation
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* type A = 'title'; // ✅
|
|
12
|
+
* type B = 'description'; // ✅
|
|
13
|
+
* type C = 'title:asc'; // ❌
|
|
14
|
+
* type D = 'title,description'; // ❌
|
|
15
|
+
*/
|
|
16
|
+
type SingleAttribute<TSchemaUID extends Common.UID.Schema> = 'id' | Utils.Guard.Never<string & Attribute.GetNonPopulatableKeys<TSchemaUID>, string>;
|
|
17
|
+
/**
|
|
18
|
+
* Ordered single non-populatable attribute representation
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* type A = 'title:asc'; // ✅
|
|
22
|
+
* type B = 'description:desc'; // ✅
|
|
23
|
+
* type C = 'title'; // ❌
|
|
24
|
+
* type D = 'title,description'; // ❌
|
|
25
|
+
*/
|
|
26
|
+
type OrderedSingleAttribute<TSchemaUID extends Common.UID.Schema> = `${SingleAttribute<TSchemaUID>}:${OrderKind.Any}`;
|
|
27
|
+
/**
|
|
28
|
+
* Union of all possible string representation for a sort
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* type A = 'title:asc'; // ✅
|
|
32
|
+
* type B = 'description:desc'; // ✅
|
|
33
|
+
* type C = 'title'; // ✅
|
|
34
|
+
* type D = 'title,description:asc'; // ✅
|
|
35
|
+
* type E = [42]; // ❌
|
|
36
|
+
* type F = { title: 'asc' }; // ❌
|
|
37
|
+
*/
|
|
38
|
+
export type StringNotation<TSchemaUID extends Common.UID.Schema> = SingleAttribute<TSchemaUID> | OrderedSingleAttribute<TSchemaUID> | `${string},${string}`;
|
|
39
|
+
/**
|
|
40
|
+
* Array notation for a sort
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* type A = ['title:asc', 'description']; // ✅
|
|
44
|
+
* type B = ['title']; // ✅
|
|
45
|
+
* type C = ['count', 'title,description:asc']; // ✅
|
|
46
|
+
* type D = { title: 'asc' }; // ❌
|
|
47
|
+
* type E = [42]; // ❌
|
|
48
|
+
* type F = 'title'; // ❌
|
|
49
|
+
*/
|
|
50
|
+
export type ArrayNotation<TSchemaUID extends Common.UID.Schema> = Any<TSchemaUID>[];
|
|
51
|
+
/**
|
|
52
|
+
* Object notation for a sort
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* type A = { title: 'asc' }; // ✅
|
|
56
|
+
* type B = { title: 'asc', description: 'desc' }; // ✅
|
|
57
|
+
* type C = { title: 'asc', author: { name: 'asc' } }; // ✅
|
|
58
|
+
* type D = { author: { email: 'asc', role: { name: 'desc' } } }; // ✅
|
|
59
|
+
* type E = ['title']; // ❌
|
|
60
|
+
* type F = 'title'; // ❌
|
|
61
|
+
*/
|
|
62
|
+
export type ObjectNotation<TSchemaUID extends Common.UID.Schema> = {
|
|
63
|
+
[key in SingleAttribute<TSchemaUID>]?: OrderKind.Any;
|
|
64
|
+
} & {
|
|
65
|
+
[key in Attribute.GetKeysWithTarget<TSchemaUID>]?: ObjectNotation<Attribute.GetTarget<TSchemaUID, key>>;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Represents any notation for a sort (string, array, object)
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* type A = 'title:asc'; // ✅
|
|
72
|
+
* type B = 'description:desc'; // ✅
|
|
73
|
+
* type C = 'title'; // ✅
|
|
74
|
+
* type D = 'title,description:asc'; // ✅
|
|
75
|
+
* type E = ['title:asc', 'description']; // ✅
|
|
76
|
+
* type F = ['title']; // ✅
|
|
77
|
+
* type G = ['count', 'title,description:asc']; // ✅
|
|
78
|
+
* type H = { title: 'asc' }; // ✅
|
|
79
|
+
* type I = { title: 'asc', description: 'desc' }; // ✅
|
|
80
|
+
* type J = { title: 'asc', author: { name: 'asc' } }; // ✅
|
|
81
|
+
* type K = { author: { email: 'asc', role: { name: 'desc' } } }; // ✅
|
|
82
|
+
*/
|
|
83
|
+
export type Any<TSchemaUID extends Common.UID.Schema> = StringNotation<TSchemaUID> | ArrayNotation<TSchemaUID> | ObjectNotation<TSchemaUID>;
|
|
84
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Common, Plugin, Utils, Shared } from '../../types';
|
|
2
|
+
export type GetPluginParams<TSchemaUID extends Common.UID.Schema> = Utils.Guard.OfTypes<[
|
|
3
|
+
never,
|
|
4
|
+
undefined
|
|
5
|
+
], Utils.Object.Values<{
|
|
6
|
+
[TPluginName in keyof Shared.EntityServicePluginParams]: Shared.EntityServicePluginParams[TPluginName] extends infer TParam ? Utils.Expression.If<Plugin.IsEnabled<TPluginName, TSchemaUID>, TParam> : never;
|
|
7
|
+
}>, unknown>;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { Attribute, Common, Utils } from '../../types';
|
|
2
|
+
import type { Params } from './index';
|
|
3
|
+
type Pagination = {
|
|
4
|
+
page: number;
|
|
5
|
+
pageSize: number;
|
|
6
|
+
pageCount: number;
|
|
7
|
+
total: number;
|
|
8
|
+
};
|
|
9
|
+
type AnyEntity = {
|
|
10
|
+
id: Params.Attribute.ID;
|
|
11
|
+
} & {
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
};
|
|
14
|
+
export type Result<TSchemaUID extends Common.UID.Schema, TParams extends Params.Pick<TSchemaUID, 'fields' | 'populate'> = never> = Utils.Expression.If<Common.AreSchemaRegistriesExtended, GetValues<TSchemaUID, Utils.Guard.Never<ExtractFields<TSchemaUID, TParams['fields']>, Attribute.GetNonPopulatableKeys<TSchemaUID>>, ExtractPopulate<TSchemaUID, TParams['populate']>>, AnyEntity>;
|
|
15
|
+
export type Entity<TSchemaUID extends Common.UID.Schema, TParams extends Params.Pick<TSchemaUID, 'fields' | 'populate'> = never> = Utils.Expression.If<Common.AreSchemaRegistriesExtended, GetValues<TSchemaUID, Utils.Guard.Never<ExtractFields<TSchemaUID, TParams['fields']>, Attribute.GetNonPopulatableKeys<TSchemaUID>>, Utils.Guard.Never<ExtractPopulate<TSchemaUID, TParams['populate']>, Attribute.GetPopulatableKeys<TSchemaUID>>>, AnyEntity>;
|
|
16
|
+
export type PartialEntity<TSchemaUID extends Common.UID.Schema, TParams extends Params.Pick<TSchemaUID, 'fields' | 'populate'> = never> = Partial<Entity<TSchemaUID, TParams>>;
|
|
17
|
+
export type PaginatedResult<TSchemaUID extends Common.UID.Schema, TParams extends Params.Pick<TSchemaUID, 'fields' | 'populate'> = never> = {
|
|
18
|
+
results: Entity<TSchemaUID, TParams>[];
|
|
19
|
+
pagination: Pagination;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Attribute.GetValues override with extended values
|
|
23
|
+
*
|
|
24
|
+
* TODO: Make it recursive for populatable fields
|
|
25
|
+
*/
|
|
26
|
+
export type GetValues<TSchemaUID extends Common.UID.Schema, TFields extends Attribute.GetKeys<TSchemaUID> = Attribute.GetNonPopulatableKeys<TSchemaUID>, TPopulate extends Attribute.GetKeys<TSchemaUID> = Attribute.GetPopulatableKeys<TSchemaUID>> = Utils.Expression.If<Common.AreSchemaRegistriesExtended, Utils.Guard.Never<TFields | TPopulate, Attribute.GetKeys<TSchemaUID>> extends infer TKeys extends Attribute.GetKeys<TSchemaUID> ? Attribute.GetValues<TSchemaUID, TKeys> : never, AnyEntity>;
|
|
27
|
+
type ExtractFields<TSchemaUID extends Common.UID.Schema, TFields extends Params.Fields.Any<TSchemaUID> | undefined> = Utils.Expression.MatchFirst<[
|
|
28
|
+
[
|
|
29
|
+
Utils.Expression.Or<Utils.Expression.StrictEqual<TFields, Params.Fields.Any<TSchemaUID>>, Utils.Expression.Or<Utils.Expression.IsNever<TFields>, Utils.Expression.StrictEqual<TFields, undefined>>>,
|
|
30
|
+
never
|
|
31
|
+
],
|
|
32
|
+
[
|
|
33
|
+
Utils.Expression.Extends<TFields, Params.Fields.StringNotation<TSchemaUID>>,
|
|
34
|
+
ParseStringFields<TSchemaUID, Utils.Cast<TFields, Params.Fields.StringNotation<TSchemaUID>>>
|
|
35
|
+
],
|
|
36
|
+
[
|
|
37
|
+
Utils.Expression.Extends<TFields, Params.Fields.ArrayNotation<TSchemaUID>>,
|
|
38
|
+
ParseStringFields<TSchemaUID, Utils.Cast<Utils.Array.Values<Utils.Cast<TFields, Params.Fields.ArrayNotation<TSchemaUID>>>, Params.Fields.StringNotation<TSchemaUID>>>
|
|
39
|
+
]
|
|
40
|
+
]>;
|
|
41
|
+
type ParseStringFields<TSchemaUID extends Common.UID.Schema, TFields extends Params.Fields.StringNotation<TSchemaUID>> = Utils.Expression.MatchFirst<[
|
|
42
|
+
[
|
|
43
|
+
Utils.Expression.StrictEqual<TFields, Params.Fields.WildcardNotation>,
|
|
44
|
+
Attribute.GetNonPopulatableKeys<TSchemaUID>
|
|
45
|
+
],
|
|
46
|
+
[
|
|
47
|
+
Utils.Expression.Extends<TFields, Params.Fields.SingleAttribute<TSchemaUID>>,
|
|
48
|
+
TFields
|
|
49
|
+
],
|
|
50
|
+
[
|
|
51
|
+
Utils.Expression.Extends<TFields, `${string},${string}`>,
|
|
52
|
+
Utils.Array.Values<Utils.String.Split<Utils.Cast<TFields, string>, ','>>
|
|
53
|
+
]
|
|
54
|
+
]>;
|
|
55
|
+
type ExtractPopulate<TSchemaUID extends Common.UID.Schema, TPopulate extends Params.Populate.Any<TSchemaUID> | undefined> = Utils.Expression.MatchFirst<[
|
|
56
|
+
[
|
|
57
|
+
Utils.Expression.Or<Utils.Expression.StrictEqual<TPopulate, Params.Populate.Any<TSchemaUID>>, Utils.Expression.IsNever<TPopulate>>,
|
|
58
|
+
never
|
|
59
|
+
],
|
|
60
|
+
[
|
|
61
|
+
Utils.Expression.Extends<TPopulate, Params.Populate.StringNotation<TSchemaUID>>,
|
|
62
|
+
ParseStringPopulate<TSchemaUID, Utils.Cast<TPopulate, Params.Populate.StringNotation<TSchemaUID>>>
|
|
63
|
+
],
|
|
64
|
+
[
|
|
65
|
+
Utils.Expression.Extends<TPopulate, Params.Populate.ArrayNotation<TSchemaUID>>,
|
|
66
|
+
ParseStringPopulate<TSchemaUID, Utils.Cast<Utils.Array.Values<Utils.Cast<TPopulate, Params.Populate.ArrayNotation<TSchemaUID>>>, Params.Populate.StringNotation<TSchemaUID>>>
|
|
67
|
+
],
|
|
68
|
+
[
|
|
69
|
+
Utils.Expression.Extends<TPopulate, Params.Populate.ObjectNotation<TSchemaUID>>,
|
|
70
|
+
ParseStringPopulate<TSchemaUID, Utils.Cast<keyof TPopulate, Params.Populate.StringNotation<TSchemaUID>>>
|
|
71
|
+
]
|
|
72
|
+
]>;
|
|
73
|
+
type ParsePopulateDotNotation<TSchemaUID extends Common.UID.Schema, TPopulate extends Params.Populate.StringNotation<TSchemaUID>> = Utils.Cast<Utils.String.Split<Utils.Cast<TPopulate, string>, '.'>[0], Attribute.GetPopulatableKeys<TSchemaUID>>;
|
|
74
|
+
type ParseStringPopulate<TSchemaUID extends Common.UID.Schema, TPopulate extends Params.Populate.StringNotation<TSchemaUID>> = Utils.Expression.MatchFirst<[
|
|
75
|
+
[
|
|
76
|
+
Utils.Expression.StrictEqual<Params.Populate.WildcardNotation, TPopulate>,
|
|
77
|
+
Attribute.GetPopulatableKeys<TSchemaUID>
|
|
78
|
+
],
|
|
79
|
+
[
|
|
80
|
+
Utils.Expression.Extends<TPopulate, `${string},${string}`>,
|
|
81
|
+
ParsePopulateDotNotation<TSchemaUID, Utils.Cast<Utils.Array.Values<Utils.String.Split<Utils.Cast<TPopulate, string>, ','>>, Params.Populate.StringNotation<TSchemaUID>>>
|
|
82
|
+
],
|
|
83
|
+
[
|
|
84
|
+
Utils.Expression.Extends<TPopulate, `${string}.${string}`>,
|
|
85
|
+
ParsePopulateDotNotation<TSchemaUID, TPopulate>
|
|
86
|
+
]
|
|
87
|
+
], TPopulate>;
|
|
88
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Common, Shared } from '../types';
|
|
2
|
+
import type * as Types from './entity-service';
|
|
3
|
+
type Entity = {
|
|
4
|
+
id: ID;
|
|
5
|
+
[key: string]: unknown;
|
|
6
|
+
} | null;
|
|
7
|
+
type ID = {
|
|
8
|
+
id: string | number;
|
|
9
|
+
};
|
|
10
|
+
export interface EntityValidator {
|
|
11
|
+
validateEntityCreation: <TUID extends Common.UID.ContentType>(model: Shared.ContentTypes[TUID], data: Types.Params.Data.Input<TUID>, options?: {
|
|
12
|
+
isDraft?: boolean;
|
|
13
|
+
}) => Promise<Types.Params.Data.Input<TUID>>;
|
|
14
|
+
validateEntityUpdate: <TUID extends Common.UID.ContentType>(model: Shared.ContentTypes[TUID], data: Partial<Types.Params.Data.Input<TUID>> | undefined, options?: {
|
|
15
|
+
isDraft?: boolean;
|
|
16
|
+
}, entity?: Entity) => Promise<Types.Params.Data.Input<TUID>>;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type Subscriber = (eventName: string, ...args: any[]) => Promise<void>;
|
|
2
|
+
export type Listener = (...args: any[]) => Promise<void>;
|
|
3
|
+
export interface EventHub {
|
|
4
|
+
emit(eventName: string, ...args: unknown[]): Promise<void>;
|
|
5
|
+
subscribe(subscriber: Subscriber): () => void;
|
|
6
|
+
unsubscribe(subscriber: Subscriber): void;
|
|
7
|
+
on(eventName: string, listener: Listener): () => void;
|
|
8
|
+
off(eventName: string, listener: Listener): void;
|
|
9
|
+
once(eventName: string, listener: Listener): () => void;
|
|
10
|
+
destroy(): EventHub;
|
|
11
|
+
removeListener(eventName: string, listener: Listener): void;
|
|
12
|
+
removeAllListeners(): EventHub;
|
|
13
|
+
addListener(eventName: string, listener: Listener): () => void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="koa__router" />
|
|
3
|
+
import type * as http from 'http';
|
|
4
|
+
import type Router from '@koa/router';
|
|
5
|
+
import type Koa from 'koa';
|
|
6
|
+
import type { Common } from '../types';
|
|
7
|
+
export interface HTTPServer extends http.Server {
|
|
8
|
+
destroy: () => Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
export interface API {
|
|
11
|
+
listRoutes(): Router.Layer[];
|
|
12
|
+
use(fn: Router.Middleware): API;
|
|
13
|
+
routes(routes: Common.Router | Omit<Common.Route, 'info'>[]): this;
|
|
14
|
+
mount(router: Router): this;
|
|
15
|
+
}
|
|
16
|
+
export interface Server {
|
|
17
|
+
app: Koa;
|
|
18
|
+
router: Router;
|
|
19
|
+
httpServer: HTTPServer;
|
|
20
|
+
api(name: 'content-api'): API;
|
|
21
|
+
api(name: 'admin'): API;
|
|
22
|
+
use(...args: Parameters<Koa['use']>): Server;
|
|
23
|
+
routes(routes: Common.Router | Omit<Common.Route, 'info'>[]): this;
|
|
24
|
+
mount(): this;
|
|
25
|
+
initRouting(): this;
|
|
26
|
+
initMiddlewares(): Promise<this>;
|
|
27
|
+
listRoutes(): Router.Layer[];
|
|
28
|
+
listen: HTTPServer['listen'];
|
|
29
|
+
destroy(): Promise<void>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Webhook } from './webhook-store';
|
|
2
|
+
interface Event {
|
|
3
|
+
event: string;
|
|
4
|
+
info: Record<string, unknown>;
|
|
5
|
+
}
|
|
6
|
+
export interface WebhookRunner {
|
|
7
|
+
deleteListener(event: string): void;
|
|
8
|
+
createListener(event: string): void;
|
|
9
|
+
executeListener({ event, info }: Event): Promise<void>;
|
|
10
|
+
run(webhook: Webhook, event: string, info?: Record<string, unknown>): Promise<unknown>;
|
|
11
|
+
add(webhook: Webhook): void;
|
|
12
|
+
update(webhook: Webhook): void;
|
|
13
|
+
remove(webhook: Webhook): void;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface Webhook {
|
|
2
|
+
id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
url: string;
|
|
5
|
+
headers: Record<string, string>;
|
|
6
|
+
events: string[];
|
|
7
|
+
isEnabled: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface WebhookStore {
|
|
10
|
+
allowedEvents: Map<string, string>;
|
|
11
|
+
addAllowedEvent(key: string, value: string): void;
|
|
12
|
+
removeAllowedEvent(key: string): void;
|
|
13
|
+
listAllowedEvents(): string[];
|
|
14
|
+
getAllowedEvent(key: string): string | undefined;
|
|
15
|
+
findWebhooks(): Promise<Webhook[]>;
|
|
16
|
+
findWebhook(id: string): Promise<Webhook | null>;
|
|
17
|
+
createWebhook(data: Webhook): Promise<Webhook>;
|
|
18
|
+
updateWebhook(id: string, data: Webhook): Promise<Webhook | null>;
|
|
19
|
+
deleteWebhook(id: string): Promise<Webhook | null>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* List of all the Strapi attribute types
|
|
3
|
+
*/
|
|
4
|
+
export type Kind = 'string' | 'text' | 'richtext' | 'email' | 'password' | 'date' | 'time' | 'datetime' | 'timestamp' | 'integer' | 'biginteger' | 'float' | 'decimal' | 'uid' | 'enumeration' | 'boolean' | 'json' | 'media' | 'relation' | 'component' | 'dynamiczone' | 'blocks';
|
|
5
|
+
/**
|
|
6
|
+
* Most basic shape of a schema attribute
|
|
7
|
+
*/
|
|
8
|
+
export interface Attribute<TKind extends Kind = Kind> {
|
|
9
|
+
/**
|
|
10
|
+
* Type of the attribute
|
|
11
|
+
*/
|
|
12
|
+
type: TKind;
|
|
13
|
+
/**
|
|
14
|
+
* Options defined and used by the plugins
|
|
15
|
+
*/
|
|
16
|
+
pluginOptions?: object;
|
|
17
|
+
useJoinTable?: boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Creates a basic Attribute of type T
|
|
21
|
+
*/
|
|
22
|
+
export type OfType<T extends Kind> = Attribute<T>;
|
|
23
|
+
export interface RequiredOption {
|
|
24
|
+
required?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface PrivateOption {
|
|
27
|
+
private?: boolean;
|
|
28
|
+
}
|
|
29
|
+
export interface UniqueOption {
|
|
30
|
+
unique?: boolean;
|
|
31
|
+
}
|
|
32
|
+
export interface DefaultOption<T> {
|
|
33
|
+
default?: T;
|
|
34
|
+
}
|
|
35
|
+
export interface ConfigurableOption {
|
|
36
|
+
configurable?: boolean;
|
|
37
|
+
}
|
|
38
|
+
export interface MinMaxOption<T = number> {
|
|
39
|
+
min?: T;
|
|
40
|
+
max?: T;
|
|
41
|
+
}
|
|
42
|
+
export interface MinMaxLengthOption {
|
|
43
|
+
minLength?: number;
|
|
44
|
+
maxLength?: number;
|
|
45
|
+
}
|
|
46
|
+
export interface WritableOption {
|
|
47
|
+
writable?: boolean;
|
|
48
|
+
}
|
|
49
|
+
export interface VisibleOption {
|
|
50
|
+
visible?: boolean;
|
|
51
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Attribute } from '..';
|
|
2
|
+
export type BigInteger = Attribute.OfType<'biginteger'> & Attribute.ConfigurableOption & Attribute.DefaultOption<BigIntegerValue> & Attribute.MinMaxOption<string> & Attribute.PrivateOption & Attribute.RequiredOption & Attribute.WritableOption & Attribute.VisibleOption & Attribute.UniqueOption;
|
|
3
|
+
export type BigIntegerValue = string;
|
|
4
|
+
export type GetBigIntegerValue<T extends Attribute.Attribute> = T extends BigInteger ? BigIntegerValue : never;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Attribute } from '..';
|
|
2
|
+
export type Blocks = Attribute.OfType<'blocks'> & Attribute.ConfigurableOption & Attribute.PrivateOption & Attribute.RequiredOption & Attribute.WritableOption & Attribute.VisibleOption;
|
|
3
|
+
export type BlocksValue<T extends object = object> = T;
|
|
4
|
+
export type GetBlocksValue<T extends Attribute.Attribute> = T extends Blocks ? BlocksValue : never;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Attribute } from '..';
|
|
2
|
+
type BooleanAttribute = Attribute.OfType<'boolean'> & Attribute.ConfigurableOption & Attribute.DefaultOption<BooleanValue> & Attribute.PrivateOption & Attribute.RequiredOption & Attribute.WritableOption & Attribute.VisibleOption;
|
|
3
|
+
export type BooleanValue = boolean;
|
|
4
|
+
export type GetBooleanValue<T extends Attribute.Attribute> = T extends BooleanAttribute ? BooleanValue : never;
|
|
5
|
+
export type Boolean = BooleanAttribute;
|
|
6
|
+
export {};
|