chore: touch ups

This commit is contained in:
Alexandre Bodin 2025-01-27 09:52:18 +01:00
parent 92055a7fb1
commit cffeb3f30b
12 changed files with 39 additions and 34 deletions

View File

@ -4,5 +4,4 @@ dist
build
.strapi
/.nx/cache
/.nx/workspace-data
/.nx/workspace-data

View File

@ -43,7 +43,7 @@ export { useHistory } from './features/BackButton';
* Hooks
*/
export { useInjectReducer } from './hooks/useInjectReducer';
export { useAPIErrorHandler, type ApiError } from './hooks/useAPIErrorHandler';
export { useAPIErrorHandler } from './hooks/useAPIErrorHandler';
export { useQueryParams } from './hooks/useQueryParams';
export { useFetchClient } from './hooks/useFetchClient';
export { useFocusInputField } from './hooks/useFocusInputField';
@ -71,14 +71,7 @@ export type { RBACContext, RBACMiddleware } from './core/apis/rbac';
* Utils
*/
export { translatedErrors } from './utils/translatedErrors';
export { getFetchClient, isFetchError, FetchError } from './utils/getFetchClient';
export type {
ErrorResponse,
FetchClient,
FetchConfig,
FetchOptions,
FetchResponse,
} from './utils/getFetchClient';
export * from './utils/getFetchClient';
export * from './utils/baseQuery';
export * from './services/api';
export type { CMAdminConfiguration } from './types/adminConfiguration';

View File

@ -1,5 +1,4 @@
import { createAuditLogsLifecycleService } from '../lifecycles';
import createEventHub from '../../../../../../../core/src/services/event-hub';
import { scheduleJob } from 'node-schedule';
import '@strapi/types';
@ -51,7 +50,16 @@ describe('Audit logs service', () => {
},
},
eventHub: {
...createEventHub(),
subs: {} as Record<string, (...args: unknown[]) => unknown>,
emit(eventName: string, ...args: unknown[]) {
this.subs[eventName](...args);
},
on(eventName: string, func: (...args: unknown[]) => unknown) {
this.subs[eventName] = func;
return () => {
delete this.subs[eventName];
};
},
subscribe: mockSubscribe,
},
hook: () => ({
@ -71,6 +79,9 @@ describe('Audit logs service', () => {
// Should not subscribe to events at first
const lifecycle = createAuditLogsLifecycleService(strapi);
await lifecycle.register();
const destroySpy = jest.spyOn(lifecycle, 'destroy');
const registerSpy = jest.spyOn(lifecycle, 'register');
expect(mockSubscribe).not.toHaveBeenCalled();
// Should subscribe to events when license gets enabled
@ -83,10 +94,9 @@ describe('Audit logs service', () => {
jest.mocked(strapi.ee.features.isEnabled).mockImplementationOnce(() => false);
await strapi.eventHub.emit('ee.disable');
expect(mockSubscribe).not.toHaveBeenCalled();
expect(destroySpy).toHaveBeenCalled();
// Should recreate the service when license updates
const destroySpy = jest.spyOn(lifecycle, 'destroy');
const registerSpy = jest.spyOn(lifecycle, 'register');
await strapi.eventHub.emit('ee.update');
expect(destroySpy).toHaveBeenCalled();
expect(registerSpy).toHaveBeenCalled();

View File

@ -23,6 +23,10 @@
"url": "https://strapi.io"
}
],
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"source": "./src/index.ts",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",

View File

@ -1,9 +1,9 @@
import type { Schema } from '@strapi/types';
import type { Struct } from '@strapi/types';
import { createService } from '../index';
import { CollectionTypeService } from '../collection-type';
import { SingleTypeService } from '../single-type';
const singleType: Schema.SingleType = {
const singleType: Struct.SingleTypeSchema = {
kind: 'singleType',
modelType: 'contentType',
uid: 'api::testModel.testModel',
@ -20,10 +20,12 @@ const singleType: Schema.SingleType = {
describe('Default Service', () => {
describe('Collection Type', () => {
test('Creates default actions', () => {
const contentType: Schema.ContentType = {
const contentType: Struct.ContentTypeSchema = {
kind: 'collectionType',
modelType: 'contentType',
uid: 'testModel',
uid: 'api::testModel.testModel',
globalId: 'testModel',
modelName: 'testModel',
attributes: {},
info: {
singularName: 'test-model',

View File

@ -1,7 +1,7 @@
import type { Schema, Common } from '@strapi/types';
import type { Schema, Internal } from '@strapi/types';
const createSchemaFromAttributes = (
uid: Common.UID.ContentType,
uid: Internal.UID.ContentType,
attributes: Schema.Attributes,
singularName?: string,
pluralName?: string,
@ -26,9 +26,9 @@ const createSchemaFromAttributes = (
};
};
export const CATEGORY_UID = 'api::category.category' as Common.UID.ContentType;
export const PRODUCT_UID = 'api::product.product' as Common.UID.ContentType;
export const SHOP_UID = 'api::shop.shop' as Common.UID.ContentType;
export const CATEGORY_UID = 'api::category.category' as Internal.UID.ContentType;
export const PRODUCT_UID = 'api::product.product' as Internal.UID.ContentType;
export const SHOP_UID = 'api::shop.shop' as Internal.UID.ContentType;
export const models: Record<string, Schema.ContentType> = {
[CATEGORY_UID]: createSchemaFromAttributes(

View File

@ -7,7 +7,6 @@ import chalk from 'chalk';
import { env } from '@strapi/utils';
import type { Core } from '@strapi/types';
// eslint-disable-next-line @typescript-eslint/no-var-requires
import pkg from '../../../package.json';
const CHECK_INTERVAL = 1000 * 60 * 60 * 24 * 1; // 1 day

View File

@ -1,5 +1,3 @@
/* eslint-disable check-file/filename-naming-convention */
import { REVIEW_WORKFLOW_COLUMNS } from '../routes/content-manager/model/constants';
import type { ListFieldLayout, ListLayout } from '@strapi/content-manager/strapi-admin';

View File

@ -11,8 +11,6 @@ const command: StrapiCommand = () => {
return createCommand('version')
.description('Output the version of Strapi')
.action(() => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
process.stdout.write(`${version}\n`);
process.exit(0);
});

View File

@ -4,6 +4,8 @@ import { FOLDER_MODEL_UID } from '../../../constants';
import { folderExists } from './utils';
import { isFolderOrChild } from '../../utils/folders';
import type { Folder } from '../../../types';
const validateDeleteManyFoldersFilesSchema = yup
.object()
.shape({
@ -67,14 +69,14 @@ const validateMoveFoldersNotInsideThemselvesSchema = yup
where: { id: destinationFolderId },
});
const folders = await strapi.db.query(FOLDER_MODEL_UID).findMany({
const folders: Folder[] = await strapi.db.query(FOLDER_MODEL_UID).findMany({
select: ['name', 'path'],
where: { id: { $in: folderIds } },
});
const unmovableFoldersNames = folders
.filter((folder: any) => isFolderOrChild(destinationFolder, folder))
.map((f: any) => f.name);
.filter((folder) => isFolderOrChild(destinationFolder, folder))
.map((f) => f.name);
if (unmovableFoldersNames.length > 0) {
return this.createError({

View File

@ -49,7 +49,7 @@
"resources"
],
"scripts": {
"build": "run-p build:code build:types",
"build": "run -T npm-run-all clean --parallel build:code build:types",
"build:code": "run -T rollup -c",
"build:types": "run -T tsc -p tsconfig.build.json --emitDeclarationOnly",
"clean": "run -T rimraf ./dist",

View File

@ -114,7 +114,7 @@ describe('Filtering API', () => {
await builder.cleanup();
});
describe.only('Basic filters', () => {
describe('Basic filters', () => {
describe('Filter $and', () => {
test('Should return an array with matching entities', async () => {
const res = await rq({