@strapi/strapi 4.2.0-beta.4 → 4.2.2

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 (47) hide show
  1. package/bin/strapi.js +8 -3
  2. package/lib/Strapi.js +4 -42
  3. package/lib/commands/admin-create.js +1 -15
  4. package/lib/commands/admin-reset.js +1 -15
  5. package/lib/commands/build.js +44 -18
  6. package/lib/commands/configurationDump.js +1 -14
  7. package/lib/commands/configurationRestore.js +1 -16
  8. package/lib/commands/console.js +2 -16
  9. package/lib/commands/develop.js +74 -114
  10. package/lib/commands/opt-in-telemetry.js +100 -0
  11. package/lib/commands/routes/list.js +1 -15
  12. package/lib/commands/start.js +2 -12
  13. package/lib/commands/watchAdmin.js +10 -10
  14. package/lib/core/app-configuration/config-loader.js +3 -1
  15. package/lib/core/app-configuration/index.js +3 -4
  16. package/lib/core/app-configuration/load-config-file.js +1 -3
  17. package/lib/core/bootstrap.js +2 -2
  18. package/lib/core/loaders/apis.js +5 -6
  19. package/lib/core/loaders/components.js +4 -5
  20. package/lib/core/loaders/middlewares.js +3 -5
  21. package/lib/core/loaders/plugins/get-enabled-plugins.js +1 -2
  22. package/lib/core/loaders/plugins/get-user-plugins-config.js +2 -2
  23. package/lib/core/loaders/plugins/index.js +1 -1
  24. package/lib/core/loaders/policies.js +2 -4
  25. package/lib/core/loaders/src-index.js +4 -6
  26. package/lib/core/registries/policies.d.ts +1 -1
  27. package/lib/core-api/controller/index.d.ts +9 -14
  28. package/lib/core-api/service/index.d.ts +9 -10
  29. package/lib/factories.d.ts +18 -22
  30. package/lib/index.d.ts +6 -7
  31. package/lib/load/load-files.js +1 -3
  32. package/lib/middlewares/favicon.js +1 -1
  33. package/lib/middlewares/public/index.js +1 -2
  34. package/lib/services/fs.js +1 -1
  35. package/lib/services/metrics/index.js +1 -5
  36. package/lib/services/metrics/sender.js +0 -7
  37. package/lib/services/server/middleware.js +1 -1
  38. package/lib/utils/get-dirs.js +10 -24
  39. package/lib/utils/index.js +0 -2
  40. package/lib/utils/update-notifier/index.js +1 -1
  41. package/package.json +13 -15
  42. package/lib/commands/builders/admin.js +0 -59
  43. package/lib/commands/builders/index.js +0 -9
  44. package/lib/commands/builders/typescript.js +0 -32
  45. package/lib/types/strapi.d.ts +0 -291
  46. package/lib/types/utils.d.ts +0 -1
  47. package/lib/utils/import-default.js +0 -9
@@ -0,0 +1,100 @@
1
+ 'use strict';
2
+
3
+ const { resolve } = require('path');
4
+ const fse = require('fs-extra');
5
+ const chalk = require('chalk');
6
+ const fetch = require('node-fetch');
7
+ const { v4: uuidv4 } = require('uuid');
8
+ const machineID = require('../utils/machine-id');
9
+
10
+ const readPackageJSON = async path => {
11
+ try {
12
+ const packageObj = await fse.readJson(path);
13
+ return packageObj;
14
+ } catch (err) {
15
+ console.error(`${chalk.red('Error')}: ${err.message}`);
16
+ }
17
+ };
18
+
19
+ const writePackageJSON = async (path, file, spacing) => {
20
+ try {
21
+ await fse.writeJson(path, file, { spaces: spacing });
22
+ return true;
23
+ } catch (err) {
24
+ console.error(`${chalk.red('Error')}: ${err.message}`);
25
+ console.log(
26
+ `${chalk.yellow(
27
+ 'Warning'
28
+ )}: There has been an error, please set "telemetryDisabled": false in the "strapi" object of your package.json manually.`
29
+ );
30
+ return false;
31
+ }
32
+ };
33
+
34
+ const generateNewPackageJSON = packageObj => {
35
+ if (!packageObj.strapi) {
36
+ return {
37
+ ...packageObj,
38
+ strapi: {
39
+ uuid: uuidv4(),
40
+ telemetryDisabled: false,
41
+ },
42
+ };
43
+ } else {
44
+ return {
45
+ ...packageObj,
46
+ strapi: {
47
+ ...packageObj.strapi,
48
+ uuid: packageObj.strapi.uuid ? packageObj.strapi.uuid : uuidv4(),
49
+ telemetryDisabled: false,
50
+ },
51
+ };
52
+ }
53
+ };
54
+
55
+ const sendEvent = async uuid => {
56
+ try {
57
+ await fetch('https://analytics.strapi.io/track', {
58
+ method: 'POST',
59
+ body: JSON.stringify({
60
+ event: 'didOptInTelemetry',
61
+ uuid,
62
+ deviceId: machineID(),
63
+ }),
64
+ headers: { 'Content-Type': 'application/json' },
65
+ });
66
+ } catch (e) {
67
+ //...
68
+ }
69
+ };
70
+
71
+ module.exports = async function optInTelemetry() {
72
+ const packageJSONPath = resolve(process.cwd(), 'package.json');
73
+ const exists = await fse.pathExists(packageJSONPath);
74
+
75
+ if (!exists) {
76
+ console.log(`${chalk.yellow('Warning')}: could not find package.json`);
77
+ process.exit(0);
78
+ }
79
+
80
+ const packageObj = await readPackageJSON(packageJSONPath);
81
+
82
+ if (packageObj.strapi && packageObj.strapi.uuid) {
83
+ if (packageObj.strapi.telemetryDisabled === false) {
84
+ console.log(`${chalk.yellow('Warning:')} telemetry is already enabled`);
85
+ process.exit(0);
86
+ }
87
+ }
88
+
89
+ const updatedPackageJSON = generateNewPackageJSON(packageObj);
90
+
91
+ const write = await writePackageJSON(packageJSONPath, updatedPackageJSON, 2);
92
+
93
+ if (!write) {
94
+ process.exit(0);
95
+ }
96
+
97
+ await sendEvent(updatedPackageJSON.strapi.uuid);
98
+ console.log(`${chalk.green('Successfully opted into and enabled Strapi telemetry')}`);
99
+ process.exit(0);
100
+ };
@@ -3,25 +3,11 @@
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 app = await strapi().load();
25
11
 
26
12
  const list = app.server.listRoutes();
27
13
 
@@ -1,18 +1,8 @@
1
1
  'use strict';
2
- const fs = require('fs');
3
- const tsUtils = require('@strapi/typescript-utils');
2
+
4
3
  const strapi = require('../index');
5
4
 
6
5
  /**
7
6
  * `$ strapi start`
8
7
  */
9
- module.exports = async specifiedDir => {
10
- const appDir = process.cwd();
11
- const isTSProject = await tsUtils.isUsingTypeScript(appDir);
12
- const outDir = await tsUtils.resolveOutDir(appDir);
13
- 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;
16
-
17
- strapi({ distDir }).start();
18
- };
8
+ module.exports = () => strapi().start();
@@ -1,22 +1,18 @@
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
- const getEnabledPlugins = require('../core/loaders/plugins/get-enabled-plugins');
6
+ const ee = require('../utils/ee');
8
7
  const addSlash = require('../utils/addSlash');
9
8
  const strapi = require('../index');
9
+ const getEnabledPlugins = require('../core/loaders/plugins/get-enabled-plugins');
10
10
 
11
11
  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;
12
+ const dir = process.cwd();
17
13
 
18
14
  const strapiInstance = strapi({
19
- distDir: buildDestDir,
15
+ dir,
20
16
  autoReload: true,
21
17
  serveAdminPanel: false,
22
18
  });
@@ -27,12 +23,14 @@ module.exports = async function({ browser }) {
27
23
 
28
24
  const adminPort = strapiInstance.config.get('admin.port', 8000);
29
25
  const adminHost = strapiInstance.config.get('admin.host', 'localhost');
26
+ const adminWatchIgnoreFiles = strapiInstance.config.get('admin.watchIgnoreFiles', []);
30
27
 
31
28
  const backendURL = getAbsoluteServerUrl(strapiInstance.config, true);
32
29
 
30
+ ee({ dir });
31
+
33
32
  strapiAdmin.watchAdmin({
34
- appDir: currentDirectory,
35
- buildDestDir,
33
+ dir,
36
34
  plugins,
37
35
  port: adminPort,
38
36
  host: adminHost,
@@ -40,6 +38,8 @@ module.exports = async function({ browser }) {
40
38
  options: {
41
39
  backend: backendURL,
42
40
  adminPath: addSlash(adminPath),
41
+ watchIgnoreFiles: adminWatchIgnoreFiles,
42
+ features: ee.isEE ? ee.features.getEnabled() : [],
43
43
  },
44
44
  });
45
45
  };
@@ -4,12 +4,14 @@ const path = require('path');
4
4
  const fs = require('fs');
5
5
  const loadFile = require('./load-config-file');
6
6
 
7
+ const VALID_EXTENSIONS = ['.js', '.json'];
8
+
7
9
  module.exports = dir => {
8
10
  if (!fs.existsSync(dir)) return {};
9
11
 
10
12
  return fs
11
13
  .readdirSync(dir, { withFileTypes: true })
12
- .filter(file => file.isFile())
14
+ .filter(file => file.isFile() && VALID_EXTENSIONS.includes(path.extname(file.name)))
13
15
  .reduce((acc, file) => {
14
16
  const key = path.basename(file.name, path.extname(file.name));
15
17
 
@@ -31,13 +31,12 @@ const defaultConfig = {
31
31
  },
32
32
  };
33
33
 
34
- module.exports = (dirs, initialConfig = {}) => {
35
- const { appDir, distDir } = dirs;
34
+ module.exports = (dir, initialConfig = {}) => {
36
35
  const { autoReload = false, serveAdminPanel = true } = initialConfig;
37
36
 
38
- const pkgJSON = require(path.resolve(appDir, 'package.json'));
37
+ const pkgJSON = require(path.resolve(dir, 'package.json'));
39
38
 
40
- const configDir = path.resolve(distDir || process.cwd(), 'config');
39
+ const configDir = path.resolve(dir || process.cwd(), 'config');
41
40
 
42
41
  const rootConfig = {
43
42
  launchedAt: Date.now(),
@@ -4,11 +4,9 @@ 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');
8
-
9
7
  const loadJsFile = file => {
10
8
  try {
11
- const jsModule = __importDefault(require(file)).default;
9
+ const jsModule = require(file);
12
10
 
13
11
  // call if function
14
12
  if (typeof jsModule === 'function') {
@@ -25,9 +25,9 @@ module.exports = async function({ strapi }) {
25
25
  }
26
26
 
27
27
  // ensure public repository exists
28
- if (!(await fse.pathExists(strapi.dirs.static.public))) {
28
+ if (!(await fse.pathExists(strapi.dirs.public))) {
29
29
  throw new Error(
30
- `The public folder (${strapi.dirs.static.public}) doesn't exist or is not accessible. Please make sure it exists.`
30
+ `The public folder (${strapi.dirs.public}) doesn't exist or is not accessible. Please make sure it exists.`
31
31
  );
32
32
  }
33
33
  };
@@ -5,7 +5,6 @@ const { existsSync } = require('fs-extra');
5
5
  const _ = require('lodash');
6
6
  const fse = require('fs-extra');
7
7
  const { isKebabCase } = require('@strapi/utils');
8
- const { importDefault } = require('../../utils');
9
8
 
10
9
  const DEFAULT_CONTENT_TYPE = {
11
10
  schema: {},
@@ -20,11 +19,11 @@ const isDirectory = fd => fd.isDirectory();
20
19
  const isDotFile = fd => fd.name.startsWith('.');
21
20
 
22
21
  module.exports = async strapi => {
23
- if (!existsSync(strapi.dirs.dist.api)) {
24
- return;
22
+ if (!existsSync(strapi.dirs.api)) {
23
+ throw new Error('Missing api folder. Please create one at `./src/api`');
25
24
  }
26
25
 
27
- const apisFDs = await (await fse.readdir(strapi.dirs.dist.api, { withFileTypes: true }))
26
+ const apisFDs = await (await fse.readdir(strapi.dirs.api, { withFileTypes: true }))
28
27
  .filter(isDirectory)
29
28
  .filter(_.negate(isDotFile));
30
29
 
@@ -33,7 +32,7 @@ module.exports = async strapi => {
33
32
  // only load folders
34
33
  for (const apiFD of apisFDs) {
35
34
  const apiName = normalizeName(apiFD.name);
36
- const api = await loadAPI(join(strapi.dirs.dist.api, apiFD.name));
35
+ const api = await loadAPI(join(strapi.dirs.api, apiFD.name));
37
36
 
38
37
  apis[apiName] = api;
39
38
  }
@@ -155,7 +154,7 @@ const loadFile = file => {
155
154
 
156
155
  switch (ext) {
157
156
  case '.js':
158
- return importDefault(require(file)).default;
157
+ return require(file);
159
158
  case '.json':
160
159
  return fse.readJSON(file);
161
160
  default:
@@ -6,20 +6,19 @@ const { pathExists } = require('fs-extra');
6
6
  const loadFiles = require('../../load/load-files');
7
7
 
8
8
  module.exports = async strapi => {
9
- if (!(await pathExists(strapi.dirs.dist.components))) {
9
+ if (!(await pathExists(strapi.dirs.components))) {
10
10
  return {};
11
11
  }
12
12
 
13
- const map = await loadFiles(strapi.dirs.dist.components, '*/*.*(js|json)');
13
+ const map = await loadFiles(strapi.dirs.components, '*/*.*(js|json)');
14
14
 
15
15
  return Object.keys(map).reduce((acc, category) => {
16
16
  Object.keys(map[category]).forEach(key => {
17
17
  const schema = map[category][key];
18
18
 
19
- if (!schema.collectionName) {
20
- // NOTE: We're using the filepath from the app directory instead of the dist for information purpose
21
- const filePath = join(strapi.dirs.app.components, category, schema.__filename__);
19
+ const filePath = join(strapi.dirs.components, category, schema.__filename__);
22
20
 
21
+ if (!schema.collectionName) {
23
22
  return strapi.stopWithError(
24
23
  `Component ${key} is missing a "collectionName" property.\nVerify file ${filePath}.`
25
24
  );
@@ -3,19 +3,17 @@
3
3
  const { join, extname, basename } = require('path');
4
4
  const fse = require('fs-extra');
5
5
 
6
- const { importDefault } = require('../../utils');
7
-
8
6
  // TODO:: allow folders with index.js inside for bigger policies
9
7
  module.exports = async function loadMiddlewares(strapi) {
10
8
  const localMiddlewares = await loadLocalMiddlewares(strapi);
11
- const internalMiddlewares = importDefault(require('../../middlewares')).default;
9
+ const internalMiddlewares = require('../../middlewares');
12
10
 
13
11
  strapi.container.get('middlewares').add(`global::`, localMiddlewares);
14
12
  strapi.container.get('middlewares').add(`strapi::`, internalMiddlewares);
15
13
  };
16
14
 
17
15
  const loadLocalMiddlewares = async strapi => {
18
- const dir = strapi.dirs.dist.middlewares;
16
+ const dir = strapi.dirs.middlewares;
19
17
 
20
18
  if (!(await fse.pathExists(dir))) {
21
19
  return {};
@@ -30,7 +28,7 @@ const loadLocalMiddlewares = async strapi => {
30
28
 
31
29
  if (fd.isFile() && extname(name) === '.js') {
32
30
  const key = basename(name, '.js');
33
- middlewares[key] = importDefault(require(fullPath)).default;
31
+ middlewares[key] = require(fullPath);
34
32
  }
35
33
  }
36
34
 
@@ -29,11 +29,10 @@ const toDetailedDeclaration = declaration => {
29
29
  let detailedDeclaration = pick(['enabled'], declaration);
30
30
  if (has('resolve', declaration)) {
31
31
  let pathToPlugin = '';
32
-
33
32
  try {
34
33
  pathToPlugin = dirname(require.resolve(declaration.resolve));
35
34
  } catch (e) {
36
- pathToPlugin = resolve(strapi.dirs.app.root, declaration.resolve);
35
+ pathToPlugin = resolve(strapi.dirs.root, declaration.resolve);
37
36
 
38
37
  if (!existsSync(pathToPlugin) || !statSync(pathToPlugin).isDirectory()) {
39
38
  throw new Error(`${declaration.resolve} couldn't be resolved`);
@@ -12,9 +12,9 @@ const loadConfigFile = require('../../app-configuration/load-config-file');
12
12
  * @return {Promise<{}>}
13
13
  */
14
14
  const getUserPluginsConfig = async () => {
15
- const globalUserConfigPath = join(strapi.dirs.dist.config, 'plugins.js');
15
+ const globalUserConfigPath = join(strapi.dirs.config, 'plugins.js');
16
16
  const currentEnvUserConfigPath = join(
17
- strapi.dirs.dist.config,
17
+ strapi.dirs.config,
18
18
  'env',
19
19
  process.env.NODE_ENV,
20
20
  'plugins.js'
@@ -26,7 +26,7 @@ const defaultPlugin = {
26
26
  };
27
27
 
28
28
  const applyUserExtension = async plugins => {
29
- const extensionsDir = strapi.dirs.dist.extensions;
29
+ const extensionsDir = strapi.dirs.extensions;
30
30
  if (!(await fse.pathExists(extensionsDir))) {
31
31
  return;
32
32
  }
@@ -3,11 +3,9 @@
3
3
  const { join, extname, basename } = require('path');
4
4
  const fse = require('fs-extra');
5
5
 
6
- const { importDefault } = require('../../utils');
7
-
8
6
  // TODO:: allow folders with index.js inside for bigger policies
9
7
  module.exports = async function loadPolicies(strapi) {
10
- const dir = strapi.dirs.dist.policies;
8
+ const dir = strapi.dirs.policies;
11
9
 
12
10
  if (!(await fse.pathExists(dir))) {
13
11
  return;
@@ -22,7 +20,7 @@ module.exports = async function loadPolicies(strapi) {
22
20
 
23
21
  if (fd.isFile() && extname(name) === '.js') {
24
22
  const key = basename(name, '.js');
25
- policies[key] = importDefault(require(fullPath)).default;
23
+ policies[key] = require(fullPath);
26
24
  }
27
25
  }
28
26
 
@@ -4,8 +4,6 @@ const { resolve } = require('path');
4
4
  const { statSync, existsSync } = require('fs');
5
5
  const { yup } = require('@strapi/utils');
6
6
 
7
- const { importDefault } = require('../../utils');
8
-
9
7
  const srcSchema = yup
10
8
  .object()
11
9
  .shape({
@@ -20,16 +18,16 @@ const validateSrcIndex = srcIndex => {
20
18
  };
21
19
 
22
20
  module.exports = strapi => {
23
- if (!existsSync(strapi.dirs.dist.src)) {
24
- return;
21
+ if (!existsSync(strapi.dirs.src)) {
22
+ throw new Error('Missing src folder. Please create one at `./src`');
25
23
  }
26
24
 
27
- const pathToSrcIndex = resolve(strapi.dirs.dist.src, 'index.js');
25
+ const pathToSrcIndex = resolve(strapi.dirs.src, 'index.js');
28
26
  if (!existsSync(pathToSrcIndex) || statSync(pathToSrcIndex).isDirectory()) {
29
27
  return {};
30
28
  }
31
29
 
32
- const srcIndex = importDefault(require(pathToSrcIndex)).default;
30
+ const srcIndex = require(pathToSrcIndex);
33
31
 
34
32
  try {
35
33
  validateSrcIndex(srcIndex);
@@ -6,4 +6,4 @@ interface PolicyContext extends BaseContext {
6
6
  is(name): boolean;
7
7
  }
8
8
 
9
- export type Policy<T=unknown> = (ctx: PolicyContext,cfg:T, { strapi: Strapi }) => boolean | undefined;
9
+ export type Policy = (ctx: PolicyContext, { strapi: Strapi }) => boolean | undefined;
@@ -1,6 +1,6 @@
1
1
  import { Context } from 'koa';
2
2
 
3
- type ControllerResponse <T=unknown> = T | Promise<T>;
3
+ type Response = object;
4
4
 
5
5
  interface BaseController {
6
6
  transformResponse(data: object, meta: object): object;
@@ -9,22 +9,17 @@ interface BaseController {
9
9
  }
10
10
 
11
11
  export interface SingleTypeController extends BaseController {
12
- find(ctx: Context): ControllerResponse;
13
- update(ctx: Context): ControllerResponse;
14
- delete(ctx: Context): ControllerResponse;
12
+ find(ctx: Context): Promise<Response>;
13
+ update(ctx: Context): Promise<Response>;
14
+ delete(ctx: Context): Promise<Response>;
15
15
  }
16
16
 
17
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;
18
+ find(ctx: Context): Promise<Response>;
19
+ findOne(ctx: Context): Promise<Response>;
20
+ create(ctx: Context): Promise<Response>;
21
+ update(ctx: Context): Promise<Response>;
22
+ delete(ctx: Context): Promise<Response>;
23
23
  }
24
24
 
25
25
  export type Controller = SingleTypeController | CollectionTypeController;
26
-
27
- export type GenericController = Partial<Controller> & {
28
- [method: string | number | symbol]: (ctx: Context) => unknown
29
- }
30
-
@@ -1,22 +1,21 @@
1
1
  type Entity = object;
2
2
 
3
3
  interface BaseService {
4
- getFetchParams?(params: object): object;
4
+ getFetchParams(params: object): object;
5
5
  }
6
6
 
7
7
  export interface SingleTypeService extends BaseService {
8
- find?(params: object): Promise<Entity> | Entity;
9
- createOrUpdate?(params: object): Promise<Entity> | Entity;
10
- delete?(params: object): Promise<Entity> | Entity;
8
+ find(params: object): Promise<Entity>;
9
+ createOrUpdate(params: object): Promise<Entity>;
10
+ delete(params: object): Promise<Entity>;
11
11
  }
12
12
 
13
13
  export interface CollectionTypeService extends BaseService {
14
- find?(params: object): Promise<Entity[]> | Entity;
15
- findOne?(entityId: string,params: object): Promise<Entity> | Entity;
16
- create?(params: object): Promise<Entity> | Entity;
17
- update?(entityId: string,params: object): Promise<Entity> | Entity;
18
- delete?(entityId: string,params: object): Promise<Entity> | Entity;
14
+ find(params: object): Promise<Entity[]>;
15
+ findOne(params: object): Promise<Entity>;
16
+ create(params: object): Promise<Entity>;
17
+ update(params: object): Promise<Entity>;
18
+ delete(params: object): Promise<Entity>;
19
19
  }
20
20
 
21
21
  export type Service = SingleTypeService | CollectionTypeService;
22
-
@@ -1,37 +1,36 @@
1
1
  import { Service } from './core-api/service';
2
- import { Controller, GenericController } from './core-api/controller';
2
+ import { Controller } from './core-api/controller';
3
3
  import { Middleware } from './middlewares';
4
4
  import { Policy } from './core/registries/policies';
5
- import { Strapi } from '@strapi/strapi'
6
5
 
7
- type ControllerConfig<T extends Controller = Controller> = T;
6
+ type ControllerConfig = Controller;
8
7
 
9
8
  type ServiceConfig = Service;
10
9
 
11
10
  type HandlerConfig = {
12
- auth?: false | { scope: string[] };
13
- policies?: Array<string | Policy>;
14
- middlewares?: Array<string | Middleware>;
11
+ auth: false | { scope: string[] };
12
+ policies: Array<string | Policy>;
13
+ middlewares: Array<string | Middleware>;
15
14
  };
16
15
 
17
16
  type SingleTypeRouterConfig = {
18
- find?: HandlerConfig;
19
- update?: HandlerConfig;
20
- delete?: HandlerConfig;
17
+ find: HandlerConfig;
18
+ update: HandlerConfig;
19
+ delete: HandlerConfig;
21
20
  };
22
21
 
23
22
  type CollectionTypeRouterConfig = {
24
- find?: HandlerConfig;
25
- findOne?: HandlerConfig;
26
- create?: HandlerConfig;
27
- update?: HandlerConfig;
28
- delete?: HandlerConfig;
23
+ find: HandlerConfig;
24
+ findOne: HandlerConfig;
25
+ create: HandlerConfig;
26
+ update: HandlerConfig;
27
+ delete: HandlerConfig;
29
28
  };
30
29
 
31
30
  type RouterConfig = {
32
- prefix?: string;
31
+ prefix: string;
33
32
  only: string[];
34
- except?: string[];
33
+ except: string[];
35
34
  config: SingleTypeRouterConfig | CollectionTypeRouterConfig;
36
35
  };
37
36
 
@@ -44,9 +43,6 @@ interface Router {
44
43
  routes: Route[];
45
44
  }
46
45
 
47
- type ControllerCallback <T extends GenericController = GenericController> = (params:{strapi:Strapi}) => T;
48
- type ServiceCallback <T extends Service = Sevice> = (params:{strapi:Strapi}) => T
49
-
50
- export function createCoreRouter(uid: string, cfg?: RouterConfig = {}): () => Router;
51
- export function createCoreController<T extends GenericController = GenericController>(uid: string, cfg?: ControllerCallback<T> | T = {}): () => T & Controller;
52
- export function createCoreService<T extends Service = Service>(uid: string, cfg?: ServiceCallback<T> | T = {}): () => T ;
46
+ export function createCoreRouter(uid: string, cfg: RouterConfig): () => Router;
47
+ export function createCoreController(uid: string, cfg: ControllerConfig): () => Controller;
48
+ export function createCoreService(uid: string, cfg: ServiceConfig): () => Service;
package/lib/index.d.ts CHANGED
@@ -1,15 +1,14 @@
1
1
  import { Database } from '@strapi/database';
2
2
  import { EntityService } from './services/entity-service';
3
+ import { Strapi as StrapiClass } from './Strapi';
3
4
 
4
- import * as Core from './types/strapi';
5
5
  export * as factories from './factories';
6
+ interface StrapiInterface extends StrapiClass {
7
+ query: Database['query'];
8
+ entityService: EntityService;
9
+ }
6
10
 
7
- export type { Core };
8
-
9
- // Alias to resolve the Strapi global type easily
10
- export type Strapi = Core.Strapi;
11
-
12
- export interface StrapiInterface extends Core.Strapi {};
11
+ export type Strapi = StrapiInterface;
13
12
 
14
13
  declare global {
15
14
  interface AllTypes {}
@@ -3,8 +3,6 @@
3
3
  const path = require('path');
4
4
  const _ = require('lodash');
5
5
  const fse = require('fs-extra');
6
-
7
- const { importDefault } = require('../utils');
8
6
  const glob = require('./glob');
9
7
  const filePathToPath = require('./filepath-to-prop-path');
10
8
 
@@ -36,7 +34,7 @@ const loadFiles = async (
36
34
  if (path.extname(absolutePath) === '.json') {
37
35
  mod = await fse.readJson(absolutePath);
38
36
  } else {
39
- mod = importDefault(requireFn(absolutePath)).default;
37
+ mod = requireFn(absolutePath);
40
38
  }
41
39
 
42
40
  Object.defineProperty(mod, '__filename__', {
@@ -15,5 +15,5 @@ const defaults = {
15
15
  module.exports = (config, { strapi }) => {
16
16
  const { maxAge, path: faviconPath } = defaultsDeep(defaults, config);
17
17
 
18
- return favicon(resolve(strapi.dirs.app.root, faviconPath), { maxAge });
18
+ return favicon(resolve(strapi.dirs.root, faviconPath), { maxAge });
19
19
  };
@@ -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,
@@ -81,7 +80,7 @@ module.exports = (config, { strapi }) => {
81
80
  {
82
81
  method: 'GET',
83
82
  path: '/(.*)',
84
- handler: koaStatic(strapi.dirs.static.public, {
83
+ handler: koaStatic(strapi.dirs.public, {
85
84
  maxage: maxAge,
86
85
  defer: true,
87
86
  }),