mirror of
https://github.com/strapi/strapi.git
synced 2025-09-25 16:29:34 +00:00
add some changes and types
This commit is contained in:
parent
1d5057de4d
commit
c0f10750b7
@ -1,5 +1,5 @@
|
||||
// import { createLogger } from '@strapi/logger';
|
||||
import type { IDestinationProvider, IMetadata, ProviderType } from '../../../types';
|
||||
import type { IDestinationProvider, IMetadata, ProviderType, IConfiguration } from '../../../types';
|
||||
import { deleteAllRecords, DeleteOptions, restoreConfigs } from './restore';
|
||||
|
||||
import chalk from 'chalk';
|
||||
@ -97,17 +97,16 @@ class LocalStrapiDestinationProvider implements IDestinationProvider {
|
||||
}
|
||||
|
||||
async getConfigurationStream(): Promise<Writable> {
|
||||
if (!this.strapi) {
|
||||
throw new Error('Not able to stream Configurations. Strapi instance not found');
|
||||
}
|
||||
|
||||
const strapi = this.strapi;
|
||||
|
||||
return new Writable({
|
||||
objectMode: true,
|
||||
async write(config, _encoding, callback) {
|
||||
write: async (config: IConfiguration<any>, _encoding, callback) => {
|
||||
if (!this.strapi) {
|
||||
throw new Error('Not able to stream Configurations. Strapi instance not found');
|
||||
}
|
||||
try {
|
||||
await restoreConfigs(strapi, config);
|
||||
if (this.options.strategy === 'restore') {
|
||||
await restoreConfigs(this.strapi, config);
|
||||
}
|
||||
callback();
|
||||
} catch (error) {
|
||||
callback(
|
||||
|
@ -1,4 +1,5 @@
|
||||
import type { ContentTypeSchema } from '@strapi/strapi';
|
||||
import type { IConfiguration } from '../../../types';
|
||||
|
||||
export type DeleteOptions = {
|
||||
contentTypes?: ContentTypeSchema[];
|
||||
@ -35,7 +36,7 @@ export const deleteAllRecords = async (strapi: Strapi.Strapi, deleteOptions?: De
|
||||
};
|
||||
|
||||
const restoreCoreStore = async (strapi: Strapi.Strapi, data: any) => {
|
||||
return await strapi.db.query('strapi::core-store').create({
|
||||
return strapi.db.query('strapi::core-store').create({
|
||||
data: {
|
||||
...data,
|
||||
value: JSON.stringify(data.value),
|
||||
@ -44,17 +45,17 @@ const restoreCoreStore = async (strapi: Strapi.Strapi, data: any) => {
|
||||
};
|
||||
|
||||
const restoreWebhooks = async (strapi: Strapi.Strapi, data: any) => {
|
||||
return await strapi.db.query('webhook').create({
|
||||
return strapi.db.query('webhook').create({
|
||||
data,
|
||||
});
|
||||
};
|
||||
|
||||
export const restoreConfigs = async (strapi: Strapi.Strapi, config: any) => {
|
||||
export const restoreConfigs = async (strapi: Strapi.Strapi, config: IConfiguration) => {
|
||||
if (config.type === 'core-store') {
|
||||
return await restoreCoreStore(strapi, config.value);
|
||||
return restoreCoreStore(strapi, config.value);
|
||||
}
|
||||
|
||||
if (config.type === 'webhook') {
|
||||
return await restoreWebhooks(strapi, config.value);
|
||||
return restoreWebhooks(strapi, config.value);
|
||||
}
|
||||
};
|
||||
|
@ -121,3 +121,11 @@ interface IMorphLink extends IDefaultLink {
|
||||
interface ICircularLink extends IDefaultLink {
|
||||
kind: 'relation.circular';
|
||||
}
|
||||
|
||||
/**
|
||||
* Strapi configurations
|
||||
*/
|
||||
interface IConfiguration<T = unknown> {
|
||||
type: 'core-store' | 'webhook';
|
||||
value: T;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user