Merge branch 'chore/ts-strapi' of https://github.com/strapi/strapi into types/plugins

This commit is contained in:
Christian Capeans 2023-09-08 14:37:51 +02:00
commit d31e079fbb
276 changed files with 2885 additions and 525 deletions

View File

@ -26,4 +26,4 @@ jobs:
- uses: ./.github/actions/security/lockfile
with:
allowedHosts: 'yarn'
allowedURLs: 'https://github.com/strapi/ts-zen.git#commit=41af3f8c6422de048bf9976ae551566b2c2b590a'
allowedURLs: 'https://github.com/strapi/ts-zen.git#commit=66e02232f5997674cc7032ea3ee59d9864863732'

2
.gitignore vendored
View File

@ -1,7 +1,7 @@
############################
# OS X
############################
examples/
.DS_Store
.AppleDouble
.LSOverride

View File

@ -1,9 +1,10 @@
const { createCoreController } = require('@strapi/strapi').factories;
module.exports = createCoreController('api::address.address', {
async find(ctx) {
const { results } = await strapi.service('api::address.address').find();
ctx.body = await this.sanitizeOutput(results);
ctx.body = await this.sanitizeOutput(results, ctx);
},
});

View File

@ -0,0 +1,154 @@
import type { Schema, Attribute } from '@strapi/strapi';
export interface BasicRelation extends Schema.Component {
collectionName: 'components_basic_relations';
info: {
displayName: 'Relation';
};
attributes: {
categories: Attribute.Relation<'basic.relation', 'oneToMany', 'api::category.category'>;
};
}
export interface BasicSimple extends Schema.Component {
collectionName: 'components_basic_simples';
info: {
displayName: 'simple';
icon: 'ambulance';
description: '';
};
attributes: {
name: Attribute.String & Attribute.Required;
test: Attribute.String;
};
}
export interface BlogTestComo extends Schema.Component {
collectionName: 'components_blog_test_comos';
info: {
displayName: 'test comp';
icon: 'air-freshener';
description: '';
};
attributes: {
name: Attribute.String & Attribute.DefaultTo<'toto'>;
};
}
export interface DefaultApple extends Schema.Component {
collectionName: 'components_default_apples';
info: {
displayName: 'apple';
icon: 'apple-alt';
description: '';
};
attributes: {
name: Attribute.String & Attribute.Required;
};
}
export interface DefaultCar extends Schema.Component {
collectionName: 'components_default_cars';
info: {
displayName: 'car';
icon: 'align-right';
};
attributes: {
name: Attribute.String;
};
}
export interface DefaultClosingperiod extends Schema.Component {
collectionName: 'components_closingperiods';
info: {
displayName: 'closingperiod';
description: '';
icon: 'angry';
};
attributes: {
label: Attribute.String & Attribute.DefaultTo<'toto'>;
start_date: Attribute.Date & Attribute.Required;
end_date: Attribute.Date & Attribute.Required;
media: Attribute.Media;
dish: Attribute.Component<'default.dish', true> &
Attribute.Required &
Attribute.SetMinMax<{
min: 2;
}>;
};
}
export interface DefaultDish extends Schema.Component {
collectionName: 'components_dishes';
info: {
displayName: 'dish';
description: '';
icon: 'address-book';
};
attributes: {
name: Attribute.String & Attribute.DefaultTo<'My super dish'>;
description: Attribute.Text;
price: Attribute.Float;
picture: Attribute.Media;
very_long_description: Attribute.RichText;
categories: Attribute.Relation<'default.dish', 'oneToOne', 'api::category.category'>;
};
}
export interface DefaultOpeningtimes extends Schema.Component {
collectionName: 'components_openingtimes';
info: {
displayName: 'openingtimes';
description: '';
icon: 'calendar';
};
attributes: {
label: Attribute.String & Attribute.Required & Attribute.DefaultTo<'something'>;
time: Attribute.String;
dishrep: Attribute.Component<'default.dish', true>;
};
}
export interface DefaultRestaurantservice extends Schema.Component {
collectionName: 'components_restaurantservices';
info: {
displayName: 'restaurantservice';
description: '';
icon: 'cannabis';
};
attributes: {
name: Attribute.String & Attribute.Required & Attribute.DefaultTo<'something'>;
media: Attribute.Media;
is_available: Attribute.Boolean & Attribute.Required & Attribute.DefaultTo<true>;
};
}
export interface DefaultTemp extends Schema.Component {
collectionName: 'components_default_temps';
info: {
displayName: 'temp';
icon: 'adjust';
description: '';
};
attributes: {
name: Attribute.String & Attribute.Required;
url: Attribute.String;
};
}
declare module '@strapi/strapi' {
export module Shared {
export interface Components {
'basic.relation': BasicRelation;
'basic.simple': BasicSimple;
'blog.test-como': BlogTestComo;
'default.apple': DefaultApple;
'default.car': DefaultCar;
'default.closingperiod': DefaultClosingperiod;
'default.dish': DefaultDish;
'default.openingtimes': DefaultOpeningtimes;
'default.restaurantservice': DefaultRestaurantservice;
'default.temp': DefaultTemp;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -155,8 +155,7 @@
},
"implicitDependencies": [
"!@strapi/data-transfer",
"!@strapi/strapi",
"!@strapi/provider-audit-logs-local"
"!@strapi/strapi"
]
}
}

View File

@ -42,6 +42,7 @@
"dependencies": {
"@strapi/logger": "4.13.3",
"@strapi/strapi": "4.13.3",
"@strapi/typings": "4.13.3",
"@strapi/utils": "4.13.3",
"chalk": "4.1.2",
"cli-table3": "0.6.2",
@ -58,9 +59,6 @@
"tar-stream": "2.2.0",
"ws": "8.13.0"
},
"peerDependencies": {
"@strapi/strapi": "^4.13.3"
},
"devDependencies": {
"@types/fs-extra": "9.0.13",
"@types/jest": "29.5.2",

View File

@ -1,5 +1,5 @@
import { Readable } from 'stream';
import type { LoadedStrapi } from '@strapi/strapi';
import type { LoadedStrapi } from '@strapi/typings';
import type { ITransferEngine, ISourceProvider, IDestinationProvider } from '../../types';
/**

View File

@ -1,4 +1,4 @@
import type { Utils } from '@strapi/strapi';
import type { Utils } from '@strapi/typings';
const expectExit = async (code: number, fn: Utils.Function.Any) => {
const exit = jest.spyOn(process, 'exit').mockImplementation((number) => {

View File

@ -2,9 +2,10 @@ import chalk from 'chalk';
import Table from 'cli-table3';
import { Command, Option } from 'commander';
import { configs, createLogger } from '@strapi/logger';
import strapiFactory, { LoadedStrapi } from '@strapi/strapi';
import strapiFactory from '@strapi/strapi';
import ora from 'ora';
import { merge } from 'lodash/fp';
import type { LoadedStrapi } from '@strapi/typings';
import { readableBytes, exitWith } from './helpers';
import { getParseListWithChoices, parseInteger, confirmMessage } from './commander';

View File

@ -1,7 +1,7 @@
import { isObject, isString, isFinite, toNumber } from 'lodash/fp';
import fs from 'fs-extra';
import chalk from 'chalk';
import type { LoadedStrapi } from '@strapi/strapi';
import type { LoadedStrapi } from '@strapi/typings';
import {
getDefaultExportName,

View File

@ -1,7 +1,5 @@
/* eslint-disable @typescript-eslint/no-var-requires */
import { yellow, red, green } from 'chalk';
import { has, isString, isArray } from 'lodash/fp';
import resolveCwd from 'resolve-cwd';
import { red, green } from 'chalk';
import { isString, isArray } from 'lodash/fp';
import type { Command } from 'commander';
const bytesPerKb = 1024;
@ -105,56 +103,4 @@ const ifOptions = (
};
};
const assertCwdContainsStrapiProject = (name: string) => {
const logErrorAndExit = () => {
console.log(
`You need to run ${yellow(
`strapi ${name}`
)} in a Strapi project. Make sure you are in the right directory.`
);
process.exit(1);
};
try {
const pkgJSON = require(`${process.cwd()}/package.json`);
if (!has('dependencies.@strapi/strapi', pkgJSON)) {
logErrorAndExit();
}
} catch (err) {
logErrorAndExit();
}
};
const getLocalScript =
(name: string) =>
(...args: unknown[]) => {
assertCwdContainsStrapiProject(name);
const cmdPath = resolveCwd.silent(`@strapi/strapi/dist/commands/actions/${name}/action`);
if (!cmdPath) {
console.log(
`Error loading the local ${yellow(
name
)} command. Strapi might not be installed in your "node_modules". You may need to run "yarn install".`
);
process.exit(1);
}
import(cmdPath)
.then((script) => {
return script(...args);
})
.catch((error) => {
console.error(error);
process.exit(1);
});
};
export {
exitWith,
assertUrlHasProtocol,
ifOptions,
readableBytes,
getLocalScript,
assertCwdContainsStrapiProject,
};
export { exitWith, assertUrlHasProtocol, ifOptions, readableBytes };

View File

@ -1,4 +1,4 @@
import type { LoadedStrapi } from '@strapi/strapi';
import type { LoadedStrapi } from '@strapi/typings';
import { isObject } from 'lodash/fp';
import {

View File

@ -1,7 +1,7 @@
import { posix, win32 } from 'path';
import { cloneDeep } from 'lodash/fp';
import { Readable, Writable } from 'stream-chain';
import type { Schema } from '@strapi/strapi';
import type { Schema } from '@strapi/typings';
import { createTransferEngine, TRANSFER_STAGES } from '..';
import type {

View File

@ -6,7 +6,7 @@ import { chain } from 'stream-chain';
import { isEmpty, uniq, last, isNumber, difference, set, omit } from 'lodash/fp';
import { diff as semverDiff } from 'semver';
import type { Schema, Utils } from '@strapi/strapi';
import type { Schema, Utils } from '@strapi/typings';
import type {
IAsset,
IDestinationProvider,

View File

@ -1,4 +1,4 @@
import type { Schema } from '@strapi/strapi';
import type { Schema } from '@strapi/typings';
import { isArray, isObject, reject } from 'lodash/fp';
import type { Diff } from '../../../utils/json';
import * as utils from '../../../utils';

View File

@ -8,7 +8,7 @@ import tar from 'tar';
import { isEmpty, keyBy } from 'lodash/fp';
import { chain } from 'stream-chain';
import { parser } from 'stream-json/jsonl/Parser';
import type { Schema } from '@strapi/strapi';
import type { Schema } from '@strapi/typings';
import type { IAsset, IMetadata, ISourceProvider, ProviderType, IFile } from '../../../../types';

View File

@ -2,7 +2,7 @@ import { Writable, Readable } from 'stream';
import path from 'path';
import * as fse from 'fs-extra';
import type { Knex } from 'knex';
import type { LoadedStrapi } from '@strapi/strapi';
import type { LoadedStrapi } from '@strapi/typings';
import type {
IAsset,
IDestinationProvider,
@ -168,7 +168,7 @@ class LocalStrapiDestinationProvider implements IDestinationProvider {
getMetadata(): IMetadata {
assertValidStrapi(this.strapi, 'Not able to get Schemas');
const strapiVersion = this.strapi.config.get('info.strapi');
const strapiVersion = this.strapi.config.get<string>('info.strapi');
const createdAt = new Date().toISOString();
return {
@ -224,7 +224,7 @@ class LocalStrapiDestinationProvider implements IDestinationProvider {
return;
}
if (this.strapi.config.get('plugin.upload').provider === 'local') {
if (this.strapi.config.get<{ provider: string }>('plugin.upload').provider === 'local') {
const assetsDirectory = path.join(this.strapi.dirs.static.public, 'uploads');
const backupDirectory = path.join(
this.strapi.dirs.static.public,
@ -265,7 +265,7 @@ class LocalStrapiDestinationProvider implements IDestinationProvider {
}
// TODO: this should catch all thrown errors and bubble it up to engine so it can be reported as a non-fatal diagnostic message telling the user they may need to manually delete assets
if (this.strapi.config.get('plugin.upload').provider === 'local') {
if (this.strapi.config.get<{ provider: string }>('plugin.upload').provider === 'local') {
assertValidStrapi(this.strapi);
const backupDirectory = path.join(
this.strapi.dirs.static.public,
@ -340,7 +340,7 @@ class LocalStrapiDestinationProvider implements IDestinationProvider {
buffer: chunk?.buffer,
};
const provider = strapi.config.get('plugin.upload').provider;
const provider = strapi.config.get<{ provider: string }>('plugin.upload').provider;
try {
await strapi.plugin('upload').provider.uploadStream(uploadData);

View File

@ -1,7 +1,7 @@
import { Writable } from 'stream';
import { omit } from 'lodash/fp';
import chalk from 'chalk';
import type { LoadedStrapi } from '@strapi/strapi';
import type { LoadedStrapi } from '@strapi/typings';
import { ProviderTransferError } from '../../../../../errors/providers';
import { IConfiguration, Transaction } from '../../../../../../types';

View File

@ -1,5 +1,5 @@
import { Writable } from 'stream';
import type { LoadedStrapi, Common, Schema } from '@strapi/strapi';
import type { LoadedStrapi, Common, Schema } from '@strapi/typings';
import { get, last } from 'lodash/fp';
@ -31,7 +31,10 @@ const createEntitiesWriteStream = (options: IEntitiesRestoreStreamOptions) => {
const { create, getDeepPopulateComponentLikeQuery } = query(type);
const contentType = strapi.getModel(type);
let cType: Schema.ContentType | ((...opts: any[]) => Schema.ContentType) = contentType;
let cType:
| Schema.ContentType
| Schema.Component
| ((...opts: any[]) => Schema.ContentType | Schema.Component) = contentType;
/**
* Resolve the component UID of an entity's attribute based

View File

@ -1,4 +1,4 @@
import type { LoadedStrapi, Schema } from '@strapi/strapi';
import type { LoadedStrapi, Schema } from '@strapi/typings';
import { ProviderTransferError } from '../../../../../errors/providers';
import * as queries from '../../../../queries';

View File

@ -1,5 +1,5 @@
import { Writable } from 'stream';
import type { LoadedStrapi } from '@strapi/strapi';
import type { LoadedStrapi } from '@strapi/typings';
import { ProviderTransferError } from '../../../../../errors/providers';
import { ILink, Transaction } from '../../../../../../types';
import { createLinkQuery } from '../../../../queries/link';

View File

@ -2,7 +2,7 @@ import { join } from 'path';
import https from 'https';
import { Duplex, PassThrough, Readable } from 'stream';
import { stat, createReadStream, ReadStream } from 'fs-extra';
import type { LoadedStrapi } from '@strapi/strapi';
import type { LoadedStrapi } from '@strapi/typings';
import type { IAsset } from '../../../../types';

View File

@ -1,7 +1,7 @@
import { Readable } from 'stream';
import { chain } from 'stream-chain';
import { set } from 'lodash/fp';
import type { LoadedStrapi } from '@strapi/strapi';
import type { LoadedStrapi } from '@strapi/typings';
import type { IConfiguration } from '../../../../types';

View File

@ -1,5 +1,5 @@
import { Readable, Transform } from 'stream';
import type { LoadedStrapi, Schema } from '@strapi/strapi';
import type { LoadedStrapi, Schema } from '@strapi/typings';
import * as shared from '../../queries';
import { IEntity } from '../../../../types';

View File

@ -1,6 +1,6 @@
import { Readable } from 'stream';
import { chain } from 'stream-chain';
import type { LoadedStrapi } from '@strapi/strapi';
import type { LoadedStrapi } from '@strapi/typings';
import type { IMetadata, ISourceProvider, ProviderType } from '../../../../types';
import { createEntitiesStream, createEntitiesTransformStream } from './entities';
@ -47,7 +47,7 @@ class LocalStrapiSourceProvider implements ISourceProvider {
}
getMetadata(): IMetadata {
const strapiVersion = strapi.config.get('info.strapi');
const strapiVersion = strapi.config.get<string>('info.strapi');
const createdAt = new Date().toISOString();
return {

View File

@ -1,5 +1,5 @@
import { Readable } from 'stream';
import type { LoadedStrapi } from '@strapi/strapi';
import type { LoadedStrapi } from '@strapi/typings';
import type { ILink } from '../../../../types';
import { createLinkQuery } from '../../queries/link';

View File

@ -2,7 +2,7 @@ import { randomUUID } from 'crypto';
import { Writable } from 'stream';
import { WebSocket } from 'ws';
import { once } from 'lodash/fp';
import type { Schema, Utils } from '@strapi/strapi';
import type { Schema, Utils } from '@strapi/typings';
import { createDispatcher, connectToWebsocket, trimTrailingSlash } from '../utils';

View File

@ -1,5 +1,5 @@
import { PassThrough, Readable, Writable } from 'stream';
import type { Schema, Utils } from '@strapi/strapi';
import type { Schema, Utils } from '@strapi/typings';
import { WebSocket } from 'ws';
import { castArray } from 'lodash/fp';

View File

@ -1,8 +1,8 @@
import { assign, isArray, isEmpty, isObject, map, omit, size } from 'lodash/fp';
import type { LoadedStrapi, Attribute, Common, Schema } from '@strapi/strapi';
import type { LoadedStrapi, Attribute, Common, Schema } from '@strapi/typings';
import * as componentsService from '../../utils/components';
const sanitizeComponentLikeAttributes = <T extends Schema.ContentType>(
const sanitizeComponentLikeAttributes = <T extends Schema.ContentType | Schema.Component>(
model: T,
data: Attribute.GetValues<T['uid']>
) => {
@ -19,7 +19,7 @@ const omitInvalidCreationAttributes = omit(['id']);
const createEntityQuery = (strapi: LoadedStrapi): any => {
const components = {
async assignToEntity(uid: string, data: any) {
async assignToEntity(uid: Common.UID.Schema, data: any) {
const model = strapi.getModel(uid);
const entityComponents = await componentsService.createComponents(
@ -46,7 +46,7 @@ const createEntityQuery = (strapi: LoadedStrapi): any => {
},
};
const query = (uid: string) => {
const query = (uid: Common.UID.Schema) => {
const create = async <T extends { data: U }, U extends object>(params: T) => {
const dataWithComponents = await components.assignToEntity(uid, params.data);
const sanitizedData = omitInvalidCreationAttributes(dataWithComponents);
@ -84,7 +84,7 @@ const createEntityQuery = (strapi: LoadedStrapi): any => {
};
const getDeepPopulateComponentLikeQuery = (
contentType: Schema.ContentType,
contentType: Schema.ContentType | Schema.Component,
params = { select: '*' }
) => {
const { attributes } = contentType;

View File

@ -1,6 +1,6 @@
import type { Knex } from 'knex';
import { clone, isNil } from 'lodash/fp';
import type { LoadedStrapi } from '@strapi/strapi';
import type { LoadedStrapi } from '@strapi/typings';
import { ILink } from '../../../types';

View File

@ -1,6 +1,6 @@
import { Readable } from 'stream';
import { randomUUID } from 'crypto';
import type { LoadedStrapi } from '@strapi/strapi';
import type { LoadedStrapi } from '@strapi/typings';
import { Handler } from './abstract';
import { handlerControllerFactory, isDataTransferMessage } from './utils';

View File

@ -1,6 +1,6 @@
import { randomUUID } from 'crypto';
import { Writable, PassThrough } from 'stream';
import type { LoadedStrapi } from '@strapi/strapi';
import type { LoadedStrapi } from '@strapi/typings';
import type { TransferFlow, Step } from '../flows';
import type { TransferStage, IAsset, Protocol } from '../../../../types';

View File

@ -2,7 +2,7 @@ import _ from 'lodash';
import { has, omit, pipe, assign } from 'lodash/fp';
import { contentTypes as contentTypesUtils, mapAsync, errors } from '@strapi/utils';
import type { Attribute, Common, Shared, Utils, EntityService as Types } from '@strapi/strapi';
import type { Attribute, Common, Schema, Utils, EntityService } from '@strapi/typings';
type LoadedComponents<TUID extends Common.UID.Schema> = Attribute.GetValues<
TUID,
@ -23,22 +23,30 @@ type ComponentBody = {
const isDialectMySQL = () => strapi.db?.dialect.client === 'mysql';
const omitComponentData = <TUID extends Common.UID.ContentType>(
contentType: Shared.ContentTypes[TUID],
data: Types.Params.Data.Input<TUID>
) => {
function omitComponentData(
contentType: Schema.ContentType,
data: EntityService.Params.Data.Input<Schema.ContentType['uid']>
): Partial<EntityService.Params.Data.Input<Schema.ContentType['uid']>>;
function omitComponentData(
contentType: Schema.Component,
data: EntityService.Params.Data.Input<Schema.Component['uid']>
): Partial<EntityService.Params.Data.Input<Schema.Component['uid']>>;
function omitComponentData(
contentType: Schema.ContentType | Schema.Component,
data: EntityService.Params.Data.Input<Schema.ContentType['uid'] | Schema.Component['uid']>
): Partial<EntityService.Params.Data.Input<Schema.ContentType['uid'] | Schema.Component['uid']>> {
const { attributes } = contentType;
const componentAttributes = Object.keys(attributes).filter((attributeName) =>
contentTypesUtils.isComponentAttribute(attributes[attributeName])
);
return omit(componentAttributes, data);
};
}
// NOTE: we could generalize the logic to allow CRUD of relation directly in the DB layer
const createComponents = async <
TUID extends Common.UID.Schema,
TData extends Types.Params.Data.Input<TUID>
TData extends EntityService.Params.Data.Input<TUID>
>(
uid: TUID,
data: TData
@ -89,7 +97,7 @@ const createComponents = async <
} else {
const component = await createComponent(
componentUID,
componentValue as Types.Params.Data.Input<Common.UID.Component>
componentValue as EntityService.Params.Data.Input<Common.UID.Component>
);
componentBody[attributeName] = {
id: component.id,
@ -106,7 +114,7 @@ const createComponents = async <
if (attribute.type === 'dynamiczone') {
const dynamiczoneValues = data[
attributeName as keyof TData
] as Types.Params.Attribute.GetValue<Attribute.DynamicZone>;
] as EntityService.Params.Attribute.GetValue<Attribute.DynamicZone>;
if (!Array.isArray(dynamiczoneValues)) {
throw new Error('Expected an array to create repeatable component');
@ -141,7 +149,7 @@ const createComponents = async <
const getComponents = async <TUID extends Common.UID.Schema>(
uid: TUID,
entity: { id: Types.Params.Attribute.ID }
entity: { id: EntityService.Params.Attribute.ID }
): Promise<LoadedComponents<TUID>> => {
const componentAttributes = contentTypesUtils.getComponentAttributes(strapi.getModel(uid));
@ -158,10 +166,10 @@ const getComponents = async <TUID extends Common.UID.Schema>(
*/
const updateComponents = async <
TUID extends Common.UID.Schema,
TData extends Partial<Types.Params.Data.Input<TUID>>
TData extends Partial<EntityService.Params.Data.Input<TUID>>
>(
uid: TUID,
entityToUpdate: { id: Types.Params.Attribute.ID },
entityToUpdate: { id: EntityService.Params.Attribute.ID },
data: TData
) => {
const { attributes = {} } = strapi.getModel(uid);
@ -257,8 +265,8 @@ const updateComponents = async <
const pickStringifiedId = ({
id,
}: {
id: Types.Params.Attribute.ID;
}): Types.Params.Attribute.ID & string => {
id: EntityService.Params.Attribute.ID;
}): EntityService.Params.Attribute.ID & string => {
if (typeof id === 'string') {
return id;
}
@ -269,7 +277,7 @@ const pickStringifiedId = ({
const deleteOldComponents = async <TUID extends Common.UID.Schema>(
uid: TUID,
componentUID: Common.UID.Component,
entityToUpdate: { id: Types.Params.Attribute.ID },
entityToUpdate: { id: EntityService.Params.Attribute.ID },
attributeName: string,
componentValue: Attribute.GetValue<Attribute.Component>
) => {
@ -299,7 +307,7 @@ const deleteOldComponents = async <TUID extends Common.UID.Schema>(
const deleteOldDZComponents = async <TUID extends Common.UID.Schema>(
uid: TUID,
entityToUpdate: { id: Types.Params.Attribute.ID },
entityToUpdate: { id: EntityService.Params.Attribute.ID },
attributeName: string,
dynamiczoneValues: Attribute.GetValue<Attribute.DynamicZone>
) => {
@ -404,8 +412,8 @@ const deleteComponents = async <
const cloneComponents = async <TUID extends Common.UID.Schema>(
uid: TUID,
entityToClone: { id: Types.Params.Attribute.ID },
data: Types.Params.Data.Input<TUID>
entityToClone: { id: EntityService.Params.Attribute.ID },
data: EntityService.Params.Data.Input<TUID>
) => {
const { attributes = {} } = strapi.getModel(uid);
@ -504,7 +512,7 @@ const cloneComponents = async <TUID extends Common.UID.Schema>(
// components can have nested compos so this must be recursive
const createComponent = async <TUID extends Common.UID.Component>(
uid: TUID,
data: Types.Params.Data.Input<TUID>
data: EntityService.Params.Data.Input<TUID>
) => {
const model = strapi.getModel(uid);
@ -524,8 +532,8 @@ const createComponent = async <TUID extends Common.UID.Component>(
// components can have nested compos so this must be recursive
const updateComponent = async <TUID extends Common.UID.Component>(
uid: TUID,
componentToUpdate: { id: Types.Params.Attribute.ID },
data: Types.Params.Data.Input<TUID>
componentToUpdate: { id: EntityService.Params.Attribute.ID },
data: EntityService.Params.Data.Input<TUID>
) => {
const model = strapi.getModel(uid);
@ -541,7 +549,7 @@ const updateComponent = async <TUID extends Common.UID.Component>(
const updateOrCreateComponent = <TUID extends Common.UID.Component>(
componentUID: TUID,
value: Types.Params.Data.Input<TUID>
value: EntityService.Params.Data.Input<TUID>
) => {
if (value === null) {
return null;
@ -567,7 +575,7 @@ const deleteComponent = async <TUID extends Common.UID.Component>(
const cloneComponent = async <TUID extends Common.UID.Component>(
uid: TUID,
data: Types.Params.Data.Input<TUID>
data: EntityService.Params.Data.Input<TUID>
) => {
const model = strapi.getModel(uid);

View File

@ -1,4 +1,4 @@
import type { LoadedStrapi } from '@strapi/strapi';
import type { LoadedStrapi } from '@strapi/typings';
import { ProviderInitializationError } from '../errors/providers';

View File

@ -1,4 +1,4 @@
import type { Schema, Utils } from '@strapi/strapi';
import type { Schema, Utils } from '@strapi/typings';
import { mapValues, pick } from 'lodash/fp';
/**

View File

@ -1,6 +1,6 @@
import { EventEmitter } from 'events';
import { randomUUID } from 'crypto';
import type { LoadedStrapi } from '@strapi/strapi';
import type { LoadedStrapi } from '@strapi/typings';
import { Transaction, TransactionCallback } from '../../types/utils';

View File

@ -1,5 +1,5 @@
import type { Readable } from 'stream';
import type { Attribute, Common } from '@strapi/strapi';
import type { Attribute, Common } from '@strapi/typings';
export interface IMetadata {
strapi?: {

View File

@ -1,5 +1,5 @@
import type { Readable, Writable } from 'stream';
import type { Schema, Utils } from '@strapi/strapi';
import type { Schema, Utils } from '@strapi/typings';
import type {
IDestinationProviderTransferResults,
IProviderTransferResults,

View File

@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/ban-types */
import type { Duplex, Readable, Transform, Writable } from 'stream';
import type { Schema } from '@strapi/strapi';
import type { Schema } from '@strapi/typings';
import type { Knex } from 'knex';
import type { IAsset, IEntity, ILink } from './common-entities';
import type { IDestinationProvider, ISourceProvider } from './providers';

View File

@ -9,7 +9,4 @@ module.exports = {
},
},
],
rules: {
'@typescript-eslint/no-namespace': 'off',
},
};

View File

@ -1 +1,5 @@
module.exports = require('./dist').default;
const strapi = require('./dist');
module.exports = strapi.default;
module.exports.factories = strapi.factories;
module.exports.compile = strapi.compile;

View File

@ -100,6 +100,7 @@
"@strapi/plugin-email": "4.13.3",
"@strapi/plugin-upload": "4.13.3",
"@strapi/typescript-utils": "4.13.3",
"@strapi/typings": "4.13.3",
"@strapi/utils": "4.13.3",
"@vitejs/plugin-react": "4.0.4",
"bcryptjs": "2.4.3",

View File

@ -7,6 +7,28 @@ import { isFunction } from 'lodash/fp';
import { Logger, createLogger } from '@strapi/logger';
import { Database } from '@strapi/database';
import { hooks } from '@strapi/utils';
import type {
Strapi as StrapiI,
Server,
Container,
EntityService,
EventHub,
StartupLogger,
CronService,
WebhookStore,
CoreStore,
TelemetryService,
RequestContext,
CustomFields,
Fetch,
StrapiFS,
StrapiDirectories,
Reloader,
EntityValidator,
Common,
Shared,
Schema,
} from '@strapi/typings';
import loadConfiguration from './core/app-configuration';
@ -14,16 +36,16 @@ import * as factories from './factories';
import compile from './compile';
import * as utils from './utils';
import { createContainer, Container } from './container';
import { createContainer } from './container';
import createStrapiFs from './services/fs';
import createEventHub, { EventHub } from './services/event-hub';
import createEventHub from './services/event-hub';
import { createServer } from './services/server';
import createWebhookRunner, { WebhookRunner } from './services/webhook-runner';
import { webhookModel, createWebhookStore } from './services/webhook-store';
import { createCoreStore, coreStoreModel } from './services/core-store';
import createEntityService, { EntityService } from './services/entity-service';
import createEntityService from './services/entity-service';
import createCronService from './services/cron';
import entityValidator, { EntityValidator } from './services/entity-validator';
import entityValidator from './services/entity-validator';
import createTelemetry from './services/metrics';
import requestContext from './services/request-context';
import createAuth from './services/auth';
@ -56,8 +78,6 @@ import convertCustomFieldType from './utils/convert-custom-field-type';
// TODO: move somewhere else
import * as draftAndPublishSync from './migrations/draft-publish';
import type { Common, Shared } from './types';
/**
* Resolve the working directories based on the instance options.
*
@ -120,40 +140,40 @@ const reloader = (strapi: Strapi) => {
export type LoadedStrapi = Required<Strapi>;
class Strapi {
server: ReturnType<typeof createServer>;
class Strapi implements StrapiI {
server: Server;
container: Container;
log: Logger;
fs: ReturnType<typeof createStrapiFs>;
fs: StrapiFS;
eventHub: EventHub;
startupLogger: ReturnType<typeof createStartupLogger>;
startupLogger: StartupLogger;
cron: ReturnType<typeof createCronService>;
cron: CronService;
webhookRunner?: WebhookRunner;
webhookStore?: ReturnType<typeof createWebhookStore>;
webhookStore?: WebhookStore;
store?: ReturnType<typeof createCoreStore>;
store?: CoreStore;
entityValidator?: EntityValidator;
entityService?: EntityService;
entityService?: EntityService.EntityService;
telemetry: ReturnType<typeof createTelemetry>;
telemetry: TelemetryService;
requestContext: typeof requestContext;
requestContext: RequestContext;
customFields: ReturnType<typeof createCustomFields>;
customFields: CustomFields.CustomFields;
fetch: ReturnType<typeof createStrapiFetch>;
fetch: Fetch;
dirs: ReturnType<typeof utils.getDirs>;
dirs: StrapiDirectories;
admin?: Common.Module;
@ -167,7 +187,7 @@ class Strapi {
components: Shared.Components;
reload: ReturnType<typeof reloader>;
reload: Reloader;
constructor(opts: StrapiOptions = {}) {
destroyOnSignal(this);
@ -603,7 +623,7 @@ class Strapi {
this.isLoaded = true;
return this as this & Required<Strapi>;
return this as this & Required<StrapiI>;
}
async startWebhooks() {
@ -634,11 +654,18 @@ class Strapi {
}
}
getModel(uid: string) {
return (
this.contentTypes[uid as Common.UID.ContentType] ||
this.components[uid as Common.UID.Component]
);
getModel(uid: Common.UID.ContentType): Schema.ContentType;
getModel(uid: Common.UID.Component): Schema.Component;
getModel<TUID extends Common.UID.Schema>(uid: TUID): Schema.ContentType | Schema.Component {
if (uid in this.contentTypes) {
return this.contentTypes[uid as Common.UID.ContentType];
}
if (uid in this.components) {
return this.components[uid as Common.UID.Component];
}
throw new Error('Model not found');
}
/**
@ -672,4 +699,3 @@ const initFn = (options: StrapiOptions = {}) => {
const init: Init = Object.assign(initFn, { factories, compile });
export default init;
export { Strapi };

View File

@ -1,4 +1,4 @@
import type { Utils } from '../../types';
import type { Utils } from '@strapi/typings';
const expectExit = async (code: number, fn: Utils.Function.Any) => {
const exit = jest.spyOn(process, 'exit').mockImplementation((number) => {

View File

@ -6,11 +6,11 @@ import execa from 'execa';
import { getOr } from 'lodash/fp';
import { joinBy } from '@strapi/utils';
import tsUtils from '@strapi/typescript-utils';
import type { Strapi } from '@strapi/typings';
import loadConfiguration from '../../../core/app-configuration';
import strapi from '../../../index';
import { buildTypeScript, buildAdmin } from '../../builders';
import type { Strapi } from '../../../Strapi';
interface CmdOptions {
build?: boolean;

View File

@ -1,7 +1,6 @@
'use strict';
const { getExportExtensionMap } = require('../../utils/pkg');
const { createBuildContext, createBuildTasks } = require('../packages');
import type { Logger } from '../../utils/logger';
import { PackageJson, getExportExtensionMap } from '../../utils/pkg';
import { BuildContext, createBuildContext, createBuildTasks } from '../packages';
describe('packages', () => {
const loggerMock = {
@ -9,7 +8,7 @@ describe('packages', () => {
info: jest.fn(),
warn: jest.fn(),
error: jest.fn(),
};
} as unknown as Logger;
const extMap = getExportExtensionMap();
@ -36,7 +35,7 @@ describe('packages', () => {
peerDependencies: {
'styled-components': '^5.3.1',
},
};
} as unknown as PackageJson;
describe('createBuildContext', () => {
it('should return a valid exports list', async () => {
@ -162,7 +161,7 @@ describe('packages', () => {
});
describe('createBuildTasks', () => {
let ctx;
let ctx: BuildContext;
beforeAll(async () => {
ctx = await createBuildContext({

View File

@ -167,7 +167,7 @@ const createBuildTasks = async (ctx: BuildContext): Promise<Task[]> => {
}: {
output: string;
path: string;
entry: string;
entry?: string;
}
) => {
const buildId = `${format}:${output}`;
@ -221,7 +221,7 @@ const createBuildTasks = async (ctx: BuildContext): Promise<Task[]> => {
*/
createViteTask('cjs', runtime, {
path: exp._path,
entry: exp.source ?? 'src/index.ts',
entry: exp.source,
output: exp.require,
});
}
@ -232,7 +232,7 @@ const createBuildTasks = async (ctx: BuildContext): Promise<Task[]> => {
*/
createViteTask('es', runtime, {
path: exp._path,
entry: exp.source ?? 'src/index.ts',
entry: exp.source,
output: exp.import,
});
}

View File

@ -151,7 +151,7 @@ const dtsTask: TaskHandler<DtsTask> = {
* TODO: this will not scale and assumes all project sourcePaths are `src/index.ts`
* so we can go back to the "root" of the project...
*/
cwd: path.join(ctx.cwd, entry.sourcePath ?? 'src/index.ts', '..', '..'),
cwd: path.join(ctx.cwd, entry.sourcePath!, '..', '..'),
path: 'tsconfig.build.json',
}).catch((err) => {
if (err instanceof TSConfigNotFoundError) {

View File

@ -39,7 +39,7 @@ const resolveViteConfig = (ctx: BuildContext, task: ViteTask): InlineConfig => {
target: targets[runtime],
outDir,
lib: {
entry: entries.map((e) => e.entry),
entry: entries.map((e) => e.entry).filter((v): v is string => Boolean(v)),
formats: [format],
/**
* this enforces the file name to match what the output we've
@ -79,7 +79,7 @@ const resolveViteConfig = (ctx: BuildContext, task: ViteTask): InlineConfig => {
interface ViteTaskEntry {
path: string;
entry: string;
entry?: string;
}
export interface ViteTask extends BuildTask {

View File

@ -1,10 +1,4 @@
import type { Strapi } from './Strapi';
export interface Container {
register<T, U extends string>(name: U, resolver: T): Container;
get<T = any>(name: string, args?: unknown): T;
extend(): Container;
}
import type { Strapi, Container } from '@strapi/typings';
export const createContainer = (strapi: Strapi): Container => {
const registered = new Map<string, unknown>();

View File

@ -1,4 +1,4 @@
import type { Schema } from '../../../types';
import type { Schema } from '@strapi/typings';
import * as transforms from '../transform';
describe('Transforms', () => {

View File

@ -1,9 +1,9 @@
import { isObject } from 'lodash/fp';
import { errors } from '@strapi/utils';
import type { CoreApi, Schema, Utils, Common } from '@strapi/typings';
import type Koa from 'koa';
import { parseBody } from './transform';
import type { CoreApi, Schema, Utils, Common } from '../../types';
interface Options {
contentType: Schema.CollectionType;

View File

@ -1,7 +1,7 @@
import { prop } from 'lodash/fp';
import type Koa from 'koa';
import { contentTypes as contentTypeUtils, sanitize, validate } from '@strapi/utils';
import type { CoreApi, Schema } from '../../types';
import type { CoreApi, Schema } from '@strapi/typings';
import { transformResponse } from './transform';
import createSingleTypeController from './single-type';

View File

@ -1,8 +1,8 @@
import { isObject } from 'lodash/fp';
import { errors } from '@strapi/utils';
import type { Schema, CoreApi, Utils, Common } from '@strapi/typings';
import { parseBody } from './transform';
import type { Schema, CoreApi, Utils, Common } from '../../types';
interface Options {
contentType: Schema.SingleType;

View File

@ -1,7 +1,7 @@
import { isNil, isPlainObject } from 'lodash/fp';
import { contentTypes as contentTypeUtils, parseMultipartData } from '@strapi/utils';
import type Koa from 'koa';
import type { Common, Schema, UID } from '../../types';
import type { Common, Schema, UID } from '@strapi/typings';
type TransformedEntry = {
id: string;

View File

@ -1,6 +1,5 @@
import { contentTypes as contentTypeUtils } from '@strapi/utils';
import type { Schema } from '../../types';
import type { Schema } from '@strapi/typings';
export const createRoutes = ({ contentType }: { contentType: Schema.ContentType }) => {
if (contentTypeUtils.isSingleType(contentType)) {

View File

@ -1,4 +1,4 @@
import { Schema } from '../../../types';
import { Schema } from '@strapi/typings';
import { createService } from '../index';
describe('Default Service', () => {

View File

@ -1,5 +1,6 @@
import { propOr } from 'lodash/fp';
import { contentTypes } from '@strapi/utils';
import type { CoreApi, Schema } from '@strapi/typings';
import {
getPaginationInfo,
@ -8,7 +9,6 @@ import {
transformPaginationResponse,
} from './pagination';
import { getFetchParams } from './get-fetch-params';
import type { CoreApi, Schema } from '../../types';
const {
hasDraftAndPublish,

View File

@ -1,10 +1,9 @@
import { contentTypes as contentTypeUtils } from '@strapi/utils';
import type { CoreApi, Schema } from '@strapi/typings';
import createSingleTypeService from './single-type';
import createCollectionTypeService from './collection-type';
import type { CoreApi, Schema } from '../../types';
const isSingleType = (contentType: Schema.ContentType): contentType is Schema.SingleType =>
contentTypeUtils.isSingleType(contentType);

View File

@ -1,7 +1,7 @@
import { propOr } from 'lodash/fp';
import type { CoreApi, Schema, Common } from '@strapi/typings';
import { errors, contentTypes as contentTypeUtils } from '@strapi/utils';
import { getFetchParams } from './get-fetch-params';
import type { CoreApi, Schema, Common } from '../../types';
const {
hasDraftAndPublish,

View File

@ -1,6 +1,6 @@
import { getConfigUrls } from '@strapi/utils';
import fse from 'fs-extra';
import type { Strapi } from '../Strapi';
import type { Strapi } from '@strapi/typings';
export default async function bootstrap({ strapi }: { strapi: Strapi }) {
strapi.config.port = strapi.config.get('server.port') || strapi.config.port;

View File

@ -1,10 +1,9 @@
import { cloneDeep } from 'lodash/fp';
import _ from 'lodash';
import { yup, contentTypes as contentTypesUtils } from '@strapi/utils';
import type { Schema } from '@strapi/typings';
import { validateContentTypeDefinition } from './validator';
import type { Common, Schema } from '../../../types';
export type ContentTypeDefinition = {
schema: Schema.ContentType;
actions: Record<string, unknown>;

View File

@ -1,6 +1,6 @@
import _ from 'lodash';
import { yup, toRegressedEnumValue } from '@strapi/utils';
import type { Schema } from '../../../types';
import type { Schema } from '@strapi/typings';
const LIFECYCLES = [
'beforeCreate',

View File

@ -1,12 +1,10 @@
import _ from 'lodash';
import { yup } from '@strapi/utils';
import type { Strapi, Common, Schema } from '@strapi/typings';
import { removeNamespace } from '../../utils';
import { validateModule } from './validation';
import type { Strapi } from '../../../Strapi';
import { Common, Schema } from '../../../types';
interface LifecyclesState {
bootstrap?: boolean;
register?: boolean;

View File

@ -1,5 +1,5 @@
import _ from 'lodash';
import type { Strapi } from '../../Strapi';
import type { Strapi } from '@strapi/typings';
export default async function loadAdmin(strapi: Strapi) {
strapi.admin = require('@strapi/admin/strapi-server');

View File

@ -3,9 +3,7 @@ import fse, { existsSync } from 'fs-extra';
import _ from 'lodash';
import { isKebabCase, importDefault } from '@strapi/utils';
import { isEmpty } from 'lodash/fp';
import type { Strapi } from '../../Strapi';
import type { Common, Schema } from '../../types';
import type { Strapi, Common, Schema } from '@strapi/typings';
interface API {
bootstrap: () => void | Promise<void>;

View File

@ -1,11 +1,9 @@
import { join } from 'path';
import _ from 'lodash';
import { pathExists } from 'fs-extra';
import type { Strapi, Common, Schema } from '@strapi/typings';
import loadFiles from '../../load/load-files';
import type { Strapi } from '../../Strapi';
import { Common, Schema } from '../../types';
type LoadedComponent = {
collectionName: string;
__filename__: string;

View File

@ -1,11 +1,9 @@
import { join, extname, basename } from 'path';
import fse from 'fs-extra';
import { importDefault } from '@strapi/utils';
import type { Strapi, Common } from '@strapi/typings';
import { middlewares as internalMiddlewares } from '../../middlewares';
import type { Strapi } from '../../Strapi';
import { Common } from '../../types';
// TODO:: allow folders with index.js inside for bigger policies
export default async function loadMiddlewares(strapi: Strapi) {
const localMiddlewares = await loadLocalMiddlewares(strapi);

View File

@ -4,9 +4,9 @@ import { statSync, existsSync } from 'fs';
import _ from 'lodash';
import { get, pickBy, defaultsDeep, map, prop, pipe } from 'lodash/fp';
import { isKebabCase } from '@strapi/utils';
import type { Strapi } from '@strapi/typings';
import { getUserPluginsConfig } from './get-user-plugins-config';
import type { Strapi } from '../../../Strapi';
interface PluginMeta {
enabled: boolean;

View File

@ -2,14 +2,12 @@ import { join } from 'path';
import fse from 'fs-extra';
import { defaultsDeep, defaults, getOr, get } from 'lodash/fp';
import { env } from '@strapi/utils';
import type { Strapi, Common, Schema } from '@strapi/typings';
import { loadFile } from '../../app-configuration/load-config-file';
import loadFiles from '../../../load/load-files';
import { getEnabledPlugins } from './get-enabled-plugins';
import { getUserPluginsConfig } from './get-user-plugins-config';
import type { Strapi } from '../../../Strapi';
import type { Common, Schema } from '../../../types';
type LoadedPlugin = {
config: {
default: Record<string, unknown> | ((opts: { env: typeof env }) => Record<string, unknown>);

View File

@ -2,8 +2,7 @@ import { join, extname, basename } from 'path';
import fse from 'fs-extra';
import { importDefault } from '@strapi/utils';
import type { Strapi } from '../../Strapi';
import { Common } from '../../types';
import type { Strapi, Common } from '@strapi/typings';
// TODO:: allow folders with index.js inside for bigger policies
export default async function loadPolicies(strapi: Strapi) {

View File

@ -1,4 +1,4 @@
import type { Strapi } from '../../Strapi';
import type { Strapi } from '@strapi/typings';
export default (strapi: Strapi) => {
strapi.container.get('sanitizers').set('content-api', { input: [], output: [], query: [] });

View File

@ -2,7 +2,7 @@ import { resolve } from 'path';
import { statSync, existsSync } from 'fs';
import { yup, importDefault } from '@strapi/utils';
import type { Strapi } from '../../Strapi';
import type { Strapi } from '@strapi/typings';
const srcSchema = yup
.object()

View File

@ -1,4 +1,4 @@
import type { Strapi } from '../../Strapi';
import type { Strapi } from '@strapi/typings';
export default (strapi: Strapi) => {
strapi.container.get('validators').set('content-api', { input: [], query: [] });

View File

@ -1,5 +1,5 @@
import { has } from 'lodash/fp';
import type { Strapi } from '../../Strapi';
import type { Strapi } from '@strapi/typings';
const apisRegistry = (strapi: Strapi) => {
const apis: Record<string, unknown> = {};

View File

@ -1,13 +1,14 @@
import type { ConfigProvider } from '@strapi/typings';
import _, { PropertyName } from 'lodash';
type Config = Record<string, unknown>;
export default (initialConfig = {}) => {
export default (initialConfig = {}): ConfigProvider => {
const _config: Config = { ...initialConfig }; // not deep clone because it would break some config
return {
..._config, // TODO: to remove
get(path: PropertyName, defaultValue: unknown) {
get(path: PropertyName, defaultValue?: unknown) {
return _.get(_config, path, defaultValue);
},
set(path: PropertyName, val: unknown) {

View File

@ -1,9 +1,8 @@
import { pickBy, has } from 'lodash/fp';
import type { Common, Schema } from '@strapi/typings';
import { createContentType, ContentTypeDefinition } from '../domain/content-type';
import { addNamespace, hasNamespace } from '../utils';
import type { Common, Schema } from '../../types';
type ContentTypesInput = Record<string, ContentTypeDefinition>;
type ContentTypeExtendFn = (contentType: Schema.ContentType) => Schema.ContentType;

View File

@ -1,7 +1,6 @@
import { pickBy, has } from 'lodash/fp';
import type { Strapi, Common } from '@strapi/typings';
import { addNamespace, hasNamespace } from '../utils';
import type { Strapi } from '../../Strapi';
import { Common } from '../../types';
export type ControllerFactory =
| ((params: { strapi: Strapi }) => Common.Controller)

View File

@ -1,7 +1,6 @@
import { has, isPlainObject } from 'lodash/fp';
import type { Strapi } from '../../Strapi';
import type { CustomFieldServerOptions } from '../../types';
import type { Strapi, CustomFields } from '@strapi/typings';
const ALLOWED_TYPES = [
'biginteger',
@ -37,7 +36,9 @@ const customFieldsRegistry = (strapi: Strapi) => {
return registeredCustomField;
},
add(customField: CustomFieldServerOptions | CustomFieldServerOptions[]) {
add(
customField: CustomFields.CustomFieldServerOptions | CustomFields.CustomFieldServerOptions[]
) {
const customFieldList = Array.isArray(customField) ? customField : [customField];
for (const cf of customFieldList) {

View File

@ -1,8 +1,7 @@
import { pickBy, has } from 'lodash/fp';
import type { Common } from '@strapi/typings';
import { addNamespace, hasNamespace } from '../utils';
import type { Common } from '../../types';
type MiddlewareExtendFn = (middleware: Common.Middleware) => Common.Middleware;
// TODO: move instantiation part here instead of in the server service

View File

@ -1,8 +1,7 @@
import { pickBy, has } from 'lodash/fp';
import type { Strapi } from '@strapi/typings';
import { createModule, RawModule, Module } from '../domain/module';
import type { Strapi } from '../../Strapi';
type ModuleMap = { [namespace: string]: Module };
const modulesRegistry = (strapi: Strapi) => {

View File

@ -1,7 +1,6 @@
import { has } from 'lodash/fp';
import type { Strapi } from '../../Strapi';
import type { Common } from '../../types';
import type { Strapi, Common } from '@strapi/typings';
type PluginMap = Record<string, Common.Plugin>;

View File

@ -1,8 +1,7 @@
import { pickBy, has } from 'lodash/fp';
import type { Common } from '@strapi/typings';
import { addNamespace, hasNamespace } from '../utils';
import type { Common } from '../../types';
type PolicyExtendFn = (policy: Common.Policy) => Common.Policy;
type PolicyMap = Record<string, Common.Policy>;

View File

@ -1,7 +1,6 @@
import { pickBy, has } from 'lodash/fp';
import type { Strapi, Common } from '@strapi/typings';
import { addNamespace, hasNamespace } from '../utils';
import type { Strapi } from '../../Strapi';
import type { Common } from '../../types';
export type ServiceFactory = (params: { strapi: Strapi }) => Common.Service | Common.Service;
export type ServiceFactoryMap = Record<string, ServiceFactory>;

View File

@ -1,9 +1,9 @@
import { pick, isEqual } from 'lodash/fp';
import type { Logger } from '@strapi/logger';
import type { Strapi } from '@strapi/typings';
import { readLicense, verifyLicense, fetchLicense, LicenseCheckError } from './license';
import { shiftCronExpression } from '../utils/cron';
import type { Strapi } from '../Strapi';
const ONE_MINUTE = 1000 * 60;

View File

@ -1,9 +1,9 @@
import fs from 'fs';
import { join, resolve } from 'path';
import crypto from 'crypto';
import type { Strapi } from '@strapi/typings';
import machineId from '../utils/machine-id';
import type { Strapi } from '../Strapi';
interface LicenseInfo {
type: 'bronze' | 'silver' | 'gold';

View File

@ -1,12 +1,10 @@
import { pipe, omit, pick } from 'lodash/fp';
import type { Strapi, Common, CoreApi, Utils } from '@strapi/typings';
import { createController } from './core-api/controller';
import { createService } from './core-api/service';
import { createRoutes } from './core-api/routes';
import type { Strapi } from './Strapi';
import { Common, CoreApi, Utils } from './types';
type WithStrapiCallback<T> = T | (<S extends { strapi: Strapi }>(params: S) => T);
// Content type is proxied to allow for dynamic content type updates
@ -14,7 +12,9 @@ const getContentTypeProxy = (strapi: Strapi, uid: Common.UID.ContentType) => {
return new Proxy(strapi.contentType(uid), {
get(target, prop) {
const contentType = strapi.contentType(uid);
return contentType[prop];
if (prop in contentType) {
return contentType[prop as keyof typeof contentType];
}
},
});
};

View File

@ -1,21 +1,8 @@
/* eslint-disable vars-on-top */
/* eslint-disable no-var */
/* eslint-disable import/export */
import strapiFactory, { Strapi, LoadedStrapi } from './Strapi';
// import './modules';
import strapiFactory from './Strapi';
export type * from './types';
export type * as EntityService from './services/entity-service';
export type * as factories from './factories';
export type * from '@strapi/typings';
declare global {
var strapi: Strapi;
namespace NodeJS {
interface Global {
strapi: Strapi;
}
}
}
export * as factories from './factories';
export { default as compile } from './compile';
export type { Strapi, LoadedStrapi };
export default strapiFactory;

View File

@ -3,7 +3,7 @@ import { defaultsDeep } from 'lodash/fp';
import body from 'koa-body';
import mime from 'mime-types';
import type Koa from 'koa';
import type { Common } from '../types';
import type { Common } from '@strapi/typings';
export type Config = body.IKoaBodyOptions;

View File

@ -1,5 +1,5 @@
import compress from 'koa-compress';
import type { Common } from '../types';
import type { Common } from '@strapi/typings';
export type Config = compress.CompressOptions;

View File

@ -1,6 +1,6 @@
import koaCors from '@koa/cors';
import type { Common } from '../types';
import type { Common } from '@strapi/typings';
export type Config = {
enabled?: boolean;

View File

@ -1,7 +1,7 @@
import { errors } from '@strapi/utils';
import type { Common } from '@strapi/typings';
import { formatApplicationError, formatHttpError, formatInternalError } from '../services/errors';
import { Common } from '../types';
const errorMiddleware: Common.MiddlewareFactory = (/* _, { strapi } */) => {
return async (ctx, next) => {

View File

@ -1,7 +1,7 @@
import { existsSync } from 'fs';
import { resolve } from 'path';
import koaFavicon from 'koa-favicon';
import type { Common } from '../types';
import type { Common } from '@strapi/typings';
export type Config = NonNullable<Parameters<typeof koaFavicon>[1]>;

View File

@ -1,3 +1,4 @@
import type { Common } from '@strapi/typings';
import { compression } from './compression';
import { cors } from './cors';
import { errors } from './errors';
@ -12,7 +13,6 @@ import { responses } from './responses';
import { security } from './security';
import { session } from './session';
import { publicStatic } from './public';
import { Common } from '../types';
export const middlewares: Record<string, Common.MiddlewareFactory> = {
compression,

View File

@ -1,5 +1,5 @@
import koaIp from 'koa-ip';
import type { Common } from '../types';
import type { Common } from '@strapi/typings';
export type Config = koaIp.KoaIPOptions;

View File

@ -1,4 +1,4 @@
import type { Common } from '../types';
import type { Common } from '@strapi/typings';
export const logger: Common.MiddlewareFactory = (_, { strapi }) => {
return async (ctx, next) => {

View File

@ -1,4 +1,4 @@
import type { Common } from '../types';
import type { Common } from '@strapi/typings';
export interface Config {
poweredBy: string;

View File

@ -4,12 +4,10 @@ import stream from 'stream';
import _ from 'lodash';
import { defaultsDeep } from 'lodash/fp';
import koaStatic from 'koa-static';
import type { Strapi, Common } from '@strapi/typings';
import * as utils from '../../utils';
import { serveStatic } from './serve-static';
import type { Strapi } from '../../Strapi';
import type { Common } from '../../types';
type Config = koaStatic.Options;
const defaults = {

View File

@ -1,6 +1,6 @@
import path from 'path';
import koaStatic from 'koa-static';
import type { Common } from '../../types';
import type { Common } from '@strapi/typings';
// serveStatic is not supposed to be used to serve a folder that have sub-folders
export const serveStatic = (filesDir: string, koaStaticOptions: koaStatic.Options = {}) => {

Some files were not shown because too many files have changed in this diff Show More