@strapi/data-transfer 5.41.0 → 5.42.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 (49) hide show
  1. package/dist/directory/index.d.ts +2 -0
  2. package/dist/directory/index.d.ts.map +1 -0
  3. package/dist/directory/index.js +8 -0
  4. package/dist/directory/index.js.map +1 -0
  5. package/dist/directory/index.mjs +3 -0
  6. package/dist/directory/index.mjs.map +1 -0
  7. package/dist/directory/providers/destination/index.d.ts +40 -0
  8. package/dist/directory/providers/destination/index.d.ts.map +1 -0
  9. package/dist/directory/providers/destination/index.js +179 -0
  10. package/dist/directory/providers/destination/index.js.map +1 -0
  11. package/dist/directory/providers/destination/index.mjs +177 -0
  12. package/dist/directory/providers/destination/index.mjs.map +1 -0
  13. package/dist/directory/providers/destination/utils.d.ts +9 -0
  14. package/dist/directory/providers/destination/utils.d.ts.map +1 -0
  15. package/dist/directory/providers/destination/utils.js +58 -0
  16. package/dist/directory/providers/destination/utils.js.map +1 -0
  17. package/dist/directory/providers/destination/utils.mjs +56 -0
  18. package/dist/directory/providers/destination/utils.mjs.map +1 -0
  19. package/dist/directory/providers/index.d.ts +3 -0
  20. package/dist/directory/providers/index.d.ts.map +1 -0
  21. package/dist/directory/providers/index.js +10 -0
  22. package/dist/directory/providers/index.js.map +1 -0
  23. package/dist/directory/providers/index.mjs +3 -0
  24. package/dist/directory/providers/index.mjs.map +1 -0
  25. package/dist/directory/providers/source/index.d.ts +28 -0
  26. package/dist/directory/providers/source/index.d.ts.map +1 -0
  27. package/dist/directory/providers/source/index.js +260 -0
  28. package/dist/directory/providers/source/index.js.map +1 -0
  29. package/dist/directory/providers/source/index.mjs +258 -0
  30. package/dist/directory/providers/source/index.mjs.map +1 -0
  31. package/dist/file/providers/destination/index.js +3 -3
  32. package/dist/file/providers/destination/index.js.map +1 -1
  33. package/dist/file/providers/source/index.js +2 -2
  34. package/dist/file/providers/source/index.js.map +1 -1
  35. package/dist/file/providers/source/index.mjs +2 -2
  36. package/dist/file/providers/source/index.mjs.map +1 -1
  37. package/dist/index.d.ts +1 -0
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +10 -8
  40. package/dist/index.js.map +1 -1
  41. package/dist/index.mjs +10 -8
  42. package/dist/index.mjs.map +1 -1
  43. package/dist/strapi/providers/local-destination/index.js +9 -9
  44. package/dist/strapi/providers/local-destination/index.js.map +1 -1
  45. package/dist/strapi/providers/local-destination/index.mjs +8 -8
  46. package/dist/strapi/providers/local-destination/index.mjs.map +1 -1
  47. package/dist/strapi/providers/local-source/assets.js +3 -3
  48. package/dist/strapi/providers/local-source/assets.js.map +1 -1
  49. package/package.json +5 -5
@@ -0,0 +1,3 @@
1
+ export * from './destination';
2
+ export * from './source';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/directory/providers/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC"}
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ var index = require('./destination/index.js');
4
+ var index$1 = require('./source/index.js');
5
+
6
+
7
+
8
+ exports.createLocalDirectoryDestinationProvider = index.createLocalDirectoryDestinationProvider;
9
+ exports.createLocalDirectorySourceProvider = index$1.createLocalDirectorySourceProvider;
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
@@ -0,0 +1,3 @@
1
+ export { createLocalDirectoryDestinationProvider } from './destination/index.mjs';
2
+ export { createLocalDirectorySourceProvider } from './source/index.mjs';
3
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -0,0 +1,28 @@
1
+ /// <reference types="node" />
2
+ import type { Readable } from 'stream';
3
+ import type { IMetadata, ISourceProvider, ProviderType } from '../../../../types';
4
+ import type { IDiagnosticReporter } from '../../../utils/diagnostic';
5
+ export interface ILocalDirectorySourceProviderOptions {
6
+ directory: {
7
+ /** Absolute or relative path to the root of an unpacked Strapi data-transfer export */
8
+ path: string;
9
+ };
10
+ }
11
+ export declare const createLocalDirectorySourceProvider: (options: ILocalDirectorySourceProviderOptions) => LocalDirectorySourceProvider;
12
+ declare class LocalDirectorySourceProvider implements ISourceProvider {
13
+ #private;
14
+ type: ProviderType;
15
+ name: string;
16
+ options: ILocalDirectorySourceProviderOptions;
17
+ constructor(options: ILocalDirectorySourceProviderOptions);
18
+ bootstrap(diagnostics: IDiagnosticReporter): Promise<void>;
19
+ getMetadata(): Promise<IMetadata | null>;
20
+ getSchemas(): Promise<any>;
21
+ createEntitiesReadStream(): Readable;
22
+ createSchemasReadStream(): Readable;
23
+ createLinksReadStream(): Readable;
24
+ createConfigurationReadStream(): Readable;
25
+ createAssetsReadStream(): Readable;
26
+ }
27
+ export {};
28
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/directory/providers/source/index.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AASvC,OAAO,KAAK,EAAU,SAAS,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC1F,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAQrE,MAAM,WAAW,oCAAoC;IACnD,SAAS,EAAE;QACT,uFAAuF;QACvF,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;CACH;AAED,eAAO,MAAM,kCAAkC,YACpC,oCAAoC,iCAG9C,CAAC;AAOF,cAAM,4BAA6B,YAAW,eAAe;;IAC3D,IAAI,EAAE,YAAY,CAAY;IAE9B,IAAI,SAA6B;IAEjC,OAAO,EAAE,oCAAoC,CAAC;gBAQlC,OAAO,EAAE,oCAAoC;IA2BnD,SAAS,CAAC,WAAW,EAAE,mBAAmB;IAkC1C,WAAW;IAQX,UAAU;IAchB,wBAAwB,IAAI,QAAQ;IAKpC,uBAAuB,IAAI,QAAQ;IAKnC,qBAAqB,IAAI,QAAQ;IAKjC,6BAA6B,IAAI,QAAQ;IAKzC,sBAAsB,IAAI,QAAQ;CA8GnC"}
@@ -0,0 +1,260 @@
1
+ 'use strict';
2
+
3
+ var path = require('path');
4
+ var stream$1 = require('stream');
5
+ var fs = require('fs-extra');
6
+ var fp = require('lodash/fp');
7
+ var streamChain = require('stream-chain');
8
+ var Parser = require('stream-json/jsonl/Parser');
9
+ require('crypto');
10
+ var stream = require('../../../utils/stream.js');
11
+ var schema = require('../../../utils/schema.js');
12
+ require('events');
13
+ var providers = require('../../../errors/providers.js');
14
+ var utils = require('../../../file/providers/source/utils.js');
15
+
16
+ function _class_private_field_loose_base(receiver, privateKey) {
17
+ if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) {
18
+ throw new TypeError("attempted to use private field on non-instance");
19
+ }
20
+ return receiver;
21
+ }
22
+ var id = 0;
23
+ function _class_private_field_loose_key(name) {
24
+ return "__private_" + id++ + "_" + name;
25
+ }
26
+ const METADATA_FILE_PATH = 'metadata.json';
27
+ const createLocalDirectorySourceProvider = (options)=>{
28
+ return new LocalDirectorySourceProvider(options);
29
+ };
30
+ const isPathInsideRoot = (root, candidate)=>{
31
+ const relative = path.relative(root, candidate);
32
+ return relative === '' || !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative);
33
+ };
34
+ var _rootResolved = /*#__PURE__*/ _class_private_field_loose_key("_rootResolved"), _metadata = /*#__PURE__*/ _class_private_field_loose_key("_metadata"), _diagnostics = /*#__PURE__*/ _class_private_field_loose_key("_diagnostics"), _reportInfo = /*#__PURE__*/ _class_private_field_loose_key("_reportInfo"), /** Resolve a posix-style relative path under the export root; rejects escapes. */ _safePath = /*#__PURE__*/ _class_private_field_loose_key("_safePath"), _loadMetadata = /*#__PURE__*/ _class_private_field_loose_key("_loadMetadata"), _pipeAssetsToStream = /*#__PURE__*/ _class_private_field_loose_key("_pipeAssetsToStream"), _readAssetMetadata = /*#__PURE__*/ _class_private_field_loose_key("_readAssetMetadata"), _listJsonlFiles = /*#__PURE__*/ _class_private_field_loose_key("_listJsonlFiles"), _streamJsonlDirectory = /*#__PURE__*/ _class_private_field_loose_key("_streamJsonlDirectory"), _pipeJsonlDirectoryToStream = /*#__PURE__*/ _class_private_field_loose_key("_pipeJsonlDirectoryToStream");
35
+ class LocalDirectorySourceProvider {
36
+ async bootstrap(diagnostics) {
37
+ _class_private_field_loose_base(this, _diagnostics)[_diagnostics] = diagnostics;
38
+ const root = _class_private_field_loose_base(this, _rootResolved)[_rootResolved];
39
+ try {
40
+ const stat = await fs.stat(root);
41
+ if (!stat.isDirectory()) {
42
+ throw new providers.ProviderInitializationError(`Path '${root}' is not a directory.`);
43
+ }
44
+ await _class_private_field_loose_base(this, _loadMetadata)[_loadMetadata]();
45
+ } catch (e) {
46
+ if (e instanceof providers.ProviderInitializationError) {
47
+ throw e;
48
+ }
49
+ throw new providers.ProviderInitializationError(`Directory '${root}' is not a valid Strapi data export.`);
50
+ }
51
+ if (!_class_private_field_loose_base(this, _metadata)[_metadata]) {
52
+ throw new providers.ProviderInitializationError('Could not load metadata from Strapi data export.');
53
+ }
54
+ }
55
+ async getMetadata() {
56
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('getting metadata');
57
+ if (!_class_private_field_loose_base(this, _metadata)[_metadata]) {
58
+ await _class_private_field_loose_base(this, _loadMetadata)[_loadMetadata]();
59
+ }
60
+ return _class_private_field_loose_base(this, _metadata)[_metadata] ?? null;
61
+ }
62
+ async getSchemas() {
63
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('getting schemas');
64
+ const schemaCollection = await stream.collect(this.createSchemasReadStream());
65
+ if (fp.isEmpty(schemaCollection)) {
66
+ throw new providers.ProviderInitializationError('Could not load schemas from Strapi data export.');
67
+ }
68
+ const schemas = fp.keyBy('uid', schemaCollection);
69
+ return schema.schemasToValidJSON(schemas);
70
+ }
71
+ createEntitiesReadStream() {
72
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('creating entities read stream');
73
+ return _class_private_field_loose_base(this, _streamJsonlDirectory)[_streamJsonlDirectory]('entities');
74
+ }
75
+ createSchemasReadStream() {
76
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('creating schemas read stream');
77
+ return _class_private_field_loose_base(this, _streamJsonlDirectory)[_streamJsonlDirectory]('schemas');
78
+ }
79
+ createLinksReadStream() {
80
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('creating links read stream');
81
+ return _class_private_field_loose_base(this, _streamJsonlDirectory)[_streamJsonlDirectory]('links');
82
+ }
83
+ createConfigurationReadStream() {
84
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('creating configuration read stream');
85
+ return _class_private_field_loose_base(this, _streamJsonlDirectory)[_streamJsonlDirectory]('configuration');
86
+ }
87
+ createAssetsReadStream() {
88
+ const outStream = new stream$1.PassThrough({
89
+ objectMode: true
90
+ });
91
+ const uploadsDir = _class_private_field_loose_base(this, _safePath)[_safePath]('assets', 'uploads');
92
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('creating assets read stream');
93
+ _class_private_field_loose_base(this, _pipeAssetsToStream)[_pipeAssetsToStream](outStream, uploadsDir).catch((e)=>{
94
+ outStream.destroy(e instanceof Error ? e : new providers.ProviderTransferError(String(e), {
95
+ details: {
96
+ error: e
97
+ }
98
+ }));
99
+ });
100
+ return outStream;
101
+ }
102
+ constructor(options){
103
+ Object.defineProperty(this, _reportInfo, {
104
+ value: reportInfo
105
+ });
106
+ Object.defineProperty(this, _safePath, {
107
+ value: safePath
108
+ });
109
+ Object.defineProperty(this, _loadMetadata, {
110
+ value: loadMetadata
111
+ });
112
+ Object.defineProperty(this, _pipeAssetsToStream, {
113
+ value: pipeAssetsToStream
114
+ });
115
+ Object.defineProperty(this, _readAssetMetadata, {
116
+ value: readAssetMetadata
117
+ });
118
+ Object.defineProperty(this, _listJsonlFiles, {
119
+ value: listJsonlFiles
120
+ });
121
+ Object.defineProperty(this, _streamJsonlDirectory, {
122
+ value: streamJsonlDirectory
123
+ });
124
+ Object.defineProperty(this, _pipeJsonlDirectoryToStream, {
125
+ value: pipeJsonlDirectoryToStream
126
+ });
127
+ Object.defineProperty(this, _rootResolved, {
128
+ writable: true,
129
+ value: void 0
130
+ });
131
+ Object.defineProperty(this, _metadata, {
132
+ writable: true,
133
+ value: void 0
134
+ });
135
+ Object.defineProperty(this, _diagnostics, {
136
+ writable: true,
137
+ value: void 0
138
+ });
139
+ this.type = 'source';
140
+ this.name = 'source::local-directory';
141
+ this.options = options;
142
+ _class_private_field_loose_base(this, _rootResolved)[_rootResolved] = path.resolve(options.directory.path);
143
+ }
144
+ }
145
+ function reportInfo(message) {
146
+ _class_private_field_loose_base(this, _diagnostics)[_diagnostics]?.report({
147
+ details: {
148
+ createdAt: new Date(),
149
+ message,
150
+ origin: 'directory-source-provider'
151
+ },
152
+ kind: 'info'
153
+ });
154
+ }
155
+ function safePath(...posixSegments) {
156
+ const joined = path.posix.join(...posixSegments);
157
+ const segments = joined.split(path.posix.sep).filter(Boolean);
158
+ const resolved = path.resolve(_class_private_field_loose_base(this, _rootResolved)[_rootResolved], ...segments);
159
+ if (!isPathInsideRoot(_class_private_field_loose_base(this, _rootResolved)[_rootResolved], resolved)) {
160
+ throw new providers.ProviderInitializationError(`Invalid path "${joined}" — escapes backup directory`);
161
+ }
162
+ return resolved;
163
+ }
164
+ async function loadMetadata() {
165
+ const metadataPath = _class_private_field_loose_base(this, _safePath)[_safePath](METADATA_FILE_PATH);
166
+ if (!await fs.pathExists(metadataPath)) {
167
+ throw new providers.ProviderInitializationError(`Missing ${METADATA_FILE_PATH} in export directory '${_class_private_field_loose_base(this, _rootResolved)[_rootResolved]}'.`);
168
+ }
169
+ _class_private_field_loose_base(this, _metadata)[_metadata] = await fs.readJson(metadataPath);
170
+ }
171
+ async function pipeAssetsToStream(outStream, uploadsDir) {
172
+ if (!await fs.pathExists(uploadsDir)) {
173
+ outStream.end();
174
+ return;
175
+ }
176
+ const names = (await fs.readdir(uploadsDir)).sort();
177
+ for (const name of names){
178
+ const absUpload = path.join(uploadsDir, name);
179
+ const stat = await fs.stat(absUpload);
180
+ if (stat.isFile()) {
181
+ let metadata;
182
+ try {
183
+ metadata = await _class_private_field_loose_base(this, _readAssetMetadata)[_readAssetMetadata](name);
184
+ } catch (error) {
185
+ outStream.destroy(new providers.ProviderTransferError(`Failed to read metadata for ${name}`, {
186
+ details: {
187
+ error
188
+ }
189
+ }));
190
+ return;
191
+ }
192
+ const normalizedPath = utils.unknownPathToPosix(path.posix.join('assets', 'uploads', name));
193
+ const asset = {
194
+ metadata,
195
+ filename: name,
196
+ filepath: normalizedPath,
197
+ stats: {
198
+ size: stat.size
199
+ },
200
+ stream: fs.createReadStream(absUpload)
201
+ };
202
+ outStream.write(asset);
203
+ }
204
+ }
205
+ outStream.end();
206
+ }
207
+ async function readAssetMetadata(filename) {
208
+ const metadataPath = _class_private_field_loose_base(this, _safePath)[_safePath]('assets', 'metadata', `${filename}.json`);
209
+ return fs.readJson(metadataPath);
210
+ }
211
+ async function listJsonlFiles(posixSubdir) {
212
+ const dirAbs = _class_private_field_loose_base(this, _safePath)[_safePath](...posixSubdir.split('/').filter(Boolean));
213
+ if (!await fs.pathExists(dirAbs)) {
214
+ return [];
215
+ }
216
+ const names = await fs.readdir(dirAbs);
217
+ return names.filter((n)=>n.endsWith('.jsonl')).sort().map((n)=>path.join(dirAbs, n));
218
+ }
219
+ function streamJsonlDirectory(posixSubdir) {
220
+ const outStream = new stream$1.PassThrough({
221
+ objectMode: true
222
+ });
223
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo](`streaming jsonl from ${posixSubdir}`);
224
+ _class_private_field_loose_base(this, _pipeJsonlDirectoryToStream)[_pipeJsonlDirectoryToStream](outStream, posixSubdir).catch((e)=>{
225
+ outStream.destroy(e instanceof Error ? e : new providers.ProviderTransferError(String(e), {
226
+ details: {
227
+ error: e
228
+ }
229
+ }));
230
+ });
231
+ return outStream;
232
+ }
233
+ async function pipeJsonlDirectoryToStream(outStream, posixSubdir) {
234
+ const files = await _class_private_field_loose_base(this, _listJsonlFiles)[_listJsonlFiles](posixSubdir);
235
+ for (const absPath of files){
236
+ const transforms = [
237
+ Parser.parser({
238
+ checkErrors: true
239
+ }),
240
+ (line)=>line.value
241
+ ];
242
+ const stream = fs.createReadStream(absPath).pipe(streamChain.chain(transforms));
243
+ try {
244
+ for await (const chunk of stream){
245
+ outStream.write(chunk);
246
+ }
247
+ } catch (e) {
248
+ outStream.destroy(new providers.ProviderTransferError(`Error parsing JSONL in ${absPath}: ${e.message}`, {
249
+ details: {
250
+ error: e
251
+ }
252
+ }));
253
+ return;
254
+ }
255
+ }
256
+ outStream.end();
257
+ }
258
+
259
+ exports.createLocalDirectorySourceProvider = createLocalDirectorySourceProvider;
260
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../../src/directory/providers/source/index.ts"],"sourcesContent":["import path from 'path';\nimport type { Readable } from 'stream';\nimport { PassThrough } from 'stream';\n\nimport fs from 'fs-extra';\nimport { isEmpty, keyBy } from 'lodash/fp';\nimport { chain } from 'stream-chain';\nimport { parser } from 'stream-json/jsonl/Parser';\nimport type { Struct } from '@strapi/types';\n\nimport type { IAsset, IMetadata, ISourceProvider, ProviderType } from '../../../../types';\nimport type { IDiagnosticReporter } from '../../../utils/diagnostic';\n\nimport * as utils from '../../../utils';\nimport { ProviderInitializationError, ProviderTransferError } from '../../../errors/providers';\nimport { unknownPathToPosix } from '../../../file/providers/source/utils';\n\nconst METADATA_FILE_PATH = 'metadata.json';\n\nexport interface ILocalDirectorySourceProviderOptions {\n directory: {\n /** Absolute or relative path to the root of an unpacked Strapi data-transfer export */\n path: string;\n };\n}\n\nexport const createLocalDirectorySourceProvider = (\n options: ILocalDirectorySourceProviderOptions\n) => {\n return new LocalDirectorySourceProvider(options);\n};\n\nconst isPathInsideRoot = (root: string, candidate: string): boolean => {\n const relative = path.relative(root, candidate);\n return relative === '' || (!relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative));\n};\n\nclass LocalDirectorySourceProvider implements ISourceProvider {\n type: ProviderType = 'source';\n\n name = 'source::local-directory';\n\n options: ILocalDirectorySourceProviderOptions;\n\n #rootResolved: string;\n\n #metadata?: IMetadata;\n\n #diagnostics?: IDiagnosticReporter;\n\n constructor(options: ILocalDirectorySourceProviderOptions) {\n this.options = options;\n this.#rootResolved = path.resolve(options.directory.path);\n }\n\n #reportInfo(message: string) {\n this.#diagnostics?.report({\n details: {\n createdAt: new Date(),\n message,\n origin: 'directory-source-provider',\n },\n kind: 'info',\n });\n }\n\n /** Resolve a posix-style relative path under the export root; rejects escapes. */\n #safePath(...posixSegments: string[]): string {\n const joined = path.posix.join(...posixSegments);\n const segments = joined.split(path.posix.sep).filter(Boolean);\n const resolved = path.resolve(this.#rootResolved, ...segments);\n if (!isPathInsideRoot(this.#rootResolved, resolved)) {\n throw new ProviderInitializationError(`Invalid path \"${joined}\" — escapes backup directory`);\n }\n return resolved;\n }\n\n async bootstrap(diagnostics: IDiagnosticReporter) {\n this.#diagnostics = diagnostics;\n const root = this.#rootResolved;\n\n try {\n const stat = await fs.stat(root);\n if (!stat.isDirectory()) {\n throw new ProviderInitializationError(`Path '${root}' is not a directory.`);\n }\n await this.#loadMetadata();\n } catch (e) {\n if (e instanceof ProviderInitializationError) {\n throw e;\n }\n throw new ProviderInitializationError(\n `Directory '${root}' is not a valid Strapi data export.`\n );\n }\n\n if (!this.#metadata) {\n throw new ProviderInitializationError('Could not load metadata from Strapi data export.');\n }\n }\n\n async #loadMetadata() {\n const metadataPath = this.#safePath(METADATA_FILE_PATH);\n if (!(await fs.pathExists(metadataPath))) {\n throw new ProviderInitializationError(\n `Missing ${METADATA_FILE_PATH} in export directory '${this.#rootResolved}'.`\n );\n }\n this.#metadata = await fs.readJson(metadataPath);\n }\n\n async getMetadata() {\n this.#reportInfo('getting metadata');\n if (!this.#metadata) {\n await this.#loadMetadata();\n }\n return this.#metadata ?? null;\n }\n\n async getSchemas() {\n this.#reportInfo('getting schemas');\n const schemaCollection = await utils.stream.collect<Struct.Schema>(\n this.createSchemasReadStream()\n );\n\n if (isEmpty(schemaCollection)) {\n throw new ProviderInitializationError('Could not load schemas from Strapi data export.');\n }\n\n const schemas = keyBy('uid', schemaCollection);\n return utils.schema.schemasToValidJSON(schemas);\n }\n\n createEntitiesReadStream(): Readable {\n this.#reportInfo('creating entities read stream');\n return this.#streamJsonlDirectory('entities');\n }\n\n createSchemasReadStream(): Readable {\n this.#reportInfo('creating schemas read stream');\n return this.#streamJsonlDirectory('schemas');\n }\n\n createLinksReadStream(): Readable {\n this.#reportInfo('creating links read stream');\n return this.#streamJsonlDirectory('links');\n }\n\n createConfigurationReadStream(): Readable {\n this.#reportInfo('creating configuration read stream');\n return this.#streamJsonlDirectory('configuration');\n }\n\n createAssetsReadStream(): Readable {\n const outStream = new PassThrough({ objectMode: true });\n const uploadsDir = this.#safePath('assets', 'uploads');\n this.#reportInfo('creating assets read stream');\n\n this.#pipeAssetsToStream(outStream, uploadsDir).catch((e: unknown) => {\n outStream.destroy(\n e instanceof Error ? e : new ProviderTransferError(String(e), { details: { error: e } })\n );\n });\n\n return outStream;\n }\n\n async #pipeAssetsToStream(outStream: PassThrough, uploadsDir: string): Promise<void> {\n if (!(await fs.pathExists(uploadsDir))) {\n outStream.end();\n return;\n }\n\n const names = (await fs.readdir(uploadsDir)).sort();\n for (const name of names) {\n const absUpload = path.join(uploadsDir, name);\n const stat = await fs.stat(absUpload);\n if (stat.isFile()) {\n let metadata: IAsset['metadata'];\n try {\n metadata = await this.#readAssetMetadata(name);\n } catch (error) {\n outStream.destroy(\n new ProviderTransferError(`Failed to read metadata for ${name}`, {\n details: { error },\n })\n );\n return;\n }\n\n const normalizedPath = unknownPathToPosix(path.posix.join('assets', 'uploads', name));\n const asset: IAsset = {\n metadata,\n filename: name,\n filepath: normalizedPath,\n stats: { size: stat.size },\n stream: fs.createReadStream(absUpload),\n };\n outStream.write(asset);\n }\n }\n outStream.end();\n }\n\n async #readAssetMetadata(filename: string): Promise<IAsset['metadata']> {\n const metadataPath = this.#safePath('assets', 'metadata', `${filename}.json`);\n return fs.readJson(metadataPath);\n }\n\n async #listJsonlFiles(posixSubdir: string): Promise<string[]> {\n const dirAbs = this.#safePath(...posixSubdir.split('/').filter(Boolean));\n if (!(await fs.pathExists(dirAbs))) {\n return [];\n }\n const names = await fs.readdir(dirAbs);\n return names\n .filter((n) => n.endsWith('.jsonl'))\n .sort()\n .map((n) => path.join(dirAbs, n));\n }\n\n #streamJsonlDirectory(posixSubdir: string): Readable {\n const outStream = new PassThrough({ objectMode: true });\n this.#reportInfo(`streaming jsonl from ${posixSubdir}`);\n\n this.#pipeJsonlDirectoryToStream(outStream, posixSubdir).catch((e: unknown) => {\n outStream.destroy(\n e instanceof Error ? e : new ProviderTransferError(String(e), { details: { error: e } })\n );\n });\n\n return outStream;\n }\n\n async #pipeJsonlDirectoryToStream(outStream: PassThrough, posixSubdir: string): Promise<void> {\n const files = await this.#listJsonlFiles(posixSubdir);\n for (const absPath of files) {\n const transforms = [\n parser({\n checkErrors: true,\n }),\n (line: { key: string; value: object }) => line.value,\n ];\n\n const stream = fs.createReadStream(absPath).pipe(chain(transforms));\n\n try {\n for await (const chunk of stream) {\n outStream.write(chunk);\n }\n } catch (e: unknown) {\n outStream.destroy(\n new ProviderTransferError(`Error parsing JSONL in ${absPath}: ${(e as Error).message}`, {\n details: {\n error: e,\n },\n })\n );\n return;\n }\n }\n outStream.end();\n }\n}\n"],"names":["METADATA_FILE_PATH","createLocalDirectorySourceProvider","options","LocalDirectorySourceProvider","isPathInsideRoot","root","candidate","relative","path","startsWith","sep","isAbsolute","bootstrap","diagnostics","stat","fs","isDirectory","ProviderInitializationError","e","getMetadata","getSchemas","schemaCollection","utils","createSchemasReadStream","isEmpty","schemas","keyBy","createEntitiesReadStream","createLinksReadStream","createConfigurationReadStream","createAssetsReadStream","outStream","PassThrough","objectMode","uploadsDir","catch","destroy","Error","ProviderTransferError","String","details","error","type","name","resolve","directory","message","report","createdAt","Date","origin","kind","posixSegments","joined","posix","join","segments","split","filter","Boolean","resolved","metadataPath","pathExists","readJson","end","names","readdir","sort","absUpload","isFile","metadata","normalizedPath","unknownPathToPosix","asset","filename","filepath","stats","size","stream","createReadStream","write","posixSubdir","dirAbs","n","endsWith","map","files","absPath","transforms","parser","checkErrors","line","value","pipe","chain","chunk"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAiBA,MAAMA,kBAAAA,GAAqB,eAAA;AASpB,MAAMC,qCAAqC,CAChDC,OAAAA,GAAAA;AAEA,IAAA,OAAO,IAAIC,4BAAAA,CAA6BD,OAAAA,CAAAA;AAC1C;AAEA,MAAME,gBAAAA,GAAmB,CAACC,IAAAA,EAAcC,SAAAA,GAAAA;AACtC,IAAA,MAAMC,QAAAA,GAAWC,IAAAA,CAAKD,QAAQ,CAACF,IAAAA,EAAMC,SAAAA,CAAAA;AACrC,IAAA,OAAOC,aAAa,EAAA,IAAO,CAACA,QAAAA,CAASE,UAAU,CAAC,CAAC,EAAE,EAAED,IAAAA,CAAKE,GAAG,CAAA,CAAE,CAAA,IAAK,CAACF,IAAAA,CAAKG,UAAU,CAACJ,QAAAA,CAAAA;AACvF,CAAA;IASE,aAAA,iBAAA,8BAAA,CAAA,eAAA,CAAA,EAEA,SAAA,iBAAA,8BAAA,CAAA,WAAA,CAAA,EAEA,YAAA,iBAAA,8BAAA,CAAA,cAAA,CAAA,EAOA,WAAA,iBAAA,8BAAA,CAAA,aAAA,CAAA,qFAYA,uEAkCM,aAAA,iBAAA,8BAAA,CAAA,eAAA,CAAA,EAkEA,mBAAA,iBAAA,8BAAA,CAAA,qBAAA,CAAA,EAqCA,k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AACF,IAAA;AACAa,IAAAA,SAAAA,CAAUiC,GAAG,EAAA;AACf;;;;"}
@@ -0,0 +1,258 @@
1
+ import path from 'path';
2
+ import { PassThrough } from 'stream';
3
+ import fs__default from 'fs-extra';
4
+ import { isEmpty, keyBy } from 'lodash/fp';
5
+ import { chain } from 'stream-chain';
6
+ import { parser } from 'stream-json/jsonl/Parser';
7
+ import 'crypto';
8
+ import { collect } from '../../../utils/stream.mjs';
9
+ import { schemasToValidJSON } from '../../../utils/schema.mjs';
10
+ import 'events';
11
+ import { ProviderInitializationError, ProviderTransferError } from '../../../errors/providers.mjs';
12
+ import { unknownPathToPosix } from '../../../file/providers/source/utils.mjs';
13
+
14
+ function _class_private_field_loose_base(receiver, privateKey) {
15
+ if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) {
16
+ throw new TypeError("attempted to use private field on non-instance");
17
+ }
18
+ return receiver;
19
+ }
20
+ var id = 0;
21
+ function _class_private_field_loose_key(name) {
22
+ return "__private_" + id++ + "_" + name;
23
+ }
24
+ const METADATA_FILE_PATH = 'metadata.json';
25
+ const createLocalDirectorySourceProvider = (options)=>{
26
+ return new LocalDirectorySourceProvider(options);
27
+ };
28
+ const isPathInsideRoot = (root, candidate)=>{
29
+ const relative = path.relative(root, candidate);
30
+ return relative === '' || !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative);
31
+ };
32
+ var _rootResolved = /*#__PURE__*/ _class_private_field_loose_key("_rootResolved"), _metadata = /*#__PURE__*/ _class_private_field_loose_key("_metadata"), _diagnostics = /*#__PURE__*/ _class_private_field_loose_key("_diagnostics"), _reportInfo = /*#__PURE__*/ _class_private_field_loose_key("_reportInfo"), /** Resolve a posix-style relative path under the export root; rejects escapes. */ _safePath = /*#__PURE__*/ _class_private_field_loose_key("_safePath"), _loadMetadata = /*#__PURE__*/ _class_private_field_loose_key("_loadMetadata"), _pipeAssetsToStream = /*#__PURE__*/ _class_private_field_loose_key("_pipeAssetsToStream"), _readAssetMetadata = /*#__PURE__*/ _class_private_field_loose_key("_readAssetMetadata"), _listJsonlFiles = /*#__PURE__*/ _class_private_field_loose_key("_listJsonlFiles"), _streamJsonlDirectory = /*#__PURE__*/ _class_private_field_loose_key("_streamJsonlDirectory"), _pipeJsonlDirectoryToStream = /*#__PURE__*/ _class_private_field_loose_key("_pipeJsonlDirectoryToStream");
33
+ class LocalDirectorySourceProvider {
34
+ async bootstrap(diagnostics) {
35
+ _class_private_field_loose_base(this, _diagnostics)[_diagnostics] = diagnostics;
36
+ const root = _class_private_field_loose_base(this, _rootResolved)[_rootResolved];
37
+ try {
38
+ const stat = await fs__default.stat(root);
39
+ if (!stat.isDirectory()) {
40
+ throw new ProviderInitializationError(`Path '${root}' is not a directory.`);
41
+ }
42
+ await _class_private_field_loose_base(this, _loadMetadata)[_loadMetadata]();
43
+ } catch (e) {
44
+ if (e instanceof ProviderInitializationError) {
45
+ throw e;
46
+ }
47
+ throw new ProviderInitializationError(`Directory '${root}' is not a valid Strapi data export.`);
48
+ }
49
+ if (!_class_private_field_loose_base(this, _metadata)[_metadata]) {
50
+ throw new ProviderInitializationError('Could not load metadata from Strapi data export.');
51
+ }
52
+ }
53
+ async getMetadata() {
54
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('getting metadata');
55
+ if (!_class_private_field_loose_base(this, _metadata)[_metadata]) {
56
+ await _class_private_field_loose_base(this, _loadMetadata)[_loadMetadata]();
57
+ }
58
+ return _class_private_field_loose_base(this, _metadata)[_metadata] ?? null;
59
+ }
60
+ async getSchemas() {
61
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('getting schemas');
62
+ const schemaCollection = await collect(this.createSchemasReadStream());
63
+ if (isEmpty(schemaCollection)) {
64
+ throw new ProviderInitializationError('Could not load schemas from Strapi data export.');
65
+ }
66
+ const schemas = keyBy('uid', schemaCollection);
67
+ return schemasToValidJSON(schemas);
68
+ }
69
+ createEntitiesReadStream() {
70
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('creating entities read stream');
71
+ return _class_private_field_loose_base(this, _streamJsonlDirectory)[_streamJsonlDirectory]('entities');
72
+ }
73
+ createSchemasReadStream() {
74
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('creating schemas read stream');
75
+ return _class_private_field_loose_base(this, _streamJsonlDirectory)[_streamJsonlDirectory]('schemas');
76
+ }
77
+ createLinksReadStream() {
78
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('creating links read stream');
79
+ return _class_private_field_loose_base(this, _streamJsonlDirectory)[_streamJsonlDirectory]('links');
80
+ }
81
+ createConfigurationReadStream() {
82
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('creating configuration read stream');
83
+ return _class_private_field_loose_base(this, _streamJsonlDirectory)[_streamJsonlDirectory]('configuration');
84
+ }
85
+ createAssetsReadStream() {
86
+ const outStream = new PassThrough({
87
+ objectMode: true
88
+ });
89
+ const uploadsDir = _class_private_field_loose_base(this, _safePath)[_safePath]('assets', 'uploads');
90
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('creating assets read stream');
91
+ _class_private_field_loose_base(this, _pipeAssetsToStream)[_pipeAssetsToStream](outStream, uploadsDir).catch((e)=>{
92
+ outStream.destroy(e instanceof Error ? e : new ProviderTransferError(String(e), {
93
+ details: {
94
+ error: e
95
+ }
96
+ }));
97
+ });
98
+ return outStream;
99
+ }
100
+ constructor(options){
101
+ Object.defineProperty(this, _reportInfo, {
102
+ value: reportInfo
103
+ });
104
+ Object.defineProperty(this, _safePath, {
105
+ value: safePath
106
+ });
107
+ Object.defineProperty(this, _loadMetadata, {
108
+ value: loadMetadata
109
+ });
110
+ Object.defineProperty(this, _pipeAssetsToStream, {
111
+ value: pipeAssetsToStream
112
+ });
113
+ Object.defineProperty(this, _readAssetMetadata, {
114
+ value: readAssetMetadata
115
+ });
116
+ Object.defineProperty(this, _listJsonlFiles, {
117
+ value: listJsonlFiles
118
+ });
119
+ Object.defineProperty(this, _streamJsonlDirectory, {
120
+ value: streamJsonlDirectory
121
+ });
122
+ Object.defineProperty(this, _pipeJsonlDirectoryToStream, {
123
+ value: pipeJsonlDirectoryToStream
124
+ });
125
+ Object.defineProperty(this, _rootResolved, {
126
+ writable: true,
127
+ value: void 0
128
+ });
129
+ Object.defineProperty(this, _metadata, {
130
+ writable: true,
131
+ value: void 0
132
+ });
133
+ Object.defineProperty(this, _diagnostics, {
134
+ writable: true,
135
+ value: void 0
136
+ });
137
+ this.type = 'source';
138
+ this.name = 'source::local-directory';
139
+ this.options = options;
140
+ _class_private_field_loose_base(this, _rootResolved)[_rootResolved] = path.resolve(options.directory.path);
141
+ }
142
+ }
143
+ function reportInfo(message) {
144
+ _class_private_field_loose_base(this, _diagnostics)[_diagnostics]?.report({
145
+ details: {
146
+ createdAt: new Date(),
147
+ message,
148
+ origin: 'directory-source-provider'
149
+ },
150
+ kind: 'info'
151
+ });
152
+ }
153
+ function safePath(...posixSegments) {
154
+ const joined = path.posix.join(...posixSegments);
155
+ const segments = joined.split(path.posix.sep).filter(Boolean);
156
+ const resolved = path.resolve(_class_private_field_loose_base(this, _rootResolved)[_rootResolved], ...segments);
157
+ if (!isPathInsideRoot(_class_private_field_loose_base(this, _rootResolved)[_rootResolved], resolved)) {
158
+ throw new ProviderInitializationError(`Invalid path "${joined}" — escapes backup directory`);
159
+ }
160
+ return resolved;
161
+ }
162
+ async function loadMetadata() {
163
+ const metadataPath = _class_private_field_loose_base(this, _safePath)[_safePath](METADATA_FILE_PATH);
164
+ if (!await fs__default.pathExists(metadataPath)) {
165
+ throw new ProviderInitializationError(`Missing ${METADATA_FILE_PATH} in export directory '${_class_private_field_loose_base(this, _rootResolved)[_rootResolved]}'.`);
166
+ }
167
+ _class_private_field_loose_base(this, _metadata)[_metadata] = await fs__default.readJson(metadataPath);
168
+ }
169
+ async function pipeAssetsToStream(outStream, uploadsDir) {
170
+ if (!await fs__default.pathExists(uploadsDir)) {
171
+ outStream.end();
172
+ return;
173
+ }
174
+ const names = (await fs__default.readdir(uploadsDir)).sort();
175
+ for (const name of names){
176
+ const absUpload = path.join(uploadsDir, name);
177
+ const stat = await fs__default.stat(absUpload);
178
+ if (stat.isFile()) {
179
+ let metadata;
180
+ try {
181
+ metadata = await _class_private_field_loose_base(this, _readAssetMetadata)[_readAssetMetadata](name);
182
+ } catch (error) {
183
+ outStream.destroy(new ProviderTransferError(`Failed to read metadata for ${name}`, {
184
+ details: {
185
+ error
186
+ }
187
+ }));
188
+ return;
189
+ }
190
+ const normalizedPath = unknownPathToPosix(path.posix.join('assets', 'uploads', name));
191
+ const asset = {
192
+ metadata,
193
+ filename: name,
194
+ filepath: normalizedPath,
195
+ stats: {
196
+ size: stat.size
197
+ },
198
+ stream: fs__default.createReadStream(absUpload)
199
+ };
200
+ outStream.write(asset);
201
+ }
202
+ }
203
+ outStream.end();
204
+ }
205
+ async function readAssetMetadata(filename) {
206
+ const metadataPath = _class_private_field_loose_base(this, _safePath)[_safePath]('assets', 'metadata', `${filename}.json`);
207
+ return fs__default.readJson(metadataPath);
208
+ }
209
+ async function listJsonlFiles(posixSubdir) {
210
+ const dirAbs = _class_private_field_loose_base(this, _safePath)[_safePath](...posixSubdir.split('/').filter(Boolean));
211
+ if (!await fs__default.pathExists(dirAbs)) {
212
+ return [];
213
+ }
214
+ const names = await fs__default.readdir(dirAbs);
215
+ return names.filter((n)=>n.endsWith('.jsonl')).sort().map((n)=>path.join(dirAbs, n));
216
+ }
217
+ function streamJsonlDirectory(posixSubdir) {
218
+ const outStream = new PassThrough({
219
+ objectMode: true
220
+ });
221
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo](`streaming jsonl from ${posixSubdir}`);
222
+ _class_private_field_loose_base(this, _pipeJsonlDirectoryToStream)[_pipeJsonlDirectoryToStream](outStream, posixSubdir).catch((e)=>{
223
+ outStream.destroy(e instanceof Error ? e : new ProviderTransferError(String(e), {
224
+ details: {
225
+ error: e
226
+ }
227
+ }));
228
+ });
229
+ return outStream;
230
+ }
231
+ async function pipeJsonlDirectoryToStream(outStream, posixSubdir) {
232
+ const files = await _class_private_field_loose_base(this, _listJsonlFiles)[_listJsonlFiles](posixSubdir);
233
+ for (const absPath of files){
234
+ const transforms = [
235
+ parser({
236
+ checkErrors: true
237
+ }),
238
+ (line)=>line.value
239
+ ];
240
+ const stream = fs__default.createReadStream(absPath).pipe(chain(transforms));
241
+ try {
242
+ for await (const chunk of stream){
243
+ outStream.write(chunk);
244
+ }
245
+ } catch (e) {
246
+ outStream.destroy(new ProviderTransferError(`Error parsing JSONL in ${absPath}: ${e.message}`, {
247
+ details: {
248
+ error: e
249
+ }
250
+ }));
251
+ return;
252
+ }
253
+ }
254
+ outStream.end();
255
+ }
256
+
257
+ export { createLocalDirectorySourceProvider };
258
+ //# sourceMappingURL=index.mjs.map