Update data transfer types

This commit is contained in:
Convly 2023-05-26 15:23:50 +02:00
parent d2be844147
commit 9fca32a25e
10 changed files with 39 additions and 34 deletions

View File

@ -1,5 +1,4 @@
import type { GetAttributesValues, RelationsType } from '@strapi/strapi';
import type { SchemaUID } from '@strapi/strapi/lib/types/utils';
import type { Attribute, Common } from '@strapi/strapi';
import type { Readable } from 'stream';
export interface IMetadata {
@ -14,7 +13,7 @@ export interface IMetadata {
* Common TransferEngine format to represent a Strapi entity
* @template T The schema UID this entity represents
*/
export interface IEntity<T extends SchemaUID | string = SchemaUID> {
export interface IEntity<T extends Common.UID.ContentType = Common.UID.ContentType> {
/**
* UID of the parent type (content-type, component, etc...)
*/
@ -29,7 +28,7 @@ export interface IEntity<T extends SchemaUID | string = SchemaUID> {
/**
* The entity data (attributes value)
*/
data: GetAttributesValues<T>;
data: Attribute.GetValues<T>;
}
/**
@ -50,7 +49,7 @@ interface IDefaultLink {
/**
* The relation type
*/
relation: RelationsType;
relation: Attribute.RelationsType;
/**
* Left side of the link

View File

@ -1,4 +1,4 @@
import type { Cipher, CipherKey, BinaryLike } from 'crypto';
import type { Cipher } from 'crypto';
export type EncryptionStrategy = (key: string) => Cipher;

View File

@ -1,16 +1,16 @@
import type { PipelineSource, PipelineDestination, Readable, Writable } from 'stream';
import type { Schema, Utils } from '@strapi/strapi';
import type { Readable, Writable } from 'stream';
import type {
IDestinationProviderTransferResults,
IProviderTransferResults,
ISourceProviderTransferResults,
Stream,
MaybePromise,
} from './utils';
import type { IMetadata } from './common-entities';
type ProviderType = 'source' | 'destination';
export type ProviderType = 'source' | 'destination';
interface IProvider {
export interface IProvider {
type: ProviderType;
name: string;
results?: IProviderTransferResults;
@ -19,7 +19,7 @@ interface IProvider {
close?(): MaybePromise<void>;
getMetadata(): MaybePromise<IMetadata | null>;
getSchemas?(): MaybePromise<Strapi.Schemas>;
getSchemas?(): MaybePromise<Utils.StringRecord<Schema.Schema> | null>;
beforeTransfer?(): MaybePromise<void>;
validateOptions?(): MaybePromise<void>;

View File

@ -5,6 +5,7 @@ import type { TransferPushMessage } from './push';
export * from './action';
export * from './pull';
export * from './push';
export * from './utils';
export type TransferMessage = { type: 'transfer'; transferID: string } & (
| Action

View File

@ -1,5 +1,5 @@
import type { IEntity, ILink, IConfiguration } from '../../../../common-entities';
import { CreateTransferMessage } from './utils';
import { CreateTransferMessage, TransferAssetFlow } from './utils';
export type TransferPullMessage = CreateTransferMessage<
'step',

View File

@ -1,5 +1,5 @@
import type { CreateTransferMessage } from './utils';
import type { IEntity, ILink, IConfiguration, IAsset } from '../../../../common-entities';
import type { CreateTransferMessage, TransferAssetFlow } from './utils';
import type { IEntity, ILink, IConfiguration } from '../../../../common-entities';
export type TransferPushMessage = CreateTransferMessage<
'step',
@ -23,9 +23,3 @@ export type TransferPushStep = TransferPushMessage['step'];
type TransferStepCommands<T extends string, U> = { step: T } & TransferStepFlow<U>;
type TransferStepFlow<U> = { action: 'start' } | { action: 'stream'; data: U } | { action: 'end' };
type TransferAssetFlow = { assetID: string } & (
| { action: 'start'; data: Omit<IAsset, 'stream'> }
| { action: 'stream'; data: Buffer }
| { action: 'end' }
);

View File

@ -1,5 +1,13 @@
import type { IAsset } from '../../../../common-entities';
export type CreateTransferMessage<T extends string, U = unknown> = {
type: 'transfer';
kind: T;
transferID: string;
} & U;
export type TransferAssetFlow = { assetID: string } & (
| { action: 'start'; data: Omit<IAsset, 'stream'> }
| { action: 'stream'; data: Buffer }
| { action: 'end' }
);

View File

@ -1,2 +1,2 @@
export * as client from './client';
export * as server from './server';
export * as Client from './client';
export * as Server from './server';

View File

@ -1,12 +1,11 @@
import type { PassThrough } from 'stream';
import type { ITransferResults, TransferTransforms, TransferProgress } from './utils';
import type { ISourceProvider, IDestinationProvider } from './providers';
import type { DiagnosticReporter } from '../src/engine/diagnostic';
import type { IDiagnosticReporter } from '../src/engine/diagnostic';
import type { Diff } from '../src/utils/json';
export type TransferFilterPreset = 'content' | 'files' | 'config';
type SchemaMap = Record<string, Schema>;
// Error resolving handler middleware for the transfer engine
export type NextMiddleware<T> = (context: T) => void | Promise<void>;
export type Middleware<T> = (context: T, next: NextMiddleware<T>) => Promise<void> | void;
@ -42,7 +41,7 @@ export interface ITransferEngine<
* A diagnostic reporter instance used to gather information about
* errors, warnings and information emitted by the engine
*/
diagnostics: DiagnosticReporter;
diagnostics: IDiagnosticReporter;
/**
* Utilities used to retrieve transfer progress data
*/

View File

@ -1,15 +1,15 @@
/* eslint-disable @typescript-eslint/ban-types */
import type { Readable, Writable, Duplex, Transform } from 'stream';
import type { Schema } from '@strapi/strapi';
import type { KnexTransaction } from 'knex';
import type { IDestinationProvider, ISourceProvider } from './providers';
import type { Knex } from 'knex';
import type { Duplex, Readable, Transform, Writable } from 'stream';
import type { IAsset, IEntity, ILink } from './common-entities';
import type { IDestinationProvider, ISourceProvider } from './providers';
export type MaybePromise<T> = T | Promise<T>;
// The data type passed in for each stage
export type TransferStageTypeMap = {
schemas: Schema;
schemas: Schema.Schema;
entities: IEntity;
links: ILink;
assets: IAsset;
@ -31,7 +31,7 @@ export type TransferMap<T> = {
};
export type Stream = Readable | Writable | Duplex | Transform;
export type TransformFunction = (chunk: any, encoding?: string) => any;
export type TransformFunction = (chunk: unknown, encoding?: string) => unknown;
export type StreamItem = Stream | TransformFunction;
export type TransferTransformsTypeMap = TransferStageTypeMap & {
@ -40,7 +40,9 @@ export type TransferTransformsTypeMap = TransferStageTypeMap & {
export type TransferStage = keyof TransferStageTypeMap;
export type TransferTransformArray<T> = TransferTransform<TransferStageTypeMap[T]>[];
export type TransferTransformArray<T extends TransferTransformOption> = TransferTransform<
TransferTransformsTypeMap[T]
>[];
export type TransferTransformOption = keyof TransferTransformsTypeMap;
@ -51,7 +53,9 @@ export type TransferTransforms = {
/*
* Filters
*/
export type TransferFilterArray<T> = TransferFilter<TransferStageTypeMap[T]>[];
export type TransferFilterArray<T extends TransferTransformOption> = TransferFilter<
TransferTransforms[T]
>[];
export type TransferFilters = {
[key in TransferTransformOption]?: boolean | TransferFilterArray<key>;
@ -86,7 +90,7 @@ export type IProviderTransferResults = {};
export type ISourceProviderTransferResults = {};
export type IDestinationProviderTransferResults = {};
export type { KnexTransaction };
export type KnexTransaction = Knex.Transaction;
export type TransactionCallback = (trx?: KnexTransaction) => Promise<void>;
export type Transaction = {
attach<T = undefined>(callback: TransactionCallback): Promise<T | undefined>;