-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
index.ts
218 lines (192 loc) · 6.16 KB
/
index.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 { CorsOptions } from 'cors';
import type { GraphQLSchema } from 'graphql';
import type { Config } from 'apollo-server-express';
import type { AssetMode, KeystoneContext } from '..';
import { SessionStrategy } from '../session';
import type { MaybePromise } from '../utils';
import type {
ListSchemaConfig,
ListConfig,
MaybeSessionFunction,
MaybeItemFunction,
IdFieldConfig,
} from './lists';
import type { BaseFields } from './fields';
import type { ListAccessControl, FieldAccessControl } from './access-control';
import type { ListHooks } from './hooks';
export type KeystoneConfig = {
lists: ListSchemaConfig;
db: DatabaseConfig;
ui?: AdminUIConfig;
server?: ServerConfig;
session?: SessionStrategy<any>;
graphql?: GraphQLConfig;
extendGraphqlSchema?: ExtendGraphqlSchema;
files?: FilesConfig;
images?: ImagesConfig;
/** Experimental config options */
experimental?: {
/** Enables nextjs graphql api route mode */
enableNextJsGraphqlApiEndpoint?: boolean;
/** Creates a file at `node_modules/.keystone/api` with a `lists` export */
generateNodeAPI?: boolean;
/** Creates a file at `node_modules/.keystone/next/graphql-api` with `default` and `config` exports that can be re-exported in a Next API route */
generateNextGraphqlAPI?: boolean;
/** Config options for Keystone Cloud */
keystoneCloud?: KeystoneCloudConfig;
};
};
// config.lists
export type {
ListSchemaConfig,
ListConfig,
BaseFields,
MaybeSessionFunction,
MaybeItemFunction,
// CacheHint,
};
// config.db
export type DatabaseConfig = {
url: string;
onConnect?: (args: KeystoneContext) => Promise<void>;
useMigrations?: boolean;
enableLogging?: boolean;
idField?: IdFieldConfig;
} & (
| (
| {
/** @deprecated The `adapter` option is deprecated. Please use `{ provider: 'postgresql' }` */
adapter: 'prisma_postgresql';
provider?: undefined;
}
| {
/** @deprecated The `adapter` option is deprecated. Please use `{ provider: 'postgresql' }` */
adapter?: undefined;
provider: 'postgresql';
}
)
| (
| {
/** @deprecated The `adapter` option is deprecated. Please use `{ provider: 'sqlite' }` */
adapter: 'prisma_sqlite';
provider?: undefined;
}
| {
/** @deprecated The `adapter` option is deprecated. Please use `{ provider: 'sqlite' }` */
adapter?: undefined;
provider: 'sqlite';
}
)
| {
/** @deprecated The `adapter` option is deprecated. Please use `{ provider: '...' }` */
adapter?: undefined;
provider: 'mongodb';
}
);
// config.ui
export type AdminUIConfig = {
/** Completely disables the Admin UI */
isDisabled?: boolean;
/** Enables certain functionality in the Admin UI that expects the session to be an item */
enableSessionItem?: boolean;
/** A function that can be run to validate that the current session should have access to the Admin UI */
isAccessAllowed?: (context: KeystoneContext) => MaybePromise<boolean>;
/** An array of page routes that can be accessed without passing the isAccessAllowed check */
publicPages?: string[];
/** The basePath for the Admin UI App */
// FIXME: currently unused
// path?: string;
getAdditionalFiles?: ((config: KeystoneConfig) => MaybePromise<AdminFileToWrite[]>)[];
pageMiddleware?: (args: {
context: KeystoneContext;
isValidSession: boolean;
}) => MaybePromise<{ kind: 'redirect'; to: string } | void>;
};
export type AdminFileToWrite =
| { mode: 'write'; src: string; outputPath: string }
| { mode: 'copy'; inputPath: string; outputPath: string };
// config.server
type HealthCheckConfig = {
path?: string;
data?: Record<string, any> | (() => Record<string, any>);
};
export type ServerConfig = {
/** Configuration options for the cors middleware. Set to `true` to use core Keystone defaults */
cors?: CorsOptions | true;
/** Port number to start the server on. Defaults to process.env.PORT || 3000 */
port?: number;
/** Maximum upload file size allowed (in bytes) */
maxFileSize?: number;
/** Health check configuration. Set to `true` to add a basic `/_healthcheck` route, or specify the path and data explicitly */
healthCheck?: HealthCheckConfig | true;
};
// config.graphql
export type GraphQLConfig = {
// FIXME: We currently hardcode `/api/graphql` in a bunch of places
// We should be able to use config.graphql.path to set this path.
// path?: string;
queryLimits?: {
maxTotalResults?: number;
};
/**
* Additional options to pass into the ApolloServer constructor.
* @see https://www.apollographql.com/docs/apollo-server/api/apollo-server/#constructor
*/
apolloConfig?: Config;
};
// config.extendGraphqlSchema
export type ExtendGraphqlSchema = (schema: GraphQLSchema) => GraphQLSchema;
// config.files
export type FilesConfig = {
upload: AssetMode;
transformFilename?: (str: string) => string;
local?: {
/**
* The path local files are uploaded to.
* @default 'public/files'
*/
storagePath?: string;
/**
* The base of the URL local files will be served from, outside of keystone.
* @default '/files'
*/
baseUrl?: string;
};
};
// config.images
export type ImagesConfig = {
upload: AssetMode;
local?: {
/**
* The path local images are uploaded to.
* @default 'public/images'
*/
storagePath?: string;
/**
* The base of the URL local images will be served from, outside of keystone.
* @default '/images'
*/
baseUrl?: string;
};
};
// config.experimental.keystoneCloud
export type KeystoneCloudConfig = {
apiKey: string;
imagesDomain: string;
graphqlApiEndpoint: string;
restApiEndpoint: string;
};
// Exports from sibling packages
export type { ListHooks, ListAccessControl, FieldAccessControl };
export type {
FieldCreateAccessArgs,
FieldReadAccessArgs,
FieldUpdateAccessArgs,
IndividualFieldAccessControl,
CreateAccessControl,
ReadListAccessControl,
DeleteListAccessControl,
UpdateListAccessControl,
} from './access-control';
export type { CommonFieldConfig } from './fields';
export type { CacheHintArgs, IdFieldConfig } from './lists';