@sanity/export 3.26.1 → 3.26.2-canary.47

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 (2) hide show
  1. package/package.json +3 -2
  2. package/src/tryParseJson.js +12 -20
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/export",
3
- "version": "3.26.1",
3
+ "version": "3.26.2-canary.47+dc645319c7",
4
4
  "description": "Export Sanity documents and assets",
5
5
  "keywords": [
6
6
  "sanity",
@@ -31,6 +31,7 @@
31
31
  "test": "jest"
32
32
  },
33
33
  "dependencies": {
34
+ "@sanity/util": "3.26.2-canary.47+dc645319c7",
34
35
  "archiver": "^5.0.0",
35
36
  "debug": "^3.2.7",
36
37
  "get-it": "^8.4.4",
@@ -49,5 +50,5 @@
49
50
  "publishConfig": {
50
51
  "access": "public"
51
52
  },
52
- "gitHead": "8a943ce177f298f8747b79afc48bacb99ea28e4b"
53
+ "gitHead": "dc645319c7d109039871bc4b3385a0df47a10d55"
53
54
  }
@@ -1,21 +1,13 @@
1
- module.exports = (line) => {
2
- try {
3
- return JSON.parse(line)
4
- } catch (err) {
5
- // Catch half-done lines with an error at the end
6
- const errorPosition = line.lastIndexOf('{"error":')
7
- if (errorPosition === -1) {
8
- err.message = `${err.message} (${line})`
9
- throw err
10
- }
1
+ const {createSafeJsonParser} = require('@sanity/util/createSafeJsonParser')
11
2
 
12
- const errorJson = line.slice(errorPosition)
13
- const errorLine = JSON.parse(errorJson)
14
- const error = errorLine && errorLine.error
15
- if (error && error.description) {
16
- throw new Error(`Error streaming dataset: ${error.description}\n\n${errorJson}\n`)
17
- }
18
-
19
- throw err
20
- }
21
- }
3
+ /**
4
+ * Safe JSON parser that is able to handle lines interrupted by an error object.
5
+ *
6
+ * This may occur when streaming NDJSON from the Export HTTP API.
7
+ *
8
+ * @internal
9
+ * @see {@link https://github.com/sanity-io/sanity/pull/1787 | Initial pull request}
10
+ */
11
+ module.exports = createSafeJsonParser({
12
+ errorLabel: 'Error streaming dataset',
13
+ })