@strapi/data-transfer 4.12.2 → 4.13.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.
Files changed (169) hide show
  1. package/dist/engine/diagnostic.d.ts +40 -0
  2. package/dist/engine/diagnostic.js +50 -0
  3. package/dist/engine/diagnostic.js.map +1 -0
  4. package/dist/engine/errors.d.ts +28 -0
  5. package/dist/engine/errors.js +29 -0
  6. package/dist/engine/errors.js.map +1 -0
  7. package/dist/engine/index.d.ts +64 -0
  8. package/dist/engine/index.js +664 -0
  9. package/dist/engine/index.js.map +1 -0
  10. package/dist/engine/validation/index.d.ts +2 -0
  11. package/dist/engine/validation/index.js +19 -0
  12. package/dist/engine/validation/index.js.map +1 -0
  13. package/dist/engine/validation/provider.d.ts +3 -0
  14. package/dist/engine/validation/provider.js +18 -0
  15. package/dist/engine/validation/provider.js.map +1 -0
  16. package/dist/engine/validation/schemas/index.d.ts +7 -0
  17. package/dist/engine/validation/schemas/index.js +70 -0
  18. package/dist/engine/validation/schemas/index.js.map +1 -0
  19. package/dist/errors/base.d.ts +8 -0
  20. package/dist/errors/base.js +13 -0
  21. package/dist/errors/base.js.map +1 -0
  22. package/dist/errors/constants.d.ts +3 -0
  23. package/dist/errors/constants.js +9 -0
  24. package/dist/errors/constants.js.map +1 -0
  25. package/dist/errors/index.d.ts +2 -0
  26. package/dist/errors/index.js +19 -0
  27. package/dist/errors/index.js.map +1 -0
  28. package/dist/errors/providers.d.ts +23 -0
  29. package/dist/errors/providers.js +32 -0
  30. package/dist/errors/providers.js.map +1 -0
  31. package/dist/file/index.d.ts +1 -0
  32. package/dist/file/index.js +28 -0
  33. package/dist/file/index.js.map +1 -0
  34. package/dist/file/providers/destination/index.d.ts +46 -0
  35. package/dist/file/providers/destination/index.js +181 -0
  36. package/dist/file/providers/destination/index.js.map +1 -0
  37. package/dist/file/providers/destination/utils.d.ts +9 -0
  38. package/dist/file/providers/destination/utils.js +62 -0
  39. package/dist/file/providers/destination/utils.js.map +1 -0
  40. package/dist/file/providers/index.d.ts +2 -0
  41. package/dist/file/providers/index.js +19 -0
  42. package/dist/file/providers/index.js.map +1 -0
  43. package/dist/file/providers/source/index.d.ts +40 -0
  44. package/dist/file/providers/source/index.js +242 -0
  45. package/dist/file/providers/source/index.js.map +1 -0
  46. package/dist/file/providers/source/utils.d.ts +37 -0
  47. package/dist/file/providers/source/utils.js +62 -0
  48. package/dist/file/providers/source/utils.js.map +1 -0
  49. package/dist/index.d.ts +4 -0
  50. package/dist/index.js +31 -0
  51. package/dist/index.js.map +1 -0
  52. package/dist/strapi/index.d.ts +3 -0
  53. package/dist/strapi/index.js +30 -0
  54. package/dist/strapi/index.js.map +1 -0
  55. package/dist/strapi/providers/index.d.ts +4 -0
  56. package/dist/strapi/providers/index.js +23 -0
  57. package/dist/strapi/providers/index.js.map +1 -0
  58. package/dist/strapi/providers/local-destination/index.d.ts +34 -0
  59. package/dist/strapi/providers/local-destination/index.js +321 -0
  60. package/dist/strapi/providers/local-destination/index.js.map +1 -0
  61. package/dist/strapi/providers/local-destination/strategies/index.d.ts +1 -0
  62. package/dist/strapi/providers/local-destination/strategies/index.js +28 -0
  63. package/dist/strapi/providers/local-destination/strategies/index.js.map +1 -0
  64. package/dist/strapi/providers/local-destination/strategies/restore/configuration.d.ts +5 -0
  65. package/dist/strapi/providers/local-destination/strategies/restore/configuration.js +51 -0
  66. package/dist/strapi/providers/local-destination/strategies/restore/configuration.js.map +1 -0
  67. package/dist/strapi/providers/local-destination/strategies/restore/entities.d.ts +11 -0
  68. package/dist/strapi/providers/local-destination/strategies/restore/entities.js +103 -0
  69. package/dist/strapi/providers/local-destination/strategies/restore/entities.js.map +1 -0
  70. package/dist/strapi/providers/local-destination/strategies/restore/index.d.ts +32 -0
  71. package/dist/strapi/providers/local-destination/strategies/restore/index.js +107 -0
  72. package/dist/strapi/providers/local-destination/strategies/restore/index.js.map +1 -0
  73. package/dist/strapi/providers/local-destination/strategies/restore/links.d.ts +4 -0
  74. package/dist/strapi/providers/local-destination/strategies/restore/links.js +32 -0
  75. package/dist/strapi/providers/local-destination/strategies/restore/links.js.map +1 -0
  76. package/dist/strapi/providers/local-source/assets.d.ts +5 -0
  77. package/dist/strapi/providers/local-source/assets.js +98 -0
  78. package/dist/strapi/providers/local-source/assets.js.map +1 -0
  79. package/dist/strapi/providers/local-source/configuration.d.ts +5 -0
  80. package/dist/strapi/providers/local-source/configuration.js +36 -0
  81. package/dist/strapi/providers/local-source/configuration.js.map +1 -0
  82. package/dist/strapi/providers/local-source/entities.d.ts +10 -0
  83. package/dist/strapi/providers/local-source/entities.js +85 -0
  84. package/dist/strapi/providers/local-source/entities.js.map +1 -0
  85. package/dist/strapi/providers/local-source/index.d.ts +26 -0
  86. package/dist/strapi/providers/local-source/index.js +98 -0
  87. package/dist/strapi/providers/local-source/index.js.map +1 -0
  88. package/dist/strapi/providers/local-source/links.d.ts +5 -0
  89. package/dist/strapi/providers/local-source/links.js +23 -0
  90. package/dist/strapi/providers/local-source/links.js.map +1 -0
  91. package/dist/strapi/providers/remote-destination/index.d.ts +39 -0
  92. package/dist/strapi/providers/remote-destination/index.js +269 -0
  93. package/dist/strapi/providers/remote-destination/index.js.map +1 -0
  94. package/dist/strapi/providers/remote-source/index.d.ts +39 -0
  95. package/dist/strapi/providers/remote-source/index.js +239 -0
  96. package/dist/strapi/providers/remote-source/index.js.map +1 -0
  97. package/dist/strapi/providers/utils.d.ts +39 -0
  98. package/dist/strapi/providers/utils.js +138 -0
  99. package/dist/strapi/providers/utils.js.map +1 -0
  100. package/dist/strapi/queries/entity.d.ts +2 -0
  101. package/dist/strapi/queries/entity.js +130 -0
  102. package/dist/strapi/queries/entity.js.map +1 -0
  103. package/dist/strapi/queries/index.d.ts +2 -0
  104. package/dist/strapi/queries/index.js +29 -0
  105. package/dist/strapi/queries/index.js.map +1 -0
  106. package/dist/strapi/queries/link.d.ts +7 -0
  107. package/dist/strapi/queries/link.js +215 -0
  108. package/dist/strapi/queries/link.js.map +1 -0
  109. package/dist/strapi/remote/constants.d.ts +4 -0
  110. package/dist/strapi/remote/constants.js +6 -0
  111. package/dist/strapi/remote/constants.js.map +1 -0
  112. package/dist/strapi/remote/flows/default.d.ts +3 -0
  113. package/dist/strapi/remote/flows/default.js +41 -0
  114. package/dist/strapi/remote/flows/default.js.map +1 -0
  115. package/dist/strapi/remote/flows/index.d.ts +18 -0
  116. package/dist/strapi/remote/flows/index.js +59 -0
  117. package/dist/strapi/remote/flows/index.js.map +1 -0
  118. package/dist/strapi/remote/handlers/abstract.d.ts +71 -0
  119. package/dist/strapi/remote/handlers/abstract.js +3 -0
  120. package/dist/strapi/remote/handlers/abstract.js.map +1 -0
  121. package/dist/strapi/remote/handlers/constants.d.ts +2 -0
  122. package/dist/strapi/remote/handlers/constants.js +5 -0
  123. package/dist/strapi/remote/handlers/constants.js.map +1 -0
  124. package/dist/strapi/remote/handlers/index.d.ts +3 -0
  125. package/dist/strapi/remote/handlers/index.js +10 -0
  126. package/dist/strapi/remote/handlers/index.js.map +1 -0
  127. package/dist/strapi/remote/handlers/pull.d.ts +22 -0
  128. package/dist/strapi/remote/handlers/pull.js +243 -0
  129. package/dist/strapi/remote/handlers/pull.js.map +1 -0
  130. package/dist/strapi/remote/handlers/push.d.ts +75 -0
  131. package/dist/strapi/remote/handlers/push.js +311 -0
  132. package/dist/strapi/remote/handlers/push.js.map +1 -0
  133. package/dist/strapi/remote/handlers/utils.d.ts +25 -0
  134. package/dist/strapi/remote/handlers/utils.js +217 -0
  135. package/dist/strapi/remote/handlers/utils.js.map +1 -0
  136. package/dist/strapi/remote/index.d.ts +2 -0
  137. package/dist/strapi/remote/index.js +29 -0
  138. package/dist/strapi/remote/index.js.map +1 -0
  139. package/dist/utils/encryption/decrypt.d.ts +11 -0
  140. package/dist/utils/encryption/decrypt.js +47 -0
  141. package/dist/utils/encryption/decrypt.js.map +1 -0
  142. package/dist/utils/encryption/encrypt.d.ts +11 -0
  143. package/dist/utils/encryption/encrypt.js +47 -0
  144. package/dist/utils/encryption/encrypt.js.map +1 -0
  145. package/dist/utils/encryption/index.d.ts +2 -0
  146. package/dist/utils/encryption/index.js +19 -0
  147. package/dist/utils/encryption/index.js.map +1 -0
  148. package/dist/utils/index.d.ts +6 -0
  149. package/dist/utils/index.js +33 -0
  150. package/dist/utils/index.js.map +1 -0
  151. package/dist/utils/json.d.ts +30 -0
  152. package/dist/utils/json.js +68 -0
  153. package/dist/utils/json.js.map +1 -0
  154. package/dist/utils/middleware.d.ts +2 -0
  155. package/dist/utils/middleware.js +14 -0
  156. package/dist/utils/middleware.js.map +1 -0
  157. package/dist/utils/providers.d.ts +2 -0
  158. package/dist/utils/providers.js +11 -0
  159. package/dist/utils/providers.js.map +1 -0
  160. package/dist/utils/schema.d.ts +6 -0
  161. package/dist/utils/schema.js +29 -0
  162. package/dist/utils/schema.js.map +1 -0
  163. package/dist/utils/stream.d.ts +27 -0
  164. package/dist/utils/stream.js +59 -0
  165. package/dist/utils/stream.js.map +1 -0
  166. package/dist/utils/transaction.d.ts +3 -0
  167. package/dist/utils/transaction.js +88 -0
  168. package/dist/utils/transaction.js.map +1 -0
  169. package/package.json +4 -4
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createTarEntryStream = exports.createFilePathFactory = void 0;
4
+ const stream_1 = require("stream");
5
+ const path_1 = require("path");
6
+ /**
7
+ * Create a file path factory for a given path & prefix.
8
+ * Upon being called, the factory will return a file path for a given index
9
+ */
10
+ const createFilePathFactory = (type) => (fileIndex = 0) => {
11
+ // always write tar files with posix paths so we have a standard format for paths regardless of system
12
+ return path_1.posix.join(
13
+ // "{type}" directory
14
+ type,
15
+ // "${type}_XXXXX.jsonl" file
16
+ `${type}_${String(fileIndex).padStart(5, '0')}.jsonl`);
17
+ };
18
+ exports.createFilePathFactory = createFilePathFactory;
19
+ const createTarEntryStream = (archive, pathFactory, maxSize = 2.56e8) => {
20
+ let fileIndex = 0;
21
+ let buffer = '';
22
+ const flush = async () => {
23
+ if (!buffer) {
24
+ return;
25
+ }
26
+ fileIndex += 1;
27
+ const name = pathFactory(fileIndex);
28
+ const size = buffer.length;
29
+ await new Promise((resolve, reject) => {
30
+ archive.entry({ name, size }, buffer, (err) => {
31
+ if (err) {
32
+ reject(err);
33
+ }
34
+ resolve();
35
+ });
36
+ });
37
+ buffer = '';
38
+ };
39
+ const push = (chunk) => {
40
+ buffer += chunk;
41
+ };
42
+ return new stream_1.Writable({
43
+ async destroy(err, callback) {
44
+ await flush();
45
+ callback(err);
46
+ },
47
+ async write(chunk, _encoding, callback) {
48
+ const size = chunk.length;
49
+ if (chunk.length > maxSize) {
50
+ callback(new Error(`payload too large: ${chunk.length}>${maxSize}`));
51
+ return;
52
+ }
53
+ if (buffer.length + size > maxSize) {
54
+ await flush();
55
+ }
56
+ push(chunk);
57
+ callback(null);
58
+ },
59
+ });
60
+ };
61
+ exports.createTarEntryStream = createTarEntryStream;
62
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/file/providers/destination/utils.ts"],"names":[],"mappings":";;;AAAA,mCAAkC;AAClC,+BAA6B;AAG7B;;;GAGG;AACI,MAAM,qBAAqB,GAChC,CAAC,IAAY,EAAE,EAAE,CACjB,CAAC,SAAS,GAAG,CAAC,EAAU,EAAE;IACxB,sGAAsG;IACtG,OAAO,YAAK,CAAC,IAAI;IACf,qBAAqB;IACrB,IAAI;IACJ,6BAA6B;IAC7B,GAAG,IAAI,IAAI,MAAM,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,QAAQ,CACtD,CAAC;AACJ,CAAC,CAAC;AAVS,QAAA,qBAAqB,yBAU9B;AAEG,MAAM,oBAAoB,GAAG,CAClC,OAAiB,EACjB,WAAuC,EACvC,OAAO,GAAG,MAAM,EAChB,EAAE;IACF,IAAI,SAAS,GAAG,CA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AK,EAAE,CAAC;aACf;YAED,IAAI,CAAC,KAAK,CAAC,CAAC;YAEZ,QAAQ,CAAC,IAAI,CAAC,CAAC;QACjB,CAAC;KACF,CAAC,CAAC;AACL,CAAC,CAAC;AAzDW,QAAA,oBAAoB,wBAyD/B"}
@@ -0,0 +1,2 @@
1
+ export * from './source';
2
+ export * from './destination';
@@ -0,0 +1,19 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./source"), exports);
18
+ __exportStar(require("./destination"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/file/providers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,gDAA8B"}
@@ -0,0 +1,40 @@
1
+ /// <reference types="lodash" />
2
+ /// <reference types="node" />
3
+ import type { Readable } from 'stream';
4
+ import type { Schema } from '@strapi/strapi';
5
+ import type { IMetadata, ISourceProvider, ProviderType } from '../../../../types';
6
+ /**
7
+ * Provider options
8
+ */
9
+ export interface ILocalFileSourceProviderOptions {
10
+ file: {
11
+ path: string;
12
+ };
13
+ encryption: {
14
+ enabled: boolean;
15
+ key?: string;
16
+ };
17
+ compression: {
18
+ enabled: boolean;
19
+ };
20
+ }
21
+ export declare const createLocalFileSourceProvider: (options: ILocalFileSourceProviderOptions) => LocalFileSourceProvider;
22
+ declare class LocalFileSourceProvider implements ISourceProvider {
23
+ #private;
24
+ type: ProviderType;
25
+ name: string;
26
+ options: ILocalFileSourceProviderOptions;
27
+ constructor(options: ILocalFileSourceProviderOptions);
28
+ /**
29
+ * Pre flight checks regarding the provided options, making sure that the file can be opened (decrypted, decompressed), etc.
30
+ */
31
+ bootstrap(): Promise<void>;
32
+ getMetadata(): Promise<IMetadata | null>;
33
+ getSchemas(): Promise<import("lodash").Dictionary<Schema.Schema>>;
34
+ createEntitiesReadStream(): Readable;
35
+ createSchemasReadStream(): Readable;
36
+ createLinksReadStream(): Readable;
37
+ createConfigurationReadStream(): Readable;
38
+ createAssetsReadStream(): Readable | Promise<Readable>;
39
+ }
40
+ export {};
@@ -0,0 +1,242 @@
1
+ "use strict";
2
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
5
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
+ };
7
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
8
+ if (kind === "m") throw new TypeError("Private method is not writable");
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
11
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ var _LocalFileSourceProvider_instances, _LocalFileSourceProvider_metadata, _LocalFileSourceProvider_loadMetadata, _LocalFileSourceProvider_loadAssetMetadata, _LocalFileSourceProvider_getBackupStream, _LocalFileSourceProvider_streamJsonlDirectory, _LocalFileSourceProvider_parseJSONFile;
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.createLocalFileSourceProvider = void 0;
19
+ const zlib_1 = __importDefault(require("zlib"));
20
+ const path_1 = __importDefault(require("path"));
21
+ const stream_1 = require("stream");
22
+ const fs_extra_1 = __importDefault(require("fs-extra"));
23
+ const tar_1 = __importDefault(require("tar"));
24
+ const fp_1 = require("lodash/fp");
25
+ const stream_chain_1 = require("stream-chain");
26
+ const Parser_1 = require("stream-json/jsonl/Parser");
27
+ const encryption_1 = require("../../../utils/encryption");
28
+ const stream_2 = require("../../../utils/stream");
29
+ const providers_1 = require("../../../errors/providers");
30
+ const utils_1 = require("./utils");
31
+ /**
32
+ * Constant for the metadata file path
33
+ */
34
+ const METADATA_FILE_PATH = 'metadata.json';
35
+ const createLocalFileSourceProvider = (options) => {
36
+ return new LocalFileSourceProvider(options);
37
+ };
38
+ exports.createLocalFileSourceProvider = createLocalFileSourceProvider;
39
+ class LocalFileSourceProvider {
40
+ constructor(options) {
41
+ _LocalFileSourceProvider_instances.add(this);
42
+ this.type = 'source';
43
+ this.name = 'source::local-file';
44
+ _LocalFileSourceProvider_metadata.set(this, void 0);
45
+ this.options = options;
46
+ const { encryption } = this.options;
47
+ if (encryption.enabled && encryption.key === undefined) {
48
+ throw new Error('Missing encryption key');
49
+ }
50
+ }
51
+ /**
52
+ * Pre flight checks regarding the provided options, making sure that the file can be opened (decrypted, decompressed), etc.
53
+ */
54
+ async bootstrap() {
55
+ const { path: filePath } = this.options.file;
56
+ try {
57
+ // Read the metadata to ensure the file can be parsed
58
+ await __classPrivateFieldGet(this, _LocalFileSourceProvider_instances, "m", _LocalFileSourceProvider_loadMetadata).call(this);
59
+ // TODO: we might also need to read the schema.jsonl files & implements a custom stream-check
60
+ }
61
+ catch (e) {
62
+ if (this.options?.encryption?.enabled) {
63
+ throw new providers_1.ProviderInitializationError(`Key is incorrect or the file '${filePath}' is not a valid Strapi data file.`);
64
+ }
65
+ throw new providers_1.ProviderInitializationError(`File '${filePath}' is not a valid Strapi data file.`);
66
+ }
67
+ if (!__classPrivateFieldGet(this, _LocalFileSourceProvider_metadata, "f")) {
68
+ throw new providers_1.ProviderInitializationError('Could not load metadata from Strapi data file.');
69
+ }
70
+ }
71
+ async getMetadata() {
72
+ if (!__classPrivateFieldGet(this, _LocalFileSourceProvider_metadata, "f")) {
73
+ await __classPrivateFieldGet(this, _LocalFileSourceProvider_instances, "m", _LocalFileSourceProvider_loadMetadata).call(this);
74
+ }
75
+ return __classPrivateFieldGet(this, _LocalFileSourceProvider_metadata, "f") ?? null;
76
+ }
77
+ async getSchemas() {
78
+ const schemas = await (0, stream_2.collect)(this.createSchemasReadStream());
79
+ if ((0, fp_1.isEmpty)(schemas)) {
80
+ throw new providers_1.ProviderInitializationError('Could not load schemas from Strapi data file.');
81
+ }
82
+ return (0, fp_1.keyBy)('uid', schemas);
83
+ }
84
+ createEntitiesReadStream() {
85
+ return __classPrivateFieldGet(this, _LocalFileSourceProvider_instances, "m", _LocalFileSourceProvider_streamJsonlDirectory).call(this, 'entities');
86
+ }
87
+ createSchemasReadStream() {
88
+ return __classPrivateFieldGet(this, _LocalFileSourceProvider_instances, "m", _LocalFileSourceProvider_streamJsonlDirectory).call(this, 'schemas');
89
+ }
90
+ createLinksReadStream() {
91
+ return __classPrivateFieldGet(this, _LocalFileSourceProvider_instances, "m", _LocalFileSourceProvider_streamJsonlDirectory).call(this, 'links');
92
+ }
93
+ createConfigurationReadStream() {
94
+ // NOTE: TBD
95
+ return __classPrivateFieldGet(this, _LocalFileSourceProvider_instances, "m", _LocalFileSourceProvider_streamJsonlDirectory).call(this, 'configuration');
96
+ }
97
+ createAssetsReadStream() {
98
+ const inStream = __classPrivateFieldGet(this, _LocalFileSourceProvider_instances, "m", _LocalFileSourceProvider_getBackupStream).call(this);
99
+ const outStream = new stream_1.PassThrough({ objectMode: true });
100
+ const loadAssetMetadata = __classPrivateFieldGet(this, _LocalFileSourceProvider_instances, "m", _LocalFileSourceProvider_loadAssetMetadata).bind(this);
101
+ (0, stream_1.pipeline)([
102
+ inStream,
103
+ new tar_1.default.Parse({
104
+ // find only files in the assets/uploads folder
105
+ filter(filePath, entry) {
106
+ if (entry.type !== 'File') {
107
+ return false;
108
+ }
109
+ return (0, utils_1.isFilePathInDirname)('assets/uploads', filePath);
110
+ },
111
+ async onentry(entry) {
112
+ const { path: filePath, size = 0 } = entry;
113
+ const normalizedPath = (0, utils_1.unknownPathToPosix)(filePath);
114
+ const file = path_1.default.basename(normalizedPath);
115
+ let metadata;
116
+ try {
117
+ metadata = await loadAssetMetadata(`assets/metadata/${file}.json`);
118
+ }
119
+ catch (error) {
120
+ console.warn(` Failed to read metadata for ${file}, Strapi will try to fix this issue automatically`);
121
+ }
122
+ const asset = {
123
+ metadata,
124
+ filename: file,
125
+ filepath: normalizedPath,
126
+ stats: { size },
127
+ stream: entry,
128
+ };
129
+ outStream.write(asset);
130
+ },
131
+ }),
132
+ ], () => outStream.end());
133
+ return outStream;
134
+ }
135
+ }
136
+ _LocalFileSourceProvider_metadata = new WeakMap(), _LocalFileSourceProvider_instances = new WeakSet(), _LocalFileSourceProvider_loadMetadata = async function _LocalFileSourceProvider_loadMetadata() {
137
+ const backupStream = __classPrivateFieldGet(this, _LocalFileSourceProvider_instances, "m", _LocalFileSourceProvider_getBackupStream).call(this);
138
+ __classPrivateFieldSet(this, _LocalFileSourceProvider_metadata, await __classPrivateFieldGet(this, _LocalFileSourceProvider_instances, "m", _LocalFileSourceProvider_parseJSONFile).call(this, backupStream, METADATA_FILE_PATH), "f");
139
+ }, _LocalFileSourceProvider_loadAssetMetadata = async function _LocalFileSourceProvider_loadAssetMetadata(path) {
140
+ const backupStream = __classPrivateFieldGet(this, _LocalFileSourceProvider_instances, "m", _LocalFileSourceProvider_getBackupStream).call(this);
141
+ return __classPrivateFieldGet(this, _LocalFileSourceProvider_instances, "m", _LocalFileSourceProvider_parseJSONFile).call(this, backupStream, path);
142
+ }, _LocalFileSourceProvider_getBackupStream = function _LocalFileSourceProvider_getBackupStream() {
143
+ const { file, encryption, compression } = this.options;
144
+ const streams = [];
145
+ try {
146
+ streams.push(fs_extra_1.default.createReadStream(file.path));
147
+ }
148
+ catch (e) {
149
+ throw new Error(`Could not read backup file path provided at "${this.options.file.path}"`);
150
+ }
151
+ if (encryption.enabled && encryption.key) {
152
+ streams.push((0, encryption_1.createDecryptionCipher)(encryption.key));
153
+ }
154
+ if (compression.enabled) {
155
+ streams.push(zlib_1.default.createGunzip());
156
+ }
157
+ return (0, stream_chain_1.chain)(streams);
158
+ }, _LocalFileSourceProvider_streamJsonlDirectory = function _LocalFileSourceProvider_streamJsonlDirectory(directory) {
159
+ const inStream = __classPrivateFieldGet(this, _LocalFileSourceProvider_instances, "m", _LocalFileSourceProvider_getBackupStream).call(this);
160
+ const outStream = new stream_1.PassThrough({ objectMode: true });
161
+ (0, stream_1.pipeline)([
162
+ inStream,
163
+ new tar_1.default.Parse({
164
+ filter(filePath, entry) {
165
+ if (entry.type !== 'File') {
166
+ return false;
167
+ }
168
+ return (0, utils_1.isFilePathInDirname)(directory, filePath);
169
+ },
170
+ async onentry(entry) {
171
+ const transforms = [
172
+ // JSONL parser to read the data chunks one by one (line by line)
173
+ (0, Parser_1.parser)({
174
+ checkErrors: true,
175
+ }),
176
+ // The JSONL parser returns each line as key/value
177
+ (line) => line.value,
178
+ ];
179
+ const stream = entry.pipe((0, stream_chain_1.chain)(transforms));
180
+ try {
181
+ for await (const chunk of stream) {
182
+ outStream.write(chunk);
183
+ }
184
+ }
185
+ catch (e) {
186
+ outStream.destroy(new providers_1.ProviderTransferError(`Error parsing backup files from backup file ${entry.path}: ${e.message}`, {
187
+ details: {
188
+ error: e,
189
+ },
190
+ }));
191
+ }
192
+ },
193
+ }),
194
+ ], async () => {
195
+ // Manually send the 'end' event to the out stream
196
+ // once every entry has finished streaming its content
197
+ outStream.end();
198
+ });
199
+ return outStream;
200
+ }, _LocalFileSourceProvider_parseJSONFile =
201
+ // For collecting an entire JSON file then parsing it, not for streaming JSONL
202
+ async function _LocalFileSourceProvider_parseJSONFile(fileStream, filePath) {
203
+ return new Promise((resolve, reject) => {
204
+ (0, stream_1.pipeline)([
205
+ fileStream,
206
+ // Custom backup archive parsing
207
+ new tar_1.default.Parse({
208
+ /**
209
+ * Filter the parsed entries to only keep the one that matches the given filepath
210
+ */
211
+ filter(entryPath, entry) {
212
+ if (entry.type !== 'File') {
213
+ return false;
214
+ }
215
+ return (0, utils_1.isPathEquivalent)(entryPath, filePath);
216
+ },
217
+ async onentry(entry) {
218
+ // Collect all the content of the entry file
219
+ const content = await entry.collect();
220
+ try {
221
+ // Parse from buffer to string to JSON
222
+ const parsedContent = JSON.parse(content.toString());
223
+ // Resolve the Promise with the parsed content
224
+ resolve(parsedContent);
225
+ }
226
+ catch (e) {
227
+ reject(e);
228
+ }
229
+ finally {
230
+ // Cleanup (close the stream associated to the entry)
231
+ entry.destroy();
232
+ }
233
+ },
234
+ }),
235
+ ], () => {
236
+ // If the promise hasn't been resolved and we've parsed all
237
+ // the archive entries, then the file doesn't exist
238
+ reject(new Error(`File "${filePath}" not found`));
239
+ });
240
+ });
241
+ };
242
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/file/providers/source/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAEA,gDAAuB;AACvB,gDAAwB;AACxB,mCAA+C;AAC/C,wDAA0B;AAC1B,8CAAsB;AACtB,kCAA2C;AAC3C,+CAAqC;AACrC,qDAAkD;AAKlD,0DAAmE;AACnE,kDAAgD;AAChD,yDAA+F;AAC/F,mCAAoF;AAIpF;;GAEG;AACH,MAAM,kBAAkB,GAAG,eAAe,CAAC;AAoBpC,MAAM,6BAA6B,GAAG,CAAC,OAAwC,EAAE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KAAK,CAAC,OAAO,EAAE,CAAC;oBAEtC,IAAI;wBACF,sCAAsC;wBACtC,MAAM,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;wBAErD,8CAA8C;wBAC9C,OAAO,CAAC,aAAa,CAAC,CAAC;qBACxB;oBAAC,OAAO,CAAC,EAAE;wBACV,MAAM,CAAC,CAAC,CAAC,CAAC;qBACX;4BAAS;wBACR,qDAAqD;wBACrD,KAAK,CAAC,OAAO,EAAE,CAAC;qBACjB;gBACH,CAAC;aACF,CAAC;SACH,EACD,GAAG,EAAE;YACH,2DAA2D;YAC3D,mDAAmD;YACnD,MAAM,CAAC,IAAI,KAAK,CAAC,SAAS,QAAQ,aAAa,CAAC,CAAC,CAAC;QACpD,CAAC,CACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Note: in versions of the transfer engine <=4.9.0, exports were generated with windows paths
3
+ * on Windows systems, and posix paths on posix systems.
4
+ *
5
+ * We now store all paths as posix, but need to leave a separator conversion for legacy purposes, and to
6
+ * support manually-created tar files coming from Windows systems (ie, if a user creates a
7
+ * backup file with a windows tar tool rather than using the `export` command)
8
+ *
9
+ * Because of this, export/import files may never contain files with a forward slash in the name, even escaped
10
+ *
11
+ * */
12
+ /**
13
+ * Check if the directory of a given filePath (which can be either posix or win32) resolves to the same as the given posix-format path posixDirName
14
+ * We must be able to assume the first argument is a path to a directory and the second is a path to a file, otherwise path.dirname will interpret a path without any slashes as the filename
15
+ *
16
+ * @param {string} posixDirName A posix path pointing to a directory
17
+ * @param {string} filePath an unknown filesystem path pointing to a file
18
+ * @returns {boolean} is the file located in the given directory
19
+ */
20
+ export declare const isFilePathInDirname: (posixDirName: string, filePath: string) => boolean;
21
+ /**
22
+ * Check if two paths that can be either in posix or win32 format resolves to the same file
23
+ *
24
+ * @param {string} pathA a path that may be either win32 or posix
25
+ * @param {string} pathB a path that may be either win32 or posix
26
+ *
27
+ * @returns {boolean} do paths point to the same place
28
+ */
29
+ export declare const isPathEquivalent: (pathA: string, pathB: string) => boolean;
30
+ /**
31
+ * Convert an unknown format path (win32 or posix) to a posix path
32
+ *
33
+ * @param {string} filePath a path that may be either win32 or posix
34
+ *
35
+ * @returns {string} a posix path
36
+ */
37
+ export declare const unknownPathToPosix: (filePath: string) => string;
@@ -0,0 +1,62 @@
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.unknownPathToPosix = exports.isPathEquivalent = exports.isFilePathInDirname = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ /**
9
+ * Note: in versions of the transfer engine <=4.9.0, exports were generated with windows paths
10
+ * on Windows systems, and posix paths on posix systems.
11
+ *
12
+ * We now store all paths as posix, but need to leave a separator conversion for legacy purposes, and to
13
+ * support manually-created tar files coming from Windows systems (ie, if a user creates a
14
+ * backup file with a windows tar tool rather than using the `export` command)
15
+ *
16
+ * Because of this, export/import files may never contain files with a forward slash in the name, even escaped
17
+ *
18
+ * */
19
+ /**
20
+ * Check if the directory of a given filePath (which can be either posix or win32) resolves to the same as the given posix-format path posixDirName
21
+ * We must be able to assume the first argument is a path to a directory and the second is a path to a file, otherwise path.dirname will interpret a path without any slashes as the filename
22
+ *
23
+ * @param {string} posixDirName A posix path pointing to a directory
24
+ * @param {string} filePath an unknown filesystem path pointing to a file
25
+ * @returns {boolean} is the file located in the given directory
26
+ */
27
+ const isFilePathInDirname = (posixDirName, filePath) => {
28
+ const normalizedDir = path_1.default.posix.dirname((0, exports.unknownPathToPosix)(filePath));
29
+ return (0, exports.isPathEquivalent)(posixDirName, normalizedDir);
30
+ };
31
+ exports.isFilePathInDirname = isFilePathInDirname;
32
+ /**
33
+ * Check if two paths that can be either in posix or win32 format resolves to the same file
34
+ *
35
+ * @param {string} pathA a path that may be either win32 or posix
36
+ * @param {string} pathB a path that may be either win32 or posix
37
+ *
38
+ * @returns {boolean} do paths point to the same place
39
+ */
40
+ const isPathEquivalent = (pathA, pathB) => {
41
+ // Check if paths appear to be win32 or posix, and if win32 convert to posix
42
+ const normalizedPathA = path_1.default.posix.normalize((0, exports.unknownPathToPosix)(pathA));
43
+ const normalizedPathB = path_1.default.posix.normalize((0, exports.unknownPathToPosix)(pathB));
44
+ return !path_1.default.posix.relative(normalizedPathB, normalizedPathA).length;
45
+ };
46
+ exports.isPathEquivalent = isPathEquivalent;
47
+ /**
48
+ * Convert an unknown format path (win32 or posix) to a posix path
49
+ *
50
+ * @param {string} filePath a path that may be either win32 or posix
51
+ *
52
+ * @returns {string} a posix path
53
+ */
54
+ const unknownPathToPosix = (filePath) => {
55
+ // if it includes a forward slash, it must be posix already -- we will not support win32 with mixed path separators
56
+ if (filePath.includes(path_1.default.posix.sep)) {
57
+ return filePath;
58
+ }
59
+ return path_1.default.normalize(filePath).split(path_1.default.win32.sep).join(path_1.default.posix.sep);
60
+ };
61
+ exports.unknownPathToPosix = unknownPathToPosix;
62
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/file/providers/source/utils.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AAExB;;;;;;;;;;KAUK;AAEL;;;;;;;GAOG;AACI,MAAM,mBAAmB,GAAG,CAAC,YAAoB,EAAE,QAAgB,EAAE,EAAE;IAC5E,MAAM,aAAa,GAAG,cAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAA,0BAAkB,EAAC,QAAQ,CAAC,CAAC,CAAC;IACvE,OAAO,IAAA,wBAAgB,EAAC,YAAY,EAAE,aAAa,CAAC,CAAC;AACvD,CAAC,CAAC;AAHW,QAAA,mBAAmB,uBAG9B;AAEF;;;;;;;GAOG;AACI,MAAM,gBAAgB,GAAG,CAAC,KAAa,EAAE,KAAa,EAAE,EAAE;IAC/D,4EAA4E;IAC5E,MAAM,eAAe,GAAG,cAAI,CAAC,KAAK,CAAC,SAAS,CAAC,IAAA,0BAAkB,EAAC,KAAK,CAAC,CAAC,CAAC;IACxE,MAAM,eAAe,GAAG,cAAI,CAAC,KAAK,CAAC,SAAS,CAAC,IAAA,0BAAkB,EAAC,KAAK,CAAC,CAAC,CAAC;IAExE,OAAO,CAAC,cAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,eAAe,EAAE,eAAe,CAAC,CAAC,MAAM,CAAC;AACvE,CAAC,CAAC;AANW,QAAA,gBAAgB,oBAM3B;AAEF;;;;;;GAMG;AACI,MAAM,kBAAkB,GAAG,CAAC,QAAgB,EAAE,EAAE;IACrD,mHAAmH;IACnH,IAAI,QAAQ,CAAC,QAAQ,CAAC,cAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;QACrC,OAAO,QAAQ,CAAC;KACjB;IAED,OAAO,cAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,cAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,cAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;AAC7E,CAAC,CAAC;AAPW,QAAA,kBAAkB,sBAO7B"}
@@ -0,0 +1,4 @@
1
+ export * as engine from './engine';
2
+ export * as strapi from './strapi';
3
+ export * as file from './file';
4
+ export * as utils from './utils';
package/dist/index.js ADDED
@@ -0,0 +1,31 @@
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.utils = exports.file = exports.strapi = exports.engine = void 0;
27
+ exports.engine = __importStar(require("./engine"));
28
+ exports.strapi = __importStar(require("./strapi"));
29
+ exports.file = __importStar(require("./file"));
30
+ exports.utils = __importStar(require("./utils"));
31
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mDAAmC;AACnC,mDAAmC;AACnC,+CAA+B;AAC/B,iDAAiC"}
@@ -0,0 +1,3 @@
1
+ export * as providers from './providers';
2
+ export * as queries from './queries';
3
+ export * as remote from './remote';
@@ -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.remote = exports.queries = exports.providers = void 0;
27
+ exports.providers = __importStar(require("./providers"));
28
+ exports.queries = __importStar(require("./queries"));
29
+ exports.remote = __importStar(require("./remote"));
30
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/strapi/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yDAAyC;AACzC,qDAAqC;AACrC,mDAAmC"}
@@ -0,0 +1,4 @@
1
+ export * from './local-destination';
2
+ export * from './local-source';
3
+ export * from './remote-destination';
4
+ export * from './remote-source';
@@ -0,0 +1,23 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ // Local
18
+ __exportStar(require("./local-destination"), exports);
19
+ __exportStar(require("./local-source"), exports);
20
+ // Remote
21
+ __exportStar(require("./remote-destination"), exports);
22
+ __exportStar(require("./remote-source"), exports);
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/strapi/providers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,QAAQ;AACR,sDAAoC;AACpC,iDAA+B;AAE/B,SAAS;AACT,uDAAqC;AACrC,kDAAgC"}
@@ -0,0 +1,34 @@
1
+ /// <reference types="node" />
2
+ import { Writable } from 'stream';
3
+ import type { IDestinationProvider, IMetadata, ProviderType, Transaction } from '../../../../types';
4
+ import { restore } from './strategies';
5
+ export declare const VALID_CONFLICT_STRATEGIES: string[];
6
+ export declare const DEFAULT_CONFLICT_STRATEGY = "restore";
7
+ export interface ILocalStrapiDestinationProviderOptions {
8
+ getStrapi(): Strapi.Strapi | Promise<Strapi.Strapi>;
9
+ autoDestroy?: boolean;
10
+ restore?: restore.IRestoreOptions;
11
+ strategy: 'restore';
12
+ }
13
+ declare class LocalStrapiDestinationProvider implements IDestinationProvider {
14
+ #private;
15
+ name: string;
16
+ type: ProviderType;
17
+ options: ILocalStrapiDestinationProviderOptions;
18
+ strapi?: Strapi.Strapi;
19
+ transaction?: Transaction;
20
+ uploadsBackupDirectoryName: string;
21
+ constructor(options: ILocalStrapiDestinationProviderOptions);
22
+ bootstrap(): Promise<void>;
23
+ close(): Promise<void>;
24
+ rollback(): Promise<void>;
25
+ beforeTransfer(): Promise<void>;
26
+ getMetadata(): IMetadata;
27
+ getSchemas(): import("@strapi/strapi/lib/types/utils/string").Dict<import("@strapi/strapi/lib/types/core/schemas").Schema>;
28
+ createEntitiesWriteStream(): Writable;
29
+ createAssetsWriteStream(): Promise<Writable>;
30
+ createConfigurationWriteStream(): Promise<Writable>;
31
+ createLinksWriteStream(): Promise<Writable>;
32
+ }
33
+ export declare const createLocalStrapiDestinationProvider: (options: ILocalStrapiDestinationProviderOptions) => LocalStrapiDestinationProvider;
34
+ export {};