@strapi/data-transfer 4.9.0 → 4.10.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 (156) hide show
  1. package/jest.config.js +14 -0
  2. package/lib/engine/diagnostic.d.ts +40 -0
  3. package/lib/engine/diagnostic.js +50 -0
  4. package/lib/engine/errors.d.ts +28 -0
  5. package/lib/engine/errors.js +29 -0
  6. package/lib/engine/index.d.ts +44 -0
  7. package/lib/engine/index.js +506 -0
  8. package/lib/engine/validation/index.d.ts +2 -0
  9. package/lib/engine/validation/index.js +19 -0
  10. package/lib/engine/validation/provider.d.ts +3 -0
  11. package/lib/engine/validation/provider.js +18 -0
  12. package/lib/engine/validation/schemas/index.d.ts +7 -0
  13. package/lib/engine/validation/schemas/index.js +53 -0
  14. package/lib/errors/base.d.ts +8 -0
  15. package/lib/errors/base.js +13 -0
  16. package/lib/errors/constants.d.ts +3 -0
  17. package/lib/errors/constants.js +9 -0
  18. package/lib/errors/index.d.ts +2 -0
  19. package/lib/errors/index.js +19 -0
  20. package/lib/errors/providers.d.ts +21 -0
  21. package/lib/errors/providers.js +32 -0
  22. package/lib/file/index.d.ts +1 -0
  23. package/lib/file/index.js +28 -0
  24. package/lib/file/providers/destination/index.d.ts +45 -0
  25. package/lib/file/providers/destination/index.js +174 -0
  26. package/lib/file/providers/destination/utils.d.ts +9 -0
  27. package/lib/file/providers/destination/utils.js +61 -0
  28. package/lib/file/providers/index.d.ts +2 -0
  29. package/lib/file/providers/index.js +19 -0
  30. package/lib/file/providers/source/index.d.ts +40 -0
  31. package/lib/file/providers/source/index.js +220 -0
  32. package/lib/index.d.ts +4 -0
  33. package/lib/index.js +31 -0
  34. package/lib/strapi/index.d.ts +3 -0
  35. package/lib/strapi/index.js +30 -0
  36. package/lib/strapi/providers/index.d.ts +3 -0
  37. package/lib/strapi/providers/index.js +22 -0
  38. package/lib/strapi/providers/local-destination/index.d.ts +34 -0
  39. package/lib/strapi/providers/local-destination/index.js +220 -0
  40. package/lib/strapi/providers/local-destination/strategies/index.d.ts +1 -0
  41. package/lib/strapi/providers/local-destination/strategies/index.js +28 -0
  42. package/lib/strapi/providers/local-destination/strategies/restore/configuration.d.ts +5 -0
  43. package/lib/strapi/providers/local-destination/strategies/restore/configuration.js +51 -0
  44. package/lib/strapi/providers/local-destination/strategies/restore/entities.d.ts +11 -0
  45. package/lib/strapi/providers/local-destination/strategies/restore/entities.js +103 -0
  46. package/lib/strapi/providers/local-destination/strategies/restore/index.d.ts +32 -0
  47. package/lib/strapi/providers/local-destination/strategies/restore/index.js +107 -0
  48. package/lib/strapi/providers/local-destination/strategies/restore/links.d.ts +4 -0
  49. package/lib/strapi/providers/local-destination/strategies/restore/links.js +32 -0
  50. package/lib/strapi/providers/local-source/assets.d.ts +5 -0
  51. package/lib/strapi/providers/local-source/assets.js +31 -0
  52. package/lib/strapi/providers/local-source/configuration.d.ts +5 -0
  53. package/lib/strapi/providers/local-source/configuration.js +36 -0
  54. package/lib/strapi/providers/local-source/entities.d.ts +10 -0
  55. package/lib/strapi/providers/local-source/entities.js +85 -0
  56. package/lib/strapi/providers/local-source/index.d.ts +27 -0
  57. package/lib/strapi/providers/local-source/index.js +98 -0
  58. package/lib/strapi/providers/local-source/links.d.ts +5 -0
  59. package/lib/strapi/providers/local-source/links.js +23 -0
  60. package/lib/strapi/providers/remote-destination/index.d.ts +37 -0
  61. package/lib/strapi/providers/remote-destination/index.js +284 -0
  62. package/lib/strapi/providers/remote-destination/utils.d.ts +31 -0
  63. package/lib/strapi/providers/remote-destination/utils.js +72 -0
  64. package/lib/strapi/queries/entity.d.ts +19 -0
  65. package/lib/strapi/queries/entity.js +130 -0
  66. package/lib/strapi/queries/index.d.ts +2 -0
  67. package/lib/strapi/queries/index.js +29 -0
  68. package/lib/strapi/queries/link.d.ts +6 -0
  69. package/lib/strapi/queries/link.js +215 -0
  70. package/lib/strapi/remote/constants.d.ts +2 -0
  71. package/lib/strapi/remote/constants.js +6 -0
  72. package/lib/strapi/remote/controllers/index.d.ts +1 -0
  73. package/lib/strapi/remote/controllers/index.js +18 -0
  74. package/lib/strapi/remote/controllers/push.d.ts +26 -0
  75. package/lib/strapi/remote/controllers/push.js +116 -0
  76. package/lib/strapi/remote/flows/default.d.ts +3 -0
  77. package/lib/strapi/remote/flows/default.js +41 -0
  78. package/lib/strapi/remote/flows/index.d.ts +18 -0
  79. package/lib/strapi/remote/flows/index.js +59 -0
  80. package/lib/strapi/remote/handlers.d.ts +10 -0
  81. package/lib/strapi/remote/handlers.js +285 -0
  82. package/lib/strapi/remote/index.d.ts +3 -0
  83. package/lib/strapi/remote/index.js +30 -0
  84. package/lib/utils/encryption/decrypt.d.ts +11 -0
  85. package/lib/utils/encryption/decrypt.js +47 -0
  86. package/lib/utils/encryption/encrypt.d.ts +11 -0
  87. package/lib/utils/encryption/encrypt.js +47 -0
  88. package/lib/utils/encryption/index.d.ts +2 -0
  89. package/lib/utils/encryption/index.js +19 -0
  90. package/lib/utils/index.d.ts +5 -0
  91. package/lib/utils/index.js +32 -0
  92. package/lib/utils/json.d.ts +30 -0
  93. package/lib/utils/json.js +68 -0
  94. package/lib/utils/providers.d.ts +2 -0
  95. package/lib/utils/providers.js +11 -0
  96. package/lib/utils/schema.d.ts +7 -0
  97. package/lib/utils/schema.js +29 -0
  98. package/lib/utils/stream.d.ts +27 -0
  99. package/lib/utils/stream.js +59 -0
  100. package/lib/utils/transaction.d.ts +3 -0
  101. package/lib/utils/transaction.js +88 -0
  102. package/package.json +16 -17
  103. package/dist/engine/diagnostic.js.map +0 -1
  104. package/dist/engine/errors.js.map +0 -1
  105. package/dist/engine/index.js.map +0 -1
  106. package/dist/engine/validation/index.js.map +0 -1
  107. package/dist/engine/validation/provider.js.map +0 -1
  108. package/dist/engine/validation/schemas/index.js.map +0 -1
  109. package/dist/errors/base.js.map +0 -1
  110. package/dist/errors/constants.js.map +0 -1
  111. package/dist/errors/index.js.map +0 -1
  112. package/dist/errors/providers.js.map +0 -1
  113. package/dist/file/index.js.map +0 -1
  114. package/dist/file/providers/destination/index.js.map +0 -1
  115. package/dist/file/providers/destination/utils.js.map +0 -1
  116. package/dist/file/providers/index.js.map +0 -1
  117. package/dist/file/providers/source/index.js.map +0 -1
  118. package/dist/index.js.map +0 -1
  119. package/dist/strapi/index.js.map +0 -1
  120. package/dist/strapi/providers/index.js.map +0 -1
  121. package/dist/strapi/providers/local-destination/index.js.map +0 -1
  122. package/dist/strapi/providers/local-destination/strategies/index.js.map +0 -1
  123. package/dist/strapi/providers/local-destination/strategies/restore/configuration.js.map +0 -1
  124. package/dist/strapi/providers/local-destination/strategies/restore/entities.js.map +0 -1
  125. package/dist/strapi/providers/local-destination/strategies/restore/index.js.map +0 -1
  126. package/dist/strapi/providers/local-destination/strategies/restore/links.js.map +0 -1
  127. package/dist/strapi/providers/local-source/assets.js.map +0 -1
  128. package/dist/strapi/providers/local-source/configuration.js.map +0 -1
  129. package/dist/strapi/providers/local-source/entities.js.map +0 -1
  130. package/dist/strapi/providers/local-source/index.js.map +0 -1
  131. package/dist/strapi/providers/local-source/links.js.map +0 -1
  132. package/dist/strapi/providers/remote-destination/index.js.map +0 -1
  133. package/dist/strapi/providers/remote-source/index.js.map +0 -1
  134. package/dist/strapi/providers/utils.js.map +0 -1
  135. package/dist/strapi/queries/entity.js.map +0 -1
  136. package/dist/strapi/queries/index.js.map +0 -1
  137. package/dist/strapi/queries/link.js.map +0 -1
  138. package/dist/strapi/remote/constants.js.map +0 -1
  139. package/dist/strapi/remote/flows/default.js.map +0 -1
  140. package/dist/strapi/remote/flows/index.js.map +0 -1
  141. package/dist/strapi/remote/handlers/abstract.js.map +0 -1
  142. package/dist/strapi/remote/handlers/constants.js.map +0 -1
  143. package/dist/strapi/remote/handlers/index.js.map +0 -1
  144. package/dist/strapi/remote/handlers/pull.js.map +0 -1
  145. package/dist/strapi/remote/handlers/push.js.map +0 -1
  146. package/dist/strapi/remote/handlers/utils.js.map +0 -1
  147. package/dist/strapi/remote/index.js.map +0 -1
  148. package/dist/utils/encryption/decrypt.js.map +0 -1
  149. package/dist/utils/encryption/encrypt.js.map +0 -1
  150. package/dist/utils/encryption/index.js.map +0 -1
  151. package/dist/utils/index.js.map +0 -1
  152. package/dist/utils/json.js.map +0 -1
  153. package/dist/utils/providers.js.map +0 -1
  154. package/dist/utils/schema.js.map +0 -1
  155. package/dist/utils/stream.js.map +0 -1
  156. package/dist/utils/transaction.js.map +0 -1
@@ -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("./constants"), exports);
18
+ __exportStar(require("./base"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,21 @@
1
+ import { DataTransferError } from './base';
2
+ import { Severity } from './constants';
3
+ declare type ProviderStep = 'initialization' | 'validation' | 'transfer';
4
+ declare type ProviderErrorDetails<P extends ProviderStep = ProviderStep, U = never> = {
5
+ step: P;
6
+ } & ([U] extends [never] ? unknown : {
7
+ details?: U;
8
+ });
9
+ export declare class ProviderError<P extends ProviderStep = ProviderStep, U = never, T extends ProviderErrorDetails<P, U> = ProviderErrorDetails<P, U>> extends DataTransferError<T> {
10
+ constructor(severity: Severity, message?: string, details?: T | null);
11
+ }
12
+ export declare class ProviderInitializationError extends ProviderError<'initialization'> {
13
+ constructor(message?: string);
14
+ }
15
+ export declare class ProviderValidationError<T = ProviderErrorDetails> extends ProviderError<'validation', T> {
16
+ constructor(message?: string, details?: T);
17
+ }
18
+ export declare class ProviderTransferError<T = ProviderErrorDetails> extends ProviderError<'transfer', T> {
19
+ constructor(message?: string, details?: T);
20
+ }
21
+ export {};
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProviderTransferError = exports.ProviderValidationError = exports.ProviderInitializationError = exports.ProviderError = void 0;
4
+ const base_1 = require("./base");
5
+ const constants_1 = require("./constants");
6
+ class ProviderError extends base_1.DataTransferError {
7
+ constructor(severity, message, details) {
8
+ super('provider', severity, message, details);
9
+ }
10
+ }
11
+ exports.ProviderError = ProviderError;
12
+ class ProviderInitializationError extends ProviderError {
13
+ constructor(message) {
14
+ super(constants_1.SeverityKind.FATAL, message, { step: 'initialization' });
15
+ }
16
+ }
17
+ exports.ProviderInitializationError = ProviderInitializationError;
18
+ // TODO: these types are not working correctly, ProviderTransferError() is accepting any details object rather than requiring T
19
+ class ProviderValidationError extends ProviderError {
20
+ constructor(message, details) {
21
+ super(constants_1.SeverityKind.SILLY, message, { step: 'validation', details });
22
+ }
23
+ }
24
+ exports.ProviderValidationError = ProviderValidationError;
25
+ // TODO: these types are not working correctly, ProviderTransferError() is accepting any details object rather than requiring T
26
+ class ProviderTransferError extends ProviderError {
27
+ constructor(message, details) {
28
+ super(constants_1.SeverityKind.FATAL, message, { step: 'transfer', details });
29
+ }
30
+ }
31
+ exports.ProviderTransferError = ProviderTransferError;
32
+ //# sourceMappingURL=providers.js.map
@@ -0,0 +1 @@
1
+ export * as providers from './providers';
@@ -0,0 +1,28 @@
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.providers = void 0;
27
+ exports.providers = __importStar(require("./providers"));
28
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,45 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="stream-chain" />
3
+ import zlib from 'zlib';
4
+ import { Writable } from 'stream';
5
+ import type { IDestinationProvider, IDestinationProviderTransferResults, IMetadata, ProviderType } from '../../../../types';
6
+ export interface ILocalFileDestinationProviderOptions {
7
+ encryption: {
8
+ enabled: boolean;
9
+ key?: string;
10
+ };
11
+ compression: {
12
+ enabled: boolean;
13
+ };
14
+ file: {
15
+ path: string;
16
+ maxSize?: number;
17
+ maxSizeJsonl?: number;
18
+ };
19
+ }
20
+ export interface ILocalFileDestinationProviderTransferResults extends IDestinationProviderTransferResults {
21
+ file?: {
22
+ path?: string;
23
+ };
24
+ }
25
+ export declare const createLocalFileDestinationProvider: (options: ILocalFileDestinationProviderOptions) => LocalFileDestinationProvider;
26
+ declare class LocalFileDestinationProvider implements IDestinationProvider {
27
+ #private;
28
+ name: string;
29
+ type: ProviderType;
30
+ options: ILocalFileDestinationProviderOptions;
31
+ results: ILocalFileDestinationProviderTransferResults;
32
+ constructor(options: ILocalFileDestinationProviderOptions);
33
+ setMetadata(target: ProviderType, metadata: IMetadata): IDestinationProvider;
34
+ createGzip(): zlib.Gzip;
35
+ bootstrap(): void | Promise<void>;
36
+ close(): Promise<void>;
37
+ rollback(): Promise<void>;
38
+ getMetadata(): null;
39
+ createSchemasWriteStream(): import("stream-chain");
40
+ createEntitiesWriteStream(): Writable;
41
+ createLinksWriteStream(): Writable;
42
+ createConfigurationWriteStream(): Writable;
43
+ createAssetsWriteStream(): Writable;
44
+ }
45
+ export {};
@@ -0,0 +1,174 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
8
+ return (mod && mod.__esModule) ? mod : { "default": mod };
9
+ };
10
+ var _LocalFileDestinationProvider_instances, _LocalFileDestinationProvider_providersMetadata, _LocalFileDestinationProvider_archive, _LocalFileDestinationProvider_archivePath_get, _LocalFileDestinationProvider_writeMetadata, _LocalFileDestinationProvider_getMetadataStream;
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.createLocalFileDestinationProvider = void 0;
13
+ const fs_extra_1 = require("fs-extra");
14
+ const tar_stream_1 = __importDefault(require("tar-stream"));
15
+ const path_1 = __importDefault(require("path"));
16
+ const zlib_1 = __importDefault(require("zlib"));
17
+ const Stringer_1 = require("stream-json/jsonl/Stringer");
18
+ const stream_chain_1 = require("stream-chain");
19
+ const stream_1 = require("stream");
20
+ const encryption_1 = require("../../../utils/encryption");
21
+ const utils_1 = require("./utils");
22
+ const providers_1 = require("../../../errors/providers");
23
+ const createLocalFileDestinationProvider = (options) => {
24
+ return new LocalFileDestinationProvider(options);
25
+ };
26
+ exports.createLocalFileDestinationProvider = createLocalFileDestinationProvider;
27
+ class LocalFileDestinationProvider {
28
+ constructor(options) {
29
+ _LocalFileDestinationProvider_instances.add(this);
30
+ this.name = 'destination::local-file';
31
+ this.type = 'destination';
32
+ this.results = {};
33
+ _LocalFileDestinationProvider_providersMetadata.set(this, {});
34
+ _LocalFileDestinationProvider_archive.set(this, {});
35
+ this.options = options;
36
+ }
37
+ setMetadata(target, metadata) {
38
+ __classPrivateFieldGet(this, _LocalFileDestinationProvider_providersMetadata, "f")[target] = metadata;
39
+ return this;
40
+ }
41
+ createGzip() {
42
+ return zlib_1.default.createGzip();
43
+ }
44
+ bootstrap() {
45
+ const { compression, encryption } = this.options;
46
+ if (encryption.enabled && !encryption.key) {
47
+ throw new Error("Can't encrypt without a key");
48
+ }
49
+ __classPrivateFieldGet(this, _LocalFileDestinationProvider_archive, "f").stream = tar_stream_1.default.pack();
50
+ const outStream = (0, fs_extra_1.createWriteStream)(__classPrivateFieldGet(this, _LocalFileDestinationProvider_instances, "a", _LocalFileDestinationProvider_archivePath_get));
51
+ outStream.on('error', (err) => {
52
+ if (err.code === 'ENOSPC') {
53
+ throw new providers_1.ProviderTransferError("Your server doesn't have space to proceed with the import.");
54
+ }
55
+ throw err;
56
+ });
57
+ const archiveTransforms = [];
58
+ if (compression.enabled) {
59
+ archiveTransforms.push(this.createGzip());
60
+ }
61
+ if (encryption.enabled && encryption.key) {
62
+ archiveTransforms.push((0, encryption_1.createEncryptionCipher)(encryption.key));
63
+ }
64
+ __classPrivateFieldGet(this, _LocalFileDestinationProvider_archive, "f").pipeline = (0, stream_chain_1.chain)([__classPrivateFieldGet(this, _LocalFileDestinationProvider_archive, "f").stream, ...archiveTransforms, outStream]);
65
+ this.results.file = { path: __classPrivateFieldGet(this, _LocalFileDestinationProvider_instances, "a", _LocalFileDestinationProvider_archivePath_get) };
66
+ }
67
+ async close() {
68
+ const { stream, pipeline } = __classPrivateFieldGet(this, _LocalFileDestinationProvider_archive, "f");
69
+ if (!stream) {
70
+ return;
71
+ }
72
+ await __classPrivateFieldGet(this, _LocalFileDestinationProvider_instances, "m", _LocalFileDestinationProvider_writeMetadata).call(this);
73
+ stream.finalize();
74
+ if (pipeline && !pipeline.closed) {
75
+ await new Promise((resolve, reject) => {
76
+ pipeline.on('close', resolve).on('error', reject);
77
+ });
78
+ }
79
+ }
80
+ async rollback() {
81
+ await this.close();
82
+ await (0, fs_extra_1.rm)(__classPrivateFieldGet(this, _LocalFileDestinationProvider_instances, "a", _LocalFileDestinationProvider_archivePath_get), { force: true });
83
+ }
84
+ getMetadata() {
85
+ return null;
86
+ }
87
+ createSchemasWriteStream() {
88
+ if (!__classPrivateFieldGet(this, _LocalFileDestinationProvider_archive, "f").stream) {
89
+ throw new Error('Archive stream is unavailable');
90
+ }
91
+ const filePathFactory = (0, utils_1.createFilePathFactory)('schemas');
92
+ const entryStream = (0, utils_1.createTarEntryStream)(__classPrivateFieldGet(this, _LocalFileDestinationProvider_archive, "f").stream, filePathFactory, this.options.file.maxSizeJsonl);
93
+ return (0, stream_chain_1.chain)([(0, Stringer_1.stringer)(), entryStream]);
94
+ }
95
+ createEntitiesWriteStream() {
96
+ if (!__classPrivateFieldGet(this, _LocalFileDestinationProvider_archive, "f").stream) {
97
+ throw new Error('Archive stream is unavailable');
98
+ }
99
+ const filePathFactory = (0, utils_1.createFilePathFactory)('entities');
100
+ const entryStream = (0, utils_1.createTarEntryStream)(__classPrivateFieldGet(this, _LocalFileDestinationProvider_archive, "f").stream, filePathFactory, this.options.file.maxSizeJsonl);
101
+ return (0, stream_chain_1.chain)([(0, Stringer_1.stringer)(), entryStream]);
102
+ }
103
+ createLinksWriteStream() {
104
+ if (!__classPrivateFieldGet(this, _LocalFileDestinationProvider_archive, "f").stream) {
105
+ throw new Error('Archive stream is unavailable');
106
+ }
107
+ const filePathFactory = (0, utils_1.createFilePathFactory)('links');
108
+ const entryStream = (0, utils_1.createTarEntryStream)(__classPrivateFieldGet(this, _LocalFileDestinationProvider_archive, "f").stream, filePathFactory, this.options.file.maxSizeJsonl);
109
+ return (0, stream_chain_1.chain)([(0, Stringer_1.stringer)(), entryStream]);
110
+ }
111
+ createConfigurationWriteStream() {
112
+ if (!__classPrivateFieldGet(this, _LocalFileDestinationProvider_archive, "f").stream) {
113
+ throw new Error('Archive stream is unavailable');
114
+ }
115
+ const filePathFactory = (0, utils_1.createFilePathFactory)('configuration');
116
+ const entryStream = (0, utils_1.createTarEntryStream)(__classPrivateFieldGet(this, _LocalFileDestinationProvider_archive, "f").stream, filePathFactory, this.options.file.maxSizeJsonl);
117
+ return (0, stream_chain_1.chain)([(0, Stringer_1.stringer)(), entryStream]);
118
+ }
119
+ createAssetsWriteStream() {
120
+ const { stream: archiveStream } = __classPrivateFieldGet(this, _LocalFileDestinationProvider_archive, "f");
121
+ if (!archiveStream) {
122
+ throw new Error('Archive stream is unavailable');
123
+ }
124
+ return new stream_1.Writable({
125
+ objectMode: true,
126
+ write(data, _encoding, callback) {
127
+ const entryPath = path_1.default.join('assets', 'uploads', data.filename);
128
+ const entry = archiveStream.entry({
129
+ name: entryPath,
130
+ size: data.stats.size,
131
+ });
132
+ if (!entry) {
133
+ callback(new Error(`Failed to created a tar entry for ${entryPath}`));
134
+ return;
135
+ }
136
+ data.stream.pipe(entry);
137
+ entry
138
+ .on('finish', () => {
139
+ callback(null);
140
+ })
141
+ .on('error', (error) => {
142
+ callback(error);
143
+ });
144
+ },
145
+ });
146
+ }
147
+ }
148
+ _LocalFileDestinationProvider_providersMetadata = new WeakMap(), _LocalFileDestinationProvider_archive = new WeakMap(), _LocalFileDestinationProvider_instances = new WeakSet(), _LocalFileDestinationProvider_archivePath_get = function _LocalFileDestinationProvider_archivePath_get() {
149
+ const { encryption, compression, file } = this.options;
150
+ let filePath = `${file.path}.tar`;
151
+ if (compression.enabled) {
152
+ filePath += '.gz';
153
+ }
154
+ if (encryption.enabled) {
155
+ filePath += '.enc';
156
+ }
157
+ return filePath;
158
+ }, _LocalFileDestinationProvider_writeMetadata = async function _LocalFileDestinationProvider_writeMetadata() {
159
+ const metadata = __classPrivateFieldGet(this, _LocalFileDestinationProvider_providersMetadata, "f").source;
160
+ if (metadata) {
161
+ await new Promise((resolve) => {
162
+ const outStream = __classPrivateFieldGet(this, _LocalFileDestinationProvider_instances, "m", _LocalFileDestinationProvider_getMetadataStream).call(this);
163
+ const data = JSON.stringify(metadata, null, 2);
164
+ stream_1.Readable.from(data).pipe(outStream).on('close', resolve);
165
+ });
166
+ }
167
+ }, _LocalFileDestinationProvider_getMetadataStream = function _LocalFileDestinationProvider_getMetadataStream() {
168
+ const { stream } = __classPrivateFieldGet(this, _LocalFileDestinationProvider_archive, "f");
169
+ if (!stream) {
170
+ throw new Error('Archive stream is unavailable');
171
+ }
172
+ return (0, utils_1.createTarEntryStream)(stream, () => 'metadata.json');
173
+ };
174
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,9 @@
1
+ /// <reference types="node" />
2
+ import { Writable } from 'stream';
3
+ import tar from 'tar-stream';
4
+ /**
5
+ * Create a file path factory for a given path & prefix.
6
+ * Upon being called, the factory will return a file path for a given index
7
+ */
8
+ export declare const createFilePathFactory: (type: string) => (fileIndex?: number) => string;
9
+ export declare const createTarEntryStream: (archive: tar.Pack, pathFactory: (index?: number | undefined) => string, maxSize?: number) => Writable;
@@ -0,0 +1,61 @@
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
+ return (0, path_1.join)(
12
+ // "{type}" directory
13
+ type,
14
+ // "${type}_XXXXX.jsonl" file
15
+ `${type}_${String(fileIndex).padStart(5, '0')}.jsonl`);
16
+ };
17
+ exports.createFilePathFactory = createFilePathFactory;
18
+ const createTarEntryStream = (archive, pathFactory, maxSize = 2.56e8) => {
19
+ let fileIndex = 0;
20
+ let buffer = '';
21
+ const flush = async () => {
22
+ if (!buffer) {
23
+ return;
24
+ }
25
+ fileIndex += 1;
26
+ const name = pathFactory(fileIndex);
27
+ const size = buffer.length;
28
+ await new Promise((resolve, reject) => {
29
+ archive.entry({ name, size }, buffer, (err) => {
30
+ if (err) {
31
+ reject(err);
32
+ }
33
+ resolve();
34
+ });
35
+ });
36
+ buffer = '';
37
+ };
38
+ const push = (chunk) => {
39
+ buffer += chunk;
40
+ };
41
+ return new stream_1.Writable({
42
+ async destroy(err, callback) {
43
+ await flush();
44
+ callback(err);
45
+ },
46
+ async write(chunk, _encoding, callback) {
47
+ const size = chunk.length;
48
+ if (chunk.length > maxSize) {
49
+ callback(new Error(`payload too large: ${chunk.length}>${maxSize}`));
50
+ return;
51
+ }
52
+ if (buffer.length + size > maxSize) {
53
+ await flush();
54
+ }
55
+ push(chunk);
56
+ callback(null);
57
+ },
58
+ });
59
+ };
60
+ exports.createTarEntryStream = createTarEntryStream;
61
+ //# sourceMappingURL=utils.js.map
@@ -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,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>;
33
+ getSchemas(): Promise<import("lodash").Dictionary<Schema>>;
34
+ createEntitiesReadStream(): Readable;
35
+ createSchemasReadStream(): Readable;
36
+ createLinksReadStream(): Readable;
37
+ createConfigurationReadStream(): Readable;
38
+ createAssetsReadStream(): Readable | Promise<Readable>;
39
+ }
40
+ export {};