@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
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { RelationsType } from '@strapi/strapi';
|
|
2
|
-
import type { ILink } from '../../../../types';
|
|
3
|
-
/**
|
|
4
|
-
* Parse every links from an entity result (including nested components and dynamic zone levels)
|
|
5
|
-
*/
|
|
6
|
-
export declare const parseEntityLinks: (entity: any, populate: any, schema: any, strapi: any) => any[];
|
|
7
|
-
/**
|
|
8
|
-
* Parse links contained in a relational attribute
|
|
9
|
-
*/
|
|
10
|
-
export declare const parseRelationLinks: ({ entity, schema, fieldName, value }: any) => ILink[];
|
|
11
|
-
/**
|
|
12
|
-
* Get a deep populate query for a given schema
|
|
13
|
-
* It will populate first level for relations and media as well as
|
|
14
|
-
* first-level relations for nested components and dynamic zones' components
|
|
15
|
-
*/
|
|
16
|
-
export declare const getDeepPopulateQuery: (schema: any, strapi: any) => {
|
|
17
|
-
[key: string]: any;
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* Domain util to create a link
|
|
21
|
-
* TODO: Move that to the domain layer when we'll update it
|
|
22
|
-
*/
|
|
23
|
-
export declare const linkBuilder: <T extends ILink = ILink>(kind: T["kind"], relation: RelationsType) => {
|
|
24
|
-
left(type: string, ref: string | number, field: string, pos?: number | undefined): any;
|
|
25
|
-
right(type: string, ref: string | number, field?: string | undefined): any;
|
|
26
|
-
readonly value: ILink | null;
|
|
27
|
-
};
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.linkBuilder = exports.getDeepPopulateQuery = exports.parseRelationLinks = exports.parseEntityLinks = void 0;
|
|
4
|
-
const fp_1 = require("lodash/fp");
|
|
5
|
-
// TODO: Fix any typings when we'll have better Strapi types
|
|
6
|
-
/**
|
|
7
|
-
* Parse every links from an entity result (including nested components and dynamic zone levels)
|
|
8
|
-
*/
|
|
9
|
-
const parseEntityLinks = (entity, populate, schema, strapi) => {
|
|
10
|
-
if (!entity) {
|
|
11
|
-
return [];
|
|
12
|
-
}
|
|
13
|
-
if (Array.isArray(entity)) {
|
|
14
|
-
return entity
|
|
15
|
-
.map((item) => (0, exports.parseEntityLinks)(item, populate, schema, strapi))
|
|
16
|
-
.reduce(fp_1.concat, [])
|
|
17
|
-
.flat();
|
|
18
|
-
}
|
|
19
|
-
const { attributes } = schema;
|
|
20
|
-
const links = [];
|
|
21
|
-
for (const key of Object.keys(populate)) {
|
|
22
|
-
const attribute = attributes[key];
|
|
23
|
-
const value = entity[key];
|
|
24
|
-
const subPopulate = populate[key];
|
|
25
|
-
// Ignore nil values (relations, components or dynamic zones not set)
|
|
26
|
-
if (!value) {
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
29
|
-
// Components
|
|
30
|
-
// Recurse to find relations
|
|
31
|
-
if (attribute.type === 'component') {
|
|
32
|
-
const componentSchema = strapi.components[attribute.component];
|
|
33
|
-
const componentLinks = (0, exports.parseEntityLinks)(value, subPopulate.populate, componentSchema, strapi);
|
|
34
|
-
links.push(...componentLinks);
|
|
35
|
-
}
|
|
36
|
-
// Dynamic Zones
|
|
37
|
-
// We need to extract links from each items in the DZ's components
|
|
38
|
-
if (attribute.type === 'dynamiczone') {
|
|
39
|
-
const dzLinks = value
|
|
40
|
-
.map(({ __component, ...item }) => (0, exports.parseEntityLinks)(item, subPopulate.populate, strapi.components[__component], strapi))
|
|
41
|
-
.reduce((acc, links) => acc.concat(...links), []);
|
|
42
|
-
links.push(...dzLinks);
|
|
43
|
-
}
|
|
44
|
-
// Relations
|
|
45
|
-
// If it's a regular relation, extract the links but do not recurse further
|
|
46
|
-
if (attribute.type === 'relation') {
|
|
47
|
-
const relationLinks = (0, exports.parseRelationLinks)({ entity, fieldName: key, value, schema });
|
|
48
|
-
links.push(...relationLinks);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return links;
|
|
52
|
-
};
|
|
53
|
-
exports.parseEntityLinks = parseEntityLinks;
|
|
54
|
-
/**
|
|
55
|
-
* Parse links contained in a relational attribute
|
|
56
|
-
*/
|
|
57
|
-
const parseRelationLinks = ({ entity, schema, fieldName, value }) => {
|
|
58
|
-
const attribute = schema.attributes[fieldName];
|
|
59
|
-
const { relation, target } = attribute;
|
|
60
|
-
// Handle ToMany relations
|
|
61
|
-
if (Array.isArray(value)) {
|
|
62
|
-
return (value
|
|
63
|
-
// Get links from value
|
|
64
|
-
.map((item) => (0, exports.parseRelationLinks)({ entity, schema, fieldName, value: item }))
|
|
65
|
-
// Flatten the results, to make sure we're dealing with the right data structure
|
|
66
|
-
.flat()
|
|
67
|
-
// Update the pos with the relation index in the collection
|
|
68
|
-
.map((link, i) => (0, fp_1.set)('left.pos', i, link)));
|
|
69
|
-
}
|
|
70
|
-
const isMorphRelation = relation.startsWith('morph');
|
|
71
|
-
const isCircularRelation = !isMorphRelation && target === schema.uid;
|
|
72
|
-
const kind = isMorphRelation
|
|
73
|
-
? // Polymorphic relations
|
|
74
|
-
'relation.morph'
|
|
75
|
-
: isCircularRelation
|
|
76
|
-
? // Self referencing relations
|
|
77
|
-
'relation.circular'
|
|
78
|
-
: // Regular relations
|
|
79
|
-
'relation.basic';
|
|
80
|
-
const link = (0, exports.linkBuilder)(kind, relation)
|
|
81
|
-
.left(schema.uid, entity.id, fieldName)
|
|
82
|
-
.right(target, value.id, attribute.inversedBy).value;
|
|
83
|
-
return link ? [link] : [];
|
|
84
|
-
};
|
|
85
|
-
exports.parseRelationLinks = parseRelationLinks;
|
|
86
|
-
/**
|
|
87
|
-
* Get a deep populate query for a given schema
|
|
88
|
-
* It will populate first level for relations and media as well as
|
|
89
|
-
* first-level relations for nested components and dynamic zones' components
|
|
90
|
-
*/
|
|
91
|
-
const getDeepPopulateQuery = (schema, strapi) => {
|
|
92
|
-
const populate = {};
|
|
93
|
-
for (const [key, attribute] of Object.entries(schema.attributes)) {
|
|
94
|
-
const setPopulateKey = (value) => {
|
|
95
|
-
populate[key] = value;
|
|
96
|
-
};
|
|
97
|
-
// Owning side of a relation
|
|
98
|
-
if (attribute.type === 'relation' && !attribute.mappedBy) {
|
|
99
|
-
setPopulateKey({ fields: ['id'] });
|
|
100
|
-
}
|
|
101
|
-
// Media
|
|
102
|
-
if (attribute.type === 'media') {
|
|
103
|
-
setPopulateKey({ fields: ['id'] });
|
|
104
|
-
}
|
|
105
|
-
// Dynamic zone (nested structure)
|
|
106
|
-
if (attribute.type === 'dynamiczone') {
|
|
107
|
-
const subPopulate = {};
|
|
108
|
-
for (const component of attribute.components) {
|
|
109
|
-
const componentSchema = strapi.components[component];
|
|
110
|
-
const componentPopulate = (0, exports.getDeepPopulateQuery)(componentSchema, strapi);
|
|
111
|
-
// FIXME: Same problem as when trying to populate dynamic zones,
|
|
112
|
-
// we don't have a way to discriminate components queries (which
|
|
113
|
-
// can cause issue when components share same fields name)
|
|
114
|
-
Object.assign(subPopulate, componentPopulate);
|
|
115
|
-
}
|
|
116
|
-
if (!(0, fp_1.isEmpty)(subPopulate)) {
|
|
117
|
-
setPopulateKey({ fields: ['id'], populate: subPopulate });
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
// Component (nested structure)
|
|
121
|
-
if (attribute.type === 'component') {
|
|
122
|
-
const componentSchema = strapi.components[attribute.component];
|
|
123
|
-
const componentPopulate = (0, exports.getDeepPopulateQuery)(componentSchema, strapi);
|
|
124
|
-
if (!(0, fp_1.isEmpty)(componentPopulate)) {
|
|
125
|
-
setPopulateKey({ fields: ['id'], populate: componentPopulate });
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
return populate;
|
|
130
|
-
};
|
|
131
|
-
exports.getDeepPopulateQuery = getDeepPopulateQuery;
|
|
132
|
-
/**
|
|
133
|
-
* Domain util to create a link
|
|
134
|
-
* TODO: Move that to the domain layer when we'll update it
|
|
135
|
-
*/
|
|
136
|
-
const linkBuilder = (kind, relation) => {
|
|
137
|
-
const link = {};
|
|
138
|
-
link.kind = kind;
|
|
139
|
-
link.relation = relation;
|
|
140
|
-
return {
|
|
141
|
-
left(type, ref, field, pos) {
|
|
142
|
-
link.left = { type, ref, field, pos };
|
|
143
|
-
return this;
|
|
144
|
-
},
|
|
145
|
-
right(type, ref, field) {
|
|
146
|
-
link.right = { type, ref, field };
|
|
147
|
-
return this;
|
|
148
|
-
},
|
|
149
|
-
get value() {
|
|
150
|
-
return link.left && link.right ? link : null;
|
|
151
|
-
},
|
|
152
|
-
};
|
|
153
|
-
};
|
|
154
|
-
exports.linkBuilder = linkBuilder;
|
|
155
|
-
//# sourceMappingURL=utils.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { Diff } from '../../types';
|
|
2
|
-
declare const strategies: {
|
|
3
|
-
exact: (diffs: Diff[]) => Diff[];
|
|
4
|
-
strict: (diffs: Diff[]) => Diff[];
|
|
5
|
-
};
|
|
6
|
-
declare const compareSchemas: <T, P>(a: T, b: P, strategy: keyof typeof strategies) => Diff[];
|
|
7
|
-
export default compareSchemas;
|
package/dist/strategies/index.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const utils_1 = require("../utils");
|
|
4
|
-
const strategies = {
|
|
5
|
-
// No diffs
|
|
6
|
-
exact: (diffs) => {
|
|
7
|
-
return diffs;
|
|
8
|
-
},
|
|
9
|
-
// Diffs allowed on specific attributes properties
|
|
10
|
-
strict: (diffs) => {
|
|
11
|
-
const isIgnorableDiff = ({ path }) => {
|
|
12
|
-
return (path.length === 3 &&
|
|
13
|
-
// Root property must be attributes
|
|
14
|
-
path[0] === 'attributes' &&
|
|
15
|
-
// Need a valid string attribute name
|
|
16
|
-
typeof path[1] === 'string' &&
|
|
17
|
-
// The diff must be on ignorable attribute properties
|
|
18
|
-
['private', 'required', 'configurable'].includes(path[2]));
|
|
19
|
-
};
|
|
20
|
-
const shouldKeepDiff = (diff) => !isIgnorableDiff(diff);
|
|
21
|
-
return diffs.filter(shouldKeepDiff);
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
const compareSchemas = (a, b, strategy) => {
|
|
25
|
-
const diffs = (0, utils_1.jsonDiffs)(a, b);
|
|
26
|
-
return strategies[strategy](diffs);
|
|
27
|
-
};
|
|
28
|
-
exports.default = compareSchemas;
|
|
29
|
-
//# sourceMappingURL=index.js.map
|
package/dist/utils.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { Readable } from 'stream';
|
|
2
|
-
import type { Context, Diff } from '../types';
|
|
3
|
-
/**
|
|
4
|
-
* Collect every entity in a Readable stream
|
|
5
|
-
*/
|
|
6
|
-
export declare const collect: <T = unknown>(stream: Readable) => Promise<T[]>;
|
|
7
|
-
export declare const jsonDiffs: (a: unknown, b: unknown, ctx?: Context) => Diff[];
|
|
8
|
-
export declare const mapSchemasValues: (schemas: any) => {
|
|
9
|
-
[x: string]: Partial<any>;
|
|
10
|
-
};
|