@strapi/data-transfer 5.12.1 → 5.12.3
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.
- package/dist/engine/errors.js +39 -0
- package/dist/engine/errors.js.map +1 -0
- package/dist/engine/errors.mjs +34 -0
- package/dist/engine/errors.mjs.map +1 -0
- package/dist/engine/index.js +797 -0
- package/dist/engine/index.js.map +1 -0
- package/dist/engine/index.mjs +792 -0
- package/dist/engine/index.mjs.map +1 -0
- package/dist/engine/validation/provider.js +19 -0
- package/dist/engine/validation/provider.js.map +1 -0
- package/dist/engine/validation/provider.mjs +17 -0
- package/dist/engine/validation/provider.mjs.map +1 -0
- package/dist/engine/validation/schemas/index.js +57 -0
- package/dist/engine/validation/schemas/index.js.map +1 -0
- package/dist/engine/validation/schemas/index.mjs +55 -0
- package/dist/engine/validation/schemas/index.mjs.map +1 -0
- package/dist/errors/base.js +13 -0
- package/dist/errors/base.js.map +1 -0
- package/dist/errors/base.mjs +11 -0
- package/dist/errors/base.mjs.map +1 -0
- package/dist/errors/constants.js +10 -0
- package/dist/errors/constants.js.map +1 -0
- package/dist/errors/constants.mjs +8 -0
- package/dist/errors/constants.mjs.map +1 -0
- package/dist/errors/providers.js +41 -0
- package/dist/errors/providers.js.map +1 -0
- package/dist/errors/providers.mjs +36 -0
- package/dist/errors/providers.mjs.map +1 -0
- package/dist/file/index.js +8 -0
- package/dist/file/index.js.map +1 -0
- package/dist/file/index.mjs +3 -0
- package/dist/file/index.mjs.map +1 -0
- package/dist/file/providers/destination/index.js +248 -0
- package/dist/file/providers/destination/index.js.map +1 -0
- package/dist/file/providers/destination/index.mjs +246 -0
- package/dist/file/providers/destination/index.mjs.map +1 -0
- package/dist/file/providers/destination/utils.js +63 -0
- package/dist/file/providers/destination/utils.js.map +1 -0
- package/dist/file/providers/destination/utils.mjs +60 -0
- package/dist/file/providers/destination/utils.mjs.map +1 -0
- package/dist/file/providers/index.js +10 -0
- package/dist/file/providers/index.js.map +1 -0
- package/dist/file/providers/index.mjs +3 -0
- package/dist/file/providers/index.mjs.map +1 -0
- package/dist/file/providers/source/index.js +288 -0
- package/dist/file/providers/source/index.js.map +1 -0
- package/dist/file/providers/source/index.mjs +286 -0
- package/dist/file/providers/source/index.mjs.map +1 -0
- package/dist/file/providers/source/utils.js +56 -0
- package/dist/file/providers/source/utils.js.map +1 -0
- package/dist/file/providers/source/utils.mjs +52 -0
- package/dist/file/providers/source/utils.mjs.map +1 -0
- package/dist/index.js +8 -5692
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +8 -5674
- package/dist/index.mjs.map +1 -1
- package/dist/strapi/index.js +12 -0
- package/dist/strapi/index.js.map +1 -0
- package/dist/strapi/index.mjs +7 -0
- package/dist/strapi/index.mjs.map +1 -0
- package/dist/strapi/providers/index.js +16 -0
- package/dist/strapi/providers/index.js.map +1 -0
- package/dist/strapi/providers/index.mjs +7 -0
- package/dist/strapi/providers/index.mjs.map +1 -0
- package/dist/strapi/providers/local-destination/index.js +419 -0
- package/dist/strapi/providers/local-destination/index.js.map +1 -0
- package/dist/strapi/providers/local-destination/index.mjs +396 -0
- package/dist/strapi/providers/local-destination/index.mjs.map +1 -0
- package/dist/strapi/providers/local-destination/strategies/restore/configuration.js +52 -0
- package/dist/strapi/providers/local-destination/strategies/restore/configuration.js.map +1 -0
- package/dist/strapi/providers/local-destination/strategies/restore/configuration.mjs +49 -0
- package/dist/strapi/providers/local-destination/strategies/restore/configuration.mjs.map +1 -0
- package/dist/strapi/providers/local-destination/strategies/restore/entities.js +64 -0
- package/dist/strapi/providers/local-destination/strategies/restore/entities.js.map +1 -0
- package/dist/strapi/providers/local-destination/strategies/restore/entities.mjs +62 -0
- package/dist/strapi/providers/local-destination/strategies/restore/entities.mjs.map +1 -0
- package/dist/strapi/providers/local-destination/strategies/restore/index.js +126 -0
- package/dist/strapi/providers/local-destination/strategies/restore/index.js.map +1 -0
- package/dist/strapi/providers/local-destination/strategies/restore/index.mjs +122 -0
- package/dist/strapi/providers/local-destination/strategies/restore/index.mjs.map +1 -0
- package/dist/strapi/providers/local-destination/strategies/restore/links.js +60 -0
- package/dist/strapi/providers/local-destination/strategies/restore/links.js.map +1 -0
- package/dist/strapi/providers/local-destination/strategies/restore/links.mjs +58 -0
- package/dist/strapi/providers/local-destination/strategies/restore/links.mjs.map +1 -0
- package/dist/strapi/providers/local-source/assets.js +123 -0
- package/dist/strapi/providers/local-source/assets.js.map +1 -0
- package/dist/strapi/providers/local-source/assets.mjs +121 -0
- package/dist/strapi/providers/local-source/assets.mjs.map +1 -0
- package/dist/strapi/providers/local-source/configuration.js +39 -0
- package/dist/strapi/providers/local-source/configuration.js.map +1 -0
- package/dist/strapi/providers/local-source/configuration.mjs +37 -0
- package/dist/strapi/providers/local-source/configuration.mjs.map +1 -0
- package/dist/strapi/providers/local-source/entities.js +62 -0
- package/dist/strapi/providers/local-source/entities.js.map +1 -0
- package/dist/strapi/providers/local-source/entities.mjs +59 -0
- package/dist/strapi/providers/local-source/entities.mjs.map +1 -0
- package/dist/strapi/providers/local-source/index.js +154 -0
- package/dist/strapi/providers/local-source/index.js.map +1 -0
- package/dist/strapi/providers/local-source/index.mjs +152 -0
- package/dist/strapi/providers/local-source/index.mjs.map +1 -0
- package/dist/strapi/providers/local-source/links.js +26 -0
- package/dist/strapi/providers/local-source/links.js.map +1 -0
- package/dist/strapi/providers/local-source/links.mjs +24 -0
- package/dist/strapi/providers/local-source/links.mjs.map +1 -0
- package/dist/strapi/providers/remote-destination/index.js +392 -0
- package/dist/strapi/providers/remote-destination/index.js.map +1 -0
- package/dist/strapi/providers/remote-destination/index.mjs +390 -0
- package/dist/strapi/providers/remote-destination/index.mjs.map +1 -0
- package/dist/strapi/providers/remote-source/index.js +405 -0
- package/dist/strapi/providers/remote-source/index.js.map +1 -0
- package/dist/strapi/providers/remote-source/index.mjs +403 -0
- package/dist/strapi/providers/remote-source/index.mjs.map +1 -0
- package/dist/strapi/providers/utils.js +173 -0
- package/dist/strapi/providers/utils.js.map +1 -0
- package/dist/strapi/providers/utils.mjs +169 -0
- package/dist/strapi/providers/utils.mjs.map +1 -0
- package/dist/strapi/queries/entity.js +125 -0
- package/dist/strapi/queries/entity.js.map +1 -0
- package/dist/strapi/queries/entity.mjs +123 -0
- package/dist/strapi/queries/entity.mjs.map +1 -0
- package/dist/strapi/queries/index.js +10 -0
- package/dist/strapi/queries/index.js.map +1 -0
- package/dist/strapi/queries/index.mjs +5 -0
- package/dist/strapi/queries/index.mjs.map +1 -0
- package/dist/strapi/queries/link.js +298 -0
- package/dist/strapi/queries/link.js.map +1 -0
- package/dist/strapi/queries/link.mjs +295 -0
- package/dist/strapi/queries/link.mjs.map +1 -0
- package/dist/strapi/remote/constants.js +11 -0
- package/dist/strapi/remote/constants.js.map +1 -0
- package/dist/strapi/remote/constants.mjs +8 -0
- package/dist/strapi/remote/constants.mjs.map +1 -0
- package/dist/strapi/remote/flows/default.js +43 -0
- package/dist/strapi/remote/flows/default.js.map +1 -0
- package/dist/strapi/remote/flows/default.mjs +41 -0
- package/dist/strapi/remote/flows/default.mjs.map +1 -0
- package/dist/strapi/remote/flows/index.js +54 -0
- package/dist/strapi/remote/flows/index.js.map +1 -0
- package/dist/strapi/remote/flows/index.mjs +52 -0
- package/dist/strapi/remote/flows/index.mjs.map +1 -0
- package/dist/strapi/remote/handlers/constants.js +10 -0
- package/dist/strapi/remote/handlers/constants.js.map +1 -0
- package/dist/strapi/remote/handlers/constants.mjs +8 -0
- package/dist/strapi/remote/handlers/constants.mjs.map +1 -0
- package/dist/strapi/remote/handlers/index.js +12 -0
- package/dist/strapi/remote/handlers/index.js.map +1 -0
- package/dist/strapi/remote/handlers/index.mjs +4 -0
- package/dist/strapi/remote/handlers/index.mjs.map +1 -0
- package/dist/strapi/remote/handlers/pull.js +348 -0
- package/dist/strapi/remote/handlers/pull.js.map +1 -0
- package/dist/strapi/remote/handlers/pull.mjs +346 -0
- package/dist/strapi/remote/handlers/pull.mjs.map +1 -0
- package/dist/strapi/remote/handlers/push.js +400 -0
- package/dist/strapi/remote/handlers/push.js.map +1 -0
- package/dist/strapi/remote/handlers/push.mjs +398 -0
- package/dist/strapi/remote/handlers/push.mjs.map +1 -0
- package/dist/strapi/remote/handlers/utils.js +316 -0
- package/dist/strapi/remote/handlers/utils.js.map +1 -0
- package/dist/strapi/remote/handlers/utils.mjs +310 -0
- package/dist/strapi/remote/handlers/utils.mjs.map +1 -0
- package/dist/strapi/remote/index.js +10 -0
- package/dist/strapi/remote/index.js.map +1 -0
- package/dist/strapi/remote/index.mjs +5 -0
- package/dist/strapi/remote/index.mjs.map +1 -0
- package/dist/utils/components.js +178 -0
- package/dist/utils/components.js.map +1 -0
- package/dist/utils/components.mjs +171 -0
- package/dist/utils/components.mjs.map +1 -0
- package/dist/utils/diagnostic.js +51 -0
- package/dist/utils/diagnostic.js.map +1 -0
- package/dist/utils/diagnostic.mjs +49 -0
- package/dist/utils/diagnostic.mjs.map +1 -0
- package/dist/utils/encryption/decrypt.js +47 -0
- package/dist/utils/encryption/decrypt.js.map +1 -0
- package/dist/utils/encryption/decrypt.mjs +45 -0
- package/dist/utils/encryption/decrypt.mjs.map +1 -0
- package/dist/utils/encryption/encrypt.js +47 -0
- package/dist/utils/encryption/encrypt.js.map +1 -0
- package/dist/utils/encryption/encrypt.mjs +45 -0
- package/dist/utils/encryption/encrypt.mjs.map +1 -0
- package/dist/utils/encryption/index.js +10 -0
- package/dist/utils/encryption/index.js.map +1 -0
- package/dist/utils/encryption/index.mjs +3 -0
- package/dist/utils/encryption/index.mjs.map +1 -0
- package/dist/utils/index.js +20 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/index.mjs +15 -0
- package/dist/utils/index.mjs.map +1 -0
- package/dist/utils/json.js +96 -0
- package/dist/utils/json.js.map +1 -0
- package/dist/utils/json.mjs +94 -0
- package/dist/utils/json.mjs.map +1 -0
- package/dist/utils/middleware.js +14 -0
- package/dist/utils/middleware.js.map +1 -0
- package/dist/utils/middleware.mjs +12 -0
- package/dist/utils/middleware.mjs.map +1 -0
- package/dist/utils/providers.js +12 -0
- package/dist/utils/providers.js.map +1 -0
- package/dist/utils/providers.mjs +10 -0
- package/dist/utils/providers.mjs.map +1 -0
- package/dist/utils/schema.js +32 -0
- package/dist/utils/schema.js.map +1 -0
- package/dist/utils/schema.mjs +29 -0
- package/dist/utils/schema.mjs.map +1 -0
- package/dist/utils/stream.js +59 -0
- package/dist/utils/stream.js.map +1 -0
- package/dist/utils/stream.mjs +55 -0
- package/dist/utils/stream.mjs.map +1 -0
- package/dist/utils/transaction.js +93 -0
- package/dist/utils/transaction.js.map +1 -0
- package/dist/utils/transaction.mjs +91 -0
- package/dist/utils/transaction.mjs.map +1 -0
- package/package.json +5 -5
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var path = require('path');
|
|
4
|
+
var stream = require('stream');
|
|
5
|
+
var fse = require('fs-extra');
|
|
6
|
+
|
|
7
|
+
function getFileStream(filepath, strapi1, isLocal = false) {
|
|
8
|
+
if (isLocal) {
|
|
9
|
+
// Todo: handle errors
|
|
10
|
+
return fse.createReadStream(filepath);
|
|
11
|
+
}
|
|
12
|
+
const readableStream = new stream.PassThrough();
|
|
13
|
+
// fetch the image from remote url and stream it
|
|
14
|
+
strapi1.fetch(filepath).then((res)=>{
|
|
15
|
+
if (res.status !== 200) {
|
|
16
|
+
readableStream.emit('error', new Error(`Request failed with status code ${res.status}`));
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (res.body) {
|
|
20
|
+
// pipe the image data
|
|
21
|
+
stream.Readable.fromWeb(res.body).pipe(readableStream);
|
|
22
|
+
} else {
|
|
23
|
+
readableStream.emit('error', new Error('Empty data found for file'));
|
|
24
|
+
}
|
|
25
|
+
}).catch((error)=>{
|
|
26
|
+
readableStream.emit('error', error);
|
|
27
|
+
});
|
|
28
|
+
return readableStream;
|
|
29
|
+
}
|
|
30
|
+
function getFileStats(filepath, strapi1, isLocal = false) {
|
|
31
|
+
if (isLocal) {
|
|
32
|
+
return fse.stat(filepath);
|
|
33
|
+
}
|
|
34
|
+
return new Promise((resolve, reject)=>{
|
|
35
|
+
strapi1.fetch(filepath).then((res)=>{
|
|
36
|
+
if (res.status !== 200) {
|
|
37
|
+
reject(new Error(`Request failed with status code ${res.status}`));
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const contentLength = res.headers.get('content-length');
|
|
41
|
+
const stats = {
|
|
42
|
+
size: contentLength ? parseInt(contentLength, 10) : 0
|
|
43
|
+
};
|
|
44
|
+
resolve(stats);
|
|
45
|
+
}).catch((error)=>{
|
|
46
|
+
reject(error);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
async function signFile(file) {
|
|
51
|
+
const { provider } = strapi.plugins.upload;
|
|
52
|
+
const { provider: providerName } = strapi.config.get('plugin.upload');
|
|
53
|
+
const isPrivate = await provider.isPrivate();
|
|
54
|
+
if (file?.provider === providerName && isPrivate) {
|
|
55
|
+
const signUrl = async (file)=>{
|
|
56
|
+
const signedUrl = await provider.getSignedUrl(file);
|
|
57
|
+
file.url = signedUrl.url;
|
|
58
|
+
};
|
|
59
|
+
// Sign the original file
|
|
60
|
+
await signUrl(file);
|
|
61
|
+
// Sign each file format
|
|
62
|
+
if (file.formats) {
|
|
63
|
+
for (const format of Object.keys(file.formats)){
|
|
64
|
+
await signUrl(file.formats[format]);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Generate and consume assets streams in order to stream each file individually
|
|
71
|
+
*/ const createAssetsStream = (strapi1)=>{
|
|
72
|
+
const generator = async function*() {
|
|
73
|
+
const stream = strapi1.db.queryBuilder('plugin::upload.file')// Create a query builder instance (default type is 'select')
|
|
74
|
+
// Fetch all columns
|
|
75
|
+
.select('*')// Get a readable stream
|
|
76
|
+
.stream();
|
|
77
|
+
for await (const file of stream){
|
|
78
|
+
const isLocalProvider = file.provider === 'local';
|
|
79
|
+
if (!isLocalProvider) {
|
|
80
|
+
await signFile(file);
|
|
81
|
+
}
|
|
82
|
+
const filepath = isLocalProvider ? path.join(strapi1.dirs.static.public, file.url) : file.url;
|
|
83
|
+
const stats = await getFileStats(filepath, strapi1, isLocalProvider);
|
|
84
|
+
const stream = getFileStream(filepath, strapi1, isLocalProvider);
|
|
85
|
+
yield {
|
|
86
|
+
metadata: file,
|
|
87
|
+
filepath,
|
|
88
|
+
filename: file.hash + file.ext,
|
|
89
|
+
stream,
|
|
90
|
+
stats: {
|
|
91
|
+
size: stats.size
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
if (file.formats) {
|
|
95
|
+
for (const format of Object.keys(file.formats)){
|
|
96
|
+
const fileFormat = file.formats[format];
|
|
97
|
+
const fileFormatFilepath = isLocalProvider ? path.join(strapi1.dirs.static.public, fileFormat.url) : fileFormat.url;
|
|
98
|
+
const fileFormatStats = await getFileStats(fileFormatFilepath, strapi1, isLocalProvider);
|
|
99
|
+
const fileFormatStream = getFileStream(fileFormatFilepath, strapi1, isLocalProvider);
|
|
100
|
+
const metadata = {
|
|
101
|
+
...fileFormat,
|
|
102
|
+
type: format,
|
|
103
|
+
id: file.id,
|
|
104
|
+
mainHash: file.hash
|
|
105
|
+
};
|
|
106
|
+
yield {
|
|
107
|
+
metadata,
|
|
108
|
+
filepath: fileFormatFilepath,
|
|
109
|
+
filename: fileFormat.hash + fileFormat.ext,
|
|
110
|
+
stream: fileFormatStream,
|
|
111
|
+
stats: {
|
|
112
|
+
size: fileFormatStats.size
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
return stream.Duplex.from(generator());
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
exports.createAssetsStream = createAssetsStream;
|
|
123
|
+
//# sourceMappingURL=assets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assets.js","sources":["../../../../src/strapi/providers/local-source/assets.ts"],"sourcesContent":["import { join } from 'path';\nimport { Duplex, PassThrough, Readable } from 'stream';\nimport { stat, createReadStream, ReadStream } from 'fs-extra';\nimport * as webStream from 'stream/web';\nimport type { Core } from '@strapi/types';\n\nimport type { IAsset, IFile } from '../../../../types';\n\nfunction getFileStream(\n filepath: string,\n strapi: Core.Strapi,\n isLocal = false\n): PassThrough | ReadStream {\n if (isLocal) {\n // Todo: handle errors\n return createReadStream(filepath);\n }\n\n const readableStream = new PassThrough();\n\n // fetch the image from remote url and stream it\n strapi\n .fetch(filepath)\n .then((res: Response) => {\n if (res.status !== 200) {\n readableStream.emit('error', new Error(`Request failed with status code ${res.status}`));\n return;\n }\n\n if (res.body) {\n // pipe the image data\n Readable.fromWeb(res.body as webStream.ReadableStream<Uint8Array>).pipe(readableStream);\n } else {\n readableStream.emit('error', new Error('Empty data found for file'));\n }\n })\n .catch((error: unknown) => {\n readableStream.emit('error', error);\n });\n\n return readableStream;\n}\n\nfunction getFileStats(\n filepath: string,\n strapi: Core.Strapi,\n isLocal = false\n): Promise<{ size: number }> {\n if (isLocal) {\n return stat(filepath);\n }\n return new Promise((resolve, reject) => {\n strapi\n .fetch(filepath)\n .then((res: Response) => {\n if (res.status !== 200) {\n reject(new Error(`Request failed with status code ${res.status}`));\n return;\n }\n\n const contentLength = res.headers.get('content-length');\n const stats = {\n size: contentLength ? parseInt(contentLength, 10) : 0,\n };\n\n resolve(stats);\n })\n .catch((error: unknown) => {\n reject(error);\n });\n });\n}\n\nasync function signFile(file: IFile) {\n const { provider } = strapi.plugins.upload;\n const { provider: providerName } = strapi.config.get('plugin.upload') as { provider: string };\n const isPrivate = await provider.isPrivate();\n if (file?.provider === providerName && isPrivate) {\n const signUrl = async (file: IFile) => {\n const signedUrl = await provider.getSignedUrl(file);\n file.url = signedUrl.url;\n };\n\n // Sign the original file\n await signUrl(file);\n // Sign each file format\n if (file.formats) {\n for (const format of Object.keys(file.formats)) {\n await signUrl(file.formats[format]);\n }\n }\n }\n}\n\n/**\n * Generate and consume assets streams in order to stream each file individually\n */\nexport const createAssetsStream = (strapi: Core.Strapi): Duplex => {\n const generator: () => AsyncGenerator<IAsset, void> = async function* () {\n const stream: Readable = strapi.db\n .queryBuilder('plugin::upload.file')\n // Create a query builder instance (default type is 'select')\n // Fetch all columns\n .select('*')\n // Get a readable stream\n .stream();\n\n for await (const file of stream) {\n const isLocalProvider = file.provider === 'local';\n if (!isLocalProvider) {\n await signFile(file);\n }\n const filepath = isLocalProvider ? join(strapi.dirs.static.public, file.url) : file.url;\n const stats = await getFileStats(filepath, strapi, isLocalProvider);\n const stream = getFileStream(filepath, strapi, isLocalProvider);\n\n yield {\n metadata: file,\n filepath,\n filename: file.hash + file.ext,\n stream,\n stats: { size: stats.size },\n };\n\n if (file.formats) {\n for (const format of Object.keys(file.formats)) {\n const fileFormat = file.formats[format];\n const fileFormatFilepath = isLocalProvider\n ? join(strapi.dirs.static.public, fileFormat.url)\n : fileFormat.url;\n const fileFormatStats = await getFileStats(fileFormatFilepath, strapi, isLocalProvider);\n const fileFormatStream = getFileStream(fileFormatFilepath, strapi, isLocalProvider);\n const metadata = { ...fileFormat, type: format, id: file.id, mainHash: file.hash };\n yield {\n metadata,\n filepath: fileFormatFilepath,\n filename: fileFormat.hash + fileFormat.ext,\n stream: fileFormatStream,\n stats: { size: fileFormatStats.size },\n };\n }\n }\n }\n };\n\n return Duplex.from(generator());\n};\n"],"names":["getFileStream","filepath","strapi","isLocal","createReadStream","readableStream","PassThrough","fetch","then","res","status","emit","Error","body","Readable","fromWeb","pipe","catch","error","getFileStats","stat","Promise","resolve","reject","contentLength","headers","get","stats","size","parseInt","signFile","file","provider","plugins","upload","providerName","config","isPrivate","signUrl","signedUrl","getSignedUrl","url","formats","format","Object","keys","createAssetsStream","generator","stream","db","queryBuilder","select","isLocalProvider","join","dirs","static","public","metadata","filename","hash","ext","fileFormat","fileFormatFil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import { createReadStream, stat } from 'fs-extra';
|
|
4
|
+
|
|
5
|
+
function getFileStream(filepath, strapi1, isLocal = false) {
|
|
6
|
+
if (isLocal) {
|
|
7
|
+
// Todo: handle errors
|
|
8
|
+
return createReadStream(filepath);
|
|
9
|
+
}
|
|
10
|
+
const readableStream = new PassThrough();
|
|
11
|
+
// fetch the image from remote url and stream it
|
|
12
|
+
strapi1.fetch(filepath).then((res)=>{
|
|
13
|
+
if (res.status !== 200) {
|
|
14
|
+
readableStream.emit('error', new Error(`Request failed with status code ${res.status}`));
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (res.body) {
|
|
18
|
+
// pipe the image data
|
|
19
|
+
Readable.fromWeb(res.body).pipe(readableStream);
|
|
20
|
+
} else {
|
|
21
|
+
readableStream.emit('error', new Error('Empty data found for file'));
|
|
22
|
+
}
|
|
23
|
+
}).catch((error)=>{
|
|
24
|
+
readableStream.emit('error', error);
|
|
25
|
+
});
|
|
26
|
+
return readableStream;
|
|
27
|
+
}
|
|
28
|
+
function getFileStats(filepath, strapi1, isLocal = false) {
|
|
29
|
+
if (isLocal) {
|
|
30
|
+
return stat(filepath);
|
|
31
|
+
}
|
|
32
|
+
return new Promise((resolve, reject)=>{
|
|
33
|
+
strapi1.fetch(filepath).then((res)=>{
|
|
34
|
+
if (res.status !== 200) {
|
|
35
|
+
reject(new Error(`Request failed with status code ${res.status}`));
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const contentLength = res.headers.get('content-length');
|
|
39
|
+
const stats = {
|
|
40
|
+
size: contentLength ? parseInt(contentLength, 10) : 0
|
|
41
|
+
};
|
|
42
|
+
resolve(stats);
|
|
43
|
+
}).catch((error)=>{
|
|
44
|
+
reject(error);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
async function signFile(file) {
|
|
49
|
+
const { provider } = strapi.plugins.upload;
|
|
50
|
+
const { provider: providerName } = strapi.config.get('plugin.upload');
|
|
51
|
+
const isPrivate = await provider.isPrivate();
|
|
52
|
+
if (file?.provider === providerName && isPrivate) {
|
|
53
|
+
const signUrl = async (file)=>{
|
|
54
|
+
const signedUrl = await provider.getSignedUrl(file);
|
|
55
|
+
file.url = signedUrl.url;
|
|
56
|
+
};
|
|
57
|
+
// Sign the original file
|
|
58
|
+
await signUrl(file);
|
|
59
|
+
// Sign each file format
|
|
60
|
+
if (file.formats) {
|
|
61
|
+
for (const format of Object.keys(file.formats)){
|
|
62
|
+
await signUrl(file.formats[format]);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Generate and consume assets streams in order to stream each file individually
|
|
69
|
+
*/ const createAssetsStream = (strapi1)=>{
|
|
70
|
+
const generator = async function*() {
|
|
71
|
+
const stream = strapi1.db.queryBuilder('plugin::upload.file')// Create a query builder instance (default type is 'select')
|
|
72
|
+
// Fetch all columns
|
|
73
|
+
.select('*')// Get a readable stream
|
|
74
|
+
.stream();
|
|
75
|
+
for await (const file of stream){
|
|
76
|
+
const isLocalProvider = file.provider === 'local';
|
|
77
|
+
if (!isLocalProvider) {
|
|
78
|
+
await signFile(file);
|
|
79
|
+
}
|
|
80
|
+
const filepath = isLocalProvider ? join(strapi1.dirs.static.public, file.url) : file.url;
|
|
81
|
+
const stats = await getFileStats(filepath, strapi1, isLocalProvider);
|
|
82
|
+
const stream = getFileStream(filepath, strapi1, isLocalProvider);
|
|
83
|
+
yield {
|
|
84
|
+
metadata: file,
|
|
85
|
+
filepath,
|
|
86
|
+
filename: file.hash + file.ext,
|
|
87
|
+
stream,
|
|
88
|
+
stats: {
|
|
89
|
+
size: stats.size
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
if (file.formats) {
|
|
93
|
+
for (const format of Object.keys(file.formats)){
|
|
94
|
+
const fileFormat = file.formats[format];
|
|
95
|
+
const fileFormatFilepath = isLocalProvider ? join(strapi1.dirs.static.public, fileFormat.url) : fileFormat.url;
|
|
96
|
+
const fileFormatStats = await getFileStats(fileFormatFilepath, strapi1, isLocalProvider);
|
|
97
|
+
const fileFormatStream = getFileStream(fileFormatFilepath, strapi1, isLocalProvider);
|
|
98
|
+
const metadata = {
|
|
99
|
+
...fileFormat,
|
|
100
|
+
type: format,
|
|
101
|
+
id: file.id,
|
|
102
|
+
mainHash: file.hash
|
|
103
|
+
};
|
|
104
|
+
yield {
|
|
105
|
+
metadata,
|
|
106
|
+
filepath: fileFormatFilepath,
|
|
107
|
+
filename: fileFormat.hash + fileFormat.ext,
|
|
108
|
+
stream: fileFormatStream,
|
|
109
|
+
stats: {
|
|
110
|
+
size: fileFormatStats.size
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
return Duplex.from(generator());
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export { createAssetsStream };
|
|
121
|
+
//# sourceMappingURL=assets.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assets.mjs","sources":["../../../../src/strapi/providers/local-source/assets.ts"],"sourcesContent":["import { join } from 'path';\nimport { Duplex, PassThrough, Readable } from 'stream';\nimport { stat, createReadStream, ReadStream } from 'fs-extra';\nimport * as webStream from 'stream/web';\nimport type { Core } from '@strapi/types';\n\nimport type { IAsset, IFile } from '../../../../types';\n\nfunction getFileStream(\n filepath: string,\n strapi: Core.Strapi,\n isLocal = false\n): PassThrough | ReadStream {\n if (isLocal) {\n // Todo: handle errors\n return createReadStream(filepath);\n }\n\n const readableStream = new PassThrough();\n\n // fetch the image from remote url and stream it\n strapi\n .fetch(filepath)\n .then((res: Response) => {\n if (res.status !== 200) {\n readableStream.emit('error', new Error(`Request failed with status code ${res.status}`));\n return;\n }\n\n if (res.body) {\n // pipe the image data\n Readable.fromWeb(res.body as webStream.ReadableStream<Uint8Array>).pipe(readableStream);\n } else {\n readableStream.emit('error', new Error('Empty data found for file'));\n }\n })\n .catch((error: unknown) => {\n readableStream.emit('error', error);\n });\n\n return readableStream;\n}\n\nfunction getFileStats(\n filepath: string,\n strapi: Core.Strapi,\n isLocal = false\n): Promise<{ size: number }> {\n if (isLocal) {\n return stat(filepath);\n }\n return new Promise((resolve, reject) => {\n strapi\n .fetch(filepath)\n .then((res: Response) => {\n if (res.status !== 200) {\n reject(new Error(`Request failed with status code ${res.status}`));\n return;\n }\n\n const contentLength = res.headers.get('content-length');\n const stats = {\n size: contentLength ? parseInt(contentLength, 10) : 0,\n };\n\n resolve(stats);\n })\n .catch((error: unknown) => {\n reject(error);\n });\n });\n}\n\nasync function signFile(file: IFile) {\n const { provider } = strapi.plugins.upload;\n const { provider: providerName } = strapi.config.get('plugin.upload') as { provider: string };\n const isPrivate = await provider.isPrivate();\n if (file?.provider === providerName && isPrivate) {\n const signUrl = async (file: IFile) => {\n const signedUrl = await provider.getSignedUrl(file);\n file.url = signedUrl.url;\n };\n\n // Sign the original file\n await signUrl(file);\n // Sign each file format\n if (file.formats) {\n for (const format of Object.keys(file.formats)) {\n await signUrl(file.formats[format]);\n }\n }\n }\n}\n\n/**\n * Generate and consume assets streams in order to stream each file individually\n */\nexport const createAssetsStream = (strapi: Core.Strapi): Duplex => {\n const generator: () => AsyncGenerator<IAsset, void> = async function* () {\n const stream: Readable = strapi.db\n .queryBuilder('plugin::upload.file')\n // Create a query builder instance (default type is 'select')\n // Fetch all columns\n .select('*')\n // Get a readable stream\n .stream();\n\n for await (const file of stream) {\n const isLocalProvider = file.provider === 'local';\n if (!isLocalProvider) {\n await signFile(file);\n }\n const filepath = isLocalProvider ? join(strapi.dirs.static.public, file.url) : file.url;\n const stats = await getFileStats(filepath, strapi, isLocalProvider);\n const stream = getFileStream(filepath, strapi, isLocalProvider);\n\n yield {\n metadata: file,\n filepath,\n filename: file.hash + file.ext,\n stream,\n stats: { size: stats.size },\n };\n\n if (file.formats) {\n for (const format of Object.keys(file.formats)) {\n const fileFormat = file.formats[format];\n const fileFormatFilepath = isLocalProvider\n ? join(strapi.dirs.static.public, fileFormat.url)\n : fileFormat.url;\n const fileFormatStats = await getFileStats(fileFormatFilepath, strapi, isLocalProvider);\n const fileFormatStream = getFileStream(fileFormatFilepath, strapi, isLocalProvider);\n const metadata = { ...fileFormat, type: format, id: file.id, mainHash: file.hash };\n yield {\n metadata,\n filepath: fileFormatFilepath,\n filename: fileFormat.hash + fileFormat.ext,\n stream: fileFormatStream,\n stats: { size: fileFormatStats.size },\n };\n }\n }\n }\n };\n\n return Duplex.from(generator());\n};\n"],"names":["getFileStream","filepath","strapi","isLocal","createReadStream","readableStream","PassThrough","fetch","then","res","status","emit","Error","body","Readable","fromWeb","pipe","catch","error","getFileStats","stat","Promise","resolve","reject","contentLength","headers","get","stats","size","parseInt","signFile","file","provider","plugins","upload","providerName","config","isPrivate","signUrl","signedUrl","getSignedUrl","url","formats","format","Object","keys","createAssetsStream","generator","stream","db","queryBuilder","select","isLocalProvider","join","dirs","static","public","metadata","filename","hash","ext","fileFormat","fileFormatFilepath","fileFormatStats","fileFormatStream","type","id","mainHash","Duplex","from"],"mappings":";;;;AAQA,SAASA,cACPC,QAAgB,EAChBC,OAAmB,EACnBC,UAAU,KAAK,EAAA;AAEf,IAAA,IAAIA,OAAS,EAAA;;AAEX,QAAA,OAAOC,gBAAiBH,CAAAA,QAAAA,CAAAA;AAC1B;AAEA,IAAA,MAAMI,iBAAiB,IAAIC,WAAAA,EAAAA;;AAG3BJ,IAAAA,OAAAA,CACGK,KAAK,CAACN,QACNO,CAAAA,CAAAA,IAAI,CAAC,CAACC,GAAAA,GAAAA;QACL,IAAIA,GAAAA,CAAIC,MAAM,KAAK,GAAK,EAAA;YACtBL,cAAeM,CAAAA,IAAI,CAAC,OAAA,EAAS,IAAIC,KAAAA,CAAM,CAAC,gCAAgC,EAAEH,GAAAA,CAAIC,MAAM,CAAC,CAAC,CAAA,CAAA;AACtF,YAAA;AACF;QAEA,IAAID,GAAAA,CAAII,IAAI,EAAE;;A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AW,GAAA;AAAE,wBAAA,GAAGI,UAAU;wBAAEI,IAAMtB,EAAAA,MAAAA;AAAQuB,wBAAAA,EAAAA,EAAInC,KAAKmC,EAAE;AAAEC,wBAAAA,QAAAA,EAAUpC,KAAK4B;AAAK,qBAAA;oBACjF,MAAM;AACJF,wBAAAA,QAAAA;wBACAxD,QAAU6D,EAAAA,kBAAAA;AACVJ,wBAAAA,QAAAA,EAAUG,UAAWF,CAAAA,IAAI,GAAGE,UAAAA,CAAWD,GAAG;wBAC1CZ,MAAQgB,EAAAA,gBAAAA;wBACRrC,KAAO,EAAA;AAAEC,4BAAAA,IAAAA,EAAMmC,gBAAgBnC;AAAK;AACtC,qBAAA;AACF;AACF;AACF;AACF,KAAA;IAEA,OAAOwC,MAAAA,CAAOC,IAAI,CAACtB,SAAAA,EAAAA,CAAAA;AACrB;;;;"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var stream = require('stream');
|
|
4
|
+
var streamChain = require('stream-chain');
|
|
5
|
+
var fp = require('lodash/fp');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Create a readable stream that export the Strapi app configuration
|
|
9
|
+
*/ const createConfigurationStream = (strapi)=>{
|
|
10
|
+
return stream.Readable.from(async function* configurationGenerator() {
|
|
11
|
+
// Core Store
|
|
12
|
+
const coreStoreStream = streamChain.chain([
|
|
13
|
+
strapi.db.queryBuilder('strapi::core-store').stream(),
|
|
14
|
+
(data)=>fp.set('value', JSON.parse(data.value), data),
|
|
15
|
+
wrapConfigurationItem('core-store')
|
|
16
|
+
]);
|
|
17
|
+
// Webhook
|
|
18
|
+
const webhooksStream = streamChain.chain([
|
|
19
|
+
strapi.db.queryBuilder('strapi::webhook').stream(),
|
|
20
|
+
wrapConfigurationItem('webhook')
|
|
21
|
+
]);
|
|
22
|
+
const streams = [
|
|
23
|
+
coreStoreStream,
|
|
24
|
+
webhooksStream
|
|
25
|
+
];
|
|
26
|
+
for (const stream of streams){
|
|
27
|
+
for await (const item of stream){
|
|
28
|
+
yield item;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}());
|
|
32
|
+
};
|
|
33
|
+
const wrapConfigurationItem = (type)=>(value)=>({
|
|
34
|
+
type,
|
|
35
|
+
value
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
exports.createConfigurationStream = createConfigurationStream;
|
|
39
|
+
//# sourceMappingURL=configuration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configuration.js","sources":["../../../../src/strapi/providers/local-source/configuration.ts"],"sourcesContent":["import { Readable } from 'stream';\nimport { chain } from 'stream-chain';\nimport { set } from 'lodash/fp';\nimport type { Core } from '@strapi/types';\n\nimport type { IConfiguration } from '../../../../types';\n\n/**\n * Create a readable stream that export the Strapi app configuration\n */\nexport const createConfigurationStream = (strapi: Core.Strapi): Readable => {\n return Readable.from(\n (async function* configurationGenerator(): AsyncGenerator<IConfiguration> {\n // Core Store\n const coreStoreStream = chain([\n strapi.db.queryBuilder('strapi::core-store').stream(),\n (data) => set('value', JSON.parse(data.value), data),\n wrapConfigurationItem('core-store'),\n ]);\n\n // Webhook\n const webhooksStream = chain([\n strapi.db.queryBuilder('strapi::webhook').stream(),\n wrapConfigurationItem('webhook'),\n ]);\n\n const streams = [coreStoreStream, webhooksStream];\n\n for (const stream of streams) {\n for await (const item of stream) {\n yield item;\n }\n }\n })()\n );\n};\n\nconst wrapConfigurationItem = (type: 'core-store' | 'webhook') => (value: unknown) => ({\n type,\n value,\n});\n"],"names":["createConfigurationStream","strapi","Readable","from","configurationGenerator","coreStoreStream","chain","db","queryBuilder","stream","data","set","JSON","parse","value","wrapConfigurationItem","webhooksStream","streams","item","type"],"mappings":";;;;;;AAOA;;IAGaA,MAAAA,yBAAAA,GAA4B,CAACC,MAAAA,GAAAA;AACxC,IAAA,OAAOC,eAASC,CAAAA,IAAI,CACjB,gBAAgBC,sBAAAA,GAAAA;;AAEf,QAAA,MAAMC,kBAAkBC,iBAAM,CAAA;AAC5BL,YAAAA,MAAAA,CAAOM,EAAE,CAACC,YAAY,CAAC,sBAAsBC,MAAM,EAAA;YACnD,CAACC,IAAAA,GAASC,OAAI,OAASC,EAAAA,IAAAA,CAAKC,KAAK,CAACH,IAAAA,CAAKI,KAAK,CAAGJ,EAAAA,IAAAA,CAAAA;YAC/CK,qBAAsB,CAAA,YAAA;AACvB,SAAA,CAAA;;AAGD,QAAA,MAAMC,iBAAiBV,iBAAM,CAAA;AAC3BL,YAAAA,MAAAA,CAAOM,EAAE,CAACC,YAAY,CAAC,mBAAmBC,MAAM,EAAA;YAChDM,qBAAsB,CAAA,SAAA;AACvB,SAAA,CAAA;AAED,QAAA,MAAME,OAAU,GAAA;AAACZ,YAAAA,eAAAA;AAAiBW,YAAAA;AAAe,SAAA;QAEjD,KAAK,MAAMP,UAAUQ,OAAS,CAAA;YAC5B,WAAW,MAAMC,QAAQT,MAAQ,CAAA;gBAC/B,MAAMS,IAAAA;AACR;AACF;AACF,KAAA,EAAA,CAAA;AAEJ;AAEA,MAAMH,qBAAwB,GAAA,CAACI,IAAmC,GAAA,CAACL,SAAoB;AACrFK,YAAAA,IAAAA;AACAL,YAAAA;SACF,CAAA;;;;"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Readable } from 'stream';
|
|
2
|
+
import { chain } from 'stream-chain';
|
|
3
|
+
import { set } from 'lodash/fp';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Create a readable stream that export the Strapi app configuration
|
|
7
|
+
*/ const createConfigurationStream = (strapi)=>{
|
|
8
|
+
return Readable.from(async function* configurationGenerator() {
|
|
9
|
+
// Core Store
|
|
10
|
+
const coreStoreStream = chain([
|
|
11
|
+
strapi.db.queryBuilder('strapi::core-store').stream(),
|
|
12
|
+
(data)=>set('value', JSON.parse(data.value), data),
|
|
13
|
+
wrapConfigurationItem('core-store')
|
|
14
|
+
]);
|
|
15
|
+
// Webhook
|
|
16
|
+
const webhooksStream = chain([
|
|
17
|
+
strapi.db.queryBuilder('strapi::webhook').stream(),
|
|
18
|
+
wrapConfigurationItem('webhook')
|
|
19
|
+
]);
|
|
20
|
+
const streams = [
|
|
21
|
+
coreStoreStream,
|
|
22
|
+
webhooksStream
|
|
23
|
+
];
|
|
24
|
+
for (const stream of streams){
|
|
25
|
+
for await (const item of stream){
|
|
26
|
+
yield item;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}());
|
|
30
|
+
};
|
|
31
|
+
const wrapConfigurationItem = (type)=>(value)=>({
|
|
32
|
+
type,
|
|
33
|
+
value
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
export { createConfigurationStream };
|
|
37
|
+
//# sourceMappingURL=configuration.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configuration.mjs","sources":["../../../../src/strapi/providers/local-source/configuration.ts"],"sourcesContent":["import { Readable } from 'stream';\nimport { chain } from 'stream-chain';\nimport { set } from 'lodash/fp';\nimport type { Core } from '@strapi/types';\n\nimport type { IConfiguration } from '../../../../types';\n\n/**\n * Create a readable stream that export the Strapi app configuration\n */\nexport const createConfigurationStream = (strapi: Core.Strapi): Readable => {\n return Readable.from(\n (async function* configurationGenerator(): AsyncGenerator<IConfiguration> {\n // Core Store\n const coreStoreStream = chain([\n strapi.db.queryBuilder('strapi::core-store').stream(),\n (data) => set('value', JSON.parse(data.value), data),\n wrapConfigurationItem('core-store'),\n ]);\n\n // Webhook\n const webhooksStream = chain([\n strapi.db.queryBuilder('strapi::webhook').stream(),\n wrapConfigurationItem('webhook'),\n ]);\n\n const streams = [coreStoreStream, webhooksStream];\n\n for (const stream of streams) {\n for await (const item of stream) {\n yield item;\n }\n }\n })()\n );\n};\n\nconst wrapConfigurationItem = (type: 'core-store' | 'webhook') => (value: unknown) => ({\n type,\n value,\n});\n"],"names":["createConfigurationStream","strapi","Readable","from","configurationGenerator","coreStoreStream","chain","db","queryBuilder","stream","data","set","JSON","parse","value","wrapConfigurationItem","webhooksStream","streams","item","type"],"mappings":";;;;AAOA;;IAGaA,MAAAA,yBAAAA,GAA4B,CAACC,MAAAA,GAAAA;AACxC,IAAA,OAAOC,QAASC,CAAAA,IAAI,CACjB,gBAAgBC,sBAAAA,GAAAA;;AAEf,QAAA,MAAMC,kBAAkBC,KAAM,CAAA;AAC5BL,YAAAA,MAAAA,CAAOM,EAAE,CAACC,YAAY,CAAC,sBAAsBC,MAAM,EAAA;YACnD,CAACC,IAAAA,GAASC,IAAI,OAASC,EAAAA,IAAAA,CAAKC,KAAK,CAACH,IAAAA,CAAKI,KAAK,CAAGJ,EAAAA,IAAAA,CAAAA;YAC/CK,qBAAsB,CAAA,YAAA;AACvB,SAAA,CAAA;;AAGD,QAAA,MAAMC,iBAAiBV,KAAM,CAAA;AAC3BL,YAAAA,MAAAA,CAAOM,EAAE,CAACC,YAAY,CAAC,mBAAmBC,MAAM,EAAA;YAChDM,qBAAsB,CAAA,SAAA;AACvB,SAAA,CAAA;AAED,QAAA,MAAME,OAAU,GAAA;AAACZ,YAAAA,eAAAA;AAAiBW,YAAAA;AAAe,SAAA;QAEjD,KAAK,MAAMP,UAAUQ,OAAS,CAAA;YAC5B,WAAW,MAAMC,QAAQT,MAAQ,CAAA;gBAC/B,MAAMS,IAAAA;AACR;AACF;AACF,KAAA,EAAA,CAAA;AAEJ;AAEA,MAAMH,qBAAwB,GAAA,CAACI,IAAmC,GAAA,CAACL,SAAoB;AACrFK,YAAAA,IAAAA;AACAL,YAAAA;SACF,CAAA;;;;"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var stream = require('stream');
|
|
4
|
+
var entity = require('../../queries/entity.js');
|
|
5
|
+
require('lodash/fp');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Generate and consume content-types streams in order to stream each entity individually
|
|
9
|
+
*/ const createEntitiesStream = (strapi)=>{
|
|
10
|
+
const contentTypes = Object.values(strapi.contentTypes);
|
|
11
|
+
async function* contentTypeStreamGenerator() {
|
|
12
|
+
for (const contentType of contentTypes){
|
|
13
|
+
const query = entity.createEntityQuery(strapi).call(null, contentType.uid);
|
|
14
|
+
const stream = strapi.db// Create a query builder instance (default type is 'select')
|
|
15
|
+
.queryBuilder(contentType.uid)// Fetch all columns
|
|
16
|
+
.select('*')// Apply the populate
|
|
17
|
+
.populate(query.deepPopulateComponentLikeQuery)// Get a readable stream
|
|
18
|
+
.stream();
|
|
19
|
+
yield {
|
|
20
|
+
contentType,
|
|
21
|
+
stream
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return stream.Readable.from(async function* entitiesGenerator() {
|
|
26
|
+
for await (const { stream, contentType } of contentTypeStreamGenerator()){
|
|
27
|
+
try {
|
|
28
|
+
for await (const entity of stream){
|
|
29
|
+
yield {
|
|
30
|
+
entity,
|
|
31
|
+
contentType
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
} catch {
|
|
35
|
+
// ignore
|
|
36
|
+
} finally{
|
|
37
|
+
stream.destroy();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}());
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Create an entity transform stream which convert the output of
|
|
44
|
+
* the multi-content-types stream to the transfer entity format
|
|
45
|
+
*/ const createEntitiesTransformStream = ()=>{
|
|
46
|
+
return new stream.Transform({
|
|
47
|
+
objectMode: true,
|
|
48
|
+
transform (data, _encoding, callback) {
|
|
49
|
+
const { entity, contentType } = data;
|
|
50
|
+
const { id, ...attributes } = entity;
|
|
51
|
+
callback(null, {
|
|
52
|
+
type: contentType.uid,
|
|
53
|
+
id,
|
|
54
|
+
data: attributes
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
exports.createEntitiesStream = createEntitiesStream;
|
|
61
|
+
exports.createEntitiesTransformStream = createEntitiesTransformStream;
|
|
62
|
+
//# sourceMappingURL=entities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entities.js","sources":["../../../../src/strapi/providers/local-source/entities.ts"],"sourcesContent":["import { Readable, Transform } from 'stream';\nimport type { Core, Struct } from '@strapi/types';\n\nimport * as shared from '../../queries';\nimport { IEntity } from '../../../../types';\n\n/**\n * Generate and consume content-types streams in order to stream each entity individually\n */\nexport const createEntitiesStream = (strapi: Core.Strapi): Readable => {\n const contentTypes: Struct.ContentTypeSchema[] = Object.values(strapi.contentTypes);\n\n async function* contentTypeStreamGenerator() {\n for (const contentType of contentTypes) {\n const query = shared.entity.createEntityQuery(strapi).call(null, contentType.uid);\n\n const stream: Readable = strapi.db\n // Create a query builder instance (default type is 'select')\n .queryBuilder(contentType.uid)\n // Fetch all columns\n .select('*')\n // Apply the populate\n .populate(query.deepPopulateComponentLikeQuery)\n // Get a readable stream\n .stream();\n\n yield { contentType, stream };\n }\n }\n\n return Readable.from(\n (async function* entitiesGenerator(): AsyncGenerator<{\n entity: IEntity;\n contentType: Struct.ContentTypeSchema;\n }> {\n for await (const { stream, contentType } of contentTypeStreamGenerator()) {\n try {\n for await (const entity of stream) {\n yield { entity, contentType };\n }\n } catch {\n // ignore\n } finally {\n stream.destroy();\n }\n }\n })()\n );\n};\n\n/**\n * Create an entity transform stream which convert the output of\n * the multi-content-types stream to the transfer entity format\n */\nexport const createEntitiesTransformStream = (): Transform => {\n return new Transform({\n objectMode: true,\n transform(data, _encoding, callback) {\n const { entity, contentType } = data;\n const { id, ...attributes } = entity;\n\n callback(null, {\n type: contentType.uid,\n id,\n data: attributes,\n });\n },\n });\n};\n"],"names":["createEntitiesStream","strapi","contentTypes","Object","values","contentTypeStreamGenerator","contentType","query","shared","call","uid","stream","db","queryBuilder","select","populate","deepPopulateComponentLikeQuery","Readable","from","entitiesGenerator","entity","destroy","createEntitiesTransformStream","Transform","objectMode","transform","data","_encoding","callback","id","attributes","type"],"mappings":";;;;;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B,IAAAA;AAChC,YAAA,MAAM,EAAEG,EAAE,EAAE,GAAGC,YAAY,GAAGV,MAAAA;AAE9BQ,YAAAA,QAAAA,CAAS,IAAM,EAAA;AACbG,gBAAAA,IAAAA,EAAMzB,YAAYI,GAAG;AACrBmB,gBAAAA,EAAAA;gBACAH,IAAMI,EAAAA;AACR,aAAA,CAAA;AACF;AACF,KAAA,CAAA;AACF;;;;;"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Readable, Transform } from 'stream';
|
|
2
|
+
import { createEntityQuery } from '../../queries/entity.mjs';
|
|
3
|
+
import 'lodash/fp';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Generate and consume content-types streams in order to stream each entity individually
|
|
7
|
+
*/ const createEntitiesStream = (strapi)=>{
|
|
8
|
+
const contentTypes = Object.values(strapi.contentTypes);
|
|
9
|
+
async function* contentTypeStreamGenerator() {
|
|
10
|
+
for (const contentType of contentTypes){
|
|
11
|
+
const query = createEntityQuery(strapi).call(null, contentType.uid);
|
|
12
|
+
const stream = strapi.db// Create a query builder instance (default type is 'select')
|
|
13
|
+
.queryBuilder(contentType.uid)// Fetch all columns
|
|
14
|
+
.select('*')// Apply the populate
|
|
15
|
+
.populate(query.deepPopulateComponentLikeQuery)// Get a readable stream
|
|
16
|
+
.stream();
|
|
17
|
+
yield {
|
|
18
|
+
contentType,
|
|
19
|
+
stream
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return Readable.from(async function* entitiesGenerator() {
|
|
24
|
+
for await (const { stream, contentType } of contentTypeStreamGenerator()){
|
|
25
|
+
try {
|
|
26
|
+
for await (const entity of stream){
|
|
27
|
+
yield {
|
|
28
|
+
entity,
|
|
29
|
+
contentType
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
} catch {
|
|
33
|
+
// ignore
|
|
34
|
+
} finally{
|
|
35
|
+
stream.destroy();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}());
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Create an entity transform stream which convert the output of
|
|
42
|
+
* the multi-content-types stream to the transfer entity format
|
|
43
|
+
*/ const createEntitiesTransformStream = ()=>{
|
|
44
|
+
return new Transform({
|
|
45
|
+
objectMode: true,
|
|
46
|
+
transform (data, _encoding, callback) {
|
|
47
|
+
const { entity, contentType } = data;
|
|
48
|
+
const { id, ...attributes } = entity;
|
|
49
|
+
callback(null, {
|
|
50
|
+
type: contentType.uid,
|
|
51
|
+
id,
|
|
52
|
+
data: attributes
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export { createEntitiesStream, createEntitiesTransformStream };
|
|
59
|
+
//# sourceMappingURL=entities.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entities.mjs","sources":["../../../../src/strapi/providers/local-source/entities.ts"],"sourcesContent":["import { Readable, Transform } from 'stream';\nimport type { Core, Struct } from '@strapi/types';\n\nimport * as shared from '../../queries';\nimport { IEntity } from '../../../../types';\n\n/**\n * Generate and consume content-types streams in order to stream each entity individually\n */\nexport const createEntitiesStream = (strapi: Core.Strapi): Readable => {\n const contentTypes: Struct.ContentTypeSchema[] = Object.values(strapi.contentTypes);\n\n async function* contentTypeStreamGenerator() {\n for (const contentType of contentTypes) {\n const query = shared.entity.createEntityQuery(strapi).call(null, contentType.uid);\n\n const stream: Readable = strapi.db\n // Create a query builder instance (default type is 'select')\n .queryBuilder(contentType.uid)\n // Fetch all columns\n .select('*')\n // Apply the populate\n .populate(query.deepPopulateComponentLikeQuery)\n // Get a readable stream\n .stream();\n\n yield { contentType, stream };\n }\n }\n\n return Readable.from(\n (async function* entitiesGenerator(): AsyncGenerator<{\n entity: IEntity;\n contentType: Struct.ContentTypeSchema;\n }> {\n for await (const { stream, contentType } of contentTypeStreamGenerator()) {\n try {\n for await (const entity of stream) {\n yield { entity, contentType };\n }\n } catch {\n // ignore\n } finally {\n stream.destroy();\n }\n }\n })()\n );\n};\n\n/**\n * Create an entity transform stream which convert the output of\n * the multi-content-types stream to the transfer entity format\n */\nexport const createEntitiesTransformStream = (): Transform => {\n return new Transform({\n objectMode: true,\n transform(data, _encoding, callback) {\n const { entity, contentType } = data;\n const { id, ...attributes } = entity;\n\n callback(null, {\n type: contentType.uid,\n id,\n data: attributes,\n });\n },\n });\n};\n"],"names":["createEntitiesStream","strapi","contentTypes","Object","values","contentTypeStreamGenerator","contentType","query","shared","call","uid","stream","db","queryBuilder","select","populate","deepPopulateComponentLikeQuery","Readable","from","entitiesGenerator","entity","destroy","createEntitiesTransformStream","Transform","objectMode","transform","data","_encoding","callback","id","attributes","type"],"mappings":";;;;AAMA;;IAGaA,MAAAA,oBAAAA,GAAuB,CAACC,MAAAA,GAAAA;AACnC,IAAA,MAAMC,YAA2CC,GAAAA,MAAAA,CAAOC,MAAM,CAACH,OAAOC,YAAY,CAAA;IAElF,gBAAgBG,0BAAAA,GAAAA;QACd,KAAK,MAAMC,eAAeJ,YAAc,CAAA;YACtC,MAAMK,KAAAA,GAAQC,iBAA+B,CAACP,MAAAA,CAAAA,CAAQQ,IAAI,CAAC,IAAMH,EAAAA,WAAAA,CAAYI,GAAG,CAAA;AAEhF,YAAA,MAAMC,MAAmBV,GAAAA,MAAAA,CAAOW,EAC9B;AACCC,aAAAA,YAAY,CAACP,WAAAA,CAAYI,GAAG,CAC7B;aACCI,MAAM,CAAC,IACR;AACCC,aAAAA,QAAQ,CAACR,KAAAA,CAAMS,8BAA8B,CAC9C;aACCL,MAAM,EAAA;YAET,MAAM;AAAEL,gBAAAA,WAAAA;AAAaK,gBAAAA;AAAO,aAAA;AAC9B;AACF;AAEA,IAAA,OAAOM,QAASC,CAAAA,IAAI,CACjB,gBAAgBC,iBAAAA,GAAAA;AAIf,QAAA,WAAW,MAAM,EAAER,MAAM,EAAEL,WAAW,EAAE,IAAID,0BAA8B,EAAA,CAAA;YACxE,IAAI;gB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