@strapi/data-transfer 4.6.0-alpha.0 → 4.6.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/jest.config.js +3 -1
- package/{dist → lib}/engine/index.d.ts +17 -10
- package/lib/engine/index.js +359 -0
- package/lib/engine/validation/index.d.ts +1 -0
- package/lib/engine/validation/index.js +28 -0
- package/lib/engine/validation/schemas/index.d.ts +7 -0
- package/lib/engine/validation/schemas/index.js +53 -0
- package/lib/file/index.d.ts +1 -0
- package/lib/file/index.js +28 -0
- package/{dist/providers/local-file-destination-provider.d.ts → lib/file/providers/destination/index.d.ts} +10 -6
- package/{dist/providers/local-file-destination-provider.js → lib/file/providers/destination/index.js} +59 -87
- package/lib/file/providers/destination/utils.d.ts +9 -0
- package/lib/file/providers/destination/utils.js +61 -0
- package/lib/file/providers/index.d.ts +2 -0
- package/{dist → lib/file}/providers/index.js +2 -6
- package/lib/file/providers/source/index.d.ts +40 -0
- package/{dist/providers/local-file-source-provider.js → lib/file/providers/source/index.js} +94 -51
- package/lib/index.d.ts +4 -0
- package/lib/index.js +31 -0
- package/lib/strapi/index.d.ts +4 -0
- package/lib/strapi/index.js +35 -0
- package/lib/strapi/providers/index.d.ts +3 -0
- package/lib/strapi/providers/index.js +22 -0
- package/lib/strapi/providers/local-destination/index.d.ts +32 -0
- package/lib/strapi/providers/local-destination/index.js +195 -0
- package/lib/strapi/providers/local-destination/strategies/index.d.ts +1 -0
- package/lib/strapi/providers/local-destination/strategies/index.js +28 -0
- package/lib/strapi/providers/local-destination/strategies/restore/configuration.d.ts +5 -0
- package/lib/strapi/providers/local-destination/strategies/restore/configuration.js +44 -0
- package/lib/strapi/providers/local-destination/strategies/restore/entities.d.ts +9 -0
- package/lib/strapi/providers/local-destination/strategies/restore/entities.js +100 -0
- package/lib/strapi/providers/local-destination/strategies/restore/index.d.ts +32 -0
- package/lib/strapi/providers/local-destination/strategies/restore/index.js +106 -0
- package/lib/strapi/providers/local-destination/strategies/restore/links.d.ts +3 -0
- package/lib/strapi/providers/local-destination/strategies/restore/links.js +29 -0
- package/lib/strapi/providers/local-source/assets.d.ts +5 -0
- package/lib/strapi/providers/local-source/assets.js +31 -0
- package/{dist/providers/local-strapi-source-provider → lib/strapi/providers/local-source}/configuration.d.ts +0 -0
- package/{dist/providers/local-strapi-source-provider → lib/strapi/providers/local-source}/configuration.js +13 -14
- package/{dist/providers/local-strapi-source-provider → lib/strapi/providers/local-source}/entities.d.ts +0 -0
- package/lib/strapi/providers/local-source/entities.js +85 -0
- package/{dist/providers/local-strapi-source-provider → lib/strapi/providers/local-source}/index.d.ts +9 -8
- package/{dist/providers/local-strapi-source-provider → lib/strapi/providers/local-source}/index.js +36 -6
- package/{dist/providers/local-strapi-source-provider/links/index.d.ts → lib/strapi/providers/local-source/links.d.ts} +1 -1
- package/lib/strapi/providers/local-source/links.js +23 -0
- package/lib/strapi/providers/remote-destination/index.d.ts +40 -0
- package/lib/strapi/providers/remote-destination/index.js +171 -0
- package/lib/strapi/providers/remote-destination/utils.d.ts +31 -0
- package/lib/strapi/providers/remote-destination/utils.js +72 -0
- package/lib/strapi/queries/entity.d.ts +19 -0
- package/lib/strapi/queries/entity.js +130 -0
- package/lib/strapi/queries/index.d.ts +2 -0
- package/lib/strapi/queries/index.js +29 -0
- package/lib/strapi/queries/link.d.ts +6 -0
- package/lib/strapi/queries/link.js +201 -0
- package/lib/strapi/register.d.ts +7 -0
- package/lib/strapi/register.js +13 -0
- package/lib/strapi/remote/constants.d.ts +1 -0
- package/lib/strapi/remote/constants.js +5 -0
- package/lib/strapi/remote/controllers/index.d.ts +1 -0
- package/{dist → lib/strapi/remote/controllers}/index.js +1 -2
- package/lib/strapi/remote/controllers/push.d.ts +25 -0
- package/lib/strapi/remote/controllers/push.js +95 -0
- package/lib/strapi/remote/handlers.d.ts +3 -0
- package/lib/strapi/remote/handlers.js +177 -0
- package/lib/strapi/remote/index.d.ts +3 -0
- package/lib/strapi/remote/index.js +30 -0
- package/lib/strapi/remote/routes.d.ts +21 -0
- package/lib/strapi/remote/routes.js +22 -0
- package/lib/utils/encryption/decrypt.d.ts +11 -0
- package/{dist → lib/utils}/encryption/decrypt.js +12 -4
- package/lib/utils/encryption/encrypt.d.ts +11 -0
- package/{dist → lib/utils}/encryption/encrypt.js +12 -4
- package/{dist → lib/utils}/encryption/index.d.ts +0 -0
- package/{dist → lib/utils}/encryption/index.js +0 -0
- package/lib/utils/index.d.ts +4 -0
- package/lib/utils/index.js +31 -0
- package/lib/utils/json.d.ts +30 -0
- package/{dist/utils.js → lib/utils/json.js} +16 -38
- package/lib/utils/schema.d.ts +7 -0
- package/lib/utils/schema.js +29 -0
- package/lib/utils/stream.d.ts +27 -0
- package/lib/utils/stream.js +59 -0
- package/package.json +19 -12
- package/dist/encryption/decrypt.d.ts +0 -3
- package/dist/encryption/encrypt.d.ts +0 -3
- package/dist/engine/index.js +0 -324
- package/dist/index.d.ts +0 -2
- package/dist/providers/index.d.ts +0 -4
- package/dist/providers/local-file-source-provider.d.ts +0 -43
- package/dist/providers/local-strapi-destination-provider.d.ts +0 -22
- package/dist/providers/local-strapi-destination-provider.js +0 -78
- package/dist/providers/local-strapi-source-provider/entities.js +0 -58
- package/dist/providers/local-strapi-source-provider/links/index.js +0 -37
- package/dist/providers/local-strapi-source-provider/links/utils.d.ts +0 -27
- package/dist/providers/local-strapi-source-provider/links/utils.js +0 -155
- package/dist/strategies/index.d.ts +0 -7
- package/dist/strategies/index.js +0 -29
- package/dist/utils.d.ts +0 -10
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.register = exports.remote = exports.queries = exports.providers = void 0;
|
|
30
|
+
exports.providers = __importStar(require("./providers"));
|
|
31
|
+
exports.queries = __importStar(require("./queries"));
|
|
32
|
+
exports.remote = __importStar(require("./remote"));
|
|
33
|
+
var register_1 = require("./register");
|
|
34
|
+
Object.defineProperty(exports, "register", { enumerable: true, get: function () { return __importDefault(register_1).default; } });
|
|
35
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
// Local
|
|
18
|
+
__exportStar(require("./local-destination"), exports);
|
|
19
|
+
__exportStar(require("./local-source"), exports);
|
|
20
|
+
// Remote
|
|
21
|
+
__exportStar(require("./remote-destination"), exports);
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/// <reference types="lodash" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { Writable } from 'stream';
|
|
4
|
+
import type { IDestinationProvider, IMetadata, ProviderType } from '../../../../types';
|
|
5
|
+
import { restore } from './strategies';
|
|
6
|
+
export declare const VALID_CONFLICT_STRATEGIES: string[];
|
|
7
|
+
export declare const DEFAULT_CONFLICT_STRATEGY = "restore";
|
|
8
|
+
export interface ILocalStrapiDestinationProviderOptions {
|
|
9
|
+
getStrapi(): Strapi.Strapi | Promise<Strapi.Strapi>;
|
|
10
|
+
autoDestroy?: boolean;
|
|
11
|
+
restore?: restore.IRestoreOptions;
|
|
12
|
+
strategy: 'restore' | 'merge';
|
|
13
|
+
}
|
|
14
|
+
declare class LocalStrapiDestinationProvider implements IDestinationProvider {
|
|
15
|
+
#private;
|
|
16
|
+
name: string;
|
|
17
|
+
type: ProviderType;
|
|
18
|
+
options: ILocalStrapiDestinationProviderOptions;
|
|
19
|
+
strapi?: Strapi.Strapi;
|
|
20
|
+
constructor(options: ILocalStrapiDestinationProviderOptions);
|
|
21
|
+
bootstrap(): Promise<void>;
|
|
22
|
+
close(): Promise<void>;
|
|
23
|
+
beforeTransfer(): Promise<void>;
|
|
24
|
+
getMetadata(): IMetadata;
|
|
25
|
+
getSchemas(): import("lodash").Dictionary<Partial<import("@strapi/strapi").Schema>>;
|
|
26
|
+
createEntitiesWriteStream(): Writable;
|
|
27
|
+
createAssetsWriteStream(): Promise<Writable>;
|
|
28
|
+
createConfigurationWriteStream(): Promise<Writable>;
|
|
29
|
+
createLinksWriteStream(): Promise<Writable>;
|
|
30
|
+
}
|
|
31
|
+
export declare const createLocalStrapiDestinationProvider: (options: ILocalStrapiDestinationProviderOptions) => LocalStrapiDestinationProvider;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
26
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
27
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
28
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
29
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
30
|
+
};
|
|
31
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
32
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
33
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
34
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
35
|
+
};
|
|
36
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
|
+
};
|
|
39
|
+
var _LocalStrapiDestinationProvider_instances, _LocalStrapiDestinationProvider_entitiesMapper, _LocalStrapiDestinationProvider_validateOptions, _LocalStrapiDestinationProvider_deleteAll;
|
|
40
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
+
exports.createLocalStrapiDestinationProvider = exports.DEFAULT_CONFLICT_STRATEGY = exports.VALID_CONFLICT_STRATEGIES = void 0;
|
|
42
|
+
const stream_1 = require("stream");
|
|
43
|
+
const path_1 = __importDefault(require("path"));
|
|
44
|
+
const fse = __importStar(require("fs-extra"));
|
|
45
|
+
const strategies_1 = require("./strategies");
|
|
46
|
+
const utils = __importStar(require("../../../utils"));
|
|
47
|
+
exports.VALID_CONFLICT_STRATEGIES = ['restore', 'merge'];
|
|
48
|
+
exports.DEFAULT_CONFLICT_STRATEGY = 'restore';
|
|
49
|
+
class LocalStrapiDestinationProvider {
|
|
50
|
+
constructor(options) {
|
|
51
|
+
_LocalStrapiDestinationProvider_instances.add(this);
|
|
52
|
+
this.name = 'destination::local-strapi';
|
|
53
|
+
this.type = 'destination';
|
|
54
|
+
/**
|
|
55
|
+
* The entities mapper is used to map old entities to their new IDs
|
|
56
|
+
*/
|
|
57
|
+
_LocalStrapiDestinationProvider_entitiesMapper.set(this, void 0);
|
|
58
|
+
this.options = options;
|
|
59
|
+
__classPrivateFieldSet(this, _LocalStrapiDestinationProvider_entitiesMapper, {}, "f");
|
|
60
|
+
}
|
|
61
|
+
async bootstrap() {
|
|
62
|
+
__classPrivateFieldGet(this, _LocalStrapiDestinationProvider_instances, "m", _LocalStrapiDestinationProvider_validateOptions).call(this);
|
|
63
|
+
this.strapi = await this.options.getStrapi();
|
|
64
|
+
}
|
|
65
|
+
async close() {
|
|
66
|
+
const { autoDestroy } = this.options;
|
|
67
|
+
// Basically `!== false` but more deterministic
|
|
68
|
+
if (autoDestroy === undefined || autoDestroy === true) {
|
|
69
|
+
await this.strapi?.destroy();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
async beforeTransfer() {
|
|
73
|
+
if (this.options.strategy === 'restore') {
|
|
74
|
+
await __classPrivateFieldGet(this, _LocalStrapiDestinationProvider_instances, "m", _LocalStrapiDestinationProvider_deleteAll).call(this);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
getMetadata() {
|
|
78
|
+
const strapiVersion = strapi.config.get('info.strapi');
|
|
79
|
+
const createdAt = new Date().toISOString();
|
|
80
|
+
const plugins = Object.keys(strapi.plugins);
|
|
81
|
+
return {
|
|
82
|
+
createdAt,
|
|
83
|
+
strapi: {
|
|
84
|
+
version: strapiVersion,
|
|
85
|
+
plugins: plugins.map((name) => ({
|
|
86
|
+
name,
|
|
87
|
+
// TODO: Get the plugin actual version when it'll be available
|
|
88
|
+
version: strapiVersion,
|
|
89
|
+
})),
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
getSchemas() {
|
|
94
|
+
if (!this.strapi) {
|
|
95
|
+
throw new Error('Not able to get Schemas. Strapi instance not found');
|
|
96
|
+
}
|
|
97
|
+
const schemas = {
|
|
98
|
+
...this.strapi.contentTypes,
|
|
99
|
+
...this.strapi.components,
|
|
100
|
+
};
|
|
101
|
+
return utils.schema.mapSchemasValues(schemas);
|
|
102
|
+
}
|
|
103
|
+
createEntitiesWriteStream() {
|
|
104
|
+
if (!this.strapi) {
|
|
105
|
+
throw new Error('Not able to import entities. Strapi instance not found');
|
|
106
|
+
}
|
|
107
|
+
const { strategy } = this.options;
|
|
108
|
+
const updateMappingTable = (type, oldID, newID) => {
|
|
109
|
+
if (!__classPrivateFieldGet(this, _LocalStrapiDestinationProvider_entitiesMapper, "f")[type]) {
|
|
110
|
+
__classPrivateFieldGet(this, _LocalStrapiDestinationProvider_entitiesMapper, "f")[type] = {};
|
|
111
|
+
}
|
|
112
|
+
Object.assign(__classPrivateFieldGet(this, _LocalStrapiDestinationProvider_entitiesMapper, "f")[type], { [oldID]: newID });
|
|
113
|
+
};
|
|
114
|
+
if (strategy === 'restore') {
|
|
115
|
+
return strategies_1.restore.createEntitiesWriteStream({
|
|
116
|
+
strapi: this.strapi,
|
|
117
|
+
updateMappingTable,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
throw new Error(`Invalid strategy supplied: "${strategy}"`);
|
|
121
|
+
}
|
|
122
|
+
// TODO: Move this logic to the restore strategy
|
|
123
|
+
async createAssetsWriteStream() {
|
|
124
|
+
if (!this.strapi) {
|
|
125
|
+
throw new Error('Not able to stream Assets. Strapi instance not found');
|
|
126
|
+
}
|
|
127
|
+
const assetsDirectory = path_1.default.join(this.strapi.dirs.static.public, 'uploads');
|
|
128
|
+
const backupDirectory = path_1.default.join(this.strapi.dirs.static.public, `uploads_backup_${Date.now()}`);
|
|
129
|
+
await fse.rename(assetsDirectory, backupDirectory);
|
|
130
|
+
await fse.mkdir(assetsDirectory);
|
|
131
|
+
return new stream_1.Writable({
|
|
132
|
+
objectMode: true,
|
|
133
|
+
async final(next) {
|
|
134
|
+
await fse.rm(backupDirectory, { recursive: true, force: true });
|
|
135
|
+
next();
|
|
136
|
+
},
|
|
137
|
+
async write(chunk, _encoding, callback) {
|
|
138
|
+
const entryPath = path_1.default.join(assetsDirectory, chunk.filename);
|
|
139
|
+
const writableStream = fse.createWriteStream(entryPath);
|
|
140
|
+
chunk.stream
|
|
141
|
+
.pipe(writableStream)
|
|
142
|
+
.on('close', callback)
|
|
143
|
+
.on('error', async (error) => {
|
|
144
|
+
try {
|
|
145
|
+
await fse.rm(assetsDirectory, { recursive: true, force: true });
|
|
146
|
+
await fse.rename(backupDirectory, assetsDirectory);
|
|
147
|
+
this.destroy(new Error(`There was an error during the transfer process. The original files have been restored to ${assetsDirectory}`));
|
|
148
|
+
}
|
|
149
|
+
catch (err) {
|
|
150
|
+
throw new Error(`There was an error doing the rollback process. The original files are in ${backupDirectory}, but we failed to restore them to ${assetsDirectory}`);
|
|
151
|
+
}
|
|
152
|
+
finally {
|
|
153
|
+
callback(error);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
async createConfigurationWriteStream() {
|
|
160
|
+
if (!this.strapi) {
|
|
161
|
+
throw new Error('Not able to stream Configurations. Strapi instance not found');
|
|
162
|
+
}
|
|
163
|
+
const { strategy } = this.options;
|
|
164
|
+
if (strategy === 'restore') {
|
|
165
|
+
return strategies_1.restore.createConfigurationWriteStream(this.strapi);
|
|
166
|
+
}
|
|
167
|
+
throw new Error(`Invalid strategy supplied: "${strategy}"`);
|
|
168
|
+
}
|
|
169
|
+
async createLinksWriteStream() {
|
|
170
|
+
if (!this.strapi) {
|
|
171
|
+
throw new Error('Not able to stream links. Strapi instance not found');
|
|
172
|
+
}
|
|
173
|
+
const { strategy } = this.options;
|
|
174
|
+
const mapID = (uid, id) => __classPrivateFieldGet(this, _LocalStrapiDestinationProvider_entitiesMapper, "f")[uid]?.[id];
|
|
175
|
+
if (strategy === 'restore') {
|
|
176
|
+
return strategies_1.restore.createLinksWriteStream(mapID, this.strapi);
|
|
177
|
+
}
|
|
178
|
+
throw new Error(`Invalid strategy supplied: "${strategy}"`);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
_LocalStrapiDestinationProvider_entitiesMapper = new WeakMap(), _LocalStrapiDestinationProvider_instances = new WeakSet(), _LocalStrapiDestinationProvider_validateOptions = function _LocalStrapiDestinationProvider_validateOptions() {
|
|
182
|
+
if (!exports.VALID_CONFLICT_STRATEGIES.includes(this.options.strategy)) {
|
|
183
|
+
throw new Error(`Invalid stategy ${this.options.strategy}`);
|
|
184
|
+
}
|
|
185
|
+
}, _LocalStrapiDestinationProvider_deleteAll = async function _LocalStrapiDestinationProvider_deleteAll() {
|
|
186
|
+
if (!this.strapi) {
|
|
187
|
+
throw new Error('Strapi instance not found');
|
|
188
|
+
}
|
|
189
|
+
return strategies_1.restore.deleteRecords(this.strapi, this.options.restore);
|
|
190
|
+
};
|
|
191
|
+
const createLocalStrapiDestinationProvider = (options) => {
|
|
192
|
+
return new LocalStrapiDestinationProvider(options);
|
|
193
|
+
};
|
|
194
|
+
exports.createLocalStrapiDestinationProvider = createLocalStrapiDestinationProvider;
|
|
195
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as restore from './restore';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.restore = void 0;
|
|
27
|
+
exports.restore = __importStar(require("./restore"));
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Writable } from 'stream';
|
|
3
|
+
import { IConfiguration } from '../../../../../../types';
|
|
4
|
+
export declare const restoreConfigs: (strapi: Strapi.Strapi, config: IConfiguration) => Promise<any>;
|
|
5
|
+
export declare const createConfigurationWriteStream: (strapi: Strapi.Strapi) => Promise<Writable>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createConfigurationWriteStream = exports.restoreConfigs = void 0;
|
|
7
|
+
const stream_1 = require("stream");
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
const restoreCoreStore = async (strapi, data) => {
|
|
10
|
+
return strapi.db.query('strapi::core-store').create({
|
|
11
|
+
data: {
|
|
12
|
+
...data,
|
|
13
|
+
value: JSON.stringify(data.value),
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
const restoreWebhooks = async (strapi, data) => {
|
|
18
|
+
return strapi.db.query('webhook').create({ data });
|
|
19
|
+
};
|
|
20
|
+
const restoreConfigs = async (strapi, config) => {
|
|
21
|
+
if (config.type === 'core-store') {
|
|
22
|
+
return restoreCoreStore(strapi, config.value);
|
|
23
|
+
}
|
|
24
|
+
if (config.type === 'webhook') {
|
|
25
|
+
return restoreWebhooks(strapi, config.value);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
exports.restoreConfigs = restoreConfigs;
|
|
29
|
+
const createConfigurationWriteStream = async (strapi) => {
|
|
30
|
+
return new stream_1.Writable({
|
|
31
|
+
objectMode: true,
|
|
32
|
+
async write(config, _encoding, callback) {
|
|
33
|
+
try {
|
|
34
|
+
await (0, exports.restoreConfigs)(strapi, config);
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
return callback(new Error(`Failed to import ${chalk_1.default.yellowBright(config.type)} (${chalk_1.default.greenBright(config.value.id)}`));
|
|
38
|
+
}
|
|
39
|
+
callback();
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
exports.createConfigurationWriteStream = createConfigurationWriteStream;
|
|
44
|
+
//# sourceMappingURL=configuration.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { SchemaUID } from '@strapi/strapi/lib/types/utils';
|
|
3
|
+
import { Writable } from 'stream';
|
|
4
|
+
interface IEntitiesRestoreStreamOptions {
|
|
5
|
+
strapi: Strapi.Strapi;
|
|
6
|
+
updateMappingTable<T extends SchemaUID | string>(type: T, oldID: number, newID: number): void;
|
|
7
|
+
}
|
|
8
|
+
declare const createEntitiesWriteStream: (options: IEntitiesRestoreStreamOptions) => Writable;
|
|
9
|
+
export { createEntitiesWriteStream };
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.createEntitiesWriteStream = void 0;
|
|
27
|
+
const fp_1 = require("lodash/fp");
|
|
28
|
+
const stream_1 = require("stream");
|
|
29
|
+
const utils_1 = require("../../../../../utils");
|
|
30
|
+
const queries = __importStar(require("../../../../queries"));
|
|
31
|
+
const createEntitiesWriteStream = (options) => {
|
|
32
|
+
const { strapi, updateMappingTable } = options;
|
|
33
|
+
const query = queries.entity.createEntityQuery(strapi);
|
|
34
|
+
return new stream_1.Writable({
|
|
35
|
+
objectMode: true,
|
|
36
|
+
async write(entity, _encoding, callback) {
|
|
37
|
+
const { type, id, data } = entity;
|
|
38
|
+
const { create, getDeepPopulateComponentLikeQuery } = query(type);
|
|
39
|
+
const contentType = strapi.getModel(type);
|
|
40
|
+
/**
|
|
41
|
+
* Resolve the component UID of an entity's attribute based
|
|
42
|
+
* on a given path (components & dynamic zones only)
|
|
43
|
+
*/
|
|
44
|
+
const resolveType = (paths) => {
|
|
45
|
+
let cType = contentType;
|
|
46
|
+
let value = data;
|
|
47
|
+
for (const path of paths) {
|
|
48
|
+
value = (0, fp_1.get)(path, value);
|
|
49
|
+
// Needed when the value of cType should be computed
|
|
50
|
+
// based on the next value (eg: dynamic zones)
|
|
51
|
+
if (typeof cType === 'function') {
|
|
52
|
+
cType = cType(value);
|
|
53
|
+
}
|
|
54
|
+
if (path in cType.attributes) {
|
|
55
|
+
const attribute = cType.attributes[path];
|
|
56
|
+
if (attribute.type === 'component') {
|
|
57
|
+
cType = strapi.getModel(attribute.component);
|
|
58
|
+
}
|
|
59
|
+
if (attribute.type === 'dynamiczone') {
|
|
60
|
+
cType = ({ __component }) => strapi.getModel(__component);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return cType?.uid;
|
|
65
|
+
};
|
|
66
|
+
try {
|
|
67
|
+
const created = await create({
|
|
68
|
+
data,
|
|
69
|
+
populate: getDeepPopulateComponentLikeQuery(contentType, { select: 'id' }),
|
|
70
|
+
select: 'id',
|
|
71
|
+
});
|
|
72
|
+
// Compute differences between original & new entities
|
|
73
|
+
const diffs = utils_1.json.diff(data, created);
|
|
74
|
+
updateMappingTable(type, id, created.id);
|
|
75
|
+
// For each difference found on an ID attribute,
|
|
76
|
+
// update the mapping the table accordingly
|
|
77
|
+
diffs.forEach((diff) => {
|
|
78
|
+
if (diff.kind === 'modified' && (0, fp_1.last)(diff.path) === 'id') {
|
|
79
|
+
const target = resolveType(diff.path);
|
|
80
|
+
// If no type is found for the given path, then ignore the diff
|
|
81
|
+
if (!target) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const [oldID, newID] = diff.values;
|
|
85
|
+
updateMappingTable(target, oldID, newID);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
catch (e) {
|
|
90
|
+
if (e instanceof Error) {
|
|
91
|
+
return callback(e);
|
|
92
|
+
}
|
|
93
|
+
return callback(new Error(`Failed to create "${type}" (${id})`));
|
|
94
|
+
}
|
|
95
|
+
return callback(null);
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
exports.createEntitiesWriteStream = createEntitiesWriteStream;
|
|
100
|
+
//# sourceMappingURL=entities.js.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ContentTypeSchema } from '@strapi/strapi';
|
|
2
|
+
export interface IRestoreOptions {
|
|
3
|
+
assets?: boolean;
|
|
4
|
+
configuration?: {
|
|
5
|
+
webhook?: boolean;
|
|
6
|
+
coreStore?: boolean;
|
|
7
|
+
};
|
|
8
|
+
entities?: {
|
|
9
|
+
include?: string[];
|
|
10
|
+
exclude?: string[];
|
|
11
|
+
filters?: ((contentType: ContentTypeSchema) => boolean)[];
|
|
12
|
+
params?: {
|
|
13
|
+
[uid: string]: unknown;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
interface IDeleteResults {
|
|
18
|
+
count: number;
|
|
19
|
+
aggregate: {
|
|
20
|
+
[uid: string]: {
|
|
21
|
+
count: number;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export declare const deleteRecords: (strapi: Strapi.Strapi, options?: IRestoreOptions | undefined) => Promise<{
|
|
26
|
+
count: number;
|
|
27
|
+
entities: IDeleteResults;
|
|
28
|
+
configuration: IDeleteResults;
|
|
29
|
+
}>;
|
|
30
|
+
export * from './entities';
|
|
31
|
+
export * from './configuration';
|
|
32
|
+
export * from './links';
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.deleteRecords = void 0;
|
|
30
|
+
const queries = __importStar(require("../../../../queries"));
|
|
31
|
+
const deleteRecords = async (strapi, options) => {
|
|
32
|
+
const entities = await deleteEntitiesRecord(strapi, options);
|
|
33
|
+
const configuration = await deleteConfigurationRecords(strapi, options);
|
|
34
|
+
return {
|
|
35
|
+
count: entities.count + configuration.count,
|
|
36
|
+
entities,
|
|
37
|
+
configuration,
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
exports.deleteRecords = deleteRecords;
|
|
41
|
+
const deleteEntitiesRecord = async (strapi, options = {}) => {
|
|
42
|
+
const { entities } = options;
|
|
43
|
+
const query = queries.entity.createEntityQuery(strapi);
|
|
44
|
+
const contentTypes = Object.values(strapi.contentTypes);
|
|
45
|
+
const contentTypesToClear = contentTypes.filter((contentType) => {
|
|
46
|
+
let keep = true;
|
|
47
|
+
if (entities?.include) {
|
|
48
|
+
keep = entities.include.includes(contentType.uid);
|
|
49
|
+
}
|
|
50
|
+
if (entities?.exclude) {
|
|
51
|
+
keep = !entities.exclude.includes(contentType.uid);
|
|
52
|
+
}
|
|
53
|
+
if (entities?.filters) {
|
|
54
|
+
keep = entities.filters.every((filter) => filter(contentType));
|
|
55
|
+
}
|
|
56
|
+
return keep;
|
|
57
|
+
});
|
|
58
|
+
const [results, updateResults] = useResults(contentTypesToClear.map((contentType) => contentType.uid));
|
|
59
|
+
const deletePromises = contentTypesToClear.map(async (contentType) => {
|
|
60
|
+
const result = await query(contentType.uid).deleteMany(entities?.params);
|
|
61
|
+
if (result) {
|
|
62
|
+
updateResults(result.count || 0, contentType.uid);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
await Promise.all(deletePromises);
|
|
66
|
+
return results;
|
|
67
|
+
};
|
|
68
|
+
const deleteConfigurationRecords = async (strapi, options = {}) => {
|
|
69
|
+
const { coreStore = true, webhook = true } = options?.configuration ?? {};
|
|
70
|
+
const models = [];
|
|
71
|
+
if (coreStore) {
|
|
72
|
+
models.push('strapi::core-store');
|
|
73
|
+
}
|
|
74
|
+
if (webhook) {
|
|
75
|
+
models.push('webhook');
|
|
76
|
+
}
|
|
77
|
+
const [results, updateResults] = useResults(models);
|
|
78
|
+
const deletePromises = models.map(async (uid) => {
|
|
79
|
+
const result = await strapi.db.query(uid).deleteMany({});
|
|
80
|
+
if (result) {
|
|
81
|
+
updateResults(result.count, uid);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
await Promise.all(deletePromises);
|
|
85
|
+
return results;
|
|
86
|
+
};
|
|
87
|
+
const useResults = (keys) => {
|
|
88
|
+
const results = {
|
|
89
|
+
count: 0,
|
|
90
|
+
aggregate: keys.reduce((acc, key) => ({ ...acc, [key]: { count: 0 } }), {}),
|
|
91
|
+
};
|
|
92
|
+
const update = (count, key) => {
|
|
93
|
+
if (key) {
|
|
94
|
+
if (!(key in results.aggregate)) {
|
|
95
|
+
throw new Error(`Unknown key "${key}" provided in results update`);
|
|
96
|
+
}
|
|
97
|
+
results.aggregate[key].count += count;
|
|
98
|
+
}
|
|
99
|
+
results.count += count;
|
|
100
|
+
};
|
|
101
|
+
return [results, update];
|
|
102
|
+
};
|
|
103
|
+
__exportStar(require("./entities"), exports);
|
|
104
|
+
__exportStar(require("./configuration"), exports);
|
|
105
|
+
__exportStar(require("./links"), exports);
|
|
106
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createLinksWriteStream = void 0;
|
|
4
|
+
const stream_1 = require("stream");
|
|
5
|
+
const link_1 = require("../../../../queries/link");
|
|
6
|
+
const createLinksWriteStream = (mapID, strapi) => {
|
|
7
|
+
return new stream_1.Writable({
|
|
8
|
+
objectMode: true,
|
|
9
|
+
async write(link, _encoding, callback) {
|
|
10
|
+
const { left, right } = link;
|
|
11
|
+
const query = (0, link_1.createLinkQuery)(strapi);
|
|
12
|
+
// Map IDs if needed
|
|
13
|
+
left.ref = mapID(left.type, left.ref) ?? left.ref;
|
|
14
|
+
right.ref = mapID(right.type, right.ref) ?? right.ref;
|
|
15
|
+
try {
|
|
16
|
+
await query().insert(link);
|
|
17
|
+
}
|
|
18
|
+
catch (e) {
|
|
19
|
+
if (e instanceof Error) {
|
|
20
|
+
return callback(e);
|
|
21
|
+
}
|
|
22
|
+
return callback(new Error(`An error happened while trying to import a ${left.type} link. ${e}`));
|
|
23
|
+
}
|
|
24
|
+
callback(null);
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
exports.createLinksWriteStream = createLinksWriteStream;
|
|
29
|
+
//# sourceMappingURL=links.js.map
|