@sanity/export 3.41.1 → 3.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.
- package/package.json +3 -2
- package/src/AssetHandler.js +17 -0
- package/src/export.js +12 -5
- package/src/util/pipeAsync.js +17 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/export",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.42.0",
|
|
4
4
|
"description": "Export Sanity documents and assets",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -41,7 +41,8 @@
|
|
|
41
41
|
"rimraf": "^6.0.1",
|
|
42
42
|
"split2": "^4.2.0",
|
|
43
43
|
"tar": "^7.0.1",
|
|
44
|
-
"yaml": "^2.4.2"
|
|
44
|
+
"yaml": "^2.4.2",
|
|
45
|
+
"json-stream-stringify": "^2.0.2"
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|
|
47
48
|
"@jest/globals": "^29.7.0",
|
package/src/AssetHandler.js
CHANGED
|
@@ -112,6 +112,20 @@ class AssetHandler {
|
|
|
112
112
|
try {
|
|
113
113
|
return await this.downloadAsset(assetDoc, dstPath)
|
|
114
114
|
} catch (err) {
|
|
115
|
+
// Ignore inaccessible assets
|
|
116
|
+
switch (err.statusCode) {
|
|
117
|
+
case 401:
|
|
118
|
+
case 403:
|
|
119
|
+
case 404:
|
|
120
|
+
console.warn(
|
|
121
|
+
`⚠ Asset failed with HTTP %d (ignoring): %s`,
|
|
122
|
+
err.statusCode,
|
|
123
|
+
assetDoc._id,
|
|
124
|
+
)
|
|
125
|
+
return true
|
|
126
|
+
default:
|
|
127
|
+
}
|
|
128
|
+
|
|
115
129
|
debug(
|
|
116
130
|
`Error downloading asset %s (destination: %s), attempt %d`,
|
|
117
131
|
assetDoc._id,
|
|
@@ -179,6 +193,9 @@ class AssetHandler {
|
|
|
179
193
|
// eslint-disable-next-line max-statements
|
|
180
194
|
async downloadAsset(assetDoc, dstPath) {
|
|
181
195
|
const {url} = assetDoc
|
|
196
|
+
|
|
197
|
+
debug('Downloading asset %s', url)
|
|
198
|
+
|
|
182
199
|
const options = this.getAssetRequestOptions(assetDoc)
|
|
183
200
|
|
|
184
201
|
let stream
|
package/src/export.js
CHANGED
|
@@ -5,8 +5,10 @@ const zlib = require('zlib')
|
|
|
5
5
|
const archiver = require('archiver')
|
|
6
6
|
const miss = require('mississippi')
|
|
7
7
|
const split = require('split2')
|
|
8
|
+
const JsonStreamStringify = require('json-stream-stringify')
|
|
8
9
|
const AssetHandler = require('./AssetHandler')
|
|
9
10
|
const debug = require('./debug')
|
|
11
|
+
const pipeAsync = require('./util/pipeAsync')
|
|
10
12
|
const filterDocumentTypes = require('./filterDocumentTypes')
|
|
11
13
|
const filterDrafts = require('./filterDrafts')
|
|
12
14
|
const filterSystemDocuments = require('./filterSystemDocuments')
|
|
@@ -33,6 +35,12 @@ async function exportDataset(opts) {
|
|
|
33
35
|
: zlib.constants.Z_NO_COMPRESSION,
|
|
34
36
|
},
|
|
35
37
|
})
|
|
38
|
+
archive.on('warning', (err) => {
|
|
39
|
+
debug('Archive warning: %s', err.message)
|
|
40
|
+
})
|
|
41
|
+
archive.on('entry', (entry) => {
|
|
42
|
+
debug('Adding archive entry: %s', entry.name)
|
|
43
|
+
})
|
|
36
44
|
|
|
37
45
|
const slugDate = new Date()
|
|
38
46
|
.toISOString()
|
|
@@ -43,6 +51,7 @@ async function exportDataset(opts) {
|
|
|
43
51
|
const tmpDir = path.join(os.tmpdir(), prefix)
|
|
44
52
|
fs.mkdirSync(tmpDir, {recursive: true})
|
|
45
53
|
const dataPath = path.join(tmpDir, 'data.ndjson')
|
|
54
|
+
const assetsPath = path.join(tmpDir, 'assets.json')
|
|
46
55
|
|
|
47
56
|
const cleanup = () =>
|
|
48
57
|
rimraf(tmpDir).catch((err) => {
|
|
@@ -209,7 +218,9 @@ async function exportDataset(opts) {
|
|
|
209
218
|
update: true,
|
|
210
219
|
})
|
|
211
220
|
|
|
212
|
-
|
|
221
|
+
const assetsStream = fs.createWriteStream(assetsPath)
|
|
222
|
+
await pipeAsync(new JsonStreamStringify(assetMap), assetsStream)
|
|
223
|
+
archive.file(assetsPath, {name: 'assets.json', prefix})
|
|
213
224
|
clearInterval(progressInterval)
|
|
214
225
|
} catch (assetErr) {
|
|
215
226
|
clearInterval(progressInterval)
|
|
@@ -227,10 +238,6 @@ async function exportDataset(opts) {
|
|
|
227
238
|
await archive.finalize()
|
|
228
239
|
})
|
|
229
240
|
|
|
230
|
-
archive.on('warning', (err) => {
|
|
231
|
-
debug('Archive warning: %s', err.message)
|
|
232
|
-
})
|
|
233
|
-
|
|
234
241
|
miss.pipe(archive, outputStream, onComplete)
|
|
235
242
|
|
|
236
243
|
async function onComplete(err) {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const miss = require('mississippi')
|
|
2
|
+
|
|
3
|
+
module.exports = async (readable, writable) => {
|
|
4
|
+
return new Promise((resolve, reject) => {
|
|
5
|
+
try {
|
|
6
|
+
miss.pipe(readable, writable, (jsonErr) => {
|
|
7
|
+
if (jsonErr) {
|
|
8
|
+
reject(jsonErr)
|
|
9
|
+
} else {
|
|
10
|
+
resolve()
|
|
11
|
+
}
|
|
12
|
+
})
|
|
13
|
+
} catch (assetErr) {
|
|
14
|
+
reject(assetErr)
|
|
15
|
+
}
|
|
16
|
+
})
|
|
17
|
+
}
|