@strapi/data-transfer 4.9.0 → 4.10.0-beta.0
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 +14 -0
- package/lib/engine/diagnostic.d.ts +40 -0
- package/lib/engine/diagnostic.js +50 -0
- package/lib/engine/errors.d.ts +28 -0
- package/lib/engine/errors.js +29 -0
- package/lib/engine/index.d.ts +44 -0
- package/lib/engine/index.js +506 -0
- package/lib/engine/validation/index.d.ts +2 -0
- package/lib/engine/validation/index.js +19 -0
- package/lib/engine/validation/provider.d.ts +3 -0
- package/lib/engine/validation/provider.js +18 -0
- package/lib/engine/validation/schemas/index.d.ts +7 -0
- package/lib/engine/validation/schemas/index.js +53 -0
- package/lib/errors/base.d.ts +8 -0
- package/lib/errors/base.js +13 -0
- package/lib/errors/constants.d.ts +3 -0
- package/lib/errors/constants.js +9 -0
- package/lib/errors/index.d.ts +2 -0
- package/lib/errors/index.js +19 -0
- package/lib/errors/providers.d.ts +21 -0
- package/lib/errors/providers.js +32 -0
- package/lib/file/index.d.ts +1 -0
- package/lib/file/index.js +28 -0
- package/lib/file/providers/destination/index.d.ts +45 -0
- package/lib/file/providers/destination/index.js +174 -0
- 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/lib/file/providers/index.js +19 -0
- package/lib/file/providers/source/index.d.ts +40 -0
- package/lib/file/providers/source/index.js +220 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +31 -0
- package/lib/strapi/index.d.ts +3 -0
- package/lib/strapi/index.js +30 -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 +34 -0
- package/lib/strapi/providers/local-destination/index.js +220 -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 +51 -0
- package/lib/strapi/providers/local-destination/strategies/restore/entities.d.ts +11 -0
- package/lib/strapi/providers/local-destination/strategies/restore/entities.js +103 -0
- package/lib/strapi/providers/local-destination/strategies/restore/index.d.ts +32 -0
- package/lib/strapi/providers/local-destination/strategies/restore/index.js +107 -0
- package/lib/strapi/providers/local-destination/strategies/restore/links.d.ts +4 -0
- package/lib/strapi/providers/local-destination/strategies/restore/links.js +32 -0
- package/lib/strapi/providers/local-source/assets.d.ts +5 -0
- package/lib/strapi/providers/local-source/assets.js +31 -0
- package/lib/strapi/providers/local-source/configuration.d.ts +5 -0
- package/lib/strapi/providers/local-source/configuration.js +36 -0
- package/lib/strapi/providers/local-source/entities.d.ts +10 -0
- package/lib/strapi/providers/local-source/entities.js +85 -0
- package/lib/strapi/providers/local-source/index.d.ts +27 -0
- package/lib/strapi/providers/local-source/index.js +98 -0
- package/lib/strapi/providers/local-source/links.d.ts +5 -0
- package/lib/strapi/providers/local-source/links.js +23 -0
- package/lib/strapi/providers/remote-destination/index.d.ts +37 -0
- package/lib/strapi/providers/remote-destination/index.js +284 -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 +215 -0
- package/lib/strapi/remote/constants.d.ts +2 -0
- package/lib/strapi/remote/constants.js +6 -0
- package/lib/strapi/remote/controllers/index.d.ts +1 -0
- package/lib/strapi/remote/controllers/index.js +18 -0
- package/lib/strapi/remote/controllers/push.d.ts +26 -0
- package/lib/strapi/remote/controllers/push.js +116 -0
- package/lib/strapi/remote/flows/default.d.ts +3 -0
- package/lib/strapi/remote/flows/default.js +41 -0
- package/lib/strapi/remote/flows/index.d.ts +18 -0
- package/lib/strapi/remote/flows/index.js +59 -0
- package/lib/strapi/remote/handlers.d.ts +10 -0
- package/lib/strapi/remote/handlers.js +285 -0
- package/lib/strapi/remote/index.d.ts +3 -0
- package/lib/strapi/remote/index.js +30 -0
- package/lib/utils/encryption/decrypt.d.ts +11 -0
- package/lib/utils/encryption/decrypt.js +47 -0
- package/lib/utils/encryption/encrypt.d.ts +11 -0
- package/lib/utils/encryption/encrypt.js +47 -0
- package/lib/utils/encryption/index.d.ts +2 -0
- package/lib/utils/encryption/index.js +19 -0
- package/lib/utils/index.d.ts +5 -0
- package/lib/utils/index.js +32 -0
- package/lib/utils/json.d.ts +30 -0
- package/lib/utils/json.js +68 -0
- package/lib/utils/providers.d.ts +2 -0
- package/lib/utils/providers.js +11 -0
- 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/lib/utils/transaction.d.ts +3 -0
- package/lib/utils/transaction.js +88 -0
- package/package.json +16 -17
- package/dist/engine/diagnostic.js.map +0 -1
- package/dist/engine/errors.js.map +0 -1
- package/dist/engine/index.js.map +0 -1
- package/dist/engine/validation/index.js.map +0 -1
- package/dist/engine/validation/provider.js.map +0 -1
- package/dist/engine/validation/schemas/index.js.map +0 -1
- package/dist/errors/base.js.map +0 -1
- package/dist/errors/constants.js.map +0 -1
- package/dist/errors/index.js.map +0 -1
- package/dist/errors/providers.js.map +0 -1
- package/dist/file/index.js.map +0 -1
- package/dist/file/providers/destination/index.js.map +0 -1
- package/dist/file/providers/destination/utils.js.map +0 -1
- package/dist/file/providers/index.js.map +0 -1
- package/dist/file/providers/source/index.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/strapi/index.js.map +0 -1
- package/dist/strapi/providers/index.js.map +0 -1
- package/dist/strapi/providers/local-destination/index.js.map +0 -1
- package/dist/strapi/providers/local-destination/strategies/index.js.map +0 -1
- package/dist/strapi/providers/local-destination/strategies/restore/configuration.js.map +0 -1
- package/dist/strapi/providers/local-destination/strategies/restore/entities.js.map +0 -1
- package/dist/strapi/providers/local-destination/strategies/restore/index.js.map +0 -1
- package/dist/strapi/providers/local-destination/strategies/restore/links.js.map +0 -1
- package/dist/strapi/providers/local-source/assets.js.map +0 -1
- package/dist/strapi/providers/local-source/configuration.js.map +0 -1
- package/dist/strapi/providers/local-source/entities.js.map +0 -1
- package/dist/strapi/providers/local-source/index.js.map +0 -1
- package/dist/strapi/providers/local-source/links.js.map +0 -1
- package/dist/strapi/providers/remote-destination/index.js.map +0 -1
- package/dist/strapi/providers/remote-source/index.js.map +0 -1
- package/dist/strapi/providers/utils.js.map +0 -1
- package/dist/strapi/queries/entity.js.map +0 -1
- package/dist/strapi/queries/index.js.map +0 -1
- package/dist/strapi/queries/link.js.map +0 -1
- package/dist/strapi/remote/constants.js.map +0 -1
- package/dist/strapi/remote/flows/default.js.map +0 -1
- package/dist/strapi/remote/flows/index.js.map +0 -1
- package/dist/strapi/remote/handlers/abstract.js.map +0 -1
- package/dist/strapi/remote/handlers/constants.js.map +0 -1
- package/dist/strapi/remote/handlers/index.js.map +0 -1
- package/dist/strapi/remote/handlers/pull.js.map +0 -1
- package/dist/strapi/remote/handlers/push.js.map +0 -1
- package/dist/strapi/remote/handlers/utils.js.map +0 -1
- package/dist/strapi/remote/index.js.map +0 -1
- package/dist/utils/encryption/decrypt.js.map +0 -1
- package/dist/utils/encryption/encrypt.js.map +0 -1
- package/dist/utils/encryption/index.js.map +0 -1
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/json.js.map +0 -1
- package/dist/utils/providers.js.map +0 -1
- package/dist/utils/schema.js.map +0 -1
- package/dist/utils/stream.js.map +0 -1
- package/dist/utils/transaction.js.map +0 -1
|
@@ -0,0 +1,51 @@
|
|
|
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 fp_1 = require("lodash/fp");
|
|
8
|
+
const stream_1 = require("stream");
|
|
9
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
10
|
+
const providers_1 = require("../../../../../errors/providers");
|
|
11
|
+
const omitInvalidCreationAttributes = (0, fp_1.omit)(['id']);
|
|
12
|
+
const restoreCoreStore = async (strapi, values) => {
|
|
13
|
+
const data = omitInvalidCreationAttributes(values);
|
|
14
|
+
return strapi.db.query('strapi::core-store').create({
|
|
15
|
+
data: {
|
|
16
|
+
...data,
|
|
17
|
+
value: JSON.stringify(data.value),
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
const restoreWebhooks = async (strapi, values) => {
|
|
22
|
+
const data = omitInvalidCreationAttributes(values);
|
|
23
|
+
return strapi.db.query('webhook').create({ data });
|
|
24
|
+
};
|
|
25
|
+
const restoreConfigs = async (strapi, config) => {
|
|
26
|
+
if (config.type === 'core-store') {
|
|
27
|
+
return restoreCoreStore(strapi, config.value);
|
|
28
|
+
}
|
|
29
|
+
if (config.type === 'webhook') {
|
|
30
|
+
return restoreWebhooks(strapi, config.value);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
exports.restoreConfigs = restoreConfigs;
|
|
34
|
+
const createConfigurationWriteStream = async (strapi, transaction) => {
|
|
35
|
+
return new stream_1.Writable({
|
|
36
|
+
objectMode: true,
|
|
37
|
+
async write(config, _encoding, callback) {
|
|
38
|
+
await transaction?.attach(async () => {
|
|
39
|
+
try {
|
|
40
|
+
await (0, exports.restoreConfigs)(strapi, config);
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
return callback(new providers_1.ProviderTransferError(`Failed to import ${chalk_1.default.yellowBright(config.type)} (${chalk_1.default.greenBright(config.value.id)}`));
|
|
44
|
+
}
|
|
45
|
+
callback();
|
|
46
|
+
});
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
exports.createConfigurationWriteStream = createConfigurationWriteStream;
|
|
51
|
+
//# sourceMappingURL=configuration.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { SchemaUID } from '@strapi/strapi/lib/types/utils';
|
|
3
|
+
import { Writable } from 'stream';
|
|
4
|
+
import type { Transaction } from '../../../../../../types';
|
|
5
|
+
interface IEntitiesRestoreStreamOptions {
|
|
6
|
+
strapi: Strapi.Strapi;
|
|
7
|
+
updateMappingTable<T extends SchemaUID | string>(type: T, oldID: number, newID: number): void;
|
|
8
|
+
transaction?: Transaction;
|
|
9
|
+
}
|
|
10
|
+
declare const createEntitiesWriteStream: (options: IEntitiesRestoreStreamOptions) => Writable;
|
|
11
|
+
export { createEntitiesWriteStream };
|
|
@@ -0,0 +1,103 @@
|
|
|
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 providers_1 = require("../../../../../errors/providers");
|
|
30
|
+
const utils_1 = require("../../../../../utils");
|
|
31
|
+
const queries = __importStar(require("../../../../queries"));
|
|
32
|
+
const createEntitiesWriteStream = (options) => {
|
|
33
|
+
const { strapi, updateMappingTable, transaction } = options;
|
|
34
|
+
const query = queries.entity.createEntityQuery(strapi);
|
|
35
|
+
return new stream_1.Writable({
|
|
36
|
+
objectMode: true,
|
|
37
|
+
async write(entity, _encoding, callback) {
|
|
38
|
+
await transaction?.attach(async () => {
|
|
39
|
+
const { type, id, data } = entity;
|
|
40
|
+
const { create, getDeepPopulateComponentLikeQuery } = query(type);
|
|
41
|
+
const contentType = strapi.getModel(type);
|
|
42
|
+
/**
|
|
43
|
+
* Resolve the component UID of an entity's attribute based
|
|
44
|
+
* on a given path (components & dynamic zones only)
|
|
45
|
+
*/
|
|
46
|
+
const resolveType = (paths) => {
|
|
47
|
+
let cType = contentType;
|
|
48
|
+
let value = data;
|
|
49
|
+
for (const path of paths) {
|
|
50
|
+
value = (0, fp_1.get)(path, value);
|
|
51
|
+
// Needed when the value of cType should be computed
|
|
52
|
+
// based on the next value (eg: dynamic zones)
|
|
53
|
+
if (typeof cType === 'function') {
|
|
54
|
+
cType = cType(value);
|
|
55
|
+
}
|
|
56
|
+
if (path in cType.attributes) {
|
|
57
|
+
const attribute = cType.attributes[path];
|
|
58
|
+
if (attribute.type === 'component') {
|
|
59
|
+
cType = strapi.getModel(attribute.component);
|
|
60
|
+
}
|
|
61
|
+
if (attribute.type === 'dynamiczone') {
|
|
62
|
+
cType = ({ __component }) => strapi.getModel(__component);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return cType?.uid;
|
|
67
|
+
};
|
|
68
|
+
try {
|
|
69
|
+
const created = await create({
|
|
70
|
+
data,
|
|
71
|
+
populate: getDeepPopulateComponentLikeQuery(contentType, { select: 'id' }),
|
|
72
|
+
select: 'id',
|
|
73
|
+
});
|
|
74
|
+
// Compute differences between original & new entities
|
|
75
|
+
const diffs = utils_1.json.diff(data, created);
|
|
76
|
+
updateMappingTable(type, id, created.id);
|
|
77
|
+
// For each difference found on an ID attribute,
|
|
78
|
+
// update the mapping the table accordingly
|
|
79
|
+
diffs.forEach((diff) => {
|
|
80
|
+
if (diff.kind === 'modified' && (0, fp_1.last)(diff.path) === 'id') {
|
|
81
|
+
const target = resolveType(diff.path);
|
|
82
|
+
// If no type is found for the given path, then ignore the diff
|
|
83
|
+
if (!target) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const [oldID, newID] = diff.values;
|
|
87
|
+
updateMappingTable(target, oldID, newID);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
catch (e) {
|
|
92
|
+
if (e instanceof Error) {
|
|
93
|
+
return callback(e);
|
|
94
|
+
}
|
|
95
|
+
return callback(new providers_1.ProviderTransferError(`Failed to create "${type}" (${id})`));
|
|
96
|
+
}
|
|
97
|
+
return callback(null);
|
|
98
|
+
});
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
exports.createEntitiesWriteStream = createEntitiesWriteStream;
|
|
103
|
+
//# 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,107 @@
|
|
|
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 providers_1 = require("../../../../../errors/providers");
|
|
31
|
+
const queries = __importStar(require("../../../../queries"));
|
|
32
|
+
const deleteRecords = async (strapi, options) => {
|
|
33
|
+
const entities = await deleteEntitiesRecord(strapi, options);
|
|
34
|
+
const configuration = await deleteConfigurationRecords(strapi, options);
|
|
35
|
+
return {
|
|
36
|
+
count: entities.count + configuration.count,
|
|
37
|
+
entities,
|
|
38
|
+
configuration,
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
exports.deleteRecords = deleteRecords;
|
|
42
|
+
const deleteEntitiesRecord = async (strapi, options = {}) => {
|
|
43
|
+
const { entities } = options;
|
|
44
|
+
const query = queries.entity.createEntityQuery(strapi);
|
|
45
|
+
const contentTypes = Object.values(strapi.contentTypes);
|
|
46
|
+
const contentTypesToClear = contentTypes.filter((contentType) => {
|
|
47
|
+
let keep = true;
|
|
48
|
+
if (entities?.include) {
|
|
49
|
+
keep = entities.include.includes(contentType.uid);
|
|
50
|
+
}
|
|
51
|
+
if (entities?.exclude) {
|
|
52
|
+
keep = !entities.exclude.includes(contentType.uid);
|
|
53
|
+
}
|
|
54
|
+
if (entities?.filters) {
|
|
55
|
+
keep = entities.filters.every((filter) => filter(contentType));
|
|
56
|
+
}
|
|
57
|
+
return keep;
|
|
58
|
+
});
|
|
59
|
+
const [results, updateResults] = useResults(contentTypesToClear.map((contentType) => contentType.uid));
|
|
60
|
+
const deletePromises = contentTypesToClear.map(async (contentType) => {
|
|
61
|
+
const result = await query(contentType.uid).deleteMany(entities?.params);
|
|
62
|
+
if (result) {
|
|
63
|
+
updateResults(result.count || 0, contentType.uid);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
await Promise.all(deletePromises);
|
|
67
|
+
return results;
|
|
68
|
+
};
|
|
69
|
+
const deleteConfigurationRecords = async (strapi, options = {}) => {
|
|
70
|
+
const { coreStore = true, webhook = true } = options?.configuration ?? {};
|
|
71
|
+
const models = [];
|
|
72
|
+
if (coreStore) {
|
|
73
|
+
models.push('strapi::core-store');
|
|
74
|
+
}
|
|
75
|
+
if (webhook) {
|
|
76
|
+
models.push('webhook');
|
|
77
|
+
}
|
|
78
|
+
const [results, updateResults] = useResults(models);
|
|
79
|
+
const deletePromises = models.map(async (uid) => {
|
|
80
|
+
const result = await strapi.db.query(uid).deleteMany({});
|
|
81
|
+
if (result) {
|
|
82
|
+
updateResults(result.count, uid);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
await Promise.all(deletePromises);
|
|
86
|
+
return results;
|
|
87
|
+
};
|
|
88
|
+
const useResults = (keys) => {
|
|
89
|
+
const results = {
|
|
90
|
+
count: 0,
|
|
91
|
+
aggregate: keys.reduce((acc, key) => ({ ...acc, [key]: { count: 0 } }), {}),
|
|
92
|
+
};
|
|
93
|
+
const update = (count, key) => {
|
|
94
|
+
if (key) {
|
|
95
|
+
if (!(key in results.aggregate)) {
|
|
96
|
+
throw new providers_1.ProviderTransferError(`Unknown key "${key}" provided in results update`);
|
|
97
|
+
}
|
|
98
|
+
results.aggregate[key].count += count;
|
|
99
|
+
}
|
|
100
|
+
results.count += count;
|
|
101
|
+
};
|
|
102
|
+
return [results, update];
|
|
103
|
+
};
|
|
104
|
+
__exportStar(require("./entities"), exports);
|
|
105
|
+
__exportStar(require("./configuration"), exports);
|
|
106
|
+
__exportStar(require("./links"), exports);
|
|
107
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Writable } from 'stream';
|
|
3
|
+
import { Transaction } from '../../../../../../types';
|
|
4
|
+
export declare const createLinksWriteStream: (mapID: (uid: string, id: number) => number | undefined, strapi: Strapi.Strapi, transaction?: Transaction | undefined) => Writable;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createLinksWriteStream = void 0;
|
|
4
|
+
const stream_1 = require("stream");
|
|
5
|
+
const providers_1 = require("../../../../../errors/providers");
|
|
6
|
+
const link_1 = require("../../../../queries/link");
|
|
7
|
+
const createLinksWriteStream = (mapID, strapi, transaction) => {
|
|
8
|
+
return new stream_1.Writable({
|
|
9
|
+
objectMode: true,
|
|
10
|
+
async write(link, _encoding, callback) {
|
|
11
|
+
await transaction?.attach(async (trx) => {
|
|
12
|
+
const { left, right } = link;
|
|
13
|
+
const query = (0, link_1.createLinkQuery)(strapi, trx);
|
|
14
|
+
// Map IDs if needed
|
|
15
|
+
left.ref = mapID(left.type, left.ref) ?? left.ref;
|
|
16
|
+
right.ref = mapID(right.type, right.ref) ?? right.ref;
|
|
17
|
+
try {
|
|
18
|
+
await query().insert(link);
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
if (e instanceof Error) {
|
|
22
|
+
return callback(e);
|
|
23
|
+
}
|
|
24
|
+
return callback(new providers_1.ProviderTransferError(`An error happened while trying to import a ${left.type} link.`));
|
|
25
|
+
}
|
|
26
|
+
callback(null);
|
|
27
|
+
});
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
exports.createLinksWriteStream = createLinksWriteStream;
|
|
32
|
+
//# sourceMappingURL=links.js.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createAssetsStream = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const fs_extra_1 = require("fs-extra");
|
|
6
|
+
const stream_1 = require("stream");
|
|
7
|
+
const IGNORED_FILES = ['.gitkeep'];
|
|
8
|
+
/**
|
|
9
|
+
* Generate and consume assets streams in order to stream each file individually
|
|
10
|
+
*/
|
|
11
|
+
const createAssetsStream = (strapi) => {
|
|
12
|
+
const assetsDirectory = (0, path_1.join)(strapi.dirs.static.public, 'uploads');
|
|
13
|
+
const generator = async function* () {
|
|
14
|
+
const files = await (0, fs_extra_1.readdir)(assetsDirectory);
|
|
15
|
+
const validFiles = files.filter((file) => !IGNORED_FILES.includes(file));
|
|
16
|
+
for (const filename of validFiles) {
|
|
17
|
+
const filepath = (0, path_1.join)(assetsDirectory, filename);
|
|
18
|
+
const stats = await (0, fs_extra_1.stat)(filepath);
|
|
19
|
+
const stream = (0, fs_extra_1.createReadStream)(filepath);
|
|
20
|
+
yield {
|
|
21
|
+
filename,
|
|
22
|
+
filepath,
|
|
23
|
+
stream,
|
|
24
|
+
stats: { size: stats.size },
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
return stream_1.Duplex.from(generator());
|
|
29
|
+
};
|
|
30
|
+
exports.createAssetsStream = createAssetsStream;
|
|
31
|
+
//# sourceMappingURL=assets.js.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createConfigurationStream = void 0;
|
|
4
|
+
const stream_chain_1 = require("stream-chain");
|
|
5
|
+
const stream_1 = require("stream");
|
|
6
|
+
const fp_1 = require("lodash/fp");
|
|
7
|
+
/**
|
|
8
|
+
* Create a readable stream that export the Strapi app configuration
|
|
9
|
+
*/
|
|
10
|
+
const createConfigurationStream = (strapi) => {
|
|
11
|
+
return stream_1.Readable.from((async function* configurationGenerator() {
|
|
12
|
+
// Core Store
|
|
13
|
+
const coreStoreStream = (0, stream_chain_1.chain)([
|
|
14
|
+
strapi.db.queryBuilder('strapi::core-store').stream(),
|
|
15
|
+
(data) => (0, fp_1.set)('value', JSON.parse(data.value), data),
|
|
16
|
+
wrapConfigurationItem('core-store'),
|
|
17
|
+
]);
|
|
18
|
+
// Webhook
|
|
19
|
+
const webhooksStream = (0, stream_chain_1.chain)([
|
|
20
|
+
strapi.db.queryBuilder('webhook').stream(),
|
|
21
|
+
wrapConfigurationItem('webhook'),
|
|
22
|
+
]);
|
|
23
|
+
const streams = [coreStoreStream, webhooksStream];
|
|
24
|
+
for (const stream of streams) {
|
|
25
|
+
for await (const item of stream) {
|
|
26
|
+
yield item;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
})());
|
|
30
|
+
};
|
|
31
|
+
exports.createConfigurationStream = createConfigurationStream;
|
|
32
|
+
const wrapConfigurationItem = (type) => (value) => ({
|
|
33
|
+
type,
|
|
34
|
+
value,
|
|
35
|
+
});
|
|
36
|
+
//# sourceMappingURL=configuration.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Readable, PassThrough } from 'stream';
|
|
2
|
+
/**
|
|
3
|
+
* Generate and consume content-types streams in order to stream each entity individually
|
|
4
|
+
*/
|
|
5
|
+
export declare const createEntitiesStream: (strapi: Strapi.Strapi) => Readable;
|
|
6
|
+
/**
|
|
7
|
+
* Create an entity transform stream which convert the output of
|
|
8
|
+
* the multi-content-types stream to the transfer entity format
|
|
9
|
+
*/
|
|
10
|
+
export declare const createEntitiesTransformStream: () => PassThrough;
|
|
@@ -0,0 +1,85 @@
|
|
|
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.createEntitiesTransformStream = exports.createEntitiesStream = void 0;
|
|
27
|
+
const stream_1 = require("stream");
|
|
28
|
+
const shared = __importStar(require("../../queries"));
|
|
29
|
+
/**
|
|
30
|
+
* Generate and consume content-types streams in order to stream each entity individually
|
|
31
|
+
*/
|
|
32
|
+
const createEntitiesStream = (strapi) => {
|
|
33
|
+
const contentTypes = Object.values(strapi.contentTypes);
|
|
34
|
+
async function* contentTypeStreamGenerator() {
|
|
35
|
+
for (const contentType of contentTypes) {
|
|
36
|
+
const query = shared.entity.createEntityQuery(strapi).call(null, contentType.uid);
|
|
37
|
+
const stream = strapi.db
|
|
38
|
+
// Create a query builder instance (default type is 'select')
|
|
39
|
+
.queryBuilder(contentType.uid)
|
|
40
|
+
// Fetch all columns
|
|
41
|
+
.select('*')
|
|
42
|
+
// Apply the populate
|
|
43
|
+
.populate(query.deepPopulateComponentLikeQuery)
|
|
44
|
+
// Get a readable stream
|
|
45
|
+
.stream();
|
|
46
|
+
yield { contentType, stream };
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return stream_1.Readable.from((async function* entitiesGenerator() {
|
|
50
|
+
for await (const { stream, contentType } of contentTypeStreamGenerator()) {
|
|
51
|
+
try {
|
|
52
|
+
for await (const entity of stream) {
|
|
53
|
+
yield { entity, contentType };
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
// ignore
|
|
58
|
+
}
|
|
59
|
+
finally {
|
|
60
|
+
stream.destroy();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
})());
|
|
64
|
+
};
|
|
65
|
+
exports.createEntitiesStream = createEntitiesStream;
|
|
66
|
+
/**
|
|
67
|
+
* Create an entity transform stream which convert the output of
|
|
68
|
+
* the multi-content-types stream to the transfer entity format
|
|
69
|
+
*/
|
|
70
|
+
const createEntitiesTransformStream = () => {
|
|
71
|
+
return new stream_1.PassThrough({
|
|
72
|
+
objectMode: true,
|
|
73
|
+
transform(data, _encoding, callback) {
|
|
74
|
+
const { entity, contentType } = data;
|
|
75
|
+
const { id, ...attributes } = entity;
|
|
76
|
+
callback(null, {
|
|
77
|
+
type: contentType.uid,
|
|
78
|
+
id,
|
|
79
|
+
data: attributes,
|
|
80
|
+
});
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
exports.createEntitiesTransformStream = createEntitiesTransformStream;
|
|
85
|
+
//# sourceMappingURL=entities.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="lodash" />
|
|
3
|
+
import { Readable } from 'stream';
|
|
4
|
+
import type { IMetadata, ISourceProvider, ProviderType } from '../../../../types';
|
|
5
|
+
export interface ILocalStrapiSourceProviderOptions {
|
|
6
|
+
getStrapi(): Strapi.Strapi | Promise<Strapi.Strapi>;
|
|
7
|
+
autoDestroy?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare const createLocalStrapiSourceProvider: (options: ILocalStrapiSourceProviderOptions) => LocalStrapiSourceProvider;
|
|
10
|
+
declare class LocalStrapiSourceProvider implements ISourceProvider {
|
|
11
|
+
name: string;
|
|
12
|
+
type: ProviderType;
|
|
13
|
+
options: ILocalStrapiSourceProviderOptions;
|
|
14
|
+
strapi?: Strapi.Strapi;
|
|
15
|
+
constructor(options: ILocalStrapiSourceProviderOptions);
|
|
16
|
+
bootstrap(): Promise<void>;
|
|
17
|
+
close(): Promise<void>;
|
|
18
|
+
getMetadata(): IMetadata;
|
|
19
|
+
createEntitiesReadStream(): Promise<Readable>;
|
|
20
|
+
createLinksReadStream(): Readable;
|
|
21
|
+
createConfigurationReadStream(): Readable;
|
|
22
|
+
getSchemas(): import("lodash").Dictionary<Partial<import("@strapi/strapi").Schema>>;
|
|
23
|
+
createSchemasReadStream(): Readable;
|
|
24
|
+
createAssetsReadStream(): Readable;
|
|
25
|
+
}
|
|
26
|
+
export declare type ILocalStrapiSourceProvider = InstanceType<typeof LocalStrapiSourceProvider>;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,98 @@
|
|
|
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.createLocalStrapiSourceProvider = void 0;
|
|
27
|
+
const stream_chain_1 = require("stream-chain");
|
|
28
|
+
const stream_1 = require("stream");
|
|
29
|
+
const entities_1 = require("./entities");
|
|
30
|
+
const links_1 = require("./links");
|
|
31
|
+
const configuration_1 = require("./configuration");
|
|
32
|
+
const assets_1 = require("./assets");
|
|
33
|
+
const utils = __importStar(require("../../../utils"));
|
|
34
|
+
const providers_1 = require("../../../utils/providers");
|
|
35
|
+
const createLocalStrapiSourceProvider = (options) => {
|
|
36
|
+
return new LocalStrapiSourceProvider(options);
|
|
37
|
+
};
|
|
38
|
+
exports.createLocalStrapiSourceProvider = createLocalStrapiSourceProvider;
|
|
39
|
+
class LocalStrapiSourceProvider {
|
|
40
|
+
constructor(options) {
|
|
41
|
+
this.name = 'source::local-strapi';
|
|
42
|
+
this.type = 'source';
|
|
43
|
+
this.options = options;
|
|
44
|
+
}
|
|
45
|
+
async bootstrap() {
|
|
46
|
+
this.strapi = await this.options.getStrapi();
|
|
47
|
+
}
|
|
48
|
+
async close() {
|
|
49
|
+
const { autoDestroy } = this.options;
|
|
50
|
+
// Basically `!== false` but more deterministic
|
|
51
|
+
if (autoDestroy === undefined || autoDestroy === true) {
|
|
52
|
+
await this.strapi?.destroy();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
getMetadata() {
|
|
56
|
+
const strapiVersion = strapi.config.get('info.strapi');
|
|
57
|
+
const createdAt = new Date().toISOString();
|
|
58
|
+
return {
|
|
59
|
+
createdAt,
|
|
60
|
+
strapi: {
|
|
61
|
+
version: strapiVersion,
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
async createEntitiesReadStream() {
|
|
66
|
+
(0, providers_1.assertValidStrapi)(this.strapi, 'Not able to stream entities');
|
|
67
|
+
return (0, stream_chain_1.chain)([
|
|
68
|
+
// Entities stream
|
|
69
|
+
(0, entities_1.createEntitiesStream)(this.strapi),
|
|
70
|
+
// Transform stream
|
|
71
|
+
(0, entities_1.createEntitiesTransformStream)(),
|
|
72
|
+
]);
|
|
73
|
+
}
|
|
74
|
+
createLinksReadStream() {
|
|
75
|
+
(0, providers_1.assertValidStrapi)(this.strapi, 'Not able to stream links');
|
|
76
|
+
return (0, links_1.createLinksStream)(this.strapi);
|
|
77
|
+
}
|
|
78
|
+
createConfigurationReadStream() {
|
|
79
|
+
(0, providers_1.assertValidStrapi)(this.strapi, 'Not able to stream configuration');
|
|
80
|
+
return (0, configuration_1.createConfigurationStream)(strapi);
|
|
81
|
+
}
|
|
82
|
+
getSchemas() {
|
|
83
|
+
(0, providers_1.assertValidStrapi)(this.strapi, 'Not able to get Schemas');
|
|
84
|
+
const schemas = {
|
|
85
|
+
...this.strapi.contentTypes,
|
|
86
|
+
...this.strapi.components,
|
|
87
|
+
};
|
|
88
|
+
return utils.schema.mapSchemasValues(schemas);
|
|
89
|
+
}
|
|
90
|
+
createSchemasReadStream() {
|
|
91
|
+
return stream_1.Readable.from(Object.values(this.getSchemas()));
|
|
92
|
+
}
|
|
93
|
+
createAssetsReadStream() {
|
|
94
|
+
(0, providers_1.assertValidStrapi)(this.strapi, 'Not able to stream assets');
|
|
95
|
+
return (0, assets_1.createAssetsStream)(this.strapi);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=index.js.map
|