mirror of
https://github.com/strapi/strapi.git
synced 2025-09-18 04:47:27 +00:00
fix comments
This commit is contained in:
parent
e6efa4681a
commit
6fdc3c99fd
@ -23,6 +23,7 @@ import type {
|
|||||||
TransferFilters,
|
TransferFilters,
|
||||||
TransferFilterPreset,
|
TransferFilterPreset,
|
||||||
SchemaDiffHandler,
|
SchemaDiffHandler,
|
||||||
|
SchemaDiffHandlerContext,
|
||||||
SchemaMap,
|
SchemaMap,
|
||||||
} from '../../types';
|
} from '../../types';
|
||||||
import type { Diff } from '../utils/json';
|
import type { Diff } from '../utils/json';
|
||||||
@ -30,11 +31,7 @@ import type { Diff } from '../utils/json';
|
|||||||
import { compareSchemas, validateProvider } from './validation';
|
import { compareSchemas, validateProvider } from './validation';
|
||||||
import { filter, map } from '../utils/stream';
|
import { filter, map } from '../utils/stream';
|
||||||
|
|
||||||
import {
|
import { TransferEngineError, TransferEngineValidationError } from './errors';
|
||||||
TransferEngineError,
|
|
||||||
TransferEngineInitializationError,
|
|
||||||
TransferEngineValidationError,
|
|
||||||
} from './errors';
|
|
||||||
import {
|
import {
|
||||||
createDiagnosticReporter,
|
createDiagnosticReporter,
|
||||||
IDiagnosticReporter,
|
IDiagnosticReporter,
|
||||||
@ -98,8 +95,6 @@ class TransferEngine<
|
|||||||
|
|
||||||
#metadata: { source?: IMetadata; destination?: IMetadata } = {};
|
#metadata: { source?: IMetadata; destination?: IMetadata } = {};
|
||||||
|
|
||||||
#ignoredDiffs: Record<string, utils.json.Diff[]> = {};
|
|
||||||
|
|
||||||
// Progress of the current stage
|
// Progress of the current stage
|
||||||
progress: {
|
progress: {
|
||||||
// metrics on the progress such as size and record count
|
// metrics on the progress such as size and record count
|
||||||
@ -556,7 +551,7 @@ class TransferEngine<
|
|||||||
if (!this.#currentStream) {
|
if (!this.#currentStream) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
this.#currentStream?.destroy(err);
|
this.#currentStream.destroy(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
async init(): Promise<void> {
|
async init(): Promise<void> {
|
||||||
@ -640,20 +635,29 @@ class TransferEngine<
|
|||||||
if (error instanceof TransferEngineValidationError && error.details?.details?.diffs) {
|
if (error instanceof TransferEngineValidationError && error.details?.details?.diffs) {
|
||||||
const schemaDiffs = error.details?.details?.diffs as Record<string, Diff[]>;
|
const schemaDiffs = error.details?.details?.diffs as Record<string, Diff[]>;
|
||||||
|
|
||||||
const context = {
|
const context: SchemaDiffHandlerContext = {
|
||||||
ignoreDiffs: {},
|
ignoredDiffs: {},
|
||||||
diffs: schemaDiffs,
|
diffs: schemaDiffs,
|
||||||
source: this.sourceProvider,
|
source: this.sourceProvider,
|
||||||
destination: this.destinationProvider,
|
destination: this.destinationProvider,
|
||||||
};
|
};
|
||||||
|
|
||||||
await runMiddleware<typeof context>(context, this.#handlers.schemaDiff);
|
// if we don't have any handlers, throw the original error
|
||||||
|
if (isEmpty(this.#handlers.schemaDiff)) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
this.#ignoredDiffs = context.ignoreDiffs;
|
await runMiddleware<SchemaDiffHandlerContext>(context, this.#handlers.schemaDiff);
|
||||||
|
|
||||||
// if there are any remaining diffs that weren't ignored
|
// if there are any remaining diffs that weren't ignored
|
||||||
if (utils.json.diff(context.diffs, this.#ignoredDiffs).length) {
|
const unresolvedDiffs = utils.json.diff(context.diffs, context.ignoredDiffs);
|
||||||
this.panic(new TransferEngineInitializationError('Unresolved differences in schema'));
|
if (unresolvedDiffs.length) {
|
||||||
|
this.panic(
|
||||||
|
new TransferEngineValidationError('Unresolved differences in schema', {
|
||||||
|
check: 'schema.changes',
|
||||||
|
unresolvedDiffs,
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -8,15 +8,16 @@ export type TransferFilterPreset = 'content' | 'files' | 'config';
|
|||||||
type SchemaMap = Record<string, Schema>;
|
type SchemaMap = Record<string, Schema>;
|
||||||
|
|
||||||
// Error resolving handler middleware for the transfer engine
|
// Error resolving handler middleware for the transfer engine
|
||||||
export type Next<T> = (context: T) => void | Promise<void>;
|
export type NextMiddleware<T> = (context: T) => void | Promise<void>;
|
||||||
export type Middleware<T> = (context: T, next: Next) => Promise<void> | void;
|
export type Middleware<T> = (context: T, next: NextMiddleware<T>) => Promise<void> | void;
|
||||||
|
|
||||||
export type SchemaDiffHandlerContext = {
|
export type SchemaDiffHandlerContext = {
|
||||||
|
ignoredDiffs: Record<string, Diff[]>;
|
||||||
diffs: Record<string, Diff[]>;
|
diffs: Record<string, Diff[]>;
|
||||||
source: ISourceProvider;
|
source: ISourceProvider;
|
||||||
destination: IDestinationProvider;
|
destination: IDestinationProvider;
|
||||||
};
|
};
|
||||||
export type SchemaDiffHandler = (data: SchemaDiffHandlerContext, next: SchemaDiffHandler) => void;
|
export type SchemaDiffHandler = Middleware<SchemaDiffHandlerContext>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines the capabilities and properties of the transfer engine
|
* Defines the capabilities and properties of the transfer engine
|
||||||
|
@ -334,7 +334,7 @@ const getDiffHandler = (engine, { force }) => {
|
|||||||
setSignalHandler(() => abortTransfer({ engine, strapi }));
|
setSignalHandler(() => abortTransfer({ engine, strapi }));
|
||||||
|
|
||||||
if (confirmed) {
|
if (confirmed) {
|
||||||
context.ignoreDiffs = merge(context.diffs, context.ignoredDiffs);
|
context.ignoredDiffs = merge(context.diffs, context.ignoredDiffs);
|
||||||
}
|
}
|
||||||
|
|
||||||
return next(context);
|
return next(context);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user