@strapi/data-transfer 4.6.0-beta.1 → 4.6.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 (113) hide show
  1. package/lib/engine/diagnostic.d.ts +40 -0
  2. package/lib/engine/diagnostic.js +50 -0
  3. package/lib/engine/errors.d.ts +28 -0
  4. package/lib/engine/errors.js +29 -0
  5. package/{dist → lib}/engine/index.d.ts +18 -4
  6. package/{dist → lib}/engine/index.js +211 -45
  7. package/lib/engine/validation/index.d.ts +2 -0
  8. package/{dist → lib/engine/validation}/index.js +2 -2
  9. package/lib/engine/validation/provider.d.ts +3 -0
  10. package/lib/engine/validation/provider.js +18 -0
  11. package/{dist/strategies → lib/engine/validation/schemas}/index.d.ts +2 -2
  12. package/{dist/strategies → lib/engine/validation/schemas}/index.js +3 -2
  13. package/lib/errors/base.d.ts +8 -0
  14. package/lib/errors/base.js +13 -0
  15. package/lib/errors/constants.d.ts +3 -0
  16. package/lib/errors/constants.js +9 -0
  17. package/lib/errors/index.d.ts +2 -0
  18. package/{dist/providers → lib/errors}/index.js +2 -6
  19. package/lib/errors/providers.d.ts +21 -0
  20. package/lib/errors/providers.js +32 -0
  21. package/lib/file/index.d.ts +1 -0
  22. package/{dist/providers/shared → lib/file}/index.js +2 -2
  23. package/{dist/providers/local-file-destination-provider → lib/file/providers/destination}/index.d.ts +6 -6
  24. package/{dist/providers/local-file-destination-provider → lib/file/providers/destination}/index.js +7 -7
  25. package/{dist/providers/local-file-destination-provider → lib/file/providers/destination}/utils.d.ts +0 -0
  26. package/{dist/providers/local-file-destination-provider → lib/file/providers/destination}/utils.js +0 -0
  27. package/lib/file/providers/index.d.ts +2 -0
  28. package/lib/file/providers/index.js +19 -0
  29. package/{dist/providers/local-file-source-provider → lib/file/providers/source}/index.d.ts +9 -8
  30. package/{dist/providers/local-file-source-provider → lib/file/providers/source}/index.js +42 -56
  31. package/lib/index.d.ts +4 -0
  32. package/lib/index.js +31 -0
  33. package/lib/strapi/index.d.ts +4 -0
  34. package/lib/strapi/index.js +35 -0
  35. package/lib/strapi/providers/index.d.ts +3 -0
  36. package/lib/strapi/providers/index.js +22 -0
  37. package/{dist/providers/local-strapi-destination-provider → lib/strapi/providers/local-destination}/index.d.ts +10 -7
  38. package/{dist/providers/local-strapi-destination-provider → lib/strapi/providers/local-destination}/index.js +65 -37
  39. package/{dist/providers/local-strapi-destination-provider → lib/strapi/providers/local-destination}/strategies/index.d.ts +0 -0
  40. package/{dist/providers/local-strapi-destination-provider → lib/strapi/providers/local-destination}/strategies/index.js +0 -0
  41. package/{dist/providers/local-strapi-destination-provider → lib/strapi/providers/local-destination}/strategies/restore/configuration.d.ts +2 -2
  42. package/{dist/providers/local-strapi-destination-provider → lib/strapi/providers/local-destination}/strategies/restore/configuration.js +17 -10
  43. package/{dist/providers/local-strapi-destination-provider → lib/strapi/providers/local-destination}/strategies/restore/entities.d.ts +2 -0
  44. package/lib/strapi/providers/local-destination/strategies/restore/entities.js +103 -0
  45. package/{dist/providers/local-strapi-destination-provider → lib/strapi/providers/local-destination}/strategies/restore/index.d.ts +0 -0
  46. package/{dist/providers/local-strapi-destination-provider → lib/strapi/providers/local-destination}/strategies/restore/index.js +4 -3
  47. package/lib/strapi/providers/local-destination/strategies/restore/links.d.ts +4 -0
  48. package/lib/strapi/providers/local-destination/strategies/restore/links.js +32 -0
  49. package/{dist/providers/local-strapi-source-provider → lib/strapi/providers/local-source}/assets.d.ts +0 -0
  50. package/{dist/providers/local-strapi-source-provider → lib/strapi/providers/local-source}/assets.js +0 -0
  51. package/{dist/providers/local-strapi-source-provider → lib/strapi/providers/local-source}/configuration.d.ts +0 -0
  52. package/{dist/providers/local-strapi-source-provider → lib/strapi/providers/local-source}/configuration.js +12 -13
  53. package/{dist/providers/local-strapi-source-provider → lib/strapi/providers/local-source}/entities.d.ts +0 -0
  54. package/{dist/providers/local-strapi-source-provider → lib/strapi/providers/local-source}/entities.js +11 -4
  55. package/{dist/providers/local-strapi-source-provider → lib/strapi/providers/local-source}/index.d.ts +6 -6
  56. package/{dist/providers/local-strapi-source-provider → lib/strapi/providers/local-source}/index.js +12 -27
  57. package/{dist/providers/local-strapi-source-provider → lib/strapi/providers/local-source}/links.d.ts +0 -0
  58. package/{dist/providers/local-strapi-source-provider → lib/strapi/providers/local-source}/links.js +1 -1
  59. package/lib/strapi/providers/remote-destination/index.d.ts +40 -0
  60. package/lib/strapi/providers/remote-destination/index.js +186 -0
  61. package/lib/strapi/providers/remote-destination/utils.d.ts +31 -0
  62. package/lib/strapi/providers/remote-destination/utils.js +72 -0
  63. package/{dist/providers/shared/strapi → lib/strapi/queries}/entity.d.ts +0 -0
  64. package/{dist/providers/shared/strapi → lib/strapi/queries}/entity.js +0 -0
  65. package/{dist/providers/shared/strapi → lib/strapi/queries}/index.d.ts +0 -0
  66. package/{dist/providers/shared/strapi → lib/strapi/queries}/index.js +0 -0
  67. package/{dist/providers/shared/strapi → lib/strapi/queries}/link.d.ts +2 -2
  68. package/{dist/providers/shared/strapi → lib/strapi/queries}/link.js +17 -3
  69. package/lib/strapi/register.d.ts +7 -0
  70. package/lib/strapi/register.js +13 -0
  71. package/lib/strapi/remote/constants.d.ts +2 -0
  72. package/lib/strapi/remote/constants.js +6 -0
  73. package/lib/strapi/remote/controllers/index.d.ts +1 -0
  74. package/lib/strapi/remote/controllers/index.js +18 -0
  75. package/lib/strapi/remote/controllers/push.d.ts +25 -0
  76. package/lib/strapi/remote/controllers/push.js +95 -0
  77. package/lib/strapi/remote/handlers.d.ts +3 -0
  78. package/lib/strapi/remote/handlers.js +193 -0
  79. package/lib/strapi/remote/index.d.ts +3 -0
  80. package/lib/strapi/remote/index.js +30 -0
  81. package/lib/strapi/remote/routes.d.ts +21 -0
  82. package/lib/strapi/remote/routes.js +22 -0
  83. package/lib/utils/encryption/decrypt.d.ts +11 -0
  84. package/{dist → lib/utils}/encryption/decrypt.js +8 -0
  85. package/lib/utils/encryption/encrypt.d.ts +11 -0
  86. package/{dist → lib/utils}/encryption/encrypt.js +8 -0
  87. package/{dist → lib/utils}/encryption/index.d.ts +0 -0
  88. package/{dist → lib/utils}/encryption/index.js +0 -0
  89. package/{dist → lib}/utils/index.d.ts +2 -0
  90. package/{dist → lib}/utils/index.js +3 -1
  91. package/{dist → lib}/utils/json.d.ts +7 -0
  92. package/{dist → lib}/utils/json.js +8 -1
  93. package/lib/utils/providers.d.ts +2 -0
  94. package/lib/utils/providers.js +11 -0
  95. package/{dist → lib}/utils/schema.d.ts +4 -0
  96. package/{dist → lib}/utils/schema.js +9 -2
  97. package/lib/utils/stream.d.ts +27 -0
  98. package/lib/utils/stream.js +59 -0
  99. package/lib/utils/transaction.d.ts +3 -0
  100. package/lib/utils/transaction.js +70 -0
  101. package/package.json +20 -12
  102. package/dist/encryption/decrypt.d.ts +0 -3
  103. package/dist/encryption/encrypt.d.ts +0 -3
  104. package/dist/index.d.ts +0 -2
  105. package/dist/providers/index.d.ts +0 -4
  106. package/dist/providers/local-strapi-destination-provider/strategies/restore/entities.js +0 -88
  107. package/dist/providers/local-strapi-destination-provider/strategies/restore/links.d.ts +0 -3
  108. package/dist/providers/local-strapi-destination-provider/strategies/restore/links.js +0 -29
  109. package/dist/providers/shared/index.d.ts +0 -1
  110. package/dist/providers/test-utils/index.d.ts +0 -111
  111. package/dist/providers/test-utils/index.js +0 -64
  112. package/dist/utils/stream.d.ts +0 -10
  113. package/dist/utils/stream.js +0 -39
@@ -23,7 +23,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- const utils = __importStar(require("../utils"));
26
+ exports.compareSchemas = void 0;
27
+ const utils = __importStar(require("../../../utils"));
27
28
  const strategies = {
28
29
  // No diffs
29
30
  exact(diffs) {
@@ -48,5 +49,5 @@ const compareSchemas = (a, b, strategy) => {
48
49
  const diffs = utils.json.diff(a, b);
49
50
  return strategies[strategy](diffs);
50
51
  };
51
- exports.default = compareSchemas;
52
+ exports.compareSchemas = compareSchemas;
52
53
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,8 @@
1
+ import { Severity } from './constants';
2
+ declare class DataTransferError<T = unknown> extends Error {
3
+ origin: string;
4
+ severity: Severity;
5
+ details: T | null;
6
+ constructor(origin: string, severity: Severity, message?: string, details?: T | null);
7
+ }
8
+ export { DataTransferError };
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DataTransferError = void 0;
4
+ class DataTransferError extends Error {
5
+ constructor(origin, severity, message, details) {
6
+ super(message);
7
+ this.origin = origin;
8
+ this.severity = severity;
9
+ this.details = details ?? null;
10
+ }
11
+ }
12
+ exports.DataTransferError = DataTransferError;
13
+ //# sourceMappingURL=base.js.map
@@ -0,0 +1,3 @@
1
+ import { ErrorDiagnosticSeverity } from '../engine/diagnostic';
2
+ export declare const SeverityKind: Record<string, ErrorDiagnosticSeverity>;
3
+ export declare type Severity = typeof SeverityKind[keyof typeof SeverityKind];
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SeverityKind = void 0;
4
+ exports.SeverityKind = {
5
+ FATAL: 'fatal',
6
+ ERROR: 'error',
7
+ SILLY: 'silly',
8
+ };
9
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1,2 @@
1
+ export * from './constants';
2
+ export * from './base';
@@ -14,10 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- // source providers
18
- __exportStar(require("./local-file-source-provider"), exports);
19
- __exportStar(require("./local-strapi-source-provider"), exports);
20
- // destination providers
21
- __exportStar(require("./local-file-destination-provider"), exports);
22
- __exportStar(require("./local-strapi-destination-provider"), exports);
17
+ __exportStar(require("./constants"), exports);
18
+ __exportStar(require("./base"), exports);
23
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';
@@ -23,6 +23,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.strapi = void 0;
27
- exports.strapi = __importStar(require("./strapi"));
26
+ exports.providers = void 0;
27
+ exports.providers = __importStar(require("./providers"));
28
28
  //# sourceMappingURL=index.js.map
@@ -2,7 +2,7 @@
2
2
  /// <reference types="stream-chain" />
3
3
  import zlib from 'zlib';
4
4
  import { Writable } from 'stream';
5
- import type { IDestinationProvider, IDestinationProviderTransferResults, IMetadata, ProviderType } from '../../../types';
5
+ import type { IDestinationProvider, IDestinationProviderTransferResults, IMetadata, ProviderType } from '../../../../types';
6
6
  export interface ILocalFileDestinationProviderOptions {
7
7
  encryption: {
8
8
  enabled: boolean;
@@ -36,10 +36,10 @@ declare class LocalFileDestinationProvider implements IDestinationProvider {
36
36
  close(): Promise<void>;
37
37
  rollback(): Promise<void>;
38
38
  getMetadata(): null;
39
- getSchemasStream(): import("stream-chain");
40
- getEntitiesStream(): Writable;
41
- getLinksStream(): Writable;
42
- getConfigurationStream(): Writable;
43
- getAssetsStream(): Writable;
39
+ createSchemasWriteStream(): import("stream-chain");
40
+ createEntitiesWriteStream(): Writable;
41
+ createLinksWriteStream(): Writable;
42
+ createConfigurationWriteStream(): Writable;
43
+ createAssetsWriteStream(): Writable;
44
44
  }
45
45
  export {};
@@ -17,7 +17,7 @@ const zlib_1 = __importDefault(require("zlib"));
17
17
  const Stringer_1 = require("stream-json/jsonl/Stringer");
18
18
  const stream_chain_1 = require("stream-chain");
19
19
  const stream_1 = require("stream");
20
- const encrypt_1 = require("../../encryption/encrypt");
20
+ const encryption_1 = require("../../../utils/encryption");
21
21
  const utils_1 = require("./utils");
22
22
  const createLocalFileDestinationProvider = (options) => {
23
23
  return new LocalFileDestinationProvider(options);
@@ -52,7 +52,7 @@ class LocalFileDestinationProvider {
52
52
  archiveTransforms.push(this.createGzip());
53
53
  }
54
54
  if (encryption.enabled && encryption.key) {
55
- archiveTransforms.push((0, encrypt_1.createEncryptionCipher)(encryption.key));
55
+ archiveTransforms.push((0, encryption_1.createEncryptionCipher)(encryption.key));
56
56
  }
57
57
  __classPrivateFieldGet(this, _LocalFileDestinationProvider_archive, "f").pipeline = (0, stream_chain_1.chain)([__classPrivateFieldGet(this, _LocalFileDestinationProvider_archive, "f").stream, ...archiveTransforms, outStream]);
58
58
  this.results.file = { path: __classPrivateFieldGet(this, _LocalFileDestinationProvider_instances, "a", _LocalFileDestinationProvider_archivePath_get) };
@@ -77,7 +77,7 @@ class LocalFileDestinationProvider {
77
77
  getMetadata() {
78
78
  return null;
79
79
  }
80
- getSchemasStream() {
80
+ createSchemasWriteStream() {
81
81
  if (!__classPrivateFieldGet(this, _LocalFileDestinationProvider_archive, "f").stream) {
82
82
  throw new Error('Archive stream is unavailable');
83
83
  }
@@ -85,7 +85,7 @@ class LocalFileDestinationProvider {
85
85
  const entryStream = (0, utils_1.createTarEntryStream)(__classPrivateFieldGet(this, _LocalFileDestinationProvider_archive, "f").stream, filePathFactory, this.options.file.maxSizeJsonl);
86
86
  return (0, stream_chain_1.chain)([(0, Stringer_1.stringer)(), entryStream]);
87
87
  }
88
- getEntitiesStream() {
88
+ createEntitiesWriteStream() {
89
89
  if (!__classPrivateFieldGet(this, _LocalFileDestinationProvider_archive, "f").stream) {
90
90
  throw new Error('Archive stream is unavailable');
91
91
  }
@@ -93,7 +93,7 @@ class LocalFileDestinationProvider {
93
93
  const entryStream = (0, utils_1.createTarEntryStream)(__classPrivateFieldGet(this, _LocalFileDestinationProvider_archive, "f").stream, filePathFactory, this.options.file.maxSizeJsonl);
94
94
  return (0, stream_chain_1.chain)([(0, Stringer_1.stringer)(), entryStream]);
95
95
  }
96
- getLinksStream() {
96
+ createLinksWriteStream() {
97
97
  if (!__classPrivateFieldGet(this, _LocalFileDestinationProvider_archive, "f").stream) {
98
98
  throw new Error('Archive stream is unavailable');
99
99
  }
@@ -101,7 +101,7 @@ class LocalFileDestinationProvider {
101
101
  const entryStream = (0, utils_1.createTarEntryStream)(__classPrivateFieldGet(this, _LocalFileDestinationProvider_archive, "f").stream, filePathFactory, this.options.file.maxSizeJsonl);
102
102
  return (0, stream_chain_1.chain)([(0, Stringer_1.stringer)(), entryStream]);
103
103
  }
104
- getConfigurationStream() {
104
+ createConfigurationWriteStream() {
105
105
  if (!__classPrivateFieldGet(this, _LocalFileDestinationProvider_archive, "f").stream) {
106
106
  throw new Error('Archive stream is unavailable');
107
107
  }
@@ -109,7 +109,7 @@ class LocalFileDestinationProvider {
109
109
  const entryStream = (0, utils_1.createTarEntryStream)(__classPrivateFieldGet(this, _LocalFileDestinationProvider_archive, "f").stream, filePathFactory, this.options.file.maxSizeJsonl);
110
110
  return (0, stream_chain_1.chain)([(0, Stringer_1.stringer)(), entryStream]);
111
111
  }
112
- getAssetsStream() {
112
+ createAssetsWriteStream() {
113
113
  const { stream: archiveStream } = __classPrivateFieldGet(this, _LocalFileDestinationProvider_archive, "f");
114
114
  if (!archiveStream) {
115
115
  throw new Error('Archive stream is unavailable');
@@ -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
@@ -1,7 +1,8 @@
1
1
  /// <reference types="lodash" />
2
2
  /// <reference types="node" />
3
3
  import type { Readable } from 'stream';
4
- import type { IMetadata, ISourceProvider, ProviderType } from '../../../types';
4
+ import type { Schema } from '@strapi/strapi';
5
+ import type { IMetadata, ISourceProvider, ProviderType } from '../../../../types';
5
6
  /**
6
7
  * Provider options
7
8
  */
@@ -25,15 +26,15 @@ declare class LocalFileSourceProvider implements ISourceProvider {
25
26
  options: ILocalFileSourceProviderOptions;
26
27
  constructor(options: ILocalFileSourceProviderOptions);
27
28
  /**
28
- * Pre flight checks regarding the provided options (making sure that the provided path is correct, etc...)
29
+ * Pre flight checks regarding the provided options, making sure that the file can be opened (decrypted, decompressed), etc.
29
30
  */
30
31
  bootstrap(): Promise<void>;
31
32
  getMetadata(): Promise<IMetadata>;
32
- getSchemas(): Promise<import("lodash").Dictionary<unknown>>;
33
- streamEntities(): Readable;
34
- streamSchemas(): Readable;
35
- streamLinks(): Readable;
36
- streamConfiguration(): Readable;
37
- streamAssets(): Readable | Promise<Readable>;
33
+ getSchemas(): Promise<import("lodash").Dictionary<Schema>>;
34
+ createEntitiesReadStream(): Readable;
35
+ createSchemasReadStream(): Readable;
36
+ createLinksReadStream(): Readable;
37
+ createConfigurationReadStream(): Readable;
38
+ createAssetsReadStream(): Readable | Promise<Readable>;
38
39
  }
39
40
  export {};
@@ -1,26 +1,9 @@
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;
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ 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");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
24
7
  };
25
8
  var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
26
9
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
@@ -30,7 +13,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
30
13
  var __importDefault = (this && this.__importDefault) || function (mod) {
31
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
32
15
  };
33
- var _LocalFileSourceProvider_instances, _LocalFileSourceProvider_getBackupStream, _LocalFileSourceProvider_streamJsonlDirectory, _LocalFileSourceProvider_parseJSONFile;
16
+ var _LocalFileSourceProvider_instances, _LocalFileSourceProvider_metadata, _LocalFileSourceProvider_getBackupStream, _LocalFileSourceProvider_streamJsonlDirectory, _LocalFileSourceProvider_parseJSONFile;
34
17
  Object.defineProperty(exports, "__esModule", { value: true });
35
18
  exports.createLocalFileSourceProvider = void 0;
36
19
  const fs_extra_1 = __importDefault(require("fs-extra"));
@@ -41,8 +24,8 @@ const fp_1 = require("lodash/fp");
41
24
  const stream_chain_1 = require("stream-chain");
42
25
  const stream_1 = require("stream");
43
26
  const Parser_1 = require("stream-json/jsonl/Parser");
44
- const encryption_1 = require("../../encryption");
45
- const utils = __importStar(require("../../utils"));
27
+ const encryption_1 = require("../../../utils/encryption");
28
+ const stream_2 = require("../../../utils/stream");
46
29
  /**
47
30
  * Constant for the metadata file path
48
31
  */
@@ -56,6 +39,7 @@ class LocalFileSourceProvider {
56
39
  _LocalFileSourceProvider_instances.add(this);
57
40
  this.type = 'source';
58
41
  this.name = 'source::local-file';
42
+ _LocalFileSourceProvider_metadata.set(this, void 0);
59
43
  this.options = options;
60
44
  const { encryption } = this.options;
61
45
  if (encryption.enabled && encryption.key === undefined) {
@@ -63,16 +47,16 @@ class LocalFileSourceProvider {
63
47
  }
64
48
  }
65
49
  /**
66
- * Pre flight checks regarding the provided options (making sure that the provided path is correct, etc...)
50
+ * Pre flight checks regarding the provided options, making sure that the file can be opened (decrypted, decompressed), etc.
67
51
  */
68
52
  async bootstrap() {
69
53
  const { path: filePath } = this.options.file;
70
54
  try {
71
- // This is only to show a nicer error, it doesn't ensure the file will still exist when we try to open it later
72
- await fs_extra_1.default.access(filePath, fs_extra_1.default.constants.R_OK);
55
+ // Read the metadata to ensure the file can be parsed
56
+ __classPrivateFieldSet(this, _LocalFileSourceProvider_metadata, await this.getMetadata(), "f");
73
57
  }
74
58
  catch (e) {
75
- throw new Error(`Can't access file "${filePath}".`);
59
+ throw new Error(`Can't read file "${filePath}".`);
76
60
  }
77
61
  }
78
62
  getMetadata() {
@@ -82,23 +66,23 @@ class LocalFileSourceProvider {
82
66
  return __classPrivateFieldGet(this, _LocalFileSourceProvider_instances, "m", _LocalFileSourceProvider_parseJSONFile).call(this, backupStream, METADATA_FILE_PATH);
83
67
  }
84
68
  async getSchemas() {
85
- const schemas = await utils.stream.collect(this.streamSchemas());
69
+ const schemas = await (0, stream_2.collect)(this.createSchemasReadStream());
86
70
  return (0, fp_1.keyBy)('uid', schemas);
87
71
  }
88
- streamEntities() {
72
+ createEntitiesReadStream() {
89
73
  return __classPrivateFieldGet(this, _LocalFileSourceProvider_instances, "m", _LocalFileSourceProvider_streamJsonlDirectory).call(this, 'entities');
90
74
  }
91
- streamSchemas() {
75
+ createSchemasReadStream() {
92
76
  return __classPrivateFieldGet(this, _LocalFileSourceProvider_instances, "m", _LocalFileSourceProvider_streamJsonlDirectory).call(this, 'schemas');
93
77
  }
94
- streamLinks() {
78
+ createLinksReadStream() {
95
79
  return __classPrivateFieldGet(this, _LocalFileSourceProvider_instances, "m", _LocalFileSourceProvider_streamJsonlDirectory).call(this, 'links');
96
80
  }
97
- streamConfiguration() {
81
+ createConfigurationReadStream() {
98
82
  // NOTE: TBD
99
83
  return __classPrivateFieldGet(this, _LocalFileSourceProvider_instances, "m", _LocalFileSourceProvider_streamJsonlDirectory).call(this, 'configuration');
100
84
  }
101
- streamAssets() {
85
+ createAssetsReadStream() {
102
86
  const inStream = __classPrivateFieldGet(this, _LocalFileSourceProvider_instances, "m", _LocalFileSourceProvider_getBackupStream).call(this);
103
87
  const outStream = new stream_1.PassThrough({ objectMode: true });
104
88
  (0, stream_1.pipeline)([
@@ -127,7 +111,7 @@ class LocalFileSourceProvider {
127
111
  return outStream;
128
112
  }
129
113
  }
130
- _LocalFileSourceProvider_instances = new WeakSet(), _LocalFileSourceProvider_getBackupStream = function _LocalFileSourceProvider_getBackupStream() {
114
+ _LocalFileSourceProvider_metadata = new WeakMap(), _LocalFileSourceProvider_instances = new WeakSet(), _LocalFileSourceProvider_getBackupStream = function _LocalFileSourceProvider_getBackupStream() {
131
115
  const { file, encryption, compression } = this.options;
132
116
  const streams = [];
133
117
  try {
@@ -153,29 +137,27 @@ _LocalFileSourceProvider_instances = new WeakSet(), _LocalFileSourceProvider_get
153
137
  if (entry.type !== 'File') {
154
138
  return false;
155
139
  }
156
- const parts = filePath.split('/');
140
+ const parts = path_1.default.relative('.', filePath).split('/');
141
+ // TODO: this method is limiting us from having additional subdirectories and is requiring us to remove any "./" prefixes (the path.relative line above)
157
142
  if (parts.length !== 2) {
158
143
  return false;
159
144
  }
160
145
  return parts[0] === directory;
161
146
  },
162
- onentry(entry) {
147
+ async onentry(entry) {
163
148
  const transforms = [
164
149
  // JSONL parser to read the data chunks one by one (line by line)
165
150
  (0, Parser_1.parser)(),
166
151
  // The JSONL parser returns each line as key/value
167
152
  (line) => line.value,
168
153
  ];
169
- entry
170
- // Pipe transforms
171
- .pipe((0, stream_chain_1.chain)(transforms))
172
- // Pipe the out stream to the whole pipeline
173
- // DO NOT send the 'end' event when this entry has finished
174
- // emitting data, so that it doesn't close the out stream
175
- .pipe(outStream, { end: false });
154
+ const stream = entry.pipe((0, stream_chain_1.chain)(transforms));
155
+ for await (const chunk of stream) {
156
+ outStream.write(chunk);
157
+ }
176
158
  },
177
159
  }),
178
- ], () => {
160
+ ], async () => {
179
161
  // Manually send the 'end' event to the out stream
180
162
  // once every entry has finished streaming its content
181
163
  outStream.end();
@@ -191,20 +173,24 @@ _LocalFileSourceProvider_instances = new WeakSet(), _LocalFileSourceProvider_get
191
173
  * Filter the parsed entries to only keep the one that matches the given filepath
192
174
  */
193
175
  filter(entryPath, entry) {
194
- return entryPath === filePath && entry.type === 'File';
176
+ return !path_1.default.relative(filePath, entryPath).length && entry.type === 'File';
195
177
  },
196
- /**
197
- * Whenever an entry passes the filter method, process it
198
- */
199
178
  async onentry(entry) {
200
179
  // Collect all the content of the entry file
201
180
  const content = await entry.collect();
202
- // Parse from buffer to string to JSON
203
- const parsedContent = JSON.parse(content.toString());
204
- // Resolve the Promise with the parsed content
205
- resolve(parsedContent);
206
- // Cleanup (close the stream associated to the entry)
207
- entry.destroy();
181
+ try {
182
+ // Parse from buffer to string to JSON
183
+ const parsedContent = JSON.parse(content.toString());
184
+ // Resolve the Promise with the parsed content
185
+ resolve(parsedContent);
186
+ }
187
+ catch (e) {
188
+ reject(e);
189
+ }
190
+ finally {
191
+ // Cleanup (close the stream associated to the entry)
192
+ entry.destroy();
193
+ }
208
194
  },
209
195
  }),
210
196
  ], () => {
package/lib/index.d.ts ADDED
@@ -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/lib/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,4 @@
1
+ export * as providers from './providers';
2
+ export * as queries from './queries';
3
+ export * as remote from './remote';
4
+ export { default as register } from './register';
@@ -0,0 +1,35 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.register = exports.remote = exports.queries = exports.providers = void 0;
30
+ exports.providers = __importStar(require("./providers"));
31
+ exports.queries = __importStar(require("./queries"));
32
+ exports.remote = __importStar(require("./remote"));
33
+ var register_1 = require("./register");
34
+ Object.defineProperty(exports, "register", { enumerable: true, get: function () { return __importDefault(register_1).default; } });
35
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,3 @@
1
+ export * from './local-destination';
2
+ export * from './local-source';
3
+ export * from './remote-destination';
@@ -0,0 +1,22 @@
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
+ //# sourceMappingURL=index.js.map
@@ -1,12 +1,13 @@
1
1
  /// <reference types="lodash" />
2
2
  /// <reference types="node" />
3
3
  import { Writable } from 'stream';
4
- import type { IDestinationProvider, IMetadata, ProviderType } from '../../../types';
4
+ import type { IDestinationProvider, IMetadata, ProviderType, Transaction } from '../../../../types';
5
5
  import { restore } from './strategies';
6
6
  export declare const VALID_CONFLICT_STRATEGIES: string[];
7
7
  export declare const DEFAULT_CONFLICT_STRATEGY = "restore";
8
- interface ILocalStrapiDestinationProviderOptions {
8
+ export interface ILocalStrapiDestinationProviderOptions {
9
9
  getStrapi(): Strapi.Strapi | Promise<Strapi.Strapi>;
10
+ autoDestroy?: boolean;
10
11
  restore?: restore.IRestoreOptions;
11
12
  strategy: 'restore' | 'merge';
12
13
  }
@@ -16,16 +17,18 @@ declare class LocalStrapiDestinationProvider implements IDestinationProvider {
16
17
  type: ProviderType;
17
18
  options: ILocalStrapiDestinationProviderOptions;
18
19
  strapi?: Strapi.Strapi;
20
+ transaction?: Transaction;
19
21
  constructor(options: ILocalStrapiDestinationProviderOptions);
20
22
  bootstrap(): Promise<void>;
21
23
  close(): Promise<void>;
24
+ rollback(): void;
22
25
  beforeTransfer(): Promise<void>;
23
- getMetadata(): IMetadata | Promise<IMetadata>;
26
+ getMetadata(): IMetadata;
24
27
  getSchemas(): import("lodash").Dictionary<Partial<import("@strapi/strapi").Schema>>;
25
- getEntitiesStream(): Writable;
26
- getAssetsStream(): Promise<Writable>;
27
- getConfigurationStream(): Promise<Writable>;
28
- getLinksStream(): Promise<Writable>;
28
+ createEntitiesWriteStream(): Writable;
29
+ createAssetsWriteStream(): Promise<Writable>;
30
+ createConfigurationWriteStream(): Promise<Writable>;
31
+ createLinksWriteStream(): Promise<Writable>;
29
32
  }
30
33
  export declare const createLocalStrapiDestinationProvider: (options: ILocalStrapiDestinationProviderOptions) => LocalStrapiDestinationProvider;
31
34
  export {};