@strapi/data-transfer 4.6.0-alpha.0 → 4.6.0-beta.1

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.
Files changed (58) hide show
  1. package/dist/encryption/decrypt.js +4 -4
  2. package/dist/encryption/encrypt.js +4 -4
  3. package/dist/engine/index.d.ts +11 -10
  4. package/dist/engine/index.js +145 -166
  5. package/dist/providers/{local-file-destination-provider.d.ts → local-file-destination-provider/index.d.ts} +9 -5
  6. package/dist/providers/{local-file-destination-provider.js → local-file-destination-provider/index.js} +54 -82
  7. package/dist/providers/local-file-destination-provider/utils.d.ts +9 -0
  8. package/dist/providers/local-file-destination-provider/utils.js +61 -0
  9. package/dist/providers/{local-file-source-provider.d.ts → local-file-source-provider/index.d.ts} +18 -22
  10. package/dist/providers/{local-file-source-provider.js → local-file-source-provider/index.js} +91 -36
  11. package/dist/providers/local-strapi-destination-provider/index.d.ts +31 -0
  12. package/dist/providers/local-strapi-destination-provider/index.js +187 -0
  13. package/dist/providers/local-strapi-destination-provider/strategies/index.d.ts +1 -0
  14. package/dist/providers/local-strapi-destination-provider/strategies/index.js +28 -0
  15. package/dist/providers/local-strapi-destination-provider/strategies/restore/configuration.d.ts +5 -0
  16. package/dist/providers/local-strapi-destination-provider/strategies/restore/configuration.js +44 -0
  17. package/dist/providers/local-strapi-destination-provider/strategies/restore/entities.d.ts +9 -0
  18. package/dist/providers/local-strapi-destination-provider/strategies/restore/entities.js +88 -0
  19. package/dist/providers/local-strapi-destination-provider/strategies/restore/index.d.ts +32 -0
  20. package/dist/providers/local-strapi-destination-provider/strategies/restore/index.js +106 -0
  21. package/dist/providers/local-strapi-destination-provider/strategies/restore/links.d.ts +3 -0
  22. package/dist/providers/local-strapi-destination-provider/strategies/restore/links.js +29 -0
  23. package/dist/providers/local-strapi-source-provider/assets.d.ts +5 -0
  24. package/dist/providers/local-strapi-source-provider/assets.js +31 -0
  25. package/dist/providers/local-strapi-source-provider/configuration.js +1 -1
  26. package/dist/providers/local-strapi-source-provider/entities.js +29 -9
  27. package/dist/providers/local-strapi-source-provider/index.d.ts +8 -7
  28. package/dist/providers/local-strapi-source-provider/index.js +32 -2
  29. package/dist/providers/local-strapi-source-provider/{links/index.d.ts → links.d.ts} +1 -1
  30. package/dist/providers/local-strapi-source-provider/links.js +23 -0
  31. package/dist/providers/shared/index.d.ts +1 -0
  32. package/dist/providers/shared/index.js +28 -0
  33. package/dist/providers/shared/strapi/entity.d.ts +19 -0
  34. package/dist/providers/shared/strapi/entity.js +130 -0
  35. package/dist/providers/shared/strapi/index.d.ts +2 -0
  36. package/dist/providers/shared/strapi/index.js +29 -0
  37. package/dist/providers/shared/strapi/link.d.ts +6 -0
  38. package/dist/providers/shared/strapi/link.js +201 -0
  39. package/dist/providers/test-utils/index.d.ts +111 -0
  40. package/dist/providers/test-utils/index.js +64 -0
  41. package/dist/strategies/index.d.ts +3 -3
  42. package/dist/strategies/index.js +27 -4
  43. package/dist/utils/index.d.ts +3 -0
  44. package/dist/utils/index.js +30 -0
  45. package/dist/utils/json.d.ts +23 -0
  46. package/dist/{utils.js → utils/json.js} +9 -38
  47. package/dist/utils/schema.d.ts +3 -0
  48. package/dist/utils/schema.js +22 -0
  49. package/dist/utils/stream.d.ts +10 -0
  50. package/dist/utils/stream.js +39 -0
  51. package/jest.config.js +3 -1
  52. package/package.json +4 -4
  53. package/dist/providers/local-strapi-destination-provider.d.ts +0 -22
  54. package/dist/providers/local-strapi-destination-provider.js +0 -78
  55. package/dist/providers/local-strapi-source-provider/links/index.js +0 -37
  56. package/dist/providers/local-strapi-source-provider/links/utils.d.ts +0 -27
  57. package/dist/providers/local-strapi-source-provider/links/utils.js +0 -155
  58. package/dist/utils.d.ts +0 -10
@@ -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
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
- };