@strapi/data-transfer 0.0.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.
- package/dist/encryption/decrypt.js +4 -4
- package/dist/encryption/encrypt.js +4 -4
- package/dist/engine/index.d.ts +11 -10
- package/dist/engine/index.js +145 -166
- package/dist/providers/{local-file-destination-provider.d.ts → local-file-destination-provider/index.d.ts} +9 -5
- package/dist/providers/{local-file-destination-provider.js → local-file-destination-provider/index.js} +54 -82
- package/dist/providers/local-file-destination-provider/utils.d.ts +9 -0
- package/dist/providers/local-file-destination-provider/utils.js +61 -0
- package/dist/providers/{local-file-source-provider.d.ts → local-file-source-provider/index.d.ts} +18 -22
- package/dist/providers/{local-file-source-provider.js → local-file-source-provider/index.js} +91 -36
- package/dist/providers/local-strapi-destination-provider/index.d.ts +31 -0
- package/dist/providers/local-strapi-destination-provider/index.js +187 -0
- package/dist/providers/local-strapi-destination-provider/strategies/index.d.ts +1 -0
- package/dist/providers/local-strapi-destination-provider/strategies/index.js +28 -0
- package/dist/providers/local-strapi-destination-provider/strategies/restore/configuration.d.ts +5 -0
- package/dist/providers/local-strapi-destination-provider/strategies/restore/configuration.js +44 -0
- package/dist/providers/local-strapi-destination-provider/strategies/restore/entities.d.ts +9 -0
- package/dist/providers/local-strapi-destination-provider/strategies/restore/entities.js +88 -0
- package/dist/providers/local-strapi-destination-provider/strategies/restore/index.d.ts +32 -0
- package/dist/providers/local-strapi-destination-provider/strategies/restore/index.js +106 -0
- package/dist/providers/local-strapi-destination-provider/strategies/restore/links.d.ts +3 -0
- package/dist/providers/local-strapi-destination-provider/strategies/restore/links.js +29 -0
- package/dist/providers/local-strapi-source-provider/assets.d.ts +5 -0
- package/dist/providers/local-strapi-source-provider/assets.js +31 -0
- package/dist/providers/local-strapi-source-provider/configuration.js +1 -1
- package/dist/providers/local-strapi-source-provider/entities.js +29 -9
- package/dist/providers/local-strapi-source-provider/index.d.ts +8 -7
- package/dist/providers/local-strapi-source-provider/index.js +32 -2
- package/dist/providers/local-strapi-source-provider/{links/index.d.ts → links.d.ts} +1 -1
- package/dist/providers/local-strapi-source-provider/links.js +23 -0
- package/dist/providers/shared/index.d.ts +1 -0
- package/dist/providers/shared/index.js +28 -0
- package/dist/providers/shared/strapi/entity.d.ts +19 -0
- package/dist/providers/shared/strapi/entity.js +130 -0
- package/dist/providers/shared/strapi/index.d.ts +2 -0
- package/dist/providers/shared/strapi/index.js +29 -0
- package/dist/providers/shared/strapi/link.d.ts +6 -0
- package/dist/providers/shared/strapi/link.js +201 -0
- package/dist/providers/test-utils/index.d.ts +111 -0
- package/dist/providers/test-utils/index.js +64 -0
- package/dist/strategies/index.d.ts +3 -3
- package/dist/strategies/index.js +27 -4
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.js +30 -0
- package/dist/utils/json.d.ts +23 -0
- package/dist/{utils.js → utils/json.js} +9 -38
- package/dist/utils/schema.d.ts +3 -0
- package/dist/utils/schema.js +22 -0
- package/dist/utils/stream.d.ts +10 -0
- package/dist/utils/stream.js +39 -0
- package/jest.config.js +3 -1
- package/package.json +5 -4
- 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/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/utils.d.ts +0 -10
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setGlobalStrapi = exports.createMockedQueryBuilder = exports.createMockedReadableFactory = exports.getContentTypes = exports.getStrapiFactory = exports.collect = void 0;
|
|
4
|
+
const stream_1 = require("stream");
|
|
5
|
+
/**
|
|
6
|
+
* Collect every entity in a Readable stream
|
|
7
|
+
*/
|
|
8
|
+
const collect = (stream) => {
|
|
9
|
+
const chunks = [];
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
11
|
+
stream
|
|
12
|
+
.on('data', (chunk) => chunks.push(chunk))
|
|
13
|
+
.on('close', () => resolve(chunks))
|
|
14
|
+
.on('error', reject);
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
exports.collect = collect;
|
|
18
|
+
/**
|
|
19
|
+
* Create a "Strapi" like object factory based on the
|
|
20
|
+
* given params and cast it to the correct type
|
|
21
|
+
*/
|
|
22
|
+
const getStrapiFactory = (properties) => () => {
|
|
23
|
+
return { ...properties };
|
|
24
|
+
};
|
|
25
|
+
exports.getStrapiFactory = getStrapiFactory;
|
|
26
|
+
/**
|
|
27
|
+
* Factory to get default content types test values
|
|
28
|
+
*/
|
|
29
|
+
const getContentTypes = () => ({
|
|
30
|
+
foo: { uid: 'foo', attributes: { title: { type: 'string' } } },
|
|
31
|
+
bar: { uid: 'bar', attributes: { age: { type: 'number' } } },
|
|
32
|
+
});
|
|
33
|
+
exports.getContentTypes = getContentTypes;
|
|
34
|
+
/**
|
|
35
|
+
* Create a factory of readable streams (wrapped with a jest mock function)
|
|
36
|
+
*/
|
|
37
|
+
const createMockedReadableFactory = (source) => jest.fn((uid) => {
|
|
38
|
+
return stream_1.Readable.from(source[uid] || []);
|
|
39
|
+
});
|
|
40
|
+
exports.createMockedReadableFactory = createMockedReadableFactory;
|
|
41
|
+
/**
|
|
42
|
+
* Create a factory of mocked query builders
|
|
43
|
+
*/
|
|
44
|
+
const createMockedQueryBuilder = (data) => jest.fn((uid) => {
|
|
45
|
+
const state = { populate: undefined };
|
|
46
|
+
return {
|
|
47
|
+
populate(populate) {
|
|
48
|
+
state.populate = populate;
|
|
49
|
+
return this;
|
|
50
|
+
},
|
|
51
|
+
stream() {
|
|
52
|
+
return stream_1.Readable.from(data[uid]);
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
});
|
|
56
|
+
exports.createMockedQueryBuilder = createMockedQueryBuilder;
|
|
57
|
+
/**
|
|
58
|
+
* Update the global store with the given strapi value
|
|
59
|
+
*/
|
|
60
|
+
const setGlobalStrapi = (strapi) => {
|
|
61
|
+
global.strapi = strapi;
|
|
62
|
+
};
|
|
63
|
+
exports.setGlobalStrapi = setGlobalStrapi;
|
|
64
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { Diff } from '
|
|
1
|
+
import type { Diff } from '../utils/json';
|
|
2
2
|
declare const strategies: {
|
|
3
|
-
exact
|
|
4
|
-
strict
|
|
3
|
+
exact(diffs: Diff[]): Diff[];
|
|
4
|
+
strict(diffs: Diff[]): Diff[];
|
|
5
5
|
};
|
|
6
6
|
declare const compareSchemas: <T, P>(a: T, b: P, strategy: keyof typeof strategies) => Diff[];
|
|
7
7
|
export default compareSchemas;
|
package/dist/strategies/index.js
CHANGED
|
@@ -1,13 +1,36 @@
|
|
|
1
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
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
26
|
+
const utils = __importStar(require("../utils"));
|
|
4
27
|
const strategies = {
|
|
5
28
|
// No diffs
|
|
6
|
-
exact
|
|
29
|
+
exact(diffs) {
|
|
7
30
|
return diffs;
|
|
8
31
|
},
|
|
9
32
|
// Diffs allowed on specific attributes properties
|
|
10
|
-
strict
|
|
33
|
+
strict(diffs) {
|
|
11
34
|
const isIgnorableDiff = ({ path }) => {
|
|
12
35
|
return (path.length === 3 &&
|
|
13
36
|
// Root property must be attributes
|
|
@@ -22,7 +45,7 @@ const strategies = {
|
|
|
22
45
|
},
|
|
23
46
|
};
|
|
24
47
|
const compareSchemas = (a, b, strategy) => {
|
|
25
|
-
const diffs =
|
|
48
|
+
const diffs = utils.json.diff(a, b);
|
|
26
49
|
return strategies[strategy](diffs);
|
|
27
50
|
};
|
|
28
51
|
exports.default = compareSchemas;
|
|
@@ -0,0 +1,30 @@
|
|
|
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.schema = exports.json = exports.stream = void 0;
|
|
27
|
+
exports.stream = __importStar(require("./stream"));
|
|
28
|
+
exports.json = __importStar(require("./json"));
|
|
29
|
+
exports.schema = __importStar(require("./schema"));
|
|
30
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export declare const diff: (a: unknown, b: unknown, ctx?: Context) => Diff[];
|
|
2
|
+
export interface AddedDiff<T = unknown> {
|
|
3
|
+
kind: 'added';
|
|
4
|
+
path: string[];
|
|
5
|
+
type: string;
|
|
6
|
+
value: T;
|
|
7
|
+
}
|
|
8
|
+
export interface ModifiedDiff<T = unknown, P = unknown> {
|
|
9
|
+
kind: 'modified';
|
|
10
|
+
path: string[];
|
|
11
|
+
types: [string, string];
|
|
12
|
+
values: [T, P];
|
|
13
|
+
}
|
|
14
|
+
export interface DeletedDiff<T = unknown> {
|
|
15
|
+
kind: 'deleted';
|
|
16
|
+
path: string[];
|
|
17
|
+
type: string;
|
|
18
|
+
value: T;
|
|
19
|
+
}
|
|
20
|
+
export declare type Diff = AddedDiff | ModifiedDiff | DeletedDiff;
|
|
21
|
+
export interface Context {
|
|
22
|
+
path: string[];
|
|
23
|
+
}
|
|
@@ -1,25 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.diff = void 0;
|
|
4
4
|
const fp_1 = require("lodash/fp");
|
|
5
|
-
/**
|
|
6
|
-
* Collect every entity in a Readable stream
|
|
7
|
-
*/
|
|
8
|
-
const collect = (stream) => {
|
|
9
|
-
const chunks = [];
|
|
10
|
-
return new Promise((resolve) => {
|
|
11
|
-
stream.on('data', (chunk) => chunks.push(chunk));
|
|
12
|
-
stream.on('end', () => {
|
|
13
|
-
stream.destroy();
|
|
14
|
-
resolve(chunks);
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
};
|
|
18
|
-
exports.collect = collect;
|
|
19
5
|
const createContext = () => ({ path: [] });
|
|
20
|
-
const
|
|
6
|
+
const diff = (a, b, ctx = createContext()) => {
|
|
21
7
|
const diffs = [];
|
|
22
8
|
const { path } = ctx;
|
|
9
|
+
const aType = typeof a;
|
|
10
|
+
const bType = typeof b;
|
|
23
11
|
// Define helpers
|
|
24
12
|
const added = () => {
|
|
25
13
|
diffs.push({ kind: 'added', path, type: bType, value: b });
|
|
@@ -38,8 +26,6 @@ const jsonDiffs = (a, b, ctx = createContext()) => {
|
|
|
38
26
|
});
|
|
39
27
|
return diffs;
|
|
40
28
|
};
|
|
41
|
-
const aType = typeof a;
|
|
42
|
-
const bType = typeof b;
|
|
43
29
|
if (aType === 'undefined') {
|
|
44
30
|
return added();
|
|
45
31
|
}
|
|
@@ -50,9 +36,9 @@ const jsonDiffs = (a, b, ctx = createContext()) => {
|
|
|
50
36
|
let k = 0;
|
|
51
37
|
for (const [aItem, bItem] of (0, fp_1.zip)(a, b)) {
|
|
52
38
|
const kCtx = { path: [...path, k.toString()] };
|
|
53
|
-
const kDiffs = (0, exports.
|
|
39
|
+
const kDiffs = (0, exports.diff)(aItem, bItem, kCtx);
|
|
54
40
|
diffs.push(...kDiffs);
|
|
55
|
-
k
|
|
41
|
+
k += 1;
|
|
56
42
|
}
|
|
57
43
|
return diffs;
|
|
58
44
|
}
|
|
@@ -61,7 +47,7 @@ const jsonDiffs = (a, b, ctx = createContext()) => {
|
|
|
61
47
|
for (const key of keys) {
|
|
62
48
|
const aValue = a[key];
|
|
63
49
|
const bValue = b[key];
|
|
64
|
-
const nestedDiffs = (0, exports.
|
|
50
|
+
const nestedDiffs = (0, exports.diff)(aValue, bValue, { path: [...path, key] });
|
|
65
51
|
diffs.push(...nestedDiffs);
|
|
66
52
|
}
|
|
67
53
|
return diffs;
|
|
@@ -71,20 +57,5 @@ const jsonDiffs = (a, b, ctx = createContext()) => {
|
|
|
71
57
|
}
|
|
72
58
|
return diffs;
|
|
73
59
|
};
|
|
74
|
-
exports.
|
|
75
|
-
|
|
76
|
-
'collectionName',
|
|
77
|
-
'info',
|
|
78
|
-
'options',
|
|
79
|
-
'pluginOptions',
|
|
80
|
-
'attributes',
|
|
81
|
-
'kind',
|
|
82
|
-
'modelType',
|
|
83
|
-
'modelName',
|
|
84
|
-
'uid',
|
|
85
|
-
'plugin',
|
|
86
|
-
'globalId',
|
|
87
|
-
];
|
|
88
|
-
const mapSchemasValues = (schemas) => (0, fp_1.mapValues)((0, fp_1.pick)(schemaSelectedKeys), schemas);
|
|
89
|
-
exports.mapSchemasValues = mapSchemasValues;
|
|
90
|
-
//# sourceMappingURL=utils.js.map
|
|
60
|
+
exports.diff = diff;
|
|
61
|
+
//# sourceMappingURL=json.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mapSchemasValues = void 0;
|
|
4
|
+
const fp_1 = require("lodash/fp");
|
|
5
|
+
const schemaSelectedKeys = [
|
|
6
|
+
'collectionName',
|
|
7
|
+
'info',
|
|
8
|
+
'options',
|
|
9
|
+
'pluginOptions',
|
|
10
|
+
'attributes',
|
|
11
|
+
'kind',
|
|
12
|
+
'modelType',
|
|
13
|
+
'modelName',
|
|
14
|
+
'uid',
|
|
15
|
+
'plugin',
|
|
16
|
+
'globalId',
|
|
17
|
+
];
|
|
18
|
+
const mapSchemasValues = (schemas) => {
|
|
19
|
+
return (0, fp_1.mapValues)((0, fp_1.pick)(schemaSelectedKeys), schemas);
|
|
20
|
+
};
|
|
21
|
+
exports.mapSchemasValues = mapSchemasValues;
|
|
22
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Transform, Readable } from 'stream';
|
|
3
|
+
declare type TransformOptions = ConstructorParameters<typeof Transform>[0];
|
|
4
|
+
export declare const filter: <T>(predicate: (value: T) => boolean | Promise<boolean>, options?: TransformOptions) => Transform;
|
|
5
|
+
export declare const map: <T>(predicate: (value: T) => T | Promise<T>, options?: TransformOptions) => Transform;
|
|
6
|
+
/**
|
|
7
|
+
* Collect every entity in a Readable stream
|
|
8
|
+
*/
|
|
9
|
+
export declare const collect: <T = unknown>(stream: Readable) => Promise<T[]>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.collect = exports.map = exports.filter = void 0;
|
|
4
|
+
const stream_1 = require("stream");
|
|
5
|
+
const filter = (predicate, options = { objectMode: true }) => {
|
|
6
|
+
return new stream_1.Transform({
|
|
7
|
+
...options,
|
|
8
|
+
async transform(chunk, _encoding, callback) {
|
|
9
|
+
const keep = await predicate(chunk);
|
|
10
|
+
callback(null, keep ? chunk : undefined);
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
exports.filter = filter;
|
|
15
|
+
const map = (predicate, options = { objectMode: true }) => {
|
|
16
|
+
return new stream_1.Transform({
|
|
17
|
+
...options,
|
|
18
|
+
async transform(chunk, _encoding, callback) {
|
|
19
|
+
const mappedValue = await predicate(chunk);
|
|
20
|
+
callback(null, mappedValue);
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
exports.map = map;
|
|
25
|
+
/**
|
|
26
|
+
* Collect every entity in a Readable stream
|
|
27
|
+
*/
|
|
28
|
+
const collect = (stream) => {
|
|
29
|
+
const chunks = [];
|
|
30
|
+
return new Promise((resolve) => {
|
|
31
|
+
stream.on('data', (chunk) => chunks.push(chunk));
|
|
32
|
+
stream.on('end', () => {
|
|
33
|
+
stream.destroy();
|
|
34
|
+
resolve(chunks);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
exports.collect = collect;
|
|
39
|
+
//# sourceMappingURL=stream.js.map
|
package/jest.config.js
CHANGED
|
@@ -5,8 +5,10 @@ const pkg = require('./package.json');
|
|
|
5
5
|
|
|
6
6
|
module.exports = {
|
|
7
7
|
...baseConfig,
|
|
8
|
-
preset: 'ts-jest',
|
|
9
8
|
displayName: (pkg.strapi && pkg.strapi.name) || pkg.name,
|
|
10
9
|
roots: [__dirname],
|
|
11
10
|
testMatch: ['**/__tests__/**/*.test.ts'],
|
|
11
|
+
transform: {
|
|
12
|
+
'^.+\\.(t|j)sx?$': ['@swc/jest'],
|
|
13
|
+
},
|
|
12
14
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/data-transfer",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.6.0-beta.1",
|
|
4
4
|
"description": "Data transfer capabilities for Strapi",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"strapi",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"lib": "./dist"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@strapi/logger": "4.
|
|
41
|
-
"@strapi/strapi": "4.
|
|
40
|
+
"@strapi/logger": "4.6.0-beta.1",
|
|
41
|
+
"@strapi/strapi": "4.6.0-beta.1",
|
|
42
42
|
"chalk": "4.1.2",
|
|
43
43
|
"fs-extra": "10.0.0",
|
|
44
44
|
"lodash": "4.17.21",
|
|
@@ -64,5 +64,6 @@
|
|
|
64
64
|
"engines": {
|
|
65
65
|
"node": ">=14.19.1 <=18.x.x",
|
|
66
66
|
"npm": ">=6.0.0"
|
|
67
|
-
}
|
|
67
|
+
},
|
|
68
|
+
"gitHead": "2c0bcabdf0bf2a269fed50c6f23ba777845968a0"
|
|
68
69
|
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import type { IDestinationProvider, IMetadata, ProviderType } from '../../types';
|
|
3
|
-
import { Duplex } from 'stream';
|
|
4
|
-
interface ILocalStrapiDestinationProviderOptions {
|
|
5
|
-
getStrapi(): Promise<Strapi.Strapi>;
|
|
6
|
-
}
|
|
7
|
-
export declare const createLocalStrapiDestinationProvider: (options: ILocalStrapiDestinationProviderOptions) => LocalStrapiDestinationProvider;
|
|
8
|
-
declare class LocalStrapiDestinationProvider implements IDestinationProvider {
|
|
9
|
-
name: string;
|
|
10
|
-
type: ProviderType;
|
|
11
|
-
options: ILocalStrapiDestinationProviderOptions;
|
|
12
|
-
strapi?: Strapi.Strapi;
|
|
13
|
-
constructor(options: ILocalStrapiDestinationProviderOptions);
|
|
14
|
-
bootstrap(): Promise<void>;
|
|
15
|
-
close(): Promise<void>;
|
|
16
|
-
getMetadata(): IMetadata | Promise<IMetadata>;
|
|
17
|
-
getSchemas(): {
|
|
18
|
-
[x: string]: Partial<any>;
|
|
19
|
-
};
|
|
20
|
-
getEntitiesStream(): Duplex;
|
|
21
|
-
}
|
|
22
|
-
export {};
|
|
@@ -1,78 +0,0 @@
|
|
|
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.createLocalStrapiDestinationProvider = void 0;
|
|
7
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
-
const stream_1 = require("stream");
|
|
9
|
-
const utils_1 = require("../utils");
|
|
10
|
-
// TODO: getting some type errors with @strapi/logger that need to be resolved first
|
|
11
|
-
// const log = createLogger();
|
|
12
|
-
const log = console;
|
|
13
|
-
const createLocalStrapiDestinationProvider = (options) => {
|
|
14
|
-
return new LocalStrapiDestinationProvider(options);
|
|
15
|
-
};
|
|
16
|
-
exports.createLocalStrapiDestinationProvider = createLocalStrapiDestinationProvider;
|
|
17
|
-
class LocalStrapiDestinationProvider {
|
|
18
|
-
constructor(options) {
|
|
19
|
-
this.name = 'destination::local-strapi';
|
|
20
|
-
this.type = 'destination';
|
|
21
|
-
this.options = options;
|
|
22
|
-
}
|
|
23
|
-
async bootstrap() {
|
|
24
|
-
this.strapi = await this.options.getStrapi();
|
|
25
|
-
}
|
|
26
|
-
async close() {
|
|
27
|
-
await this.strapi?.destroy?.();
|
|
28
|
-
}
|
|
29
|
-
// TODO
|
|
30
|
-
getMetadata() {
|
|
31
|
-
return {};
|
|
32
|
-
}
|
|
33
|
-
getSchemas() {
|
|
34
|
-
if (!this.strapi) {
|
|
35
|
-
throw new Error('Not able to get Schemas. Strapi instance not found');
|
|
36
|
-
}
|
|
37
|
-
const schemas = {
|
|
38
|
-
...this.strapi.contentTypes,
|
|
39
|
-
...this.strapi.components,
|
|
40
|
-
};
|
|
41
|
-
return (0, utils_1.mapSchemasValues)(schemas);
|
|
42
|
-
}
|
|
43
|
-
getEntitiesStream() {
|
|
44
|
-
const self = this;
|
|
45
|
-
return new stream_1.Duplex({
|
|
46
|
-
objectMode: true,
|
|
47
|
-
async write(entity, _encoding, callback) {
|
|
48
|
-
if (!self.strapi) {
|
|
49
|
-
callback(new Error('Strapi instance not found'));
|
|
50
|
-
}
|
|
51
|
-
const { type: uid, id, data } = entity;
|
|
52
|
-
try {
|
|
53
|
-
await strapi.entityService.create(uid, { data });
|
|
54
|
-
}
|
|
55
|
-
catch (e) {
|
|
56
|
-
// TODO: remove "any" cast
|
|
57
|
-
log.warn(chalk_1.default.bold(`Failed to import ${chalk_1.default.yellowBright(uid)} (${chalk_1.default.greenBright(id)})`));
|
|
58
|
-
e.details.errors
|
|
59
|
-
.map((err, i) => {
|
|
60
|
-
// TODO: add correct error type
|
|
61
|
-
const info = {
|
|
62
|
-
uid: chalk_1.default.yellowBright(`[${uid}]`),
|
|
63
|
-
path: chalk_1.default.blueBright(`[${err.path.join('.')}]`),
|
|
64
|
-
id: chalk_1.default.greenBright(`[${id}]`),
|
|
65
|
-
message: err.message,
|
|
66
|
-
};
|
|
67
|
-
return `(${i}) ${info.uid}${info.id}${info.path}: ${info.message}`;
|
|
68
|
-
})
|
|
69
|
-
.forEach((message) => log.warn(message));
|
|
70
|
-
}
|
|
71
|
-
finally {
|
|
72
|
-
callback();
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
//# sourceMappingURL=local-strapi-destination-provider.js.map
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createLinksStream = void 0;
|
|
4
|
-
const stream_1 = require("stream");
|
|
5
|
-
const fp_1 = require("lodash/fp");
|
|
6
|
-
const utils_1 = require("./utils");
|
|
7
|
-
/**
|
|
8
|
-
* Create a Duplex instance which will stream all the links from a Strapi instance
|
|
9
|
-
*/
|
|
10
|
-
const createLinksStream = (strapi) => {
|
|
11
|
-
const schemas = Object.values(strapi.contentTypes);
|
|
12
|
-
// Destroy the Duplex stream instance
|
|
13
|
-
const destroy = () => {
|
|
14
|
-
if (!stream.destroyed) {
|
|
15
|
-
stream.destroy();
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
// Async generator stream that returns every link from a Strapi instance
|
|
19
|
-
const stream = stream_1.Readable.from((async function* () {
|
|
20
|
-
for (const schema of schemas) {
|
|
21
|
-
const populate = (0, utils_1.getDeepPopulateQuery)(schema, strapi);
|
|
22
|
-
const query = { fields: ['id'], populate };
|
|
23
|
-
// TODO: Replace with the DB stream API
|
|
24
|
-
const results = await strapi.entityService.findMany(schema.uid, query);
|
|
25
|
-
for (const entity of (0, fp_1.castArray)(results)) {
|
|
26
|
-
const links = (0, utils_1.parseEntityLinks)(entity, populate, schema, strapi);
|
|
27
|
-
for (const link of links) {
|
|
28
|
-
yield link;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
destroy();
|
|
33
|
-
})());
|
|
34
|
-
return stream;
|
|
35
|
-
};
|
|
36
|
-
exports.createLinksStream = createLinksStream;
|
|
37
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -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
|
-
};
|