@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,2 @@
1
+ export * as providers from './providers';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/directory/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC"}
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+
3
+ var index = require('./providers/index.js');
4
+
5
+
6
+
7
+ exports.providers = index;
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
@@ -0,0 +1,3 @@
1
+ import * as index from './providers/index.mjs';
2
+ export { index as providers };
3
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -0,0 +1,40 @@
1
+ /// <reference types="stream-chain" />
2
+ /// <reference types="node" />
3
+ import { Writable } from 'stream';
4
+ import type { IDestinationProvider, IDestinationProviderTransferResults, IMetadata, ProviderType } from '../../../../types';
5
+ import type { IDiagnosticReporter } from '../../../utils/diagnostic';
6
+ export interface ILocalDirectoryDestinationProviderOptions {
7
+ directory: {
8
+ /** Output root: unpacked Strapi export layout (metadata.json, entities/, …) */
9
+ path: string;
10
+ };
11
+ file: {
12
+ maxSizeJsonl?: number;
13
+ };
14
+ }
15
+ export interface ILocalDirectoryDestinationProviderTransferResults extends IDestinationProviderTransferResults {
16
+ file?: {
17
+ path?: string;
18
+ };
19
+ }
20
+ export declare const createLocalDirectoryDestinationProvider: (options: ILocalDirectoryDestinationProviderOptions) => LocalDirectoryDestinationProvider;
21
+ declare class LocalDirectoryDestinationProvider implements IDestinationProvider {
22
+ #private;
23
+ name: string;
24
+ type: ProviderType;
25
+ options: ILocalDirectoryDestinationProviderOptions;
26
+ results: ILocalDirectoryDestinationProviderTransferResults;
27
+ constructor(options: ILocalDirectoryDestinationProviderOptions);
28
+ setMetadata(target: ProviderType, metadata: IMetadata): IDestinationProvider;
29
+ bootstrap(diagnostics: IDiagnosticReporter): Promise<void>;
30
+ close(): Promise<void>;
31
+ rollback(): Promise<void>;
32
+ getMetadata(): null;
33
+ createSchemasWriteStream(): import("stream-chain");
34
+ createEntitiesWriteStream(): Writable;
35
+ createLinksWriteStream(): Writable;
36
+ createConfigurationWriteStream(): Writable;
37
+ createAssetsWriteStream(): Writable;
38
+ }
39
+ export {};
40
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/directory/providers/destination/index.ts"],"names":[],"mappings":";;AAEA,OAAO,EAAE,QAAQ,EAAY,MAAM,QAAQ,CAAC;AAK5C,OAAO,KAAK,EAEV,oBAAoB,EACpB,mCAAmC,EACnC,SAAS,EACT,YAAY,EACb,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAIrE,MAAM,WAAW,yCAAyC;IACxD,SAAS,EAAE;QACT,+EAA+E;QAC/E,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;IACF,IAAI,EAAE;QACJ,YAAY,CAAC,EAAE,MAAM,CAAC;KACvB,CAAC;CACH;AAED,MAAM,WAAW,iDACf,SAAQ,mCAAmC;IAC3C,IAAI,CAAC,EAAE;QACL,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,CAAC;CACH;AAED,eAAO,MAAM,uCAAuC,YACzC,yCAAyC,sCAGnD,CAAC;AAEF,cAAM,iCAAkC,YAAW,oBAAoB;;IACrE,IAAI,SAAkC;IAEtC,IAAI,EAAE,YAAY,CAAiB;IAEnC,OAAO,EAAE,yCAAyC,CAAC;IAEnD,OAAO,EAAE,iDAAiD,CAAM;gBAQpD,OAAO,EAAE,yCAAyC;IAgB9D,WAAW,CAAC,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,SAAS,GAAG,oBAAoB;IAKtE,SAAS,CAAC,WAAW,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAO1D,KAAK;IAIL,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAK/B,WAAW;IAcX,wBAAwB;IAWxB,yBAAyB,IAAI,QAAQ;IAWrC,sBAAsB,IAAI,QAAQ;IAWlC,8BAA8B,IAAI,QAAQ;IAW1C,uBAAuB,IAAI,QAAQ;CAwCpC"}
@@ -0,0 +1,179 @@
1
+ 'use strict';
2
+
3
+ var path = require('path');
4
+ var fs$1 = require('fs');
5
+ var stream = require('stream');
6
+ var fs = require('fs-extra');
7
+ var Stringer = require('stream-json/jsonl/Stringer');
8
+ var streamChain = require('stream-chain');
9
+ var utils = require('./utils.js');
10
+ var providers = require('../../../errors/providers.js');
11
+ var utils$1 = require('../../../file/providers/destination/utils.js');
12
+
13
+ function _class_private_field_loose_base(receiver, privateKey) {
14
+ if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) {
15
+ throw new TypeError("attempted to use private field on non-instance");
16
+ }
17
+ return receiver;
18
+ }
19
+ var id = 0;
20
+ function _class_private_field_loose_key(name) {
21
+ return "__private_" + id++ + "_" + name;
22
+ }
23
+ const createLocalDirectoryDestinationProvider = (options)=>{
24
+ return new LocalDirectoryDestinationProvider(options);
25
+ };
26
+ var _providersMetadata = /*#__PURE__*/ _class_private_field_loose_key("_providersMetadata"), _rootResolved = /*#__PURE__*/ _class_private_field_loose_key("_rootResolved"), _diagnostics = /*#__PURE__*/ _class_private_field_loose_key("_diagnostics"), _reportInfo = /*#__PURE__*/ _class_private_field_loose_key("_reportInfo"), _writeMetadata = /*#__PURE__*/ _class_private_field_loose_key("_writeMetadata");
27
+ class LocalDirectoryDestinationProvider {
28
+ setMetadata(target, metadata) {
29
+ _class_private_field_loose_base(this, _providersMetadata)[_providersMetadata][target] = metadata;
30
+ return this;
31
+ }
32
+ async bootstrap(diagnostics) {
33
+ _class_private_field_loose_base(this, _diagnostics)[_diagnostics] = diagnostics;
34
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('preparing directory export');
35
+ await fs.mkdir(_class_private_field_loose_base(this, _rootResolved)[_rootResolved], {
36
+ recursive: true
37
+ });
38
+ this.results.file = {
39
+ path: _class_private_field_loose_base(this, _rootResolved)[_rootResolved]
40
+ };
41
+ }
42
+ async close() {
43
+ await _class_private_field_loose_base(this, _writeMetadata)[_writeMetadata]();
44
+ }
45
+ async rollback() {
46
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('rolling back');
47
+ await fs.rm(_class_private_field_loose_base(this, _rootResolved)[_rootResolved], {
48
+ recursive: true,
49
+ force: true
50
+ });
51
+ }
52
+ getMetadata() {
53
+ return null;
54
+ }
55
+ createSchemasWriteStream() {
56
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('creating schemas write stream');
57
+ const filePathFactory = utils$1.createFilePathFactory('schemas');
58
+ const entryStream = utils.createDirectoryJsonlWriter(_class_private_field_loose_base(this, _rootResolved)[_rootResolved], filePathFactory, this.options.file.maxSizeJsonl);
59
+ return streamChain.chain([
60
+ Stringer.stringer(),
61
+ entryStream
62
+ ]);
63
+ }
64
+ createEntitiesWriteStream() {
65
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('creating entities write stream');
66
+ const filePathFactory = utils$1.createFilePathFactory('entities');
67
+ const entryStream = utils.createDirectoryJsonlWriter(_class_private_field_loose_base(this, _rootResolved)[_rootResolved], filePathFactory, this.options.file.maxSizeJsonl);
68
+ return streamChain.chain([
69
+ Stringer.stringer(),
70
+ entryStream
71
+ ]);
72
+ }
73
+ createLinksWriteStream() {
74
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('creating links write stream');
75
+ const filePathFactory = utils$1.createFilePathFactory('links');
76
+ const entryStream = utils.createDirectoryJsonlWriter(_class_private_field_loose_base(this, _rootResolved)[_rootResolved], filePathFactory, this.options.file.maxSizeJsonl);
77
+ return streamChain.chain([
78
+ Stringer.stringer(),
79
+ entryStream
80
+ ]);
81
+ }
82
+ createConfigurationWriteStream() {
83
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('creating configuration write stream');
84
+ const filePathFactory = utils$1.createFilePathFactory('configuration');
85
+ const entryStream = utils.createDirectoryJsonlWriter(_class_private_field_loose_base(this, _rootResolved)[_rootResolved], filePathFactory, this.options.file.maxSizeJsonl);
86
+ return streamChain.chain([
87
+ Stringer.stringer(),
88
+ entryStream
89
+ ]);
90
+ }
91
+ createAssetsWriteStream() {
92
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('creating assets write stream');
93
+ const root = _class_private_field_loose_base(this, _rootResolved)[_rootResolved];
94
+ return new stream.Writable({
95
+ objectMode: true,
96
+ write (data, _encoding, callback) {
97
+ const { filename } = data;
98
+ const entryPath = path.join(root, 'assets', 'uploads', filename);
99
+ const entryMetadataPath = path.join(root, 'assets', 'metadata', `${filename}.json`);
100
+ const assetWriteError = (cause)=>new providers.ProviderTransferError(`Failed to write asset ${filename}`, {
101
+ details: {
102
+ error: cause instanceof Error ? cause : new Error(String(cause))
103
+ }
104
+ });
105
+ let fileStream;
106
+ try {
107
+ fs.mkdirSync(path.dirname(entryPath), {
108
+ recursive: true
109
+ });
110
+ fs.mkdirSync(path.dirname(entryMetadataPath), {
111
+ recursive: true
112
+ });
113
+ fs.writeFileSync(entryMetadataPath, JSON.stringify(data.metadata), 'utf8');
114
+ fileStream = fs$1.createWriteStream(entryPath);
115
+ } catch (error) {
116
+ callback(assetWriteError(error));
117
+ return;
118
+ }
119
+ stream.pipeline(data.stream, fileStream, (err)=>{
120
+ if (err) {
121
+ callback(assetWriteError(err));
122
+ return;
123
+ }
124
+ callback(null);
125
+ });
126
+ }
127
+ });
128
+ }
129
+ constructor(options){
130
+ Object.defineProperty(this, _reportInfo, {
131
+ value: reportInfo
132
+ });
133
+ Object.defineProperty(this, _writeMetadata, {
134
+ value: writeMetadata
135
+ });
136
+ Object.defineProperty(this, _providersMetadata, {
137
+ writable: true,
138
+ value: void 0
139
+ });
140
+ Object.defineProperty(this, _rootResolved, {
141
+ writable: true,
142
+ value: void 0
143
+ });
144
+ Object.defineProperty(this, _diagnostics, {
145
+ writable: true,
146
+ value: void 0
147
+ });
148
+ this.name = 'destination::local-directory';
149
+ this.type = 'destination';
150
+ this.results = {};
151
+ _class_private_field_loose_base(this, _providersMetadata)[_providersMetadata] = {};
152
+ this.options = options;
153
+ _class_private_field_loose_base(this, _rootResolved)[_rootResolved] = path.resolve(options.directory.path);
154
+ }
155
+ }
156
+ function reportInfo(message) {
157
+ _class_private_field_loose_base(this, _diagnostics)[_diagnostics]?.report({
158
+ details: {
159
+ createdAt: new Date(),
160
+ message,
161
+ origin: 'directory-destination-provider'
162
+ },
163
+ kind: 'info'
164
+ });
165
+ }
166
+ async function writeMetadata() {
167
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('writing metadata');
168
+ const metadata = _class_private_field_loose_base(this, _providersMetadata)[_providersMetadata].source;
169
+ if (metadata) {
170
+ const target = path.join(_class_private_field_loose_base(this, _rootResolved)[_rootResolved], 'metadata.json');
171
+ await fs.mkdir(path.dirname(target), {
172
+ recursive: true
173
+ });
174
+ await fs.writeFile(target, JSON.stringify(metadata, null, 2), 'utf8');
175
+ }
176
+ }
177
+
178
+ exports.createLocalDirectoryDestinationProvider = createLocalDirectoryDestinationProvider;
179
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../../src/directory/providers/destination/index.ts"],"sourcesContent":["import path from 'path';\nimport { createWriteStream } from 'fs';\nimport { Writable, pipeline } from 'stream';\nimport fs from 'fs-extra';\nimport { stringer } from 'stream-json/jsonl/Stringer';\nimport { chain } from 'stream-chain';\n\nimport type {\n IAsset,\n IDestinationProvider,\n IDestinationProviderTransferResults,\n IMetadata,\n ProviderType,\n} from '../../../../types';\nimport type { IDiagnosticReporter } from '../../../utils/diagnostic';\nimport { createDirectoryJsonlWriter, createFilePathFactory } from './utils';\nimport { ProviderTransferError } from '../../../errors/providers';\n\nexport interface ILocalDirectoryDestinationProviderOptions {\n directory: {\n /** Output root: unpacked Strapi export layout (metadata.json, entities/, …) */\n path: string;\n };\n file: {\n maxSizeJsonl?: number;\n };\n}\n\nexport interface ILocalDirectoryDestinationProviderTransferResults\n extends IDestinationProviderTransferResults {\n file?: {\n path?: string;\n };\n}\n\nexport const createLocalDirectoryDestinationProvider = (\n options: ILocalDirectoryDestinationProviderOptions\n) => {\n return new LocalDirectoryDestinationProvider(options);\n};\n\nclass LocalDirectoryDestinationProvider implements IDestinationProvider {\n name = 'destination::local-directory';\n\n type: ProviderType = 'destination';\n\n options: ILocalDirectoryDestinationProviderOptions;\n\n results: ILocalDirectoryDestinationProviderTransferResults = {};\n\n #providersMetadata: { source?: IMetadata; destination?: IMetadata } = {};\n\n #rootResolved: string;\n\n #diagnostics?: IDiagnosticReporter;\n\n constructor(options: ILocalDirectoryDestinationProviderOptions) {\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-destination-provider',\n },\n kind: 'info',\n });\n }\n\n setMetadata(target: ProviderType, metadata: IMetadata): IDestinationProvider {\n this.#providersMetadata[target] = metadata;\n return this;\n }\n\n async bootstrap(diagnostics: IDiagnosticReporter): Promise<void> {\n this.#diagnostics = diagnostics;\n this.#reportInfo('preparing directory export');\n await fs.mkdir(this.#rootResolved, { recursive: true });\n this.results.file = { path: this.#rootResolved };\n }\n\n async close() {\n await this.#writeMetadata();\n }\n\n async rollback(): Promise<void> {\n this.#reportInfo('rolling back');\n await fs.rm(this.#rootResolved, { recursive: true, force: true });\n }\n\n getMetadata() {\n return null;\n }\n\n async #writeMetadata(): Promise<void> {\n this.#reportInfo('writing metadata');\n const metadata = this.#providersMetadata.source;\n if (metadata) {\n const target = path.join(this.#rootResolved, 'metadata.json');\n await fs.mkdir(path.dirname(target), { recursive: true });\n await fs.writeFile(target, JSON.stringify(metadata, null, 2), 'utf8');\n }\n }\n\n createSchemasWriteStream() {\n this.#reportInfo('creating schemas write stream');\n const filePathFactory = createFilePathFactory('schemas');\n const entryStream = createDirectoryJsonlWriter(\n this.#rootResolved,\n filePathFactory,\n this.options.file.maxSizeJsonl\n );\n return chain([stringer(), entryStream]);\n }\n\n createEntitiesWriteStream(): Writable {\n this.#reportInfo('creating entities write stream');\n const filePathFactory = createFilePathFactory('entities');\n const entryStream = createDirectoryJsonlWriter(\n this.#rootResolved,\n filePathFactory,\n this.options.file.maxSizeJsonl\n );\n return chain([stringer(), entryStream]);\n }\n\n createLinksWriteStream(): Writable {\n this.#reportInfo('creating links write stream');\n const filePathFactory = createFilePathFactory('links');\n const entryStream = createDirectoryJsonlWriter(\n this.#rootResolved,\n filePathFactory,\n this.options.file.maxSizeJsonl\n );\n return chain([stringer(), entryStream]);\n }\n\n createConfigurationWriteStream(): Writable {\n this.#reportInfo('creating configuration write stream');\n const filePathFactory = createFilePathFactory('configuration');\n const entryStream = createDirectoryJsonlWriter(\n this.#rootResolved,\n filePathFactory,\n this.options.file.maxSizeJsonl\n );\n return chain([stringer(), entryStream]);\n }\n\n createAssetsWriteStream(): Writable {\n this.#reportInfo('creating assets write stream');\n const root = this.#rootResolved;\n\n return new Writable({\n objectMode: true,\n write(data: IAsset, _encoding, callback) {\n const { filename } = data;\n const entryPath = path.join(root, 'assets', 'uploads', filename);\n const entryMetadataPath = path.join(root, 'assets', 'metadata', `${filename}.json`);\n\n const assetWriteError = (cause: unknown) =>\n new ProviderTransferError(`Failed to write asset ${filename}`, {\n details: {\n error: cause instanceof Error ? cause : new Error(String(cause)),\n },\n });\n\n let fileStream: ReturnType<typeof createWriteStream>;\n\n try {\n fs.mkdirSync(path.dirname(entryPath), { recursive: true });\n fs.mkdirSync(path.dirname(entryMetadataPath), { recursive: true });\n fs.writeFileSync(entryMetadataPath, JSON.stringify(data.metadata), 'utf8');\n fileStream = createWriteStream(entryPath);\n } catch (error: unknown) {\n callback(assetWriteError(error));\n return;\n }\n\n pipeline(data.stream, fileStream, (err) => {\n if (err) {\n callback(assetWriteError(err));\n return;\n }\n callback(null);\n });\n },\n });\n }\n}\n"],"names":["createLocalDirectoryDestinationProvider","options","LocalDirectoryDestinationProvider","setMetadata","target","metadata","bootstrap","diagnostics","fs","mkdir","recursive","results","file","path","close","rollback","rm","force","getMetadata","createSchemasWriteStream","filePathFactory","createFilePathFactory","entryStream","createDirectoryJsonlWriter","maxSizeJsonl","chain","stringer","createEntitiesWriteStream","createLinksWriteStream","createConfigurationWriteStream","createAssetsWriteStream","root","Writable","objectMode","write","data","_encoding","callback","filename","entryPath","join","entryMetadataPath","assetWriteError","cause","ProviderTransferError","details","error","Error","String","fileStream","mkdirSync","dirname","writeFileSync","JSON","stringify","createWriteStream","pipeline","stream","err","name","type","resolve","directory","message","report","createdAt","Date","origin","kind","source","writeFile"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAmCO,MAAMA,0CAA0C,CACrDC,OAAAA,GAAAA;AAEA,IAAA,OAAO,IAAIC,iCAAAA,CAAkCD,OAAAA,CAAAA;AAC/C;IAWE,kBAAA,iBAAA,8BAAA,CAAA,oBAAA,CAAA,EAEA,aAAA,iBAAA,8BAAA,CAAA,eAAA,CAAA,EAEA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AI,CAAC,gCAAA,IAAI,EAAC,eAAA,aAAA,CAAA,EAAe,eAAA,CAAA;AAC7C,QAAA,MAAMhC,GAAGC,KAAK,CAACI,IAAAA,CAAKsC,OAAO,CAAC/C,MAAAA,CAAAA,EAAS;YAAEM,SAAAA,EAAW;AAAK,SAAA,CAAA;QACvD,MAAMF,EAAAA,CAAG8D,SAAS,CAAClE,MAAAA,EAAQiD,KAAKC,SAAS,CAACjD,QAAAA,EAAU,IAAA,EAAM,CAAA,CAAA,EAAI,MAAA,CAAA;AAChE,IAAA;AACF;;;;"}
@@ -0,0 +1,177 @@
1
+ import path from 'path';
2
+ import { createWriteStream } from 'fs';
3
+ import { Writable, pipeline } from 'stream';
4
+ import fs__default from 'fs-extra';
5
+ import { stringer } from 'stream-json/jsonl/Stringer';
6
+ import { chain } from 'stream-chain';
7
+ import { createDirectoryJsonlWriter } from './utils.mjs';
8
+ import { ProviderTransferError } from '../../../errors/providers.mjs';
9
+ import { createFilePathFactory } from '../../../file/providers/destination/utils.mjs';
10
+
11
+ function _class_private_field_loose_base(receiver, privateKey) {
12
+ if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) {
13
+ throw new TypeError("attempted to use private field on non-instance");
14
+ }
15
+ return receiver;
16
+ }
17
+ var id = 0;
18
+ function _class_private_field_loose_key(name) {
19
+ return "__private_" + id++ + "_" + name;
20
+ }
21
+ const createLocalDirectoryDestinationProvider = (options)=>{
22
+ return new LocalDirectoryDestinationProvider(options);
23
+ };
24
+ var _providersMetadata = /*#__PURE__*/ _class_private_field_loose_key("_providersMetadata"), _rootResolved = /*#__PURE__*/ _class_private_field_loose_key("_rootResolved"), _diagnostics = /*#__PURE__*/ _class_private_field_loose_key("_diagnostics"), _reportInfo = /*#__PURE__*/ _class_private_field_loose_key("_reportInfo"), _writeMetadata = /*#__PURE__*/ _class_private_field_loose_key("_writeMetadata");
25
+ class LocalDirectoryDestinationProvider {
26
+ setMetadata(target, metadata) {
27
+ _class_private_field_loose_base(this, _providersMetadata)[_providersMetadata][target] = metadata;
28
+ return this;
29
+ }
30
+ async bootstrap(diagnostics) {
31
+ _class_private_field_loose_base(this, _diagnostics)[_diagnostics] = diagnostics;
32
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('preparing directory export');
33
+ await fs__default.mkdir(_class_private_field_loose_base(this, _rootResolved)[_rootResolved], {
34
+ recursive: true
35
+ });
36
+ this.results.file = {
37
+ path: _class_private_field_loose_base(this, _rootResolved)[_rootResolved]
38
+ };
39
+ }
40
+ async close() {
41
+ await _class_private_field_loose_base(this, _writeMetadata)[_writeMetadata]();
42
+ }
43
+ async rollback() {
44
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('rolling back');
45
+ await fs__default.rm(_class_private_field_loose_base(this, _rootResolved)[_rootResolved], {
46
+ recursive: true,
47
+ force: true
48
+ });
49
+ }
50
+ getMetadata() {
51
+ return null;
52
+ }
53
+ createSchemasWriteStream() {
54
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('creating schemas write stream');
55
+ const filePathFactory = createFilePathFactory('schemas');
56
+ const entryStream = createDirectoryJsonlWriter(_class_private_field_loose_base(this, _rootResolved)[_rootResolved], filePathFactory, this.options.file.maxSizeJsonl);
57
+ return chain([
58
+ stringer(),
59
+ entryStream
60
+ ]);
61
+ }
62
+ createEntitiesWriteStream() {
63
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('creating entities write stream');
64
+ const filePathFactory = createFilePathFactory('entities');
65
+ const entryStream = createDirectoryJsonlWriter(_class_private_field_loose_base(this, _rootResolved)[_rootResolved], filePathFactory, this.options.file.maxSizeJsonl);
66
+ return chain([
67
+ stringer(),
68
+ entryStream
69
+ ]);
70
+ }
71
+ createLinksWriteStream() {
72
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('creating links write stream');
73
+ const filePathFactory = createFilePathFactory('links');
74
+ const entryStream = createDirectoryJsonlWriter(_class_private_field_loose_base(this, _rootResolved)[_rootResolved], filePathFactory, this.options.file.maxSizeJsonl);
75
+ return chain([
76
+ stringer(),
77
+ entryStream
78
+ ]);
79
+ }
80
+ createConfigurationWriteStream() {
81
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('creating configuration write stream');
82
+ const filePathFactory = createFilePathFactory('configuration');
83
+ const entryStream = createDirectoryJsonlWriter(_class_private_field_loose_base(this, _rootResolved)[_rootResolved], filePathFactory, this.options.file.maxSizeJsonl);
84
+ return chain([
85
+ stringer(),
86
+ entryStream
87
+ ]);
88
+ }
89
+ createAssetsWriteStream() {
90
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('creating assets write stream');
91
+ const root = _class_private_field_loose_base(this, _rootResolved)[_rootResolved];
92
+ return new Writable({
93
+ objectMode: true,
94
+ write (data, _encoding, callback) {
95
+ const { filename } = data;
96
+ const entryPath = path.join(root, 'assets', 'uploads', filename);
97
+ const entryMetadataPath = path.join(root, 'assets', 'metadata', `${filename}.json`);
98
+ const assetWriteError = (cause)=>new ProviderTransferError(`Failed to write asset ${filename}`, {
99
+ details: {
100
+ error: cause instanceof Error ? cause : new Error(String(cause))
101
+ }
102
+ });
103
+ let fileStream;
104
+ try {
105
+ fs__default.mkdirSync(path.dirname(entryPath), {
106
+ recursive: true
107
+ });
108
+ fs__default.mkdirSync(path.dirname(entryMetadataPath), {
109
+ recursive: true
110
+ });
111
+ fs__default.writeFileSync(entryMetadataPath, JSON.stringify(data.metadata), 'utf8');
112
+ fileStream = createWriteStream(entryPath);
113
+ } catch (error) {
114
+ callback(assetWriteError(error));
115
+ return;
116
+ }
117
+ pipeline(data.stream, fileStream, (err)=>{
118
+ if (err) {
119
+ callback(assetWriteError(err));
120
+ return;
121
+ }
122
+ callback(null);
123
+ });
124
+ }
125
+ });
126
+ }
127
+ constructor(options){
128
+ Object.defineProperty(this, _reportInfo, {
129
+ value: reportInfo
130
+ });
131
+ Object.defineProperty(this, _writeMetadata, {
132
+ value: writeMetadata
133
+ });
134
+ Object.defineProperty(this, _providersMetadata, {
135
+ writable: true,
136
+ value: void 0
137
+ });
138
+ Object.defineProperty(this, _rootResolved, {
139
+ writable: true,
140
+ value: void 0
141
+ });
142
+ Object.defineProperty(this, _diagnostics, {
143
+ writable: true,
144
+ value: void 0
145
+ });
146
+ this.name = 'destination::local-directory';
147
+ this.type = 'destination';
148
+ this.results = {};
149
+ _class_private_field_loose_base(this, _providersMetadata)[_providersMetadata] = {};
150
+ this.options = options;
151
+ _class_private_field_loose_base(this, _rootResolved)[_rootResolved] = path.resolve(options.directory.path);
152
+ }
153
+ }
154
+ function reportInfo(message) {
155
+ _class_private_field_loose_base(this, _diagnostics)[_diagnostics]?.report({
156
+ details: {
157
+ createdAt: new Date(),
158
+ message,
159
+ origin: 'directory-destination-provider'
160
+ },
161
+ kind: 'info'
162
+ });
163
+ }
164
+ async function writeMetadata() {
165
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('writing metadata');
166
+ const metadata = _class_private_field_loose_base(this, _providersMetadata)[_providersMetadata].source;
167
+ if (metadata) {
168
+ const target = path.join(_class_private_field_loose_base(this, _rootResolved)[_rootResolved], 'metadata.json');
169
+ await fs__default.mkdir(path.dirname(target), {
170
+ recursive: true
171
+ });
172
+ await fs__default.writeFile(target, JSON.stringify(metadata, null, 2), 'utf8');
173
+ }
174
+ }
175
+
176
+ export { createLocalDirectoryDestinationProvider };
177
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":["../../../../src/directory/providers/destination/index.ts"],"sourcesContent":["import path from 'path';\nimport { createWriteStream } from 'fs';\nimport { Writable, pipeline } from 'stream';\nimport fs from 'fs-extra';\nimport { stringer } from 'stream-json/jsonl/Stringer';\nimport { chain } from 'stream-chain';\n\nimport type {\n IAsset,\n IDestinationProvider,\n IDestinationProviderTransferResults,\n IMetadata,\n ProviderType,\n} from '../../../../types';\nimport type { IDiagnosticReporter } from '../../../utils/diagnostic';\nimport { createDirectoryJsonlWriter, createFilePathFactory } from './utils';\nimport { ProviderTransferError } from '../../../errors/providers';\n\nexport interface ILocalDirectoryDestinationProviderOptions {\n directory: {\n /** Output root: unpacked Strapi export layout (metadata.json, entities/, …) */\n path: string;\n };\n file: {\n maxSizeJsonl?: number;\n };\n}\n\nexport interface ILocalDirectoryDestinationProviderTransferResults\n extends IDestinationProviderTransferResults {\n file?: {\n path?: string;\n };\n}\n\nexport const createLocalDirectoryDestinationProvider = (\n options: ILocalDirectoryDestinationProviderOptions\n) => {\n return new LocalDirectoryDestinationProvider(options);\n};\n\nclass LocalDirectoryDestinationProvider implements IDestinationProvider {\n name = 'destination::local-directory';\n\n type: ProviderType = 'destination';\n\n options: ILocalDirectoryDestinationProviderOptions;\n\n results: ILocalDirectoryDestinationProviderTransferResults = {};\n\n #providersMetadata: { source?: IMetadata; destination?: IMetadata } = {};\n\n #rootResolved: string;\n\n #diagnostics?: IDiagnosticReporter;\n\n constructor(options: ILocalDirectoryDestinationProviderOptions) {\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-destination-provider',\n },\n kind: 'info',\n });\n }\n\n setMetadata(target: ProviderType, metadata: IMetadata): IDestinationProvider {\n this.#providersMetadata[target] = metadata;\n return this;\n }\n\n async bootstrap(diagnostics: IDiagnosticReporter): Promise<void> {\n this.#diagnostics = diagnostics;\n this.#reportInfo('preparing directory export');\n await fs.mkdir(this.#rootResolved, { recursive: true });\n this.results.file = { path: this.#rootResolved };\n }\n\n async close() {\n await this.#writeMetadata();\n }\n\n async rollback(): Promise<void> {\n this.#reportInfo('rolling back');\n await fs.rm(this.#rootResolved, { recursive: true, force: true });\n }\n\n getMetadata() {\n return null;\n }\n\n async #writeMetadata(): Promise<void> {\n this.#reportInfo('writing metadata');\n const metadata = this.#providersMetadata.source;\n if (metadata) {\n const target = path.join(this.#rootResolved, 'metadata.json');\n await fs.mkdir(path.dirname(target), { recursive: true });\n await fs.writeFile(target, JSON.stringify(metadata, null, 2), 'utf8');\n }\n }\n\n createSchemasWriteStream() {\n this.#reportInfo('creating schemas write stream');\n const filePathFactory = createFilePathFactory('schemas');\n const entryStream = createDirectoryJsonlWriter(\n this.#rootResolved,\n filePathFactory,\n this.options.file.maxSizeJsonl\n );\n return chain([stringer(), entryStream]);\n }\n\n createEntitiesWriteStream(): Writable {\n this.#reportInfo('creating entities write stream');\n const filePathFactory = createFilePathFactory('entities');\n const entryStream = createDirectoryJsonlWriter(\n this.#rootResolved,\n filePathFactory,\n this.options.file.maxSizeJsonl\n );\n return chain([stringer(), entryStream]);\n }\n\n createLinksWriteStream(): Writable {\n this.#reportInfo('creating links write stream');\n const filePathFactory = createFilePathFactory('links');\n const entryStream = createDirectoryJsonlWriter(\n this.#rootResolved,\n filePathFactory,\n this.options.file.maxSizeJsonl\n );\n return chain([stringer(), entryStream]);\n }\n\n createConfigurationWriteStream(): Writable {\n this.#reportInfo('creating configuration write stream');\n const filePathFactory = createFilePathFactory('configuration');\n const entryStream = createDirectoryJsonlWriter(\n this.#rootResolved,\n filePathFactory,\n this.options.file.maxSizeJsonl\n );\n return chain([stringer(), entryStream]);\n }\n\n createAssetsWriteStream(): Writable {\n this.#reportInfo('creating assets write stream');\n const root = this.#rootResolved;\n\n return new Writable({\n objectMode: true,\n write(data: IAsset, _encoding, callback) {\n const { filename } = data;\n const entryPath = path.join(root, 'assets', 'uploads', filename);\n const entryMetadataPath = path.join(root, 'assets', 'metadata', `${filename}.json`);\n\n const assetWriteError = (cause: unknown) =>\n new ProviderTransferError(`Failed to write asset ${filename}`, {\n details: {\n error: cause instanceof Error ? cause : new Error(String(cause)),\n },\n });\n\n let fileStream: ReturnType<typeof createWriteStream>;\n\n try {\n fs.mkdirSync(path.dirname(entryPath), { recursive: true });\n fs.mkdirSync(path.dirname(entryMetadataPath), { recursive: true });\n fs.writeFileSync(entryMetadataPath, JSON.stringify(data.metadata), 'utf8');\n fileStream = createWriteStream(entryPath);\n } catch (error: unknown) {\n callback(assetWriteError(error));\n return;\n }\n\n pipeline(data.stream, fileStream, (err) => {\n if (err) {\n callback(assetWriteError(err));\n return;\n }\n callback(null);\n });\n },\n });\n }\n}\n"],"names":["createLocalDirectoryDestinationProvider","options","LocalDirectoryDestinationProvider","setMetadata","target","metadata","bootstrap","diagnostics","fs","mkdir","recursive","results","file","path","close","rollback","rm","force","getMetadata","createSchemasWriteStream","filePathFactory","createFilePathFactory","entryStream","createDirectoryJsonlWriter","maxSizeJsonl","chain","stringer","createEntitiesWriteStream","createLinksWriteStream","createConfigurationWriteStream","createAssetsWriteStream","root","Writable","objectMode","write","data","_encoding","callback","filename","entryPath","join","entryMetadataPath","assetWriteError","cause","ProviderTransferError","details","error","Error","String","fileStream","mkdirSync","dirname","writeFileSync","JSON","stringify","createWriteStream","pipeline","stream","err","name","type","resolve","directory","message","report","createdAt","Date","origin","kind","source","writeFile"],"mappings":";;;;;;;;;;;;;;;;;;;;AAmCO,MAAMA,0CAA0C,CACrDC,OAAAA,GAAAA;AAEA,IAAA,OAAO,IAAIC,iCAAAA,CAAkCD,OAAAA,CAAAA;AAC/C;IAWE,kBAAA,iBAAA,8BAAA,CAAA,oBAAA,CAAA,EAEA,aAAA,iBAAA,8BAAA,CAAA,eAAA,CAAA,EAEA,6EAOA,WAAA,iBAAA,8BAAA,CAAA,aAAA,CAAA,EAoCM,cAAA,iBAAA,8BAAA,CAAA,gBAAA,CAAA;AAxDR,MAAMC,iCAAAA,CAAAA;IA+BJC,WAAAA,CAAYC,MAAoB,EAAEC,QAAmB,EAAwB;AAC3E,QAAA,+BAAA,CAAA,IAAI,EAAC,kBAAA,CAAA,CAAA,kBAAA,CAAkB,CAACD,OAAO,GAAGC,QAAAA;AAClC,QAAA,OAAO,IAAI;AACb,IAAA;IAEA,MAAMC,SAAAA,CAAUC,WAAgC,EAAiB;QAC/D,+BAAA,CAAA,IAAI,EAAC,YAAA,CAAA,CAAA,YAAA,CAAA,GAAeA,WAAAA;QACpB,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AA,kBAAA,CAAA,CAAA,sBAAsE,EAAC;QAOrE,IAAI,CAACV,OAAO,GAAGA,OAAAA;QACf,+BAAA,CAAA,IAAI,EAAC,aAAA,CAAA,CAAA,aAAA,CAAA,GAAgBY,IAAAA,CAAKgD,OAAO,CAAC5D,OAAAA,CAAQ6D,SAAS,CAACjD,IAAI,CAAA;AAC1D,IAAA;AAoIF;AAlIE,SAAA,WAAYkD,OAAe,EAAA;AACzB,IAAA,+BAAA,CAAA,IAAI,EAAC,YAAA,CAAA,CAAA,YAAA,CAAA,EAAcC,MAAAA,CAAO;QACxBnB,OAAAA,EAAS;AACPoB,YAAAA,SAAAA,EAAW,IAAIC,IAAAA,EAAAA;AACfH,YAAAA,OAAAA;YACAI,MAAAA,EAAQ;AACV,SAAA;QACAC,IAAAA,EAAM;AACR,KAAA,CAAA;AACF;AA2BA,eAAA,aAAA,GAAA;IACE,+BAAA,CAAA,IAAI,EAAC,WAAA,CAAA,CAAA,WAAA,CAAA,CAAY,kBAAA,CAAA;AACjB,IAAA,MAAM/D,WAAW,+BAAA,CAAA,IAAI,EAAC,kBAAA,CAAA,CAAA,oBAAmBgE,MAAM;AAC/C,IAAA,IAAIhE,QAAAA,EAAU;QACZ,MAAMD,MAAAA,GAASS,KAAK2B,IAAI,CAAC,gCAAA,IAAI,EAAC,eAAA,aAAA,CAAA,EAAe,eAAA,CAAA;AAC7C,QAAA,MAAMhC,YAAGC,KAAK,CAACI,IAAAA,CAAKsC,OAAO,CAAC/C,MAAAA,CAAAA,EAAS;YAAEM,SAAAA,EAAW;AAAK,SAAA,CAAA;QACvD,MAAMF,WAAAA,CAAG8D,SAAS,CAAClE,MAAAA,EAAQiD,KAAKC,SAAS,CAACjD,QAAAA,EAAU,IAAA,EAAM,CAAA,CAAA,EAAI,MAAA,CAAA;AAChE,IAAA;AACF;;;;"}
@@ -0,0 +1,9 @@
1
+ /// <reference types="node" />
2
+ import { Writable } from 'stream';
3
+ import { createFilePathFactory } from '../../../file/providers/destination/utils';
4
+ export { createFilePathFactory };
5
+ /**
6
+ * JSONL writer that mirrors {@link createTarEntryStream} but writes files under a root directory.
7
+ */
8
+ export declare const createDirectoryJsonlWriter: (rootDir: string, pathFactory: (index?: number) => string, maxSize?: number) => Writable;
9
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/directory/providers/destination/utils.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC,OAAO,EAAE,qBAAqB,EAAE,MAAM,2CAA2C,CAAC;AAElF,OAAO,EAAE,qBAAqB,EAAE,CAAC;AAEjC;;GAEG;AACH,eAAO,MAAM,0BAA0B,YAC5B,MAAM,eACF,CAAC,KAAK,CAAC,EAAE,MAAM,KAAK,MAAM,+BAyDxC,CAAC"}
@@ -0,0 +1,58 @@
1
+ 'use strict';
2
+
3
+ var fs = require('fs');
4
+ var path = require('path');
5
+ var stream = require('stream');
6
+
7
+ /**
8
+ * JSONL writer that mirrors {@link createTarEntryStream} but writes files under a root directory.
9
+ */ const createDirectoryJsonlWriter = (rootDir, pathFactory, maxSize = 2.56e8)=>{
10
+ let fileIndex = 0;
11
+ let buffer = '';
12
+ const resolvePath = (posixName)=>path.join(rootDir, ...posixName.split('/'));
13
+ const flush = async ()=>{
14
+ if (!buffer) {
15
+ return;
16
+ }
17
+ fileIndex += 1;
18
+ const name = pathFactory(fileIndex);
19
+ const targetPath = resolvePath(name);
20
+ await fs.promises.mkdir(path.dirname(targetPath), {
21
+ recursive: true
22
+ });
23
+ await fs.promises.writeFile(targetPath, buffer, 'utf8');
24
+ buffer = '';
25
+ };
26
+ const push = (chunk)=>{
27
+ buffer += chunk;
28
+ };
29
+ return new stream.Writable({
30
+ async final (callback) {
31
+ try {
32
+ await flush();
33
+ callback();
34
+ } catch (err) {
35
+ callback(err instanceof Error ? err : new Error(String(err)));
36
+ }
37
+ },
38
+ async destroy (err, callback) {
39
+ await flush();
40
+ callback(err);
41
+ },
42
+ async write (chunk, _encoding, callback) {
43
+ const size = chunk.length;
44
+ if (chunk.length > maxSize) {
45
+ callback(new Error(`payload too large: ${chunk.length}>${maxSize}`));
46
+ return;
47
+ }
48
+ if (buffer.length + size > maxSize) {
49
+ await flush();
50
+ }
51
+ push(chunk);
52
+ callback(null);
53
+ }
54
+ });
55
+ };
56
+
57
+ exports.createDirectoryJsonlWriter = createDirectoryJsonlWriter;
58
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sources":["../../../../src/directory/providers/destination/utils.ts"],"sourcesContent":["import { promises as fsp } from 'fs';\nimport path from 'path';\nimport { Writable } from 'stream';\n\nimport { createFilePathFactory } from '../../../file/providers/destination/utils';\n\nexport { createFilePathFactory };\n\n/**\n * JSONL writer that mirrors {@link createTarEntryStream} but writes files under a root directory.\n */\nexport const createDirectoryJsonlWriter = (\n rootDir: string,\n pathFactory: (index?: number) => string,\n maxSize = 2.56e8\n) => {\n let fileIndex = 0;\n let buffer = '';\n\n const resolvePath = (posixName: string) => path.join(rootDir, ...posixName.split('/'));\n\n const flush = async () => {\n if (!buffer) {\n return;\n }\n\n fileIndex += 1;\n const name = pathFactory(fileIndex);\n const targetPath = resolvePath(name);\n await fsp.mkdir(path.dirname(targetPath), { recursive: true });\n await fsp.writeFile(targetPath, buffer, 'utf8');\n buffer = '';\n };\n\n const push = (chunk: string | Buffer) => {\n buffer += chunk;\n };\n\n return new Writable({\n async final(callback) {\n try {\n await flush();\n callback();\n } catch (err: unknown) {\n callback(err instanceof Error ? err : new Error(String(err)));\n }\n },\n\n async destroy(err, callback) {\n await flush();\n callback(err);\n },\n\n async write(chunk, _encoding, callback) {\n const size = chunk.length;\n\n if (chunk.length > maxSize) {\n callback(new Error(`payload too large: ${chunk.length}>${maxSize}`));\n return;\n }\n\n if (buffer.length + size > maxSize) {\n await flush();\n }\n\n push(chunk);\n\n callback(null);\n },\n });\n};\n"],"names":["createDirectoryJsonlWriter","rootDir","pathFactory","maxSize","fileIndex","buffer","resolvePath","posixName","path","join","split","flush","name","targetPath","fsp","mkdir","dirname","recursive","writeFile","push","chunk","Writable","final","callback","err","Error","String","destroy","write","_encoding","size","length"],"mappings":";;;;;;AAQA;;AAEC,IACM,MAAMA,0BAAAA,GAA6B,CACxCC,OAAAA,EACAC,WAAAA,EACAC,UAAU,MAAM,GAAA;AAEhB,IAAA,IAAIC,SAAAA,GAAY,CAAA;AAChB,IAAA,IAAIC,MAAAA,GAAS,EAAA;IAEb,MAAMC,WAAAA,GAAc,CAACC,SAAAA,GAAsBC,IAAAA,CAAKC,IAAI,CAACR,OAAAA,EAAAA,GAAYM,SAAAA,CAAUG,KAAK,CAAC,GAAA,CAAA,CAAA;AAEjF,IAAA,MAAMC,KAAAA,GAAQ,UAAA;AACZ,QAAA,IAAI,CAACN,MAAAA,EAAQ;AACX,YAAA;AACF,QAAA;QAEAD,SAAAA,IAAa,CAAA;AACb,QAAA,MAAMQ,OAAOV,WAAAA,CAAYE,SAAAA,CAAAA;AACzB,QAAA,MAAMS,aAAaP,WAAAA,CAAYM,IAAAA,CAAAA;AAC/B,QAAA,MAAME,YAAIC,KAAK,CAACP,IAAAA,CAAKQ,OAAO,CAACH,UAAAA,CAAAA,EAAa;YAAEI,SAAAA,EAAW;AAAK,SAAA,CAAA;AAC5D,QAAA,MAAMH,WAAAA,CAAII,SAAS,CAACL,UAAAA,EAAYR,MAAAA,EAAQ,MAAA,CAAA;QACxCA,MAAAA,GAAS,EAAA;AACX,IAAA,CAAA;AAEA,IAAA,MAAMc,OAAO,CAACC,KAAAA,GAAAA;QACZf,MAAAA,IAAUe,KAAAA;AACZ,IAAA,CAAA;AAEA,IAAA,OAAO,IAAIC,eAAAA,CAAS;AAClB,QAAA,MAAMC,OAAMC,QAAQ,EAAA;YAClB,IAAI;gBACF,MAAMZ,KAAAA,EAAAA;AACNY,gBAAAA,QAAAA,EAAAA;AACF,YAAA,CAAA,CAAE,OAAOC,GAAAA,EAAc;AACrBD,gBAAAA,QAAAA,CAASC,GAAAA,YAAeC,KAAAA,GAAQD,GAAAA,GAAM,IAAIC,MAAMC,MAAAA,CAAOF,GAAAA,CAAAA,CAAAA,CAAAA;AACzD,YAAA;AACF,QAAA,CAAA;QAEA,MAAMG,OAAAA,CAAAA,CAAQH,GAAG,EAAED,QAAQ,EAAA;YACzB,MAAMZ,KAAAA,EAAAA;YACNY,QAAAA,CAASC,GAAAA,CAAAA;AACX,QAAA,CAAA;AAEA,QAAA,MAAMI,KAAAA,CAAAA,CAAMR,KAAK,EAAES,SAAS,EAAEN,QAAQ,EAAA;YACpC,MAAMO,IAAAA,GAAOV,MAAMW,MAAM;YAEzB,IAAIX,KAAAA,CAAMW,MAAM,GAAG5B,OAAAA,EAAS;gBAC1BoB,QAAAA,CAAS,IAAIE,KAAAA,CAAM,CAAC,mBAAmB,EAAEL,MAAMW,MAAM,CAAC,CAAC,EAAE5B,OAAAA,CAAAA,CAAS,CAAA,CAAA;AAClE,gBAAA;AACF,YAAA;AAEA,YAAA,IAAIE,MAAAA,CAAO0B,MAAM,GAAGD,IAAAA,GAAO3B,OAAAA,EAAS;gBAClC,MAAMQ,KAAAA,EAAAA;AACR,YAAA;YAEAQ,IAAAA,CAAKC,KAAAA,CAAAA;YAELG,QAAAA,CAAS,IAAA,CAAA;AACX,QAAA;AACF,KAAA,CAAA;AACF;;;;"}
@@ -0,0 +1,56 @@
1
+ import { promises } from 'fs';
2
+ import path from 'path';
3
+ import { Writable } from 'stream';
4
+
5
+ /**
6
+ * JSONL writer that mirrors {@link createTarEntryStream} but writes files under a root directory.
7
+ */ const createDirectoryJsonlWriter = (rootDir, pathFactory, maxSize = 2.56e8)=>{
8
+ let fileIndex = 0;
9
+ let buffer = '';
10
+ const resolvePath = (posixName)=>path.join(rootDir, ...posixName.split('/'));
11
+ const flush = async ()=>{
12
+ if (!buffer) {
13
+ return;
14
+ }
15
+ fileIndex += 1;
16
+ const name = pathFactory(fileIndex);
17
+ const targetPath = resolvePath(name);
18
+ await promises.mkdir(path.dirname(targetPath), {
19
+ recursive: true
20
+ });
21
+ await promises.writeFile(targetPath, buffer, 'utf8');
22
+ buffer = '';
23
+ };
24
+ const push = (chunk)=>{
25
+ buffer += chunk;
26
+ };
27
+ return new Writable({
28
+ async final (callback) {
29
+ try {
30
+ await flush();
31
+ callback();
32
+ } catch (err) {
33
+ callback(err instanceof Error ? err : new Error(String(err)));
34
+ }
35
+ },
36
+ async destroy (err, callback) {
37
+ await flush();
38
+ callback(err);
39
+ },
40
+ async write (chunk, _encoding, callback) {
41
+ const size = chunk.length;
42
+ if (chunk.length > maxSize) {
43
+ callback(new Error(`payload too large: ${chunk.length}>${maxSize}`));
44
+ return;
45
+ }
46
+ if (buffer.length + size > maxSize) {
47
+ await flush();
48
+ }
49
+ push(chunk);
50
+ callback(null);
51
+ }
52
+ });
53
+ };
54
+
55
+ export { createDirectoryJsonlWriter };
56
+ //# sourceMappingURL=utils.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.mjs","sources":["../../../../src/directory/providers/destination/utils.ts"],"sourcesContent":["import { promises as fsp } from 'fs';\nimport path from 'path';\nimport { Writable } from 'stream';\n\nimport { createFilePathFactory } from '../../../file/providers/destination/utils';\n\nexport { createFilePathFactory };\n\n/**\n * JSONL writer that mirrors {@link createTarEntryStream} but writes files under a root directory.\n */\nexport const createDirectoryJsonlWriter = (\n rootDir: string,\n pathFactory: (index?: number) => string,\n maxSize = 2.56e8\n) => {\n let fileIndex = 0;\n let buffer = '';\n\n const resolvePath = (posixName: string) => path.join(rootDir, ...posixName.split('/'));\n\n const flush = async () => {\n if (!buffer) {\n return;\n }\n\n fileIndex += 1;\n const name = pathFactory(fileIndex);\n const targetPath = resolvePath(name);\n await fsp.mkdir(path.dirname(targetPath), { recursive: true });\n await fsp.writeFile(targetPath, buffer, 'utf8');\n buffer = '';\n };\n\n const push = (chunk: string | Buffer) => {\n buffer += chunk;\n };\n\n return new Writable({\n async final(callback) {\n try {\n await flush();\n callback();\n } catch (err: unknown) {\n callback(err instanceof Error ? err : new Error(String(err)));\n }\n },\n\n async destroy(err, callback) {\n await flush();\n callback(err);\n },\n\n async write(chunk, _encoding, callback) {\n const size = chunk.length;\n\n if (chunk.length > maxSize) {\n callback(new Error(`payload too large: ${chunk.length}>${maxSize}`));\n return;\n }\n\n if (buffer.length + size > maxSize) {\n await flush();\n }\n\n push(chunk);\n\n callback(null);\n },\n });\n};\n"],"names":["createDirectoryJsonlWriter","rootDir","pathFactory","maxSize","fileIndex","buffer","resolvePath","posixName","path","join","split","flush","name","targetPath","fsp","mkdir","dirname","recursive","writeFile","push","chunk","Writable","final","callback","err","Error","String","destroy","write","_encoding","size","length"],"mappings":";;;;AAQA;;AAEC,IACM,MAAMA,0BAAAA,GAA6B,CACxCC,OAAAA,EACAC,WAAAA,EACAC,UAAU,MAAM,GAAA;AAEhB,IAAA,IAAIC,SAAAA,GAAY,CAAA;AAChB,IAAA,IAAIC,MAAAA,GAAS,EAAA;IAEb,MAAMC,WAAAA,GAAc,CAACC,SAAAA,GAAsBC,IAAAA,CAAKC,IAAI,CAACR,OAAAA,EAAAA,GAAYM,SAAAA,CAAUG,KAAK,CAAC,GAAA,CAAA,CAAA;AAEjF,IAAA,MAAMC,KAAAA,GAAQ,UAAA;AACZ,QAAA,IAAI,CAACN,MAAAA,EAAQ;AACX,YAAA;AACF,QAAA;QAEAD,SAAAA,IAAa,CAAA;AACb,QAAA,MAAMQ,OAAOV,WAAAA,CAAYE,SAAAA,CAAAA;AACzB,QAAA,MAAMS,aAAaP,WAAAA,CAAYM,IAAAA,CAAAA;AAC/B,QAAA,MAAME,SAAIC,KAAK,CAACP,IAAAA,CAAKQ,OAAO,CAACH,UAAAA,CAAAA,EAAa;YAAEI,SAAAA,EAAW;AAAK,SAAA,CAAA;AAC5D,QAAA,MAAMH,QAAAA,CAAII,SAAS,CAACL,UAAAA,EAAYR,MAAAA,EAAQ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