@sanity/export 2.21.10-shopify.5 → 2.21.12-purple-unicorn.1302

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.
@@ -5,16 +5,16 @@ module.exports = line => {
5
5
  return JSON.parse(line);
6
6
  } catch (err) {
7
7
  // Catch half-done lines with an error at the end
8
- var errorPosition = line.lastIndexOf('{"error":');
8
+ const errorPosition = line.lastIndexOf('{"error":');
9
9
 
10
10
  if (errorPosition === -1) {
11
11
  err.message = "".concat(err.message, " (").concat(line, ")");
12
12
  throw err;
13
13
  }
14
14
 
15
- var errorJson = line.slice(errorPosition);
16
- var errorLine = JSON.parse(errorJson);
17
- var error = errorLine && errorLine.error;
15
+ const errorJson = line.slice(errorPosition);
16
+ const errorLine = JSON.parse(errorJson);
17
+ const error = errorLine && errorLine.error;
18
18
 
19
19
  if (error && error.description) {
20
20
  throw new Error("Error streaming dataset: ".concat(error.description, "\n\n").concat(errorJson, "\n"));
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
 
3
- var defaults = require('lodash/defaults');
3
+ const defaults = require('lodash/defaults');
4
4
 
5
- var clientMethods = ['getUrl', 'config'];
6
- var booleanFlags = ['assets', 'raw', 'compress', 'drafts'];
7
- var exportDefaults = {
5
+ const clientMethods = ['getUrl', 'config'];
6
+ const booleanFlags = ['assets', 'raw', 'compress', 'drafts'];
7
+ const exportDefaults = {
8
8
  compress: true,
9
9
  drafts: true,
10
10
  assets: true,
@@ -12,7 +12,7 @@ var exportDefaults = {
12
12
  };
13
13
 
14
14
  function validateOptions(opts) {
15
- var options = defaults({}, opts, exportDefaults);
15
+ const options = defaults({}, opts, exportDefaults);
16
16
 
17
17
  if (typeof options.dataset !== 'string' || options.dataset.length < 1) {
18
18
  throw new Error("options.dataset must be a valid dataset name");
@@ -26,13 +26,13 @@ function validateOptions(opts) {
26
26
  throw new Error('`options.client` must be set to an instance of @sanity/client');
27
27
  }
28
28
 
29
- var missing = clientMethods.find(key => typeof options.client[key] !== 'function');
29
+ const missing = clientMethods.find(key => typeof options.client[key] !== 'function');
30
30
 
31
31
  if (missing) {
32
32
  throw new Error("`options.client` is not a valid @sanity/client instance - no \"".concat(missing, "\" method found"));
33
33
  }
34
34
 
35
- var clientConfig = options.client.config();
35
+ const clientConfig = options.client.config();
36
36
 
37
37
  if (!clientConfig.token) {
38
38
  throw new Error('Client is not instantiated with a `token`');
package/package.json CHANGED
@@ -1,18 +1,20 @@
1
1
  {
2
2
  "name": "@sanity/export",
3
- "version": "2.21.10-shopify.5+8e1b6afb9",
3
+ "version": "2.21.12-purple-unicorn.1302+847175b7f3",
4
4
  "description": "Export Sanity documents and assets",
5
- "main": "lib/export.js",
5
+ "main": "./lib/export.js",
6
+ "types": "./lib/dts/src/export.d.ts",
6
7
  "engines": {
7
8
  "node": ">=12.0.0"
8
9
  },
9
10
  "author": "Sanity.io <hello@sanity.io>",
10
11
  "license": "MIT",
11
12
  "scripts": {
12
- "build": "babel src --copy-files --out-dir lib",
13
- "clean": "rimraf lib dest",
14
- "prebuild": "npm run clean",
15
- "test": "jest"
13
+ "build": "../../../bin/pkg-utils transpile --target node",
14
+ "clean": "rimraf lib",
15
+ "prebuild": "yarn clean",
16
+ "test": "jest",
17
+ "watch": "../../../bin/pkg-utils transpile --target node --watch"
16
18
  },
17
19
  "keywords": [
18
20
  "sanity",
@@ -24,18 +26,17 @@
24
26
  "ndjson"
25
27
  ],
26
28
  "dependencies": {
27
- "agentkeepalive": "^4.1.0",
28
29
  "archiver": "^5.0.0",
29
30
  "debug": "^3.2.7",
30
31
  "fs-extra": "^7.0.0",
31
- "lodash": "^4.17.15",
32
+ "get-it": "^5.2.1",
33
+ "lodash": "^4.17.21",
32
34
  "mississippi": "^4.0.0",
33
35
  "p-queue": "^2.3.0",
34
- "simple-get": "^4.0.0",
35
36
  "split2": "^3.2.2"
36
37
  },
37
38
  "devDependencies": {
38
- "rimraf": "^2.7.1",
39
+ "rimraf": "^3.0.2",
39
40
  "string-to-stream": "^1.1.0"
40
41
  },
41
42
  "publishConfig": {
@@ -50,5 +51,5 @@
50
51
  "url": "https://github.com/sanity-io/sanity/issues"
51
52
  },
52
53
  "homepage": "https://www.sanity.io/",
53
- "gitHead": "8e1b6afb9ba5a3c78662e354cea66523ac456c6b"
54
+ "gitHead": "847175b7f3ddc82e4a956ab4e0dbb74a4dff41b8"
54
55
  }
package/src/export.js CHANGED
@@ -48,8 +48,14 @@ function exportDataset(opts) {
48
48
 
49
49
  debug('Outputting assets (temporarily) to %s', tmpDir)
50
50
  debug('Outputting to %s', options.outputPath === '-' ? 'stdout' : options.outputPath)
51
- const outputStream =
52
- options.outputPath === '-' ? process.stdout : fse.createWriteStream(options.outputPath)
51
+
52
+ let outputStream
53
+ if (isWritableStream(options.outputPath)) {
54
+ outputStream = options.outputPath
55
+ } else {
56
+ outputStream =
57
+ options.outputPath === '-' ? process.stdout : fse.createWriteStream(options.outputPath)
58
+ }
53
59
 
54
60
  let assetStreamHandler = assetHandler.noop
55
61
  if (!options.raw) {
@@ -195,4 +201,14 @@ function exportDataset(opts) {
195
201
  })
196
202
  }
197
203
 
204
+ function isWritableStream(val) {
205
+ return (
206
+ val !== null &&
207
+ typeof val === 'object' &&
208
+ typeof val.pipe === 'function' &&
209
+ typeof val._write === 'function' &&
210
+ typeof val._writableState === 'object'
211
+ )
212
+ }
213
+
198
214
  module.exports = exportDataset
@@ -1,53 +1,29 @@
1
- const simpleGet = require('simple-get')
2
- const HttpAgent = require('agentkeepalive')
1
+ const getIt = require('get-it')
2
+ const {keepAlive, promise} = require('get-it/middleware')
3
3
  const debug = require('./debug')
4
4
 
5
- const HttpsAgent = HttpAgent.HttpsAgent
6
- const httpAgent = new HttpAgent()
7
- const httpsAgent = new HttpsAgent()
5
+ const request = getIt([keepAlive(), promise({onlyBody: true})])
8
6
  const socketsWithTimeout = new WeakSet()
9
7
 
10
8
  const CONNECTION_TIMEOUT = 15 * 1000 // 15 seconds
11
9
  const READ_TIMEOUT = 3 * 60 * 1000 // 3 minutes
12
10
  const MAX_RETRIES = 5
13
11
 
14
- // Just a promisified simpleGet
15
- function getStream(options) {
16
- return new Promise((resolve, reject) => {
17
- let rejected = false
18
- const openTimeout = setTimeout(() => {
19
- rejected = true
20
- reject(new Error(`Connection timed out after ${CONNECTION_TIMEOUT} ms`))
21
- }, CONNECTION_TIMEOUT)
22
-
23
- simpleGet(options, (err, res) => {
24
- clearTimeout(openTimeout)
25
- if (rejected) {
26
- return
27
- }
28
-
29
- if (err) {
30
- reject(err)
31
- return
32
- }
33
-
34
- resolve(res)
35
- })
36
- })
37
- }
38
-
39
12
  function delay(ms) {
40
13
  return new Promise((resolve) => setTimeout(resolve, ms))
41
14
  }
42
15
 
43
16
  /* eslint-disable no-await-in-loop, max-depth */
44
17
  module.exports = async (options) => {
45
- const agent = options.url.startsWith('https:') ? httpsAgent : httpAgent
46
- const reqOptions = {...options, followRedirects: false, agent}
47
18
  let error
48
19
  for (let i = 0; i < MAX_RETRIES; i++) {
49
20
  try {
50
- const response = await getStream(reqOptions)
21
+ const response = await request({
22
+ ...options,
23
+ stream: true,
24
+ maxRedirects: 0,
25
+ timeout: {connect: CONNECTION_TIMEOUT, socket: READ_TIMEOUT},
26
+ })
51
27
 
52
28
  if (
53
29
  response.connection &&
@@ -66,7 +42,7 @@ module.exports = async (options) => {
66
42
  } catch (err) {
67
43
  error = err
68
44
 
69
- if (err.statusCode && err.statusCode < 500) {
45
+ if (err.response && err.response.statusCode && err.response.statusCode < 500) {
70
46
  break
71
47
  }
72
48