@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,130 @@
|
|
|
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.createEntityQuery = void 0;
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
28
|
+
// @ts-ignore
|
|
29
|
+
const componentsService = __importStar(require("@strapi/strapi/lib/services/entity-service/components"));
|
|
30
|
+
const fp_1 = require("lodash/fp");
|
|
31
|
+
const sanitizeComponentLikeAttributes = (model, data) => {
|
|
32
|
+
const { attributes } = model;
|
|
33
|
+
const componentLikeAttributesKey = Object.entries(attributes)
|
|
34
|
+
.filter(([, attribute]) => ['component', 'dynamiczone'].includes(attribute.type))
|
|
35
|
+
.map(([key]) => key);
|
|
36
|
+
return (0, fp_1.omit)(componentLikeAttributesKey, data);
|
|
37
|
+
};
|
|
38
|
+
const omitInvalidCreationAttributes = (0, fp_1.omit)(['id']);
|
|
39
|
+
const createEntityQuery = (strapi) => {
|
|
40
|
+
const components = {
|
|
41
|
+
async assignToEntity(uid, data) {
|
|
42
|
+
const model = strapi.getModel(uid);
|
|
43
|
+
const entityComponents = await componentsService.createComponents(uid, data);
|
|
44
|
+
const dataWithoutComponents = sanitizeComponentLikeAttributes(model, data);
|
|
45
|
+
return (0, fp_1.assign)(entityComponents, dataWithoutComponents);
|
|
46
|
+
},
|
|
47
|
+
async get(uid, entity) {
|
|
48
|
+
return componentsService.getComponents(uid, entity);
|
|
49
|
+
},
|
|
50
|
+
delete(uid, componentsToDelete) {
|
|
51
|
+
return componentsService.deleteComponents(uid, componentsToDelete, { loadComponents: false });
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
const query = (uid) => {
|
|
55
|
+
const create = async (params) => {
|
|
56
|
+
const dataWithComponents = await components.assignToEntity(uid, params.data);
|
|
57
|
+
const sanitizedData = omitInvalidCreationAttributes(dataWithComponents);
|
|
58
|
+
return strapi.db.query(uid).create({ ...params, data: sanitizedData });
|
|
59
|
+
};
|
|
60
|
+
const createMany = async (params) => {
|
|
61
|
+
return (Promise.resolve(params.data)
|
|
62
|
+
// Create components for each entity
|
|
63
|
+
.then((0, fp_1.map)((data) => components.assignToEntity(uid, data)))
|
|
64
|
+
// Remove unwanted attributes
|
|
65
|
+
.then((0, fp_1.map)(omitInvalidCreationAttributes))
|
|
66
|
+
// Execute a strapi db createMany query with all the entities + their created components
|
|
67
|
+
.then((data) => strapi.db.query(uid).createMany({ ...params, data })));
|
|
68
|
+
};
|
|
69
|
+
const deleteMany = async (params) => {
|
|
70
|
+
const entitiesToDelete = await strapi.db.query(uid).findMany(params ?? {});
|
|
71
|
+
if (!entitiesToDelete.length) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
const componentsToDelete = await Promise.all(entitiesToDelete.map((entityToDelete) => components.get(uid, entityToDelete)));
|
|
75
|
+
const deletedEntities = await strapi.db.query(uid).deleteMany(params);
|
|
76
|
+
await Promise.all(componentsToDelete.map((compos) => components.delete(uid, compos)));
|
|
77
|
+
return deletedEntities;
|
|
78
|
+
};
|
|
79
|
+
const getDeepPopulateComponentLikeQuery = (contentType, params = { select: '*' }) => {
|
|
80
|
+
const { attributes } = contentType;
|
|
81
|
+
const populate = {};
|
|
82
|
+
const entries = Object.entries(attributes);
|
|
83
|
+
for (const [key, attribute] of entries) {
|
|
84
|
+
if (attribute.type === 'component') {
|
|
85
|
+
const component = strapi.getModel(attribute.component);
|
|
86
|
+
const subPopulate = getDeepPopulateComponentLikeQuery(component, params);
|
|
87
|
+
if (((0, fp_1.isArray)(subPopulate) || (0, fp_1.isObject)(subPopulate)) && (0, fp_1.size)(subPopulate) > 0) {
|
|
88
|
+
populate[key] = { ...params, populate: subPopulate };
|
|
89
|
+
}
|
|
90
|
+
if ((0, fp_1.isArray)(subPopulate) && (0, fp_1.isEmpty)(subPopulate)) {
|
|
91
|
+
populate[key] = { ...params };
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (attribute.type === 'dynamiczone') {
|
|
95
|
+
const { components: componentsUID } = attribute;
|
|
96
|
+
const on = {};
|
|
97
|
+
for (const componentUID of componentsUID) {
|
|
98
|
+
const component = strapi.getModel(componentUID);
|
|
99
|
+
const subPopulate = getDeepPopulateComponentLikeQuery(component, params);
|
|
100
|
+
if (((0, fp_1.isArray)(subPopulate) || (0, fp_1.isObject)(subPopulate)) && (0, fp_1.size)(subPopulate) > 0) {
|
|
101
|
+
on[componentUID] = { ...params, populate: subPopulate };
|
|
102
|
+
}
|
|
103
|
+
if ((0, fp_1.isArray)(subPopulate) && (0, fp_1.isEmpty)(subPopulate)) {
|
|
104
|
+
on[componentUID] = { ...params };
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
populate[key] = (0, fp_1.size)(on) > 0 ? { on } : true;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const values = Object.values(populate);
|
|
111
|
+
if (values.every((value) => value === true)) {
|
|
112
|
+
return Object.keys(populate);
|
|
113
|
+
}
|
|
114
|
+
return populate;
|
|
115
|
+
};
|
|
116
|
+
return {
|
|
117
|
+
create,
|
|
118
|
+
createMany,
|
|
119
|
+
deleteMany,
|
|
120
|
+
getDeepPopulateComponentLikeQuery,
|
|
121
|
+
get deepPopulateComponentLikeQuery() {
|
|
122
|
+
const contentType = strapi.getModel(uid);
|
|
123
|
+
return getDeepPopulateComponentLikeQuery(contentType);
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
return query;
|
|
128
|
+
};
|
|
129
|
+
exports.createEntityQuery = createEntityQuery;
|
|
130
|
+
//# sourceMappingURL=entity.js.map
|
|
@@ -0,0 +1,29 @@
|
|
|
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.link = exports.entity = void 0;
|
|
27
|
+
exports.entity = __importStar(require("./entity"));
|
|
28
|
+
exports.link = __importStar(require("./link"));
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ILink } from '../../../types';
|
|
2
|
+
export declare const createLinkQuery: (strapi: Strapi.Strapi) => () => {
|
|
3
|
+
generateAll: (uid: string) => AsyncGenerator<ILink>;
|
|
4
|
+
generateAllForAttribute: (uid: string, fieldName: string) => AsyncGenerator<ILink>;
|
|
5
|
+
insert: (link: ILink) => Promise<void>;
|
|
6
|
+
};
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createLinkQuery = void 0;
|
|
4
|
+
const fp_1 = require("lodash/fp");
|
|
5
|
+
// TODO: Remove any types when we'll have types for DB metadata
|
|
6
|
+
const createLinkQuery = (strapi) => {
|
|
7
|
+
const query = () => {
|
|
8
|
+
const { connection } = strapi.db;
|
|
9
|
+
async function* generateAllForAttribute(uid, fieldName) {
|
|
10
|
+
const metadata = strapi.db.metadata.get(uid);
|
|
11
|
+
if (!metadata) {
|
|
12
|
+
throw new Error(`No metadata found for ${uid}`);
|
|
13
|
+
}
|
|
14
|
+
const attributes = filterValidRelationalAttributes(metadata.attributes);
|
|
15
|
+
if (!(fieldName in attributes)) {
|
|
16
|
+
throw new Error(`${fieldName} is not a valid relational attribute name`);
|
|
17
|
+
}
|
|
18
|
+
const attribute = attributes[fieldName];
|
|
19
|
+
const kind = getLinkKind(attribute, uid);
|
|
20
|
+
const { relation, target } = attribute;
|
|
21
|
+
// The relation is stored in the same table
|
|
22
|
+
// TODO: handle manyToOne joinColumn
|
|
23
|
+
if (attribute.joinColumn) {
|
|
24
|
+
const joinColumnName = attribute.joinColumn.name;
|
|
25
|
+
const qb = connection.queryBuilder().select('id', joinColumnName).from(metadata.tableName);
|
|
26
|
+
// TODO: stream the query to improve performances
|
|
27
|
+
const entries = await qb;
|
|
28
|
+
for (const entry of entries) {
|
|
29
|
+
const ref = entry[joinColumnName];
|
|
30
|
+
if (ref !== null) {
|
|
31
|
+
yield {
|
|
32
|
+
kind,
|
|
33
|
+
relation,
|
|
34
|
+
left: { type: uid, ref: entry.id, field: fieldName },
|
|
35
|
+
right: { type: target, ref },
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// The relation uses a join table
|
|
41
|
+
if (attribute.joinTable) {
|
|
42
|
+
const { name, joinColumn, inverseJoinColumn, orderColumnName, morphColumn, inverseOrderColumnName, } = attribute.joinTable;
|
|
43
|
+
const qb = connection.queryBuilder().from(name);
|
|
44
|
+
const columns = {
|
|
45
|
+
left: { ref: null },
|
|
46
|
+
right: { ref: null },
|
|
47
|
+
};
|
|
48
|
+
const left = { type: uid, field: fieldName };
|
|
49
|
+
const right = {};
|
|
50
|
+
if (kind === 'relation.basic' || kind === 'relation.circular') {
|
|
51
|
+
right.type = attribute.target;
|
|
52
|
+
right.field = attribute.inversedBy;
|
|
53
|
+
columns.left.ref = joinColumn.name;
|
|
54
|
+
columns.right.ref = inverseJoinColumn.name;
|
|
55
|
+
if (orderColumnName) {
|
|
56
|
+
columns.left.order = orderColumnName;
|
|
57
|
+
}
|
|
58
|
+
if (inverseOrderColumnName) {
|
|
59
|
+
columns.right.order = inverseOrderColumnName;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (kind === 'relation.morph') {
|
|
63
|
+
columns.left.ref = joinColumn.name;
|
|
64
|
+
columns.right.ref = morphColumn.idColumn.name;
|
|
65
|
+
columns.right.type = morphColumn.typeColumn.name;
|
|
66
|
+
columns.right.field = 'field';
|
|
67
|
+
columns.right.order = 'order';
|
|
68
|
+
}
|
|
69
|
+
const validColumns = [
|
|
70
|
+
// Left
|
|
71
|
+
columns.left.ref,
|
|
72
|
+
columns.left.order,
|
|
73
|
+
// Right
|
|
74
|
+
columns.right.ref,
|
|
75
|
+
columns.right.type,
|
|
76
|
+
columns.right.field,
|
|
77
|
+
columns.right.order,
|
|
78
|
+
].filter((column) => !(0, fp_1.isNil)(column));
|
|
79
|
+
qb.select(validColumns);
|
|
80
|
+
// TODO: stream the query to improve performances
|
|
81
|
+
const entries = await qb;
|
|
82
|
+
for (const entry of entries) {
|
|
83
|
+
if (columns.left.ref) {
|
|
84
|
+
left.ref = entry[columns.left.ref];
|
|
85
|
+
}
|
|
86
|
+
if (columns.right.ref) {
|
|
87
|
+
right.ref = entry[columns.right.ref];
|
|
88
|
+
}
|
|
89
|
+
if (columns.left.order) {
|
|
90
|
+
left.pos = entry[columns.left.order];
|
|
91
|
+
}
|
|
92
|
+
if (columns.right.order) {
|
|
93
|
+
right.pos = entry[columns.right.order];
|
|
94
|
+
}
|
|
95
|
+
if (columns.right.type) {
|
|
96
|
+
right.type = entry[columns.right.type];
|
|
97
|
+
}
|
|
98
|
+
if (columns.right.field) {
|
|
99
|
+
right.field = entry[columns.right.field];
|
|
100
|
+
}
|
|
101
|
+
const link = {
|
|
102
|
+
kind,
|
|
103
|
+
relation,
|
|
104
|
+
left: (0, fp_1.clone)(left),
|
|
105
|
+
right: (0, fp_1.clone)(right),
|
|
106
|
+
};
|
|
107
|
+
yield link;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
async function* generateAll(uid) {
|
|
112
|
+
const metadata = strapi.db.metadata.get(uid);
|
|
113
|
+
if (!metadata) {
|
|
114
|
+
throw new Error(`No metadata found for ${uid}`);
|
|
115
|
+
}
|
|
116
|
+
const attributes = filterValidRelationalAttributes(metadata.attributes);
|
|
117
|
+
for (const fieldName of Object.keys(attributes)) {
|
|
118
|
+
for await (const link of generateAllForAttribute(uid, fieldName)) {
|
|
119
|
+
yield link;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const insert = async (link) => {
|
|
124
|
+
const { kind, left, right } = link;
|
|
125
|
+
const metadata = strapi.db.metadata.get(left.type);
|
|
126
|
+
const attribute = metadata.attributes[left.field];
|
|
127
|
+
const payload = {};
|
|
128
|
+
if (attribute.joinColumn) {
|
|
129
|
+
const joinColumnName = attribute.joinColumn.name;
|
|
130
|
+
await connection(metadata.tableName)
|
|
131
|
+
.where('id', left.ref)
|
|
132
|
+
.update({ [joinColumnName]: right.ref });
|
|
133
|
+
}
|
|
134
|
+
if (attribute.joinTable) {
|
|
135
|
+
const { name, joinColumn, inverseJoinColumn, orderColumnName, inverseOrderColumnName, morphColumn, } = attribute.joinTable;
|
|
136
|
+
if (joinColumn) {
|
|
137
|
+
Object.assign(payload, { [joinColumn.name]: left.ref });
|
|
138
|
+
}
|
|
139
|
+
const assignInverseColumn = () => {
|
|
140
|
+
if (inverseJoinColumn) {
|
|
141
|
+
Object.assign(payload, {
|
|
142
|
+
[inverseJoinColumn.name]: right.ref,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
const assignOrderColumns = () => {
|
|
147
|
+
if (orderColumnName) {
|
|
148
|
+
Object.assign(payload, { [orderColumnName]: left.pos ?? null });
|
|
149
|
+
}
|
|
150
|
+
if (inverseOrderColumnName) {
|
|
151
|
+
Object.assign(payload, { [inverseOrderColumnName]: right.pos ?? null });
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
const assignMorphColumns = () => {
|
|
155
|
+
const { idColumn, typeColumn } = morphColumn ?? {};
|
|
156
|
+
if (idColumn) {
|
|
157
|
+
Object.assign(payload, { [idColumn.name]: right.ref });
|
|
158
|
+
}
|
|
159
|
+
if (typeColumn) {
|
|
160
|
+
Object.assign(payload, { [typeColumn.name]: right.type });
|
|
161
|
+
}
|
|
162
|
+
Object.assign(payload, { order: right.pos ?? null, field: right.field ?? null });
|
|
163
|
+
};
|
|
164
|
+
if (kind === 'relation.basic' || kind === 'relation.circular') {
|
|
165
|
+
assignInverseColumn();
|
|
166
|
+
}
|
|
167
|
+
if (kind === 'relation.morph') {
|
|
168
|
+
assignMorphColumns();
|
|
169
|
+
}
|
|
170
|
+
assignOrderColumns();
|
|
171
|
+
await connection.insert(payload).into(name);
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
return { generateAll, generateAllForAttribute, insert };
|
|
175
|
+
};
|
|
176
|
+
return query;
|
|
177
|
+
};
|
|
178
|
+
exports.createLinkQuery = createLinkQuery;
|
|
179
|
+
const filterValidRelationalAttributes = (attributes) => {
|
|
180
|
+
const isOwner = (attribute) => {
|
|
181
|
+
return attribute.owner || (!attribute.mappedBy && !attribute.morphBy);
|
|
182
|
+
};
|
|
183
|
+
const isComponentLike = (attribute) => {
|
|
184
|
+
return attribute.component || attribute.components;
|
|
185
|
+
};
|
|
186
|
+
return Object.entries(attributes)
|
|
187
|
+
.filter(([, attribute]) => {
|
|
188
|
+
return attribute.type === 'relation' && isOwner(attribute) && !isComponentLike(attribute);
|
|
189
|
+
})
|
|
190
|
+
.reduce((acc, [key, attribute]) => ({ ...acc, [key]: attribute }), {});
|
|
191
|
+
};
|
|
192
|
+
const getLinkKind = (attribute, uid) => {
|
|
193
|
+
if (attribute.relation.startsWith('morph')) {
|
|
194
|
+
return 'relation.morph';
|
|
195
|
+
}
|
|
196
|
+
if (attribute.target === uid) {
|
|
197
|
+
return 'relation.circular';
|
|
198
|
+
}
|
|
199
|
+
return 'relation.basic';
|
|
200
|
+
};
|
|
201
|
+
//# sourceMappingURL=link.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const remote_1 = require("./remote");
|
|
4
|
+
/**
|
|
5
|
+
* This is intended to be called on Strapi register phase.
|
|
6
|
+
*
|
|
7
|
+
* It registers a transfer route in the Strapi admin router.
|
|
8
|
+
*/
|
|
9
|
+
const register = (strapi) => {
|
|
10
|
+
remote_1.routes.registerAdminTransferRoute(strapi);
|
|
11
|
+
};
|
|
12
|
+
exports.default = register;
|
|
13
|
+
//# sourceMappingURL=register.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const TRANSFER_PATH = "/transfer";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './push';
|
|
@@ -14,6 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
18
|
-
__exportStar(require("./providers"), exports);
|
|
17
|
+
__exportStar(require("./push"), exports);
|
|
19
18
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Writable } from 'stream-chain';
|
|
3
|
+
import type { IMetadata } from '../../../../types';
|
|
4
|
+
import type { TransferPushMessage, TransferPushStep } from '../../../../types/remote/protocol/client';
|
|
5
|
+
import { ILocalStrapiDestinationProviderOptions } from '../../providers';
|
|
6
|
+
export interface IPushController {
|
|
7
|
+
streams: {
|
|
8
|
+
[stage in TransferPushStep]?: Writable;
|
|
9
|
+
};
|
|
10
|
+
actions: {
|
|
11
|
+
getMetadata(): Promise<IMetadata>;
|
|
12
|
+
getSchemas(): Strapi.Schemas;
|
|
13
|
+
bootstrap(): Promise<void>;
|
|
14
|
+
close(): Promise<void>;
|
|
15
|
+
beforeTransfer(): Promise<void>;
|
|
16
|
+
};
|
|
17
|
+
transfer: {
|
|
18
|
+
[key in TransferPushStep]: <T extends TransferPushMessage>(value: T extends {
|
|
19
|
+
step: key;
|
|
20
|
+
data: infer U;
|
|
21
|
+
} ? U : never) => Promise<void>;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
declare const createPushController: (options: ILocalStrapiDestinationProviderOptions) => IPushController;
|
|
25
|
+
export default createPushController;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const stream_chain_1 = require("stream-chain");
|
|
4
|
+
const providers_1 = require("../../providers");
|
|
5
|
+
const createPushController = (options) => {
|
|
6
|
+
const provider = (0, providers_1.createLocalStrapiDestinationProvider)(options);
|
|
7
|
+
const streams = {};
|
|
8
|
+
const assets = {};
|
|
9
|
+
const writeAsync = (stream, data) => {
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
11
|
+
stream.write(data, (error) => {
|
|
12
|
+
if (error) {
|
|
13
|
+
reject(error);
|
|
14
|
+
}
|
|
15
|
+
resolve();
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
return {
|
|
20
|
+
streams,
|
|
21
|
+
actions: {
|
|
22
|
+
async getSchemas() {
|
|
23
|
+
return provider.getSchemas();
|
|
24
|
+
},
|
|
25
|
+
async getMetadata() {
|
|
26
|
+
return provider.getMetadata();
|
|
27
|
+
},
|
|
28
|
+
async bootstrap() {
|
|
29
|
+
return provider.bootstrap();
|
|
30
|
+
},
|
|
31
|
+
async close() {
|
|
32
|
+
return provider.close();
|
|
33
|
+
},
|
|
34
|
+
async beforeTransfer() {
|
|
35
|
+
return provider.beforeTransfer();
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
transfer: {
|
|
39
|
+
async entities(entity) {
|
|
40
|
+
if (!streams.entities) {
|
|
41
|
+
streams.entities = provider.createEntitiesWriteStream();
|
|
42
|
+
}
|
|
43
|
+
await writeAsync(streams.entities, entity);
|
|
44
|
+
},
|
|
45
|
+
async links(link) {
|
|
46
|
+
if (!streams.links) {
|
|
47
|
+
streams.links = await provider.createLinksWriteStream();
|
|
48
|
+
}
|
|
49
|
+
await writeAsync(streams.links, link);
|
|
50
|
+
},
|
|
51
|
+
async configuration(config) {
|
|
52
|
+
if (!streams.configuration) {
|
|
53
|
+
streams.configuration = await provider.createConfigurationWriteStream();
|
|
54
|
+
}
|
|
55
|
+
await writeAsync(streams.configuration, config);
|
|
56
|
+
},
|
|
57
|
+
async assets(payload) {
|
|
58
|
+
// TODO: close the stream upong receiving an 'end' event instead
|
|
59
|
+
if (payload === null) {
|
|
60
|
+
streams.assets?.end();
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const { action, assetID } = payload;
|
|
64
|
+
if (!streams.assets) {
|
|
65
|
+
streams.assets = await provider.createAssetsWriteStream();
|
|
66
|
+
}
|
|
67
|
+
if (action === 'start') {
|
|
68
|
+
assets[assetID] = { ...payload.data, stream: new stream_chain_1.PassThrough() };
|
|
69
|
+
writeAsync(streams.assets, assets[assetID]);
|
|
70
|
+
}
|
|
71
|
+
if (action === 'stream') {
|
|
72
|
+
// The buffer has gone through JSON operations and is now of shape { type: "Buffer"; data: UInt8Array }
|
|
73
|
+
// We need to transform it back into a Buffer instance
|
|
74
|
+
const rawBuffer = payload.data;
|
|
75
|
+
const chunk = Buffer.from(rawBuffer.data);
|
|
76
|
+
await writeAsync(assets[assetID].stream, chunk);
|
|
77
|
+
}
|
|
78
|
+
if (action === 'end') {
|
|
79
|
+
await new Promise((resolve, reject) => {
|
|
80
|
+
const { stream } = assets[assetID];
|
|
81
|
+
stream
|
|
82
|
+
.on('close', () => {
|
|
83
|
+
delete assets[assetID];
|
|
84
|
+
resolve();
|
|
85
|
+
})
|
|
86
|
+
.on('error', reject)
|
|
87
|
+
.end();
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
exports.default = createPushController;
|
|
95
|
+
//# sourceMappingURL=push.js.map
|