Merge pull request #19860 from strapi/v5/types/fix-incorrect-imports

This commit is contained in:
Jean-Sébastien Herbaux 2024-03-21 16:01:26 +01:00 committed by GitHub
commit 4d5f8c255d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
19 changed files with 63 additions and 54 deletions

View File

@ -220,7 +220,7 @@ Before submitting an issue you need to make sure:
- You are experiencing a technical issue with Strapi. - You are experiencing a technical issue with Strapi.
- You have already searched for related [issues](https://github.com/strapi/strapi/issues) and found none open (if you found a related _closed_ issue, please link to it from your post). - You have already searched for related [issues](https://github.com/strapi/strapi/issues) and found none open (if you found a related _closed_ issue, please link to it from your post).
- You are not asking a question about how to use Strapi or about whether or not Strapi has a certain feature. For general help using Strapi, you may: - You are not asking a question about how to use Strapi or about whether Strapi has a certain feature. For general help using Strapi, you may:
- Refer to the [official Strapi documentation](https://docs.strapi.io). - Refer to the [official Strapi documentation](https://docs.strapi.io).
- Ask a member of the community in the [Strapi Discord Community](https://discord.strapi.io/). - Ask a member of the community in the [Strapi Discord Community](https://discord.strapi.io/).
- Ask a question on the [Strapi community forum](https://forum.strapi.io). - Ask a question on the [Strapi community forum](https://forum.strapi.io).

View File

@ -1,4 +1,4 @@
import { LoadedStrapi, Common } from '@strapi/types'; import type { Core, UID } from '@strapi/types';
import { testInTransaction as wrapInTransaction } from '../../../../utils'; import { testInTransaction as wrapInTransaction } from '../../../../utils';
// Wrap "it" with a transaction // Wrap "it" with a transaction
@ -22,13 +22,13 @@ const { createTestBuilder } = require('api-tests/builder');
const { createStrapiInstance } = require('api-tests/strapi'); const { createStrapiInstance } = require('api-tests/strapi');
const { createAuthRequest } = require('api-tests/request'); const { createAuthRequest } = require('api-tests/request');
let strapi: LoadedStrapi; let strapi: Core.LoadedStrapi;
let shopDocuments; let shopDocuments;
let shopsDB; let shopsDB;
let rq; let rq;
const builder = createTestBuilder(); const builder = createTestBuilder();
const SHOP_UID = 'api::shop.shop' as Common.UID.ContentType; const SHOP_UID = 'api::shop.shop' as UID.ContentType;
const shopModel = { const shopModel = {
attributes: { attributes: {

View File

@ -1,23 +1,24 @@
/** /**
* Relations interactions with non DP content types. * Relations interactions with non DP content types.
*/ */
import { LoadedStrapi, Common } from '@strapi/types'; import type { Core, UID } from '@strapi/types';
import { testInTransaction } from '../../../../utils'; import { testInTransaction } from '../../../../utils';
const { createTestBuilder } = require('api-tests/builder'); const { createTestBuilder } = require('api-tests/builder');
const { createStrapiInstance } = require('api-tests/strapi'); const { createStrapiInstance } = require('api-tests/strapi');
const { createAuthRequest } = require('api-tests/request'); const { createAuthRequest } = require('api-tests/request');
let strapi: LoadedStrapi; let strapi: Core.LoadedStrapi;
const builder = createTestBuilder(); const builder = createTestBuilder();
let productDocuments; let productDocuments;
let tagDocuments; let tagDocuments;
let shopDocuments; let shopDocuments;
let rq; let rq;
const PRODUCT_UID = 'api::product.product' as Common.UID.ContentType; const PRODUCT_UID = 'api::product.product' as UID.ContentType;
const TAG_UID = 'api::tag.tag' as Common.UID.ContentType; const TAG_UID = 'api::tag.tag' as UID.ContentType;
const SHOP_UID = 'api::shop.shop' as Common.UID.ContentType; const SHOP_UID = 'api::shop.shop' as UID.ContentType;
const productModel = { const productModel = {
attributes: { attributes: {

View File

@ -1,3 +1,5 @@
import type { StrapiApp } from '@strapi/strapi/admin';
export default { export default {
config: { config: {
locales: [ locales: [
@ -29,7 +31,7 @@ export default {
// 'zh', // 'zh',
], ],
}, },
bootstrap(app) { bootstrap(app: StrapiApp) {
console.log(app); console.log(app);
}, },
}; };

View File

@ -46,6 +46,7 @@ export { useRBAC } from './hooks/useRBAC';
/** /**
* Types * Types
*/ */
export type { StrapiApp } from './StrapiApp';
export type { Store } from './core/store/configure'; export type { Store } from './core/store/configure';
export type { SanitizedAdminUser } from '../../shared/contracts/shared'; export type { SanitizedAdminUser } from '../../shared/contracts/shared';
export type { export type {

View File

@ -1,5 +1,5 @@
import { assign } from 'lodash/fp'; import { assign } from 'lodash/fp';
import type { Strapi } from '@strapi/types'; import type { Core } from '@strapi/types';
import { getService } from '../utils'; import { getService } from '../utils';
const getSSOProvidersList = async () => { const getSSOProvidersList = async () => {
@ -8,7 +8,7 @@ const getSSOProvidersList = async () => {
return providerRegistry.getAll().map(({ uid }: { uid: string }) => uid); return providerRegistry.getAll().map(({ uid }: { uid: string }) => uid);
}; };
const sendUpdateProjectInformation = async (strapi: Strapi) => { const sendUpdateProjectInformation = async (strapi: Core.Strapi) => {
let groupProperties = {}; let groupProperties = {};
const numberOfActiveAdminUsers = await getService('user').count({ isActive: true }); const numberOfActiveAdminUsers = await getService('user').count({ isActive: true });
@ -47,7 +47,7 @@ const sendUpdateProjectInformation = async (strapi: Strapi) => {
}); });
}; };
const startCron = (strapi: Strapi) => { const startCron = (strapi: Core.Strapi) => {
strapi.cron.add({ strapi.cron.add({
'0 0 0 * * *': () => sendUpdateProjectInformation(strapi), '0 0 0 * * *': () => sendUpdateProjectInformation(strapi),
}); });

View File

@ -1,5 +1,4 @@
import { LoadedStrapi as Strapi } from '@strapi/types'; import { filter, forEach, pipe, map, stubTrue, cond, defaultsDeep } from 'lodash/fp';
import { filter, set, forEach, pipe, map, stubTrue, cond, defaultsDeep } from 'lodash/fp';
import { getService } from '../../utils'; import { getService } from '../../utils';
import { getVisibleContentTypesUID, hasStageAttribute } from '../../utils/review-workflows'; import { getVisibleContentTypesUID, hasStageAttribute } from '../../utils/review-workflows';
import defaultStages from '../../constants/default-stages.json'; import defaultStages from '../../constants/default-stages.json';
@ -15,6 +14,8 @@ import {
import { persistTables, removePersistedTablesWithSuffix } from '../../utils/persisted-tables'; import { persistTables, removePersistedTablesWithSuffix } from '../../utils/persisted-tables';
import webhookEvents from '../../constants/webhookEvents'; import webhookEvents from '../../constants/webhookEvents';
import type { Core } from '@strapi/types';
const MAX_DB_TABLE_NAME_LEN = 63; // Postgres limit const MAX_DB_TABLE_NAME_LEN = 63; // Postgres limit
// The longest index name that Strapi can create is prefixed with '_strapi_stage_links_inv_fk', so the content type name should be no longer than this. // The longest index name that Strapi can create is prefixed with '_strapi_stage_links_inv_fk', so the content type name should be no longer than this.
const MAX_JOIN_TABLE_NAME_SUFFIX = const MAX_JOIN_TABLE_NAME_SUFFIX =
@ -68,7 +69,7 @@ const setReviewWorkflowAttributes = (contentType: any) => {
setAssigneeAttribute(contentType); setAssigneeAttribute(contentType);
}; };
function extendReviewWorkflowContentTypes({ strapi }: { strapi: Strapi }) { function extendReviewWorkflowContentTypes({ strapi }: { strapi: Core.LoadedStrapi }) {
const extendContentType = (contentTypeUID: any) => { const extendContentType = (contentTypeUID: any) => {
const assertContentTypeCompatibility = (contentType: any) => const assertContentTypeCompatibility = (contentType: any) =>
contentType.collectionName.length <= MAX_CONTENT_TYPE_NAME_LEN; contentType.collectionName.length <= MAX_CONTENT_TYPE_NAME_LEN;
@ -95,7 +96,7 @@ function extendReviewWorkflowContentTypes({ strapi }: { strapi: Strapi }) {
])(strapi.contentTypes); ])(strapi.contentTypes);
} }
function persistStagesJoinTables({ strapi }: { strapi: Strapi }) { function persistStagesJoinTables({ strapi }: { strapi: Core.LoadedStrapi }) {
return async ({ contentTypes }: any) => { return async ({ contentTypes }: any) => {
const getStageTableToPersist = (contentTypeUID: any) => { const getStageTableToPersist = (contentTypeUID: any) => {
// Persist the stage join table // Persist the stage join table
@ -116,12 +117,12 @@ function persistStagesJoinTables({ strapi }: { strapi: Strapi }) {
}; };
} }
const registerWebhookEvents = async ({ strapi }: { strapi: Strapi }) => const registerWebhookEvents = async ({ strapi }: { strapi: Core.LoadedStrapi }) =>
Object.entries(webhookEvents).forEach(([eventKey, event]) => Object.entries(webhookEvents).forEach(([eventKey, event]) =>
strapi.webhookStore.addAllowedEvent(eventKey, event) strapi.webhookStore.addAllowedEvent(eventKey, event)
); );
export default ({ strapi }: { strapi: Strapi }) => { export default ({ strapi }: { strapi: Core.LoadedStrapi }) => {
const workflowsService = getService('workflows', { strapi }); const workflowsService = getService('workflows', { strapi });
const stagesService = getService('stages', { strapi }); const stagesService = getService('stages', { strapi });
const workflowsValidationService = getService('review-workflows-validation', { strapi }); const workflowsValidationService = getService('review-workflows-validation', { strapi });

View File

@ -1,5 +1,5 @@
import type { Strapi } from '@strapi/types'; import type { Core } from '@strapi/types';
declare global { declare global {
const strapi: Strapi; const strapi: Core.Strapi;
} }

View File

@ -22,12 +22,12 @@ const TYPESCRIPT = (pluginName: string): TemplateFile[] => [
import policies from './policies'; import policies from './policies';
import routes from './routes'; import routes from './routes';
import services from './services'; import services from './services';
export default { export default {
bootstrap, bootstrap,
destroy, destroy,
register, register,
config, config,
controllers, controllers,
contentTypes, contentTypes,
@ -41,9 +41,9 @@ const TYPESCRIPT = (pluginName: string): TemplateFile[] => [
{ {
name: 'server/src/bootstrap.ts', name: 'server/src/bootstrap.ts',
contents: outdent` contents: outdent`
import type { Strapi } from '@strapi/strapi'; import type { Core } from '@strapi/strapi';
const bootstrap = ({ strapi }: { strapi: Strapi }) => { const bootstrap = ({ strapi }: { strapi: Core.Strapi }) => {
// bootstrap phase // bootstrap phase
}; };
@ -53,9 +53,9 @@ const TYPESCRIPT = (pluginName: string): TemplateFile[] => [
{ {
name: 'server/src/destroy.ts', name: 'server/src/destroy.ts',
contents: outdent` contents: outdent`
import type { Strapi } from '@strapi/strapi'; import type { Core } from '@strapi/strapi';
const destroy = ({ strapi }: { strapi: Strapi }) => { const destroy = ({ strapi }: { strapi: Core.Strapi }) => {
// destroy phase // destroy phase
}; };
@ -65,9 +65,9 @@ const TYPESCRIPT = (pluginName: string): TemplateFile[] => [
{ {
name: 'server/src/register.ts', name: 'server/src/register.ts',
contents: outdent` contents: outdent`
import type { Strapi } from '@strapi/strapi'; import type { Core } from '@strapi/strapi';
const register = ({ strapi }: { strapi: Strapi }) => { const register = ({ strapi }: { strapi: Core.Strapi }) => {
// register phase // register phase
}; };
@ -102,9 +102,9 @@ const TYPESCRIPT = (pluginName: string): TemplateFile[] => [
{ {
name: 'server/src/controllers/controller.ts', name: 'server/src/controllers/controller.ts',
contents: outdent` contents: outdent`
import type { Strapi } from '@strapi/strapi'; import type { Core } from '@strapi/strapi';
const controller = ({ strapi }: { strapi: Strapi }) => ({ const controller = ({ strapi }: { strapi: Core.Strapi }) => ({
index(ctx) { index(ctx) {
ctx.body = strapi ctx.body = strapi
.plugin('${pluginName}') .plugin('${pluginName}')
@ -158,9 +158,9 @@ const TYPESCRIPT = (pluginName: string): TemplateFile[] => [
{ {
name: 'server/src/services/service.ts', name: 'server/src/services/service.ts',
contents: outdent` contents: outdent`
import type { Strapi } from '@strapi/strapi'; import type { Core } from '@strapi/strapi';
const service = ({ strapi }: { strapi: Strapi }) => ({ const service = ({ strapi }: { strapi: Core.Strapi }) => ({
getWelcomeMessage() { getWelcomeMessage() {
return 'Welcome to Strapi 🚀'; return 'Welcome to Strapi 🚀';
}, },
@ -199,7 +199,7 @@ const JAVASCRIPT = (pluginName: string): TemplateFile[] => [
bootstrap, bootstrap,
destroy, destroy,
register, register,
config, config,
controllers, controllers,
contentTypes, contentTypes,
@ -230,7 +230,7 @@ const JAVASCRIPT = (pluginName: string): TemplateFile[] => [
const destroy = ({ strapi }) => { const destroy = ({ strapi }) => {
// destroy phase // destroy phase
}; };
module.exports = destroy; module.exports = destroy;
`, `,
}, },
@ -242,7 +242,7 @@ const JAVASCRIPT = (pluginName: string): TemplateFile[] => [
const register = ({ strapi }) => { const register = ({ strapi }) => {
// register phase // register phase
}; };
module.exports = register; module.exports = register;
`, `,
}, },

View File

@ -15,7 +15,7 @@ import packageJSON from './resources/json/common/package.json';
import jsconfig from './resources/json/js/jsconfig.json'; import jsconfig from './resources/json/js/jsconfig.json';
import adminTsconfig from './resources/json/ts/tsconfig-admin.json'; import adminTsconfig from './resources/json/ts/tsconfig-admin.json';
import serverTsconfig from './resources/json/ts/tsconfig-server.json'; import serverTsconfig from './resources/json/ts/tsconfig-server.json';
import { createDatabaseConfig, generateDbEnvariables } from './resources/templates/database'; import { createDatabaseConfig, generateDbEnvVariables } from './resources/templates/database';
import createEnvFile from './resources/templates/env'; import createEnvFile from './resources/templates/env';
import { Configuration, Scope, isStderrError } from './types'; import { Configuration, Scope, isStderrError } from './types';
@ -110,7 +110,7 @@ export default async function createProject(
await fse.ensureDir(join(rootPath, 'node_modules')); await fse.ensureDir(join(rootPath, 'node_modules'));
// create config/database // create config/database
await fse.appendFile(join(rootPath, '.env'), generateDbEnvariables({ client, connection })); await fse.appendFile(join(rootPath, '.env'), generateDbEnvVariables({ client, connection }));
await fse.writeFile( await fse.writeFile(
join(rootPath, `config/database.${language}`), join(rootPath, `config/database.${language}`),
createDatabaseConfig({ useTypescript }) createDatabaseConfig({ useTypescript })

View File

@ -1,3 +1,5 @@
import type { StrapiApp } from '@strapi/strapi/admin';
export default { export default {
config: { config: {
locales: [ locales: [
@ -29,7 +31,7 @@ export default {
// 'zh', // 'zh',
], ],
}, },
bootstrap(app) { bootstrap(app: StrapiApp) {
console.log(app); console.log(app);
}, },
}; };

View File

@ -1,3 +1,5 @@
// import type { Core } from '@strapi/strapi';
export default { export default {
/** /**
* An asynchronous register function that runs before * An asynchronous register function that runs before
@ -5,7 +7,7 @@ export default {
* *
* This gives you an opportunity to extend code. * This gives you an opportunity to extend code.
*/ */
register(/*{ strapi }*/) {}, register(/* { strapi }: { strapi: Core.Strapi } */) {},
/** /**
* An asynchronous bootstrap function that runs before * An asynchronous bootstrap function that runs before
@ -14,5 +16,5 @@ export default {
* This gives you an opportunity to set up your data model, * This gives you an opportunity to set up your data model,
* run jobs, or perform some special logic. * run jobs, or perform some special logic.
*/ */
bootstrap(/*{ strapi }*/) {}, bootstrap(/* { strapi }: { strapi: Core.Strapi } */) {},
}; };

View File

@ -13,7 +13,7 @@ export const createDatabaseConfig = ({ useTypescript }: { useTypescript: boolean
return compile(); return compile();
}; };
export const generateDbEnvariables = ({ export const generateDbEnvVariables = ({
connection, connection,
client, client,
}: { }: {

View File

@ -1,5 +1,5 @@
import { Core } from '@strapi/strapi'; // import type { Core } from '@strapi/strapi';
export default ({ strapi }: { strapi: Core.Strapi }) => { export default (/* { strapi }: { strapi: Core.Strapi } */) => {
// bootstrap phase // bootstrap phase
}; };

View File

@ -1,6 +1,6 @@
import { Strapi } from '@strapi/strapi'; import type { Core } from '@strapi/strapi';
export default ({ strapi }: { strapi: Strapi }) => ({ export default ({ strapi }: { strapi: Core.Strapi }) => ({
index(ctx) { index(ctx) {
ctx.body = strapi ctx.body = strapi
.plugin('{{ pluginName }}') .plugin('{{ pluginName }}')

View File

@ -1,5 +1,5 @@
import { Core } from '@strapi/strapi'; // import type { Core } from '@strapi/strapi';
export default ({ strapi }: { strapi: Core.Strapi }) => { export default (/* { strapi }: { strapi: Core.Strapi } */) => {
// destroy phase // destroy phase
}; };

View File

@ -1,5 +1,5 @@
import { Core } from '@strapi/strapi'; // import type { Core } from '@strapi/strapi';
export default ({ strapi }: { strapi: Core.Strapi }) => { export default (/* { strapi }: { strapi: Core.Strapi } */) => {
// register phase // register phase
}; };

View File

@ -1,6 +1,6 @@
import { Strapi } from '@strapi/strapi'; // import type { Core } from '@strapi/strapi';
export default ({ strapi }: { strapi: Strapi }) => ({ export default (/* { strapi }: { strapi: Core.Strapi } */) => ({
getWelcomeMessage() { getWelcomeMessage() {
return 'Welcome to Strapi 🚀'; return 'Welcome to Strapi 🚀';
}, },

View File

@ -2,9 +2,9 @@
* `{{ name }}` middleware * `{{ name }}` middleware
*/ */
import { Strapi } from '@strapi/strapi'; import type { Core } from '@strapi/strapi';
export default (config, { strapi }: { strapi: Strapi }) => { export default (config, { strapi }: { strapi: Core.Strapi }) => {
// Add your own logic here. // Add your own logic here.
return async (ctx, next) => { return async (ctx, next) => {
strapi.log.info('In {{ name }} middleware.'); strapi.log.info('In {{ name }} middleware.');