@strapi/strapi 4.2.0-beta.3 → 4.3.0-beta.1

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.
Files changed (36) hide show
  1. package/bin/strapi.js +1 -1
  2. package/lib/Strapi.js +1 -10
  3. package/lib/commands/admin-create.js +2 -15
  4. package/lib/commands/admin-reset.js +2 -15
  5. package/lib/commands/build.js +5 -17
  6. package/lib/commands/builders/admin.js +1 -4
  7. package/lib/commands/configurationDump.js +2 -14
  8. package/lib/commands/configurationRestore.js +2 -15
  9. package/lib/commands/console.js +2 -15
  10. package/lib/commands/content-types/list.js +2 -1
  11. package/lib/commands/controllers/list.js +2 -1
  12. package/lib/commands/develop.js +0 -3
  13. package/lib/commands/hooks/list.js +2 -1
  14. package/lib/commands/middlewares/list.js +2 -1
  15. package/lib/commands/policies/list.js +2 -1
  16. package/lib/commands/routes/list.js +2 -15
  17. package/lib/commands/services/list.js +2 -1
  18. package/lib/commands/start.js +10 -4
  19. package/lib/commands/watchAdmin.js +4 -9
  20. package/lib/compile.js +20 -0
  21. package/lib/core/app-configuration/load-config-file.js +2 -2
  22. package/lib/core/loaders/apis.js +1 -1
  23. package/lib/core/loaders/middlewares.js +2 -2
  24. package/lib/core/loaders/policies.js +1 -1
  25. package/lib/core/loaders/src-index.js +1 -1
  26. package/lib/core-api/controller/index.d.ts +15 -18
  27. package/lib/index.js +1 -0
  28. package/lib/load/load-files.js +2 -2
  29. package/lib/middlewares/public/index.js +0 -1
  30. package/lib/services/entity-service/index.d.ts +7 -1
  31. package/lib/services/entity-service/index.js +11 -1
  32. package/lib/services/utils/upload-files.js +1 -1
  33. package/lib/types/strapi.d.ts +85 -6
  34. package/lib/utils/import-default.js +6 -5
  35. package/lib/utils/lifecycles.js +15 -0
  36. package/package.json +14 -14
package/bin/strapi.js CHANGED
@@ -101,7 +101,7 @@ program
101
101
 
102
102
  // `$ strapi start`
103
103
  program
104
- .command('start [dir]')
104
+ .command('start')
105
105
  .description('Start your Strapi application')
106
106
  .action(getLocalScript('start'));
107
107
 
package/lib/Strapi.js CHANGED
@@ -24,6 +24,7 @@ const createTelemetry = require('./services/metrics');
24
24
  const createAuth = require('./services/auth');
25
25
  const createUpdateNotifier = require('./utils/update-notifier');
26
26
  const createStartupLogger = require('./utils/startup-logger');
27
+ const { LIFECYCLES } = require('./utils/lifecycles');
27
28
  const ee = require('./utils/ee');
28
29
  const contentTypesRegistry = require('./core/registries/content-types');
29
30
  const servicesRegistry = require('./core/registries/services');
@@ -43,16 +44,6 @@ const sanitizersRegistry = require('./core/registries/sanitizers');
43
44
  // TODO: move somewhere else
44
45
  const draftAndPublishSync = require('./migrations/draft-publish');
45
46
 
46
- /**
47
- * A map of all the available Strapi lifecycles
48
- * @type {import('@strapi/strapi').Core.Lifecycles}
49
- */
50
- const LIFECYCLES = {
51
- REGISTER: 'register',
52
- BOOTSTRAP: 'bootstrap',
53
- DESTROY: 'destroy',
54
- };
55
-
56
47
  /**
57
48
  * Resolve the working directories based on the instance options.
58
49
  *
@@ -3,7 +3,6 @@
3
3
  const { yup } = require('@strapi/utils');
4
4
  const _ = require('lodash');
5
5
  const inquirer = require('inquirer');
6
- const tsUtils = require('@strapi/typescript-utils');
7
6
  const strapi = require('../index');
8
7
 
9
8
  const emailValidator = yup
@@ -91,20 +90,8 @@ module.exports = async function(cmdOptions = {}) {
91
90
  };
92
91
 
93
92
  async function createAdmin({ email, password, firstname, lastname }) {
94
- const appDir = process.cwd();
95
-
96
- const isTSProject = await tsUtils.isUsingTypeScript(appDir);
97
- const outDir = await tsUtils.resolveOutDir(appDir);
98
-
99
- if (isTSProject)
100
- await tsUtils.compile(appDir, {
101
- watch: false,
102
- configOptions: { options: { incremental: true } },
103
- });
104
-
105
- const distDir = isTSProject ? outDir : appDir;
106
-
107
- const app = await strapi({ appDir, distDir }).load();
93
+ const appContext = await strapi.compile();
94
+ const app = await strapi(appContext).load();
108
95
 
109
96
  const user = await app.admin.services.user.exists({ email });
110
97
 
@@ -2,7 +2,6 @@
2
2
 
3
3
  const _ = require('lodash');
4
4
  const inquirer = require('inquirer');
5
- const tsUtils = require('@strapi/typescript-utils');
6
5
  const strapi = require('../index');
7
6
 
8
7
  const promptQuestions = [
@@ -43,20 +42,8 @@ module.exports = async function(cmdOptions = {}) {
43
42
  };
44
43
 
45
44
  async function changePassword({ email, password }) {
46
- const appDir = process.cwd();
47
-
48
- const isTSProject = await tsUtils.isUsingTypeScript(appDir);
49
- const outDir = await tsUtils.resolveOutDir(appDir);
50
-
51
- if (isTSProject)
52
- await tsUtils.compile(appDir, {
53
- watch: false,
54
- configOptions: { options: { incremental: true } },
55
- });
56
-
57
- const distDir = isTSProject ? outDir : appDir;
58
-
59
- const app = await strapi({ appDir, distDir }).load();
45
+ const appContext = await strapi.compile();
46
+ const app = await strapi(appContext).load();
60
47
 
61
48
  await app.admin.services.user.resetPasswordByEmail(email, password);
62
49
 
@@ -1,30 +1,18 @@
1
1
  'use strict';
2
2
 
3
- const tsUtils = require('@strapi/typescript-utils');
4
- const { buildAdmin, buildTypeScript } = require('./builders');
3
+ const strapi = require('../');
4
+ const { buildAdmin } = require('./builders');
5
5
 
6
6
  /**
7
7
  * `$ strapi build`
8
8
  */
9
9
  module.exports = async ({ optimization, forceBuild = true }) => {
10
- let buildDestDir = process.cwd();
11
- const srcDir = process.cwd();
12
-
13
- const useTypeScriptServer = await tsUtils.isUsingTypeScript(srcDir);
14
- const outDir = await tsUtils.resolveOutDir(srcDir);
15
-
16
- // Typescript
17
- if (useTypeScriptServer) {
18
- await buildTypeScript({ srcDir, watch: false });
19
-
20
- // Update the dir path for the next steps
21
- buildDestDir = outDir;
22
- }
10
+ const { appDir, distDir } = await strapi.compile();
23
11
 
24
12
  await buildAdmin({
25
- buildDestDir,
26
13
  forceBuild,
27
14
  optimization,
28
- srcDir,
15
+ buildDestDir: distDir,
16
+ srcDir: appDir,
29
17
  });
30
18
  };
@@ -28,12 +28,9 @@ module.exports = async ({ buildDestDir, forceBuild = true, optimization, srcDir
28
28
  console.log(`Building your admin UI with ${green(env)} configuration...`);
29
29
 
30
30
  // Always remove the .cache and build folders
31
- // FIXME the BE should remove the build dir and the admin should only
32
- // be responsible of removing the .cache dir.
33
31
  await strapiAdmin.clean({ appDir: srcDir, buildDestDir });
34
32
 
35
- // @convly shouldn't we use the app dir here?
36
- ee({ dir: buildDestDir });
33
+ ee({ dir: srcDir });
37
34
 
38
35
  return strapiAdmin
39
36
  .build({
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  const fs = require('fs');
4
- const tsUtils = require('@strapi/typescript-utils');
5
4
  const strapi = require('../index');
6
5
 
7
6
  const CHUNK_SIZE = 100;
@@ -13,19 +12,8 @@ const CHUNK_SIZE = 100;
13
12
  module.exports = async function({ file: filePath, pretty }) {
14
13
  const output = filePath ? fs.createWriteStream(filePath) : process.stdout;
15
14
 
16
- const appDir = process.cwd();
17
-
18
- const isTSProject = await tsUtils.isUsingTypeScript(appDir);
19
- const outDir = await tsUtils.resolveOutDir(appDir);
20
- if (isTSProject)
21
- await tsUtils.compile(appDir, {
22
- watch: false,
23
- configOptions: { options: { incremental: true } },
24
- });
25
-
26
- const distDir = isTSProject ? outDir : appDir;
27
-
28
- const app = await strapi({ appDir, distDir }).load();
15
+ const appContext = await strapi.compile();
16
+ const app = await strapi(appContext).load();
29
17
 
30
18
  const count = await app.query('strapi::core-store').count();
31
19
 
@@ -2,7 +2,6 @@
2
2
 
3
3
  const fs = require('fs');
4
4
  const _ = require('lodash');
5
- const tsUtils = require('@strapi/typescript-utils');
6
5
 
7
6
  const strapi = require('../index');
8
7
 
@@ -14,20 +13,8 @@ const strapi = require('../index');
14
13
  module.exports = async function({ file: filePath, strategy = 'replace' }) {
15
14
  const input = filePath ? fs.readFileSync(filePath) : await readStdin(process.stdin);
16
15
 
17
- const appDir = process.cwd();
18
-
19
- const isTSProject = await tsUtils.isUsingTypeScript(appDir);
20
- const outDir = await tsUtils.resolveOutDir(appDir);
21
-
22
- if (isTSProject)
23
- await tsUtils.compile(appDir, {
24
- watch: false,
25
- configOptions: { options: { incremental: true } },
26
- });
27
-
28
- const distDir = isTSProject ? outDir : appDir;
29
-
30
- const app = await strapi({ appDir, distDir }).load();
16
+ const appContext = await strapi.compile();
17
+ const app = await strapi(appContext).load();
31
18
 
32
19
  let dataToImport;
33
20
  try {
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  const REPL = require('repl');
4
- const tsUtils = require('@strapi/typescript-utils');
5
4
 
6
5
  const strapi = require('../index');
7
6
 
@@ -9,20 +8,8 @@ const strapi = require('../index');
9
8
  * `$ strapi console`
10
9
  */
11
10
  module.exports = async () => {
12
- // Now load up the Strapi framework for real.
13
- const appDir = process.cwd();
14
- const isTSProject = await tsUtils.isUsingTypeScript(appDir);
15
- const outDir = await tsUtils.resolveOutDir(appDir);
16
-
17
- if (isTSProject)
18
- await tsUtils.compile(appDir, {
19
- watch: false,
20
- configOptions: { options: { incremental: true } },
21
- });
22
-
23
- const distDir = isTSProject ? outDir : appDir;
24
-
25
- const app = await strapi({ appDir, distDir }).load();
11
+ const appContext = await strapi.compile();
12
+ const app = await strapi(appContext).load();
26
13
 
27
14
  app.start().then(() => {
28
15
  const repl = REPL.start(app.config.info.name + ' > ' || 'strapi > '); // eslint-disable-line prefer-template
@@ -6,7 +6,8 @@ const chalk = require('chalk');
6
6
  const strapi = require('../../index');
7
7
 
8
8
  module.exports = async function() {
9
- const app = await strapi().register();
9
+ const appContext = await strapi.compile();
10
+ const app = await strapi(appContext).register();
10
11
 
11
12
  const list = app.container.get('content-types').keys();
12
13
 
@@ -6,7 +6,8 @@ const chalk = require('chalk');
6
6
  const strapi = require('../../index');
7
7
 
8
8
  module.exports = async function() {
9
- const app = await strapi().register();
9
+ const appContext = await strapi.compile();
10
+ const app = await strapi(appContext).register();
10
11
 
11
12
  const list = app.container.get('controllers').keys();
12
13
 
@@ -149,7 +149,6 @@ function watchFileChanges({ appDir, strapiInstance, watchIgnoreFiles, polling })
149
149
  }
150
150
  };
151
151
 
152
- // @soupette should we keep watching the dist dir (for the watch admin?)
153
152
  const watcher = chokidar.watch(appDir, {
154
153
  ignoreInitial: true,
155
154
  usePolling: polling,
@@ -158,8 +157,6 @@ function watchFileChanges({ appDir, strapiInstance, watchIgnoreFiles, polling })
158
157
  /tmp/,
159
158
  '**/src/admin/**',
160
159
  '**/src/plugins/**/admin/**',
161
- // FIXME pass the plugin path to the strapiAdmin.build and strapiAdmin.watch in order to stop copying
162
- // the FE files when using TS
163
160
  '**/dist/src/plugins/test/admin/**',
164
161
  '**/documentation',
165
162
  '**/documentation/**',
@@ -6,7 +6,8 @@ const chalk = require('chalk');
6
6
  const strapi = require('../../index');
7
7
 
8
8
  module.exports = async function() {
9
- const app = await strapi().register();
9
+ const appContext = await strapi.compile();
10
+ const app = await strapi(appContext).register();
10
11
 
11
12
  const list = app.container.get('hooks').keys();
12
13
 
@@ -6,7 +6,8 @@ const chalk = require('chalk');
6
6
  const strapi = require('../../index');
7
7
 
8
8
  module.exports = async function() {
9
- const app = await strapi().register();
9
+ const appContext = await strapi.compile();
10
+ const app = await strapi(appContext).register();
10
11
 
11
12
  const list = app.container.get('middlewares').keys();
12
13
 
@@ -6,7 +6,8 @@ const chalk = require('chalk');
6
6
  const strapi = require('../../index');
7
7
 
8
8
  module.exports = async function() {
9
- const app = await strapi().register();
9
+ const appContext = await strapi.compile();
10
+ const app = await strapi(appContext).register();
10
11
 
11
12
  const list = app.container.get('policies').keys();
12
13
 
@@ -3,25 +3,12 @@
3
3
  const CLITable = require('cli-table3');
4
4
  const chalk = require('chalk');
5
5
  const { toUpper } = require('lodash/fp');
6
- const tsUtils = require('@strapi/typescript-utils');
7
6
 
8
7
  const strapi = require('../../index');
9
8
 
10
9
  module.exports = async function() {
11
- const appDir = process.cwd();
12
-
13
- const isTSProject = await tsUtils.isUsingTypeScript(appDir);
14
- const outDir = await tsUtils.resolveOutDir(appDir);
15
-
16
- if (isTSProject)
17
- await tsUtils.compile(appDir, {
18
- watch: false,
19
- configOptions: { options: { incremental: true } },
20
- });
21
-
22
- const distDir = isTSProject ? outDir : appDir;
23
-
24
- const app = await strapi({ appDir, distDir }).load();
10
+ const appContext = await strapi.compile();
11
+ const app = await strapi(appContext).load();
25
12
 
26
13
  const list = app.server.listRoutes();
27
14
 
@@ -6,7 +6,8 @@ const chalk = require('chalk');
6
6
  const strapi = require('../../index');
7
7
 
8
8
  module.exports = async function() {
9
- const app = await strapi().register();
9
+ const appContext = await strapi.compile();
10
+ const app = await strapi(appContext).register();
10
11
 
11
12
  const list = app.container.get('services').keys();
12
13
 
@@ -6,13 +6,19 @@ const strapi = require('../index');
6
6
  /**
7
7
  * `$ strapi start`
8
8
  */
9
- module.exports = async specifiedDir => {
9
+ module.exports = async () => {
10
10
  const appDir = process.cwd();
11
+
11
12
  const isTSProject = await tsUtils.isUsingTypeScript(appDir);
13
+
12
14
  const outDir = await tsUtils.resolveOutDir(appDir);
15
+ const distDir = isTSProject ? outDir : appDir;
16
+
13
17
  const buildDirExists = fs.existsSync(outDir);
14
- if (isTSProject && !buildDirExists) throw new Error(`${outDir} directory not found. Please run the build command before starting your application`);
15
- const distDir = isTSProject && !specifiedDir ? outDir : specifiedDir;
18
+ if (isTSProject && !buildDirExists)
19
+ throw new Error(
20
+ `${outDir} directory not found. Please run the build command before starting your application`
21
+ );
16
22
 
17
- strapi({ distDir }).start();
23
+ return strapi({ appDir, distDir }).start();
18
24
  };
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  const strapiAdmin = require('@strapi/admin');
4
- const tsUtils = require('@strapi/typescript-utils');
5
4
  const { getConfigUrls, getAbsoluteServerUrl } = require('@strapi/utils');
6
5
 
7
6
  const getEnabledPlugins = require('../core/loaders/plugins/get-enabled-plugins');
@@ -9,14 +8,10 @@ const addSlash = require('../utils/addSlash');
9
8
  const strapi = require('../index');
10
9
 
11
10
  module.exports = async function({ browser }) {
12
- const currentDirectory = process.cwd();
13
-
14
- const isTSProject = await tsUtils.isUsingTypeScript(currentDirectory);
15
- const outDir = await tsUtils.resolveOutDir(currentDirectory);
16
- const buildDestDir = isTSProject ? outDir : currentDirectory;
11
+ const appContext = await strapi.compile();
17
12
 
18
13
  const strapiInstance = strapi({
19
- distDir: buildDestDir,
14
+ ...appContext,
20
15
  autoReload: true,
21
16
  serveAdminPanel: false,
22
17
  });
@@ -31,8 +26,8 @@ module.exports = async function({ browser }) {
31
26
  const backendURL = getAbsoluteServerUrl(strapiInstance.config, true);
32
27
 
33
28
  strapiAdmin.watchAdmin({
34
- appDir: currentDirectory,
35
- buildDestDir,
29
+ appDir: appContext.appDir,
30
+ buildDestDir: appContext.distDir,
36
31
  plugins,
37
32
  port: adminPort,
38
33
  host: adminHost,
package/lib/compile.js ADDED
@@ -0,0 +1,20 @@
1
+ 'use strict';
2
+
3
+ const tsUtils = require('@strapi/typescript-utils');
4
+
5
+ module.exports = async dir => {
6
+ const appDir = dir || process.cwd();
7
+ const isTSProject = await tsUtils.isUsingTypeScript(appDir);
8
+ const outDir = await tsUtils.resolveOutDir(appDir);
9
+
10
+ if (isTSProject) {
11
+ await tsUtils.compile(appDir, {
12
+ watch: false,
13
+ configOptions: { options: { incremental: true } },
14
+ });
15
+ }
16
+
17
+ const distDir = isTSProject ? outDir : appDir;
18
+
19
+ return { appDir, distDir };
20
+ };
@@ -4,11 +4,11 @@ const path = require('path');
4
4
  const fs = require('fs');
5
5
  const { templateConfiguration, env } = require('@strapi/utils');
6
6
 
7
- const __importDefault = require('../../utils/import-default');
7
+ const importDefault = require('../../utils/import-default');
8
8
 
9
9
  const loadJsFile = file => {
10
10
  try {
11
- const jsModule = __importDefault(require(file)).default;
11
+ const jsModule = importDefault(file);
12
12
 
13
13
  // call if function
14
14
  if (typeof jsModule === 'function') {
@@ -155,7 +155,7 @@ const loadFile = file => {
155
155
 
156
156
  switch (ext) {
157
157
  case '.js':
158
- return importDefault(require(file)).default;
158
+ return importDefault(file);
159
159
  case '.json':
160
160
  return fse.readJSON(file);
161
161
  default:
@@ -8,7 +8,7 @@ const { importDefault } = require('../../utils');
8
8
  // TODO:: allow folders with index.js inside for bigger policies
9
9
  module.exports = async function loadMiddlewares(strapi) {
10
10
  const localMiddlewares = await loadLocalMiddlewares(strapi);
11
- const internalMiddlewares = importDefault(require('../../middlewares')).default;
11
+ const internalMiddlewares = require('../../middlewares');
12
12
 
13
13
  strapi.container.get('middlewares').add(`global::`, localMiddlewares);
14
14
  strapi.container.get('middlewares').add(`strapi::`, internalMiddlewares);
@@ -30,7 +30,7 @@ const loadLocalMiddlewares = async strapi => {
30
30
 
31
31
  if (fd.isFile() && extname(name) === '.js') {
32
32
  const key = basename(name, '.js');
33
- middlewares[key] = importDefault(require(fullPath)).default;
33
+ middlewares[key] = importDefault(fullPath);
34
34
  }
35
35
  }
36
36
 
@@ -22,7 +22,7 @@ module.exports = async function loadPolicies(strapi) {
22
22
 
23
23
  if (fd.isFile() && extname(name) === '.js') {
24
24
  const key = basename(name, '.js');
25
- policies[key] = importDefault(require(fullPath)).default;
25
+ policies[key] = importDefault(fullPath);
26
26
  }
27
27
  }
28
28
 
@@ -29,7 +29,7 @@ module.exports = strapi => {
29
29
  return {};
30
30
  }
31
31
 
32
- const srcIndex = importDefault(require(pathToSrcIndex)).default;
32
+ const srcIndex = importDefault(pathToSrcIndex);
33
33
 
34
34
  try {
35
35
  validateSrcIndex(srcIndex);
@@ -1,30 +1,27 @@
1
- import { Context } from 'koa';
1
+ import { Context, Next } from 'koa';
2
2
 
3
- type ControllerResponse <T=unknown> = T | Promise<T>;
3
+ type ControllerResponse<T = unknown> = T | Promise<T> | undefined;
4
4
 
5
- interface BaseController {
5
+ interface Controller {
6
6
  transformResponse(data: object, meta: object): object;
7
7
  sanitizeOutput(data: object, ctx: Context): Promise<object>;
8
8
  sanitizeInput(data: object, ctx: Context): Promise<object>;
9
9
  }
10
10
 
11
- export interface SingleTypeController extends BaseController {
12
- find(ctx: Context): ControllerResponse;
13
- update(ctx: Context): ControllerResponse;
14
- delete(ctx: Context): ControllerResponse;
11
+ export interface SingleTypeController extends Controller {
12
+ find?(ctx: Context, next: Next): ControllerResponse;
13
+ update?(ctx: Context, next: Next): ControllerResponse;
14
+ delete?(ctx: Context, next: Next): ControllerResponse;
15
15
  }
16
16
 
17
- export interface CollectionTypeController extends BaseController {
18
- find(ctx: Context): ControllerResponse;
19
- findOne(ctx: Context): ControllerResponse
20
- create(ctx: Context): ControllerResponse;
21
- update(ctx: Context): ControllerResponse;
22
- delete(ctx: Context): ControllerResponse;
17
+ export interface CollectionTypeController extends Controller {
18
+ find?(ctx: Context, next: Next): ControllerResponse;
19
+ findOne?(ctx: Context, next: Next): ControllerResponse;
20
+ create?(ctx: Context, next: Next): ControllerResponse;
21
+ update?(ctx: Context, next: Next): ControllerResponse;
22
+ delete?(ctx: Context, next: Next): ControllerResponse;
23
23
  }
24
24
 
25
- export type Controller = SingleTypeController | CollectionTypeController;
26
-
27
25
  export type GenericController = Partial<Controller> & {
28
- [method: string | number | symbol]: (ctx: Context) => unknown
29
- }
30
-
26
+ [method: string | number | symbol]: (ctx: Context) => unknown;
27
+ };
package/lib/index.js CHANGED
@@ -3,5 +3,6 @@
3
3
  const Strapi = require('./Strapi');
4
4
 
5
5
  Strapi.factories = require('./factories');
6
+ Strapi.compile = require('./compile');
6
7
 
7
8
  module.exports = Strapi;
@@ -21,7 +21,7 @@ const filePathToPath = require('./filepath-to-prop-path');
21
21
  const loadFiles = async (
22
22
  dir,
23
23
  pattern,
24
- { requireFn = require, shouldUseFileNameAsKey = () => true, globArgs = {} } = {}
24
+ { requireFn = importDefault, shouldUseFileNameAsKey = () => true, globArgs = {} } = {}
25
25
  ) => {
26
26
  const root = {};
27
27
  const files = await glob(pattern, { cwd: dir, ...globArgs });
@@ -36,7 +36,7 @@ const loadFiles = async (
36
36
  if (path.extname(absolutePath) === '.json') {
37
37
  mod = await fse.readJson(absolutePath);
38
38
  } else {
39
- mod = importDefault(requireFn(absolutePath)).default;
39
+ mod = requireFn(absolutePath);
40
40
  }
41
41
 
42
42
  Object.defineProperty(mod, '__filename__', {
@@ -71,7 +71,6 @@ module.exports = (config, { strapi }) => {
71
71
  {
72
72
  method: 'GET',
73
73
  path: '/assets/images/(.*)',
74
- // Why do we use the __dirname and not strapi.dirs here? @alexandrebodin
75
74
  handler: serveStatic(path.resolve(__dirname, 'assets/images'), {
76
75
  maxage: maxAge,
77
76
  defer: true,
@@ -6,6 +6,7 @@ type ID = number | string;
6
6
  type EntityServiceAction =
7
7
  | 'findMany'
8
8
  | 'findPage'
9
+ | 'findWithRelationCountsPage'
9
10
  | 'findWithRelationCounts'
10
11
  | 'findOne'
11
12
  | 'count'
@@ -54,7 +55,7 @@ export interface EntityService {
54
55
  pagination: PaginationInfo;
55
56
  }>;
56
57
 
57
- findWithRelationCounts<K extends keyof AllTypes, T extends AllTypes[K]>(
58
+ findWithRelationCountsPage<K extends keyof AllTypes, T extends AllTypes[K]>(
58
59
  uid: K,
59
60
  params: Params<T>
60
61
  ): Promise<{
@@ -62,6 +63,11 @@ export interface EntityService {
62
63
  pagination: PaginationInfo;
63
64
  }>;
64
65
 
66
+ findWithRelationCounts<K extends keyof AllTypes, T extends AllTypes[K]>(
67
+ uid: K,
68
+ params: Params<T>
69
+ ): Promise<T[]>;
70
+
65
71
  findOne<K extends keyof AllTypes, T extends AllTypes[K]>(
66
72
  uid: K,
67
73
  entityId: ID,
@@ -125,7 +125,7 @@ const createDefaultImplementation = ({ strapi, db, eventHub, entityValidator })
125
125
  },
126
126
 
127
127
  // TODO: streamline the logic based on the populate option
128
- async findWithRelationCounts(uid, opts) {
128
+ async findWithRelationCountsPage(uid, opts) {
129
129
  const wrappedParams = await this.wrapParams(opts, { uid, action: 'findWithRelationCounts' });
130
130
 
131
131
  const query = transformParamsToQuery(uid, wrappedParams);
@@ -138,6 +138,16 @@ const createDefaultImplementation = ({ strapi, db, eventHub, entityValidator })
138
138
  };
139
139
  },
140
140
 
141
+ async findWithRelationCounts(uid, opts) {
142
+ const wrappedParams = await this.wrapParams(opts, { uid, action: 'findWithRelationCounts' });
143
+
144
+ const query = transformParamsToQuery(uid, wrappedParams);
145
+
146
+ const results = await db.query(uid).findMany(query);
147
+
148
+ return results;
149
+ },
150
+
141
151
  async findOne(uid, entityId, opts) {
142
152
  const wrappedParams = await this.wrapParams(opts, { uid, action: 'findOne' });
143
153
 
@@ -3,7 +3,7 @@
3
3
  const _ = require('lodash');
4
4
 
5
5
  /**
6
- * Upload files and like them to an entity
6
+ * Upload files and link them to an entity
7
7
  * @param {string} uid model uid
8
8
  * @param {object} entity entity created
9
9
  * @param {object} files files to upload
@@ -1,10 +1,7 @@
1
1
  import type Koa from 'koa';
2
2
 
3
3
  import type { StringMap } from './utils';
4
-
5
- type Controller = {
6
- [methodName: string | number | symbol]: (context: Koa.Context) => unknown;
7
- }
4
+ import type { GenericController } from '../core-api/controller'
8
5
 
9
6
  /**
10
7
  * The Strapi interface implemented by the main Strapi class.
@@ -47,12 +44,12 @@ export interface Strapi {
47
44
  *
48
45
  * It returns all the registered controllers
49
46
  */
50
- readonly controllers: StringMap<Controller>;
47
+ readonly controllers: StringMap<GenericController>;
51
48
 
52
49
  /**
53
50
  * Find a controller using its unique identifier
54
51
  */
55
- controller(uid: string): Controller | undefined;
52
+ controller(uid: string): GenericController | undefined;
56
53
 
57
54
  /**
58
55
  * Getter for the Strapi content types container
@@ -282,6 +279,62 @@ export interface Strapi {
282
279
  * Binds database queries for a specific model based on its unique identifier.
283
280
  */
284
281
  query(uid: string): any;
282
+
283
+ /**
284
+ * Main Strapi container holding all the registries and providers (config, content-types, services, policies, etc...)
285
+ */
286
+ container: any;
287
+
288
+ /**
289
+ * References to all the directories handled by Strapi
290
+ */
291
+ dirs: StrapiDirectories;
292
+
293
+ /**
294
+ * Internal flag used to check if the application has been loaded
295
+ */
296
+ isLoaded: boolean;
297
+
298
+ /**
299
+ * Fully reload the application
300
+ */
301
+ reload(): void;
302
+
303
+ /**
304
+ * Holds a reference to the Koa application and the http server used by Strapi
305
+ */
306
+ server: any;
307
+
308
+ /**
309
+ * Strapi util used to manage application files
310
+ */
311
+ fs: any;
312
+
313
+ /**
314
+ * Event hub used to send and receive events from anywhere in the application
315
+ */
316
+ eventHub: any;
317
+
318
+ /**
319
+ * Internal util used to log stats and messages on application Startup
320
+ */
321
+ startupLogger: any;
322
+
323
+ /**
324
+ * Strapi logger used to send errors, warning or information messages
325
+ */
326
+ log: any;
327
+
328
+
329
+ /**
330
+ * Used to manage cron within Strapi
331
+ */
332
+ cron: any;
333
+
334
+ /**
335
+ * Telemetry util used to collect anonymous data on the application usage
336
+ */
337
+ telemetry: any;
285
338
  }
286
339
 
287
340
  export interface Lifecycles {
@@ -289,3 +342,29 @@ export interface Lifecycles {
289
342
  BOOTSTRAP: 'bootstrap';
290
343
  DESTROY: 'destroy';
291
344
  }
345
+
346
+ export interface StrapiDirectories {
347
+ static: {
348
+ public: string;
349
+ };
350
+ app: {
351
+ root: string;
352
+ src: string;
353
+ api: string;
354
+ components: string;
355
+ extensions: string;
356
+ policies: string;
357
+ middlewares: string;
358
+ config: string;
359
+ };
360
+ dist: {
361
+ root: string;
362
+ src: string;
363
+ api: string;
364
+ components: string;
365
+ extensions: string;
366
+ policies: string;
367
+ middlewares: string;
368
+ config: string;
369
+ };
370
+ }
@@ -1,9 +1,10 @@
1
1
  'use strict';
2
2
 
3
- const __importDefault =
4
- (this && this.__importDefault) ||
5
- function(mod) {
6
- return mod && mod.__esModule ? mod : { default: mod };
3
+ const importDefault =
4
+ (this && this.importDefault) ||
5
+ function(modName) {
6
+ const mod = require(modName);
7
+ return mod && mod.__esModule ? mod.default : mod;
7
8
  };
8
9
 
9
- module.exports = __importDefault;
10
+ module.exports = importDefault;
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/strapi",
3
- "version": "4.2.0-beta.3",
3
+ "version": "4.3.0-beta.1",
4
4
  "description": "An open source headless CMS solution to create and manage your own API. It provides a powerful dashboard and features to make your life easier. Databases supported: MySQL, MariaDB, PostgreSQL, SQLite",
5
5
  "keywords": [
6
6
  "strapi",
@@ -80,17 +80,17 @@
80
80
  "dependencies": {
81
81
  "@koa/cors": "3.1.0",
82
82
  "@koa/router": "10.1.1",
83
- "@strapi/admin": "4.2.0-beta.3",
84
- "@strapi/database": "4.2.0-beta.3",
85
- "@strapi/generate-new": "4.2.0-beta.3",
86
- "@strapi/generators": "4.2.0-beta.3",
87
- "@strapi/logger": "4.2.0-beta.3",
88
- "@strapi/plugin-content-manager": "4.2.0-beta.3",
89
- "@strapi/plugin-content-type-builder": "4.2.0-beta.3",
90
- "@strapi/plugin-email": "4.2.0-beta.3",
91
- "@strapi/plugin-upload": "4.2.0-beta.3",
92
- "@strapi/typescript-utils": "4.2.0-beta.3",
93
- "@strapi/utils": "4.2.0-beta.3",
83
+ "@strapi/admin": "4.3.0-beta.1",
84
+ "@strapi/database": "4.3.0-beta.1",
85
+ "@strapi/generate-new": "4.3.0-beta.1",
86
+ "@strapi/generators": "4.3.0-beta.1",
87
+ "@strapi/logger": "4.3.0-beta.1",
88
+ "@strapi/plugin-content-manager": "4.3.0-beta.1",
89
+ "@strapi/plugin-content-type-builder": "4.3.0-beta.1",
90
+ "@strapi/plugin-email": "4.3.0-beta.1",
91
+ "@strapi/plugin-upload": "4.3.0-beta.1",
92
+ "@strapi/typescript-utils": "4.3.0-beta.1",
93
+ "@strapi/utils": "4.3.0-beta.1",
94
94
  "bcryptjs": "2.4.3",
95
95
  "boxen": "5.1.2",
96
96
  "chalk": "4.1.2",
@@ -136,8 +136,8 @@
136
136
  "typescript": "4.6.2"
137
137
  },
138
138
  "engines": {
139
- "node": ">=12.22.0 <=16.x.x",
139
+ "node": ">=14.19.1 <=16.x.x",
140
140
  "npm": ">=6.0.0"
141
141
  },
142
- "gitHead": "c4addbad6ecbc8ef7633bbba3806f3b0a2ae5f49"
142
+ "gitHead": "9d6555398960c39159d66bb4eea3bcb0362e37e3"
143
143
  }