/
types.ts
218 lines (195 loc) · 6.25 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
import { GraphQLSchemaModule } from "apollo-graphql";
import { Context as APIContext, GraphQLFieldResolver, Plugin } from "@webiny/graphql/types";
import { Context as I18NContext, I18NLocale } from "@webiny/api-i18n/types";
import { Context as CommodoContext } from "@webiny/api-plugin-commodo-db-proxy/types";
export interface CmsDataManager {
generateRevisionIndexes({ revision }): Promise<void>;
deleteRevisionIndexes({ revision }): Promise<void>;
generateContentModelIndexes({ contentModel }): Promise<void>;
deleteEnvironment({ environment }): Promise<void>;
copyEnvironment({ copyFrom, copyTo }): Promise<void>;
}
export type CmsLocalizedModelFieldValue<T> = {
locale: string;
value: T;
};
export type CmsEnvironment = {
id: string;
name: string;
description: string;
changedOn: Date;
save(): Promise<boolean>;
};
export type CmsEnvironmentAlias = {
id: string;
name: string;
slug: string;
description: string;
};
export type Context = {
cms: {
// API type
type: string;
// Requested environment
environment: string;
// Returns an instance of current environment.
getEnvironment: () => CmsEnvironment;
// Returns an instance of current environment alias.
getEnvironmentAlias: () => CmsEnvironmentAlias;
// Requested locale
locale: I18NLocale;
// This is a READ API
READ: boolean;
// This is a MANAGE API
MANAGE: boolean;
// This is a PREVIEW API
PREVIEW: boolean;
// Data manager instance
dataManager: CmsDataManager;
};
};
/**
* This combines all contexts used in the CMS into a single type.
*/
export type CmsContext = APIContext & I18NContext & CommodoContext & Context;
export type CmsModelFieldValue<T> = {
values: CmsLocalizedModelFieldValue<T>[];
};
export type CmsFieldValidation = {
name: string;
message: CmsModelFieldValue<string>;
settings: { [key: string]: any };
};
export type CmsContentModelField = {
_id: string;
label: CmsModelFieldValue<string>;
type: string;
fieldId: string;
validation: CmsFieldValidation[];
multipleValues: boolean;
settings?: { [key: string]: any };
};
export type CmsModelFieldValidatorPlugin = Plugin & {
type: "cms-model-field-validator";
validator: {
name: string;
validate(params: {
value: any;
validator: CmsFieldValidation;
context: CmsContext;
}): Promise<boolean>;
};
};
export type CmsModelFieldPatternValidatorPlugin = Plugin & {
type: "cms-model-field-validator-pattern";
pattern: {
name: string;
regex: string;
flags: string;
};
};
export type FieldId = string;
export type CmsContentModelIndex = {
fields: FieldId[];
createdOn: Date;
};
export type LockedField = {
fieldId: string;
multipleValues: boolean;
type: string;
[key: string]: any;
};
export type CmsContentModel = {
environment: string;
title: string;
description: string;
modelId: string;
lockedFields: LockedField[];
titleFieldId: string;
indexes: CmsContentModelIndex[];
fields: CmsContentModelField[];
getUniqueIndexFields(): FieldId[];
save(): Promise<boolean>;
};
export type CmsModelFieldToCommodoFieldPlugin<TContext = CmsContext> = Plugin & {
type: "cms-model-field-to-commodo-field";
fieldType: string;
dataModel(params: {
context: TContext;
model: Function;
field: CmsContentModelField;
validation(value): Promise<boolean>;
}): void;
searchModel?(params: {
context: TContext;
model: Function;
field: CmsContentModelField;
validation?(value): Promise<boolean>;
}): void;
};
export type ContextBeforeContentModelsPlugin<T = Context> = Plugin & {
type: "context-before-content-models";
apply?: (context: T) => void | Promise<void>;
};
export type ContextAfterContentModelsPlugin<T = Context> = Plugin & {
type: "context-after-content-models";
apply?: (context: T) => void | Promise<void>;
};
export type CmsModelFieldDefinition = {
fields: string;
typeDefs?: string;
};
export type CmsModelFieldToGraphQLPlugin = Plugin & {
type: "cms-model-field-to-graphql";
fieldType: string;
read: {
createGetFilters?(params: { model: CmsContentModel; field: CmsContentModelField }): string;
createListFilters?(params: { model: CmsContentModel; field: CmsContentModelField }): string;
createTypeField(params: { model: CmsContentModel; field: CmsContentModelField }): string;
createResolver(params: {
models: CmsContentModel[];
model: CmsContentModel;
field: CmsContentModelField;
}): GraphQLFieldResolver;
createSchema?(params: {
models: CmsContentModel[];
model: CmsContentModel;
}): GraphQLSchemaModule;
};
manage: {
createListFilters?(params: { model: CmsContentModel; field: CmsContentModelField }): string;
createSchema?(params: {
models: CmsContentModel[];
model: CmsContentModel;
}): GraphQLSchemaModule;
createTypeField(params: {
model: CmsContentModel;
field: CmsContentModelField;
}): CmsModelFieldDefinition | string;
createInputField(params: { model: CmsContentModel; field: CmsContentModelField }): string;
createResolver(params: {
models: CmsContentModel[];
model: CmsContentModel;
field: CmsContentModelField;
}): GraphQLFieldResolver;
};
};
export type CmsModelLockedFieldPlugin = Plugin & {
type: "cms-model-locked-field";
fieldType: string;
checkLockedField?(params: { lockedField: LockedField; field: CmsContentModelField }): void;
getLockedFieldData?(params: { field: CmsContentModelField }): { [key: string]: any };
};
export type CmsFieldTypePlugins = {
[key: string]: CmsModelFieldToGraphQLPlugin;
};
export type CmsFindFilterOperator = Plugin & {
type: "cms-find-filter-operator";
operator: string;
createCondition(params: {
fieldId: string;
field: CmsContentModelField;
value: any;
context: CmsContext;
}): { [key: string]: any };
};