@strapi/strapi 4.2.3 → 4.3.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/bin/strapi.js +13 -0
- package/lib/Strapi.js +41 -10
- package/lib/commands/admin-create.js +2 -1
- package/lib/commands/admin-reset.js +2 -1
- package/lib/commands/build.js +8 -46
- package/lib/commands/builders/admin.js +56 -0
- package/lib/commands/builders/index.js +9 -0
- package/lib/commands/builders/typescript.js +32 -0
- package/lib/commands/configurationDump.js +2 -1
- package/lib/commands/configurationRestore.js +3 -1
- package/lib/commands/console.js +4 -3
- package/lib/commands/content-types/list.js +2 -1
- package/lib/commands/controllers/list.js +2 -1
- package/lib/commands/develop.js +111 -74
- package/lib/commands/hooks/list.js +2 -1
- package/lib/commands/middlewares/list.js +2 -1
- package/lib/commands/policies/list.js +2 -1
- package/lib/commands/routes/list.js +2 -1
- package/lib/commands/services/list.js +2 -1
- package/lib/commands/start.js +18 -2
- package/lib/commands/ts/generate-types.js +26 -0
- package/lib/commands/watchAdmin.js +5 -10
- package/lib/compile.js +20 -0
- package/lib/core/app-configuration/index.js +4 -3
- package/lib/core/app-configuration/load-config-file.js +3 -1
- package/lib/core/bootstrap.js +2 -2
- package/lib/core/domain/content-type/validator.js +29 -8
- package/lib/core/loaders/apis.js +6 -5
- package/lib/core/loaders/components.js +5 -4
- package/lib/core/loaders/middlewares.js +4 -2
- package/lib/core/loaders/plugins/get-enabled-plugins.js +2 -1
- package/lib/core/loaders/plugins/get-user-plugins-config.js +2 -2
- package/lib/core/loaders/plugins/index.js +1 -1
- package/lib/core/loaders/policies.js +4 -2
- package/lib/core/loaders/src-index.js +6 -4
- package/lib/core/registries/policies.d.ts +1 -1
- package/lib/core-api/controller/index.d.ts +16 -14
- package/lib/core-api/service/index.d.ts +10 -9
- package/lib/global.d.ts +61 -0
- package/lib/index.d.ts +2 -24
- package/lib/index.js +1 -0
- package/lib/load/load-files.js +3 -1
- package/lib/middlewares/favicon.js +1 -1
- package/lib/middlewares/public/index.js +1 -1
- package/lib/services/cron.js +7 -3
- package/lib/services/entity-service/index.d.ts +7 -1
- package/lib/services/entity-service/index.js +11 -1
- package/lib/services/fs.js +1 -1
- package/lib/services/metrics/index.js +5 -1
- package/lib/services/metrics/sender.js +7 -0
- package/lib/services/server/middleware.js +1 -1
- package/lib/services/utils/upload-files.js +1 -1
- package/lib/types/core/attributes/base.d.ts +74 -0
- package/lib/types/core/attributes/biginteger.d.ts +22 -0
- package/lib/types/core/attributes/boolean.d.ts +20 -0
- package/lib/types/core/attributes/common.d.ts +42 -0
- package/lib/types/core/attributes/component.d.ts +41 -0
- package/lib/types/core/attributes/date-time.d.ts +22 -0
- package/lib/types/core/attributes/date.d.ts +22 -0
- package/lib/types/core/attributes/decimal.d.ts +22 -0
- package/lib/types/core/attributes/dynamic-zone.d.ts +29 -0
- package/lib/types/core/attributes/email.d.ts +24 -0
- package/lib/types/core/attributes/enumeration.d.ts +28 -0
- package/lib/types/core/attributes/float.d.ts +22 -0
- package/lib/types/core/attributes/index.d.ts +26 -0
- package/lib/types/core/attributes/integer.d.ts +22 -0
- package/lib/types/core/attributes/json.d.ts +14 -0
- package/lib/types/core/attributes/media.d.ts +36 -0
- package/lib/types/core/attributes/password.d.ts +22 -0
- package/lib/types/core/attributes/relation.d.ts +66 -0
- package/lib/types/core/attributes/richtext.d.ts +22 -0
- package/lib/types/core/attributes/string.d.ts +30 -0
- package/lib/types/core/attributes/text.d.ts +30 -0
- package/lib/types/core/attributes/time.d.ts +22 -0
- package/lib/types/core/attributes/timestamp.d.ts +22 -0
- package/lib/types/core/attributes/uid.d.ts +57 -0
- package/lib/types/core/attributes/utils.d.ts +99 -0
- package/lib/types/core/index.d.ts +3 -0
- package/lib/types/core/schemas/index.d.ts +126 -0
- package/lib/types/core/strapi/index.d.ts +391 -0
- package/lib/types/factories.d.ts +60 -0
- package/lib/types/index.d.ts +4 -0
- package/lib/types/utils.d.ts +95 -0
- package/lib/utils/get-dirs.js +24 -10
- package/lib/utils/import-default.js +10 -0
- package/lib/utils/index.js +2 -0
- package/lib/utils/lifecycles.js +15 -0
- package/lib/utils/machine-id.js +2 -2
- package/lib/utils/update-notifier/index.js +1 -1
- package/package.json +18 -16
- package/lib/factories.d.ts +0 -48
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
import type Koa from 'koa';
|
|
2
|
+
import { Database } from '@strapi/database';
|
|
3
|
+
|
|
4
|
+
import type { StringMap } from './utils';
|
|
5
|
+
import type { GenericController } from '../core-api/controller'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The Strapi interface implemented by the main Strapi class.
|
|
9
|
+
*/
|
|
10
|
+
export interface Strapi {
|
|
11
|
+
/**
|
|
12
|
+
* Getter for the Strapi enterprise edition configuration
|
|
13
|
+
*/
|
|
14
|
+
readonly EE: any;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Getter for the Strapi configuration container
|
|
18
|
+
*/
|
|
19
|
+
readonly config: any;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Getter for the Strapi auth container
|
|
23
|
+
*/
|
|
24
|
+
readonly auth: any;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Getter for the Strapi sanitizers container
|
|
28
|
+
*/
|
|
29
|
+
readonly sanitizers: any;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Getter for the Strapi services container
|
|
33
|
+
*
|
|
34
|
+
* It returns all the registered services
|
|
35
|
+
*/
|
|
36
|
+
readonly services: StringMap<Service>;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Find a service using its unique identifier
|
|
40
|
+
*/
|
|
41
|
+
service<T extends Service = unknown>(uid: string): T | undefined;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Getter for the Strapi controllers container
|
|
45
|
+
*
|
|
46
|
+
* It returns all the registered controllers
|
|
47
|
+
*/
|
|
48
|
+
readonly controllers: StringMap<GenericController>;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Find a controller using its unique identifier
|
|
52
|
+
*/
|
|
53
|
+
controller(uid: string): GenericController | undefined;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Getter for the Strapi content types container
|
|
57
|
+
*
|
|
58
|
+
* It returns all the registered content types
|
|
59
|
+
*/
|
|
60
|
+
readonly contentTypes: any;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Find a content type using its unique identifier
|
|
64
|
+
*/
|
|
65
|
+
contentType(uid: string): any;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Getter for the Strapi policies container
|
|
69
|
+
*
|
|
70
|
+
* It returns all the registered policies
|
|
71
|
+
*/
|
|
72
|
+
readonly policies: any;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Find a policy using its name
|
|
76
|
+
*/
|
|
77
|
+
policy(name: string): any;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Getter for the Strapi middlewares container
|
|
81
|
+
*
|
|
82
|
+
* It returns all the registered middlewares
|
|
83
|
+
*/
|
|
84
|
+
readonly middlewares: any;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Find a middleware using its name
|
|
88
|
+
*/
|
|
89
|
+
middleware(): any;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Getter for the Strapi plugins container
|
|
93
|
+
*
|
|
94
|
+
* It returns all the registered plugins
|
|
95
|
+
*/
|
|
96
|
+
readonly plugins: any;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Find a plugin using its name
|
|
100
|
+
*/
|
|
101
|
+
plugin(name: string): any;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Getter for the Strapi hooks container
|
|
105
|
+
*
|
|
106
|
+
* It returns all the registered hooks
|
|
107
|
+
*/
|
|
108
|
+
readonly hooks: any;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Find a hook using its name
|
|
112
|
+
*/
|
|
113
|
+
hook(): any;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Getter for the Strapi APIs container
|
|
117
|
+
*
|
|
118
|
+
* It returns all the registered APIs
|
|
119
|
+
*/
|
|
120
|
+
readonly api: any;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Strapi Register Lifecycle.
|
|
124
|
+
*
|
|
125
|
+
* - Load
|
|
126
|
+
* - The user application
|
|
127
|
+
* - The plugins
|
|
128
|
+
* - The admin
|
|
129
|
+
* - The APIs
|
|
130
|
+
* - The components
|
|
131
|
+
* - The middlewares
|
|
132
|
+
* - The policies
|
|
133
|
+
* - Trigger Strapi internal bootstrap
|
|
134
|
+
* - Create the webhooks runner
|
|
135
|
+
* - Create the internal hooks registry.
|
|
136
|
+
* - Init the telemetry cron job and middleware
|
|
137
|
+
* - Run all the `register` lifecycle methods loaded by the user application or the enabled plugins
|
|
138
|
+
*/
|
|
139
|
+
register(): Promise<Strapi>;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Bootstraping phase.
|
|
143
|
+
*
|
|
144
|
+
* - Load all the content types
|
|
145
|
+
* - Initialize the database layer
|
|
146
|
+
* - Initialize the entity service
|
|
147
|
+
* - Run the schemas/database synchronization
|
|
148
|
+
* - Start the webhooks and initializing middlewares and routes
|
|
149
|
+
* - Run all the `bootstrap` lifecycle methods loaded by the
|
|
150
|
+
* user application or the enabled plugins
|
|
151
|
+
*/
|
|
152
|
+
bootstrap(): Promise<Strapi>;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Destroy phase
|
|
156
|
+
*
|
|
157
|
+
* - Destroy Strapi server
|
|
158
|
+
* - Run all the `destroy` lifecycle methods loaded by the
|
|
159
|
+
* user application or the enabled plugins
|
|
160
|
+
* - Cleanup the event hub
|
|
161
|
+
* - Gracefully stop the database
|
|
162
|
+
* - Stop the telemetry and cron instance
|
|
163
|
+
* - Cleanup the global scope by removing global.strapi
|
|
164
|
+
*/
|
|
165
|
+
destroy(): Promise<void>;
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Run all functions registered for a given lifecycle. (Strapi core, user app, plugins)
|
|
169
|
+
*/
|
|
170
|
+
runLifecyclesFunctions<T extends Lifecycles[keyof Lifecycles]>(lifecycleName: T): Promise<void>;
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Load the application if needed and start the server
|
|
174
|
+
*/
|
|
175
|
+
start(): Promise<void>;
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Stop the server and provide a custom error and message
|
|
179
|
+
*/
|
|
180
|
+
stopWithError<TError = unknown>(error: TError, customMessage?: string): void;
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Gracefully stop the server
|
|
184
|
+
* Call the destroy method.
|
|
185
|
+
*/
|
|
186
|
+
stop(code?: number): void;
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Load the server and the user application.
|
|
190
|
+
* It basically triggers the register and bootstrap phases
|
|
191
|
+
*/
|
|
192
|
+
load(): Promise<Strapi>;
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Restart the server and reload all the configuration.
|
|
196
|
+
* It re-runs all the lifecycles phases.
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ``` ts
|
|
200
|
+
* setImmediate(() => strapi.reload());
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
reload(): () => void;
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Initialize and start all the webhooks registered in the webhook store
|
|
207
|
+
*/
|
|
208
|
+
startWebhooks(): Promise<void>;
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Method called when the server is fully initialized and listen to incomming requests.
|
|
212
|
+
* It handles tasks such as logging the startup message
|
|
213
|
+
* or automatically opening the administration panel.
|
|
214
|
+
*/
|
|
215
|
+
postListen(): Promise<void>;
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Start listening for incomming requests
|
|
219
|
+
*/
|
|
220
|
+
listen(): Promise<void | Error>;
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Opent he administration panel in a browser if the option is enabled.
|
|
224
|
+
* You can disable it using the admin.autoOpen configuration variable.
|
|
225
|
+
*
|
|
226
|
+
* Note: It only works in development envs.
|
|
227
|
+
*/
|
|
228
|
+
openAdmin(options: { isInitialized: boolean }): Promise<void>;
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Load the admin panel server logic into the server code and initialize its configuration.
|
|
232
|
+
*/
|
|
233
|
+
loadAdmin(): Promise<void>;
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Resolve every enabled plugin and load them into the application.
|
|
237
|
+
*/
|
|
238
|
+
loadPlugins(): Promise<void>;
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Load every global policies in the policies container by
|
|
242
|
+
* reading from the `strapi.dirs.dist.policies` directory.
|
|
243
|
+
*/
|
|
244
|
+
loadPolicies(): Promise<void>;
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Load every APIs and their components (config, routes, controllers, services,
|
|
248
|
+
* policies, middlewares, content-types) in the API container.
|
|
249
|
+
*/
|
|
250
|
+
loadAPIs(): Promise<void>;
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Resolve every components in the user application and store them in `strapi.components`
|
|
254
|
+
*/
|
|
255
|
+
loadComponents(): Promise<void>;
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Load every global and core middlewares in the middlewares container by
|
|
259
|
+
* reading from the `strapi.dirs.dist.middlewares` and internal middlewares directory.
|
|
260
|
+
*/
|
|
261
|
+
loadMiddlewares(): Promise<void>;
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Load the user application in the server by reading the `src/index.js` file.
|
|
265
|
+
*/
|
|
266
|
+
loadApp(): Promise<void>;
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Add internal hooks to the hooks container.
|
|
270
|
+
* Those hooks are meant for internal usage and might break in future releases.
|
|
271
|
+
*/
|
|
272
|
+
registerInternalHooks(): void;
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Find a model (content-type, component) based on its unique identifier.
|
|
276
|
+
*/
|
|
277
|
+
getModel(uid: string): any;
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Binds database queries for a specific model based on its unique identifier.
|
|
281
|
+
*/
|
|
282
|
+
query(uid: string): any;
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Main Strapi container holding all the registries and providers (config, content-types, services, policies, etc...)
|
|
286
|
+
*/
|
|
287
|
+
container: any;
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* References to all the directories handled by Strapi
|
|
291
|
+
*/
|
|
292
|
+
dirs: StrapiDirectories;
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Internal flag used to check if the application has been loaded
|
|
296
|
+
*/
|
|
297
|
+
isLoaded: boolean;
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Fully reload the application
|
|
301
|
+
*/
|
|
302
|
+
reload(): void;
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Holds a reference to the Koa application and the http server used by Strapi
|
|
306
|
+
*/
|
|
307
|
+
server: any;
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Strapi util used to manage application files
|
|
311
|
+
*/
|
|
312
|
+
fs: any;
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Event hub used to send and receive events from anywhere in the application
|
|
316
|
+
*/
|
|
317
|
+
eventHub: any;
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Internal util used to log stats and messages on application Startup
|
|
321
|
+
*/
|
|
322
|
+
startupLogger: any;
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Strapi logger used to send errors, warning or information messages
|
|
326
|
+
*/
|
|
327
|
+
log: any;
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Used to manage cron within Strapi
|
|
332
|
+
*/
|
|
333
|
+
cron: any;
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Telemetry util used to collect anonymous data on the application usage
|
|
337
|
+
*/
|
|
338
|
+
telemetry: any;
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Strapi DB layer instance
|
|
342
|
+
*/
|
|
343
|
+
db: Database;
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Core Store accessor
|
|
347
|
+
*/
|
|
348
|
+
store: any;
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Entity Validator instance
|
|
352
|
+
*/
|
|
353
|
+
entityValidator: any;
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Entity Service instance
|
|
357
|
+
*/
|
|
358
|
+
entityService: any;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
export interface Lifecycles {
|
|
362
|
+
REGISTER: 'register';
|
|
363
|
+
BOOTSTRAP: 'bootstrap';
|
|
364
|
+
DESTROY: 'destroy';
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
export interface StrapiDirectories {
|
|
368
|
+
static: {
|
|
369
|
+
public: string;
|
|
370
|
+
};
|
|
371
|
+
app: {
|
|
372
|
+
root: string;
|
|
373
|
+
src: string;
|
|
374
|
+
api: string;
|
|
375
|
+
components: string;
|
|
376
|
+
extensions: string;
|
|
377
|
+
policies: string;
|
|
378
|
+
middlewares: string;
|
|
379
|
+
config: string;
|
|
380
|
+
};
|
|
381
|
+
dist: {
|
|
382
|
+
root: string;
|
|
383
|
+
src: string;
|
|
384
|
+
api: string;
|
|
385
|
+
components: string;
|
|
386
|
+
extensions: string;
|
|
387
|
+
policies: string;
|
|
388
|
+
middlewares: string;
|
|
389
|
+
config: string;
|
|
390
|
+
};
|
|
391
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Service } from '../core-api/service';
|
|
2
|
+
import { Controller, GenericController } from '../core-api/controller';
|
|
3
|
+
import { Middleware } from '../middlewares';
|
|
4
|
+
import { Policy } from '../core/registries/policies';
|
|
5
|
+
import { Strapi } from '@strapi/strapi';
|
|
6
|
+
|
|
7
|
+
type ControllerConfig<T extends Controller = Controller> = T;
|
|
8
|
+
|
|
9
|
+
type ServiceConfig = Service;
|
|
10
|
+
|
|
11
|
+
type HandlerConfig = {
|
|
12
|
+
auth?: false | { scope: string[] };
|
|
13
|
+
policies?: Array<string | Policy | { name: string; config: object }>;
|
|
14
|
+
middlewares?: Array<string | Middleware | { name: string; config: object }>;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type SingleTypeRouterConfig = {
|
|
18
|
+
find?: HandlerConfig;
|
|
19
|
+
update?: HandlerConfig;
|
|
20
|
+
delete?: HandlerConfig;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
type CollectionTypeRouterConfig = {
|
|
24
|
+
find?: HandlerConfig;
|
|
25
|
+
findOne?: HandlerConfig;
|
|
26
|
+
create?: HandlerConfig;
|
|
27
|
+
update?: HandlerConfig;
|
|
28
|
+
delete?: HandlerConfig;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
type RouterConfig = {
|
|
32
|
+
prefix?: string;
|
|
33
|
+
only: string[];
|
|
34
|
+
except?: string[];
|
|
35
|
+
config: SingleTypeRouterConfig | CollectionTypeRouterConfig;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
interface Route {
|
|
39
|
+
method: string;
|
|
40
|
+
path: string;
|
|
41
|
+
}
|
|
42
|
+
interface Router {
|
|
43
|
+
prefix: string;
|
|
44
|
+
routes: Route[];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
type ControllerCallback<T extends GenericController = GenericController> = (params: {
|
|
48
|
+
strapi: Strapi;
|
|
49
|
+
}) => T;
|
|
50
|
+
type ServiceCallback<T extends Service = Service> = (params: { strapi: Strapi }) => T;
|
|
51
|
+
|
|
52
|
+
export function createCoreRouter(uid: string, cfg?: RouterConfig = {}): () => Router;
|
|
53
|
+
export function createCoreController<T extends GenericController = GenericController>(
|
|
54
|
+
uid: string,
|
|
55
|
+
cfg?: ControllerCallback<T> | T = {}
|
|
56
|
+
): () => T & Controller;
|
|
57
|
+
export function createCoreService<T extends Service = Service>(
|
|
58
|
+
uid: string,
|
|
59
|
+
cfg?: ServiceCallback<T> | T = {}
|
|
60
|
+
): () => T;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Common utilities used across Strapi typings
|
|
4
|
+
*
|
|
5
|
+
* */
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* Extract the array values into an union type
|
|
10
|
+
*
|
|
11
|
+
**/
|
|
12
|
+
export type GetArrayValues<T extends Array<unknown>> = T extends Array<infer U> ? U : never;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Creates a record where every key is a string and every value is `T`
|
|
16
|
+
*/
|
|
17
|
+
export type StringRecord<T> = Record<string, T>;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Retrieve object's (`T`) keys if they extends the given `U` type.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* type X = KeysBy<{ foo: 'bar', bar: 'foo', foobar: 2 }, string>
|
|
24
|
+
* // 'foo' | 'bar'
|
|
25
|
+
*
|
|
26
|
+
* type Base = { x: 'foo' | 'bar' };
|
|
27
|
+
* type Obj = { foo: { x: 'foo' }, bar: { x: 'bar' }, other: { x: '42' } };
|
|
28
|
+
* type X = KeysBy<Obj, Base>
|
|
29
|
+
* // 'foo' | 'bar'
|
|
30
|
+
*/
|
|
31
|
+
export type KeysBy<T, U> = {
|
|
32
|
+
[key in keyof T]: T[key] extends U ? key : never;
|
|
33
|
+
}[keyof T];
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Retrieve object's (`T`) properties if their value extends the given `U` type.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* type X = KeysBy<{ foo: 'bar', bar: 'foo', foobar: 2 }, string>
|
|
40
|
+
* // { foo: 'bar', bar: 'foo' }
|
|
41
|
+
*
|
|
42
|
+
* type Base = { x: 'foo' | 'bar' };
|
|
43
|
+
* type Obj = { foo: { x: 'foo' }, bar: { x: 'bar' }, other: { x: '42' } };
|
|
44
|
+
* type X = KeysBy<Obj, Base>
|
|
45
|
+
* // { foo: { x: 'foo' }, bar: { x: 'bar' } }
|
|
46
|
+
*/
|
|
47
|
+
export type PickBy<T, U> = Pick<T, KeysBy<T, U>>;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Assign a default value `U` to `T` if `T` is of type `never`
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* type X = NeverGuard<{ foo: 'bar' }, string>
|
|
54
|
+
* // { foo: 'bar' }
|
|
55
|
+
*
|
|
56
|
+
* type X = NeverGuard<never>
|
|
57
|
+
* // unknown
|
|
58
|
+
*
|
|
59
|
+
* type X = NeverGuard<never, string>
|
|
60
|
+
* // string
|
|
61
|
+
*/
|
|
62
|
+
export type NeverGuard<T, U = unknown> = [T] extends [never] ? U : T;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Dynamic type based on the keys of `Strapi.Schemas`.
|
|
66
|
+
* It represents all the registered schemas' UID as a union type.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
*
|
|
70
|
+
* declare global {
|
|
71
|
+
* namespace Strapi {
|
|
72
|
+
* interface Schemas {
|
|
73
|
+
* 'api::foo.foo': CollectionTypeSchema;
|
|
74
|
+
* 'api::bar.bar': ComponentSchema;
|
|
75
|
+
* }
|
|
76
|
+
* }
|
|
77
|
+
* }
|
|
78
|
+
*
|
|
79
|
+
* type X = SchemaUID;
|
|
80
|
+
* // 'api::foo.foo' | 'api::bar.bar'
|
|
81
|
+
*/
|
|
82
|
+
export type SchemaUID = keyof Strapi.Schemas;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Get the type of a specific key `U` in `T`
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
*
|
|
89
|
+
* type X = Get<{ foo: 'bar', 'bar': 'foo' }, 'foo'>
|
|
90
|
+
* // 'bar'
|
|
91
|
+
*
|
|
92
|
+
* type X = Get<{ foo: 'bar', 'bar': 'foo' }, 'bar'>
|
|
93
|
+
* // 'foo'
|
|
94
|
+
*/
|
|
95
|
+
export type Get<T, U extends keyof T> = T[U];
|
package/lib/utils/get-dirs.js
CHANGED
|
@@ -2,16 +2,30 @@
|
|
|
2
2
|
|
|
3
3
|
const { join, resolve } = require('path');
|
|
4
4
|
|
|
5
|
-
const getDirs = (
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
const getDirs = ({ app: appDir, dist: distDir }, { strapi }) => ({
|
|
6
|
+
dist: {
|
|
7
|
+
root: distDir,
|
|
8
|
+
src: join(distDir, 'src'),
|
|
9
|
+
api: join(distDir, 'src', 'api'),
|
|
10
|
+
components: join(distDir, 'src', 'components'),
|
|
11
|
+
extensions: join(distDir, 'src', 'extensions'),
|
|
12
|
+
policies: join(distDir, 'src', 'policies'),
|
|
13
|
+
middlewares: join(distDir, 'src', 'middlewares'),
|
|
14
|
+
config: join(distDir, 'config'),
|
|
15
|
+
},
|
|
16
|
+
app: {
|
|
17
|
+
root: appDir,
|
|
18
|
+
src: join(appDir, 'src'),
|
|
19
|
+
api: join(appDir, 'src', 'api'),
|
|
20
|
+
components: join(appDir, 'src', 'components'),
|
|
21
|
+
extensions: join(appDir, 'src', 'extensions'),
|
|
22
|
+
policies: join(appDir, 'src', 'policies'),
|
|
23
|
+
middlewares: join(appDir, 'src', 'middlewares'),
|
|
24
|
+
config: join(appDir, 'config'),
|
|
25
|
+
},
|
|
26
|
+
static: {
|
|
27
|
+
public: resolve(appDir, strapi.config.get('server.dirs.public')),
|
|
28
|
+
},
|
|
15
29
|
});
|
|
16
30
|
|
|
17
31
|
module.exports = getDirs;
|
package/lib/utils/index.js
CHANGED
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
const openBrowser = require('./open-browser');
|
|
4
4
|
const isInitialized = require('./is-initialized');
|
|
5
5
|
const getDirs = require('./get-dirs');
|
|
6
|
+
const importDefault = require('./import-default');
|
|
6
7
|
|
|
7
8
|
module.exports = {
|
|
8
9
|
isInitialized,
|
|
9
10
|
openBrowser,
|
|
10
11
|
getDirs,
|
|
12
|
+
importDefault,
|
|
11
13
|
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A map of all the available Strapi lifecycles
|
|
5
|
+
* @type {import('@strapi/strapi').Core.Lifecycles}
|
|
6
|
+
*/
|
|
7
|
+
const LIFECYCLES = {
|
|
8
|
+
REGISTER: 'register',
|
|
9
|
+
BOOTSTRAP: 'bootstrap',
|
|
10
|
+
DESTROY: 'destroy',
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
module.exports = {
|
|
14
|
+
LIFECYCLES,
|
|
15
|
+
};
|
package/lib/utils/machine-id.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const { machineIdSync } = require('node-machine-id');
|
|
4
|
-
const
|
|
4
|
+
const { v4: uuidv4 } = require('uuid');
|
|
5
5
|
|
|
6
6
|
module.exports = () => {
|
|
7
7
|
try {
|
|
8
8
|
const deviceId = machineIdSync();
|
|
9
9
|
return deviceId;
|
|
10
10
|
} catch (error) {
|
|
11
|
-
const deviceId =
|
|
11
|
+
const deviceId = uuidv4();
|
|
12
12
|
return deviceId;
|
|
13
13
|
}
|
|
14
14
|
};
|
|
@@ -38,7 +38,7 @@ const createUpdateNotifier = strapi => {
|
|
|
38
38
|
config = new Configstore(
|
|
39
39
|
pkg.name,
|
|
40
40
|
{},
|
|
41
|
-
{ configPath: path.join(strapi.dirs.root, '.strapi-updater.json') }
|
|
41
|
+
{ configPath: path.join(strapi.dirs.app.root, '.strapi-updater.json') }
|
|
42
42
|
);
|
|
43
43
|
} catch {
|
|
44
44
|
// we don't have write access to the file system
|