@sanity/export 5.0.0 → 6.0.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/dist/AssetHandler.d.ts +47 -0
- package/dist/AssetHandler.d.ts.map +1 -0
- package/dist/AssetHandler.js +384 -0
- package/dist/AssetHandler.js.map +1 -0
- package/dist/constants.d.ts +45 -0
- package/dist/constants.d.ts.map +1 -0
- package/{src → dist}/constants.js +13 -18
- package/dist/constants.js.map +1 -0
- package/dist/debug.d.ts +3 -0
- package/dist/debug.d.ts.map +1 -0
- package/dist/debug.js +3 -0
- package/dist/debug.js.map +1 -0
- package/dist/export.d.ts +43 -0
- package/dist/export.d.ts.map +1 -0
- package/dist/export.js +269 -0
- package/dist/export.js.map +1 -0
- package/dist/filterDocumentTypes.d.ts +3 -0
- package/dist/filterDocumentTypes.d.ts.map +1 -0
- package/dist/filterDocumentTypes.js +16 -0
- package/dist/filterDocumentTypes.js.map +1 -0
- package/dist/filterDocuments.d.ts +3 -0
- package/dist/filterDocuments.d.ts.map +1 -0
- package/dist/filterDocuments.js +36 -0
- package/dist/filterDocuments.js.map +1 -0
- package/dist/getDocumentCursorStream.d.ts +4 -0
- package/dist/getDocumentCursorStream.d.ts.map +1 -0
- package/dist/getDocumentCursorStream.js +85 -0
- package/dist/getDocumentCursorStream.js.map +1 -0
- package/dist/getDocumentsStream.d.ts +5 -0
- package/dist/getDocumentsStream.d.ts.map +1 -0
- package/dist/getDocumentsStream.js +28 -0
- package/dist/getDocumentsStream.js.map +1 -0
- package/dist/getUserAgent.d.ts +2 -0
- package/dist/getUserAgent.d.ts.map +1 -0
- package/dist/getUserAgent.js +12 -0
- package/dist/getUserAgent.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/logFirstChunk.d.ts +3 -0
- package/dist/logFirstChunk.d.ts.map +1 -0
- package/dist/logFirstChunk.js +14 -0
- package/dist/logFirstChunk.js.map +1 -0
- package/dist/options.d.ts +14 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/options.js +97 -0
- package/dist/options.js.map +1 -0
- package/dist/rejectOnApiError.d.ts +3 -0
- package/dist/rejectOnApiError.d.ts.map +1 -0
- package/dist/rejectOnApiError.js +35 -0
- package/dist/rejectOnApiError.js.map +1 -0
- package/dist/requestStream.d.ts +3 -0
- package/dist/requestStream.d.ts.map +1 -0
- package/dist/requestStream.js +48 -0
- package/dist/requestStream.js.map +1 -0
- package/dist/stringifyStream.d.ts +3 -0
- package/dist/stringifyStream.d.ts.map +1 -0
- package/dist/stringifyStream.js +5 -0
- package/dist/stringifyStream.js.map +1 -0
- package/dist/tryParseJson.d.ts +10 -0
- package/dist/tryParseJson.d.ts.map +1 -0
- package/dist/tryParseJson.js +36 -0
- package/dist/tryParseJson.js.map +1 -0
- package/dist/types.d.ts +241 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/util/delay.d.ts +2 -0
- package/dist/util/delay.d.ts.map +1 -0
- package/dist/util/delay.js +4 -0
- package/dist/util/delay.js.map +1 -0
- package/dist/util/extractFirstError.d.ts +2 -0
- package/dist/util/extractFirstError.d.ts.map +1 -0
- package/dist/util/extractFirstError.js +22 -0
- package/dist/util/extractFirstError.js.map +1 -0
- package/dist/util/friendlyError.d.ts +2 -0
- package/dist/util/friendlyError.d.ts.map +1 -0
- package/dist/util/friendlyError.js +49 -0
- package/dist/util/friendlyError.js.map +1 -0
- package/dist/util/streamHelpers.d.ts +10 -0
- package/dist/util/streamHelpers.d.ts.map +1 -0
- package/dist/util/streamHelpers.js +99 -0
- package/dist/util/streamHelpers.js.map +1 -0
- package/package.json +22 -7
- package/src/{AssetHandler.js → AssetHandler.ts} +174 -99
- package/src/constants.ts +50 -0
- package/src/debug.ts +3 -0
- package/src/{export.js → export.ts} +127 -71
- package/src/filterDocumentTypes.ts +21 -0
- package/src/filterDocuments.ts +55 -0
- package/src/{getDocumentCursorStream.js → getDocumentCursorStream.ts} +37 -18
- package/src/{getDocumentsStream.js → getDocumentsStream.ts} +16 -6
- package/src/{getUserAgent.js → getUserAgent.ts} +8 -3
- package/src/index.ts +11 -0
- package/src/{logFirstChunk.js → logFirstChunk.ts} +6 -4
- package/src/options.ts +138 -0
- package/src/rejectOnApiError.ts +62 -0
- package/src/requestStream.ts +81 -0
- package/src/stringifyStream.ts +7 -0
- package/src/{tryParseJson.js → tryParseJson.ts} +29 -17
- package/src/types.ts +274 -0
- package/src/util/{delay.js → delay.ts} +1 -1
- package/src/util/extractFirstError.ts +31 -0
- package/src/util/friendlyError.ts +75 -0
- package/src/util/{streamHelpers.js → streamHelpers.ts} +35 -18
- package/src/debug.js +0 -3
- package/src/filterDocumentTypes.js +0 -18
- package/src/filterDocuments.js +0 -33
- package/src/rejectOnApiError.js +0 -31
- package/src/requestStream.js +0 -64
- package/src/stringifyStream.js +0 -5
- package/src/util/extractFirstError.js +0 -14
- package/src/util/friendlyError.js +0 -58
- package/src/validateOptions.js +0 -113
package/dist/options.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { ASSET_DOWNLOAD_MAX_RETRIES, DOCUMENT_STREAM_MAX_RETRIES, MODE_CURSOR, MODE_STREAM, REQUEST_READ_TIMEOUT, } from './constants.js';
|
|
2
|
+
const booleanFlags = ['assets', 'raw', 'compress', 'drafts'];
|
|
3
|
+
const numberFlags = ['maxAssetRetries', 'maxRetries', 'assetConcurrency', 'readTimeout'];
|
|
4
|
+
const exportDefaults = {
|
|
5
|
+
compress: true,
|
|
6
|
+
drafts: true,
|
|
7
|
+
assets: true,
|
|
8
|
+
assetsMap: true,
|
|
9
|
+
raw: false,
|
|
10
|
+
mode: MODE_STREAM,
|
|
11
|
+
maxRetries: DOCUMENT_STREAM_MAX_RETRIES,
|
|
12
|
+
maxAssetRetries: ASSET_DOWNLOAD_MAX_RETRIES,
|
|
13
|
+
readTimeout: REQUEST_READ_TIMEOUT,
|
|
14
|
+
filterDocument: () => true,
|
|
15
|
+
transformDocument: (doc) => doc,
|
|
16
|
+
};
|
|
17
|
+
export function validateOptions(opts) {
|
|
18
|
+
const options = { ...exportDefaults, ...opts };
|
|
19
|
+
const dataset = 'dataset' in options && typeof options.dataset === 'string' ? options.dataset : undefined;
|
|
20
|
+
const mediaLibraryId = 'mediaLibraryId' in options && typeof options.mediaLibraryId === 'string'
|
|
21
|
+
? options.mediaLibraryId
|
|
22
|
+
: undefined;
|
|
23
|
+
if (dataset && mediaLibraryId) {
|
|
24
|
+
throw new Error('either `options.dataset` or `options.mediaLibraryId` must be specified, got both');
|
|
25
|
+
}
|
|
26
|
+
if (!dataset && !mediaLibraryId) {
|
|
27
|
+
throw new Error('either `options.dataset` or `options.mediaLibraryId` must be specified, got neither');
|
|
28
|
+
}
|
|
29
|
+
const source = getSource(options);
|
|
30
|
+
if (!source.id.trim()) {
|
|
31
|
+
throw new Error(`Source (${source.type}) specified but was empty`);
|
|
32
|
+
}
|
|
33
|
+
// Type narrowing for mode validation
|
|
34
|
+
const mode = options.mode;
|
|
35
|
+
if (typeof mode !== 'string' || (mode !== MODE_STREAM && mode !== MODE_CURSOR)) {
|
|
36
|
+
throw new Error(`options.mode must be either "${MODE_STREAM}" or "${MODE_CURSOR}", got "${mode}"`);
|
|
37
|
+
}
|
|
38
|
+
if (typeof options.onProgress !== 'undefined' && typeof options.onProgress !== 'function') {
|
|
39
|
+
throw new Error(`options.onProgress must be a function`);
|
|
40
|
+
}
|
|
41
|
+
if (
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
43
|
+
!options.client ||
|
|
44
|
+
!('config' in options.client) ||
|
|
45
|
+
typeof options.client.getUrl !== 'function') {
|
|
46
|
+
throw new Error('`options.client` must be set to an instance of @sanity/client');
|
|
47
|
+
}
|
|
48
|
+
const clientConfig = options.client.config();
|
|
49
|
+
if (!clientConfig.token) {
|
|
50
|
+
throw new Error('Client is not instantiated with a `token`');
|
|
51
|
+
}
|
|
52
|
+
for (const flag of booleanFlags) {
|
|
53
|
+
if (typeof options[flag] !== 'boolean') {
|
|
54
|
+
throw new Error(`Flag ${flag} must be a boolean (true/false)`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
for (const flag of numberFlags) {
|
|
58
|
+
if (typeof options[flag] !== 'undefined' && typeof options[flag] !== 'number') {
|
|
59
|
+
throw new Error(`Flag ${flag} must be a number if specified`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (!options.outputPath) {
|
|
63
|
+
throw new Error('outputPath must be specified (- for stdout)');
|
|
64
|
+
}
|
|
65
|
+
if (options.assetConcurrency && (options.assetConcurrency < 1 || options.assetConcurrency > 24)) {
|
|
66
|
+
throw new Error('`assetConcurrency` must be between 1 and 24');
|
|
67
|
+
}
|
|
68
|
+
if (typeof options.filterDocument !== 'undefined' &&
|
|
69
|
+
typeof options.filterDocument !== 'function') {
|
|
70
|
+
throw new Error('`filterDocument` must be a function');
|
|
71
|
+
}
|
|
72
|
+
if (typeof options.transformDocument !== 'undefined' &&
|
|
73
|
+
typeof options.transformDocument !== 'function') {
|
|
74
|
+
throw new Error('`transformDocument` must be a function');
|
|
75
|
+
}
|
|
76
|
+
if (typeof options.assetsMap !== 'undefined' && typeof options.assetsMap !== 'boolean') {
|
|
77
|
+
throw new Error('`assetsMap` must be a boolean');
|
|
78
|
+
}
|
|
79
|
+
return options;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Determines the source type and ID from the provided options.
|
|
83
|
+
*
|
|
84
|
+
* @param options - The export options containing either dataset or mediaLibraryId.
|
|
85
|
+
* @returns An object with the source type and its corresponding ID.
|
|
86
|
+
* @internal
|
|
87
|
+
*/
|
|
88
|
+
export function getSource(options) {
|
|
89
|
+
if ('dataset' in options && typeof options.dataset === 'string') {
|
|
90
|
+
return { type: 'dataset', id: options.dataset };
|
|
91
|
+
}
|
|
92
|
+
else if ('mediaLibraryId' in options && typeof options.mediaLibraryId === 'string') {
|
|
93
|
+
return { type: 'media-library', id: options.mediaLibraryId };
|
|
94
|
+
}
|
|
95
|
+
throw new Error('Either dataset or mediaLibraryId must be specified');
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,2BAA2B,EAC3B,WAAW,EACX,WAAW,EACX,oBAAoB,GACrB,MAAM,gBAAgB,CAAA;AAGvB,MAAM,YAAY,GAAG,CAAC,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,CAAU,CAAA;AACrE,MAAM,WAAW,GAAG,CAAC,iBAAiB,EAAE,YAAY,EAAE,kBAAkB,EAAE,aAAa,CAAU,CAAA;AAEjG,MAAM,cAAc,GAAG;IACrB,QAAQ,EAAE,IAAI;IACd,MAAM,EAAE,IAAI;IACZ,MAAM,EAAE,IAAI;IACZ,SAAS,EAAE,IAAI;IACf,GAAG,EAAE,KAAK;IACV,IAAI,EAAE,WAAW;IACjB,UAAU,EAAE,2BAA2B;IACvC,eAAe,EAAE,0BAA0B;IAC3C,WAAW,EAAE,oBAAoB;IACjC,cAAc,EAAE,GAAY,EAAE,CAAC,IAAI;IACnC,iBAAiB,EAAE,CAAC,GAAmB,EAAkB,EAAE,CAAC,GAAG;CACvD,CAAA;AAEV,MAAM,UAAU,eAAe,CAAC,IAAmB;IACjD,MAAM,OAAO,GAAG,EAAC,GAAG,cAAc,EAAE,GAAG,IAAI,EAAC,CAAA;IAE5C,MAAM,OAAO,GACX,SAAS,IAAI,OAAO,IAAI,OAAO,OAAO,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAA;IAC3F,MAAM,cAAc,GAClB,gBAAgB,IAAI,OAAO,IAAI,OAA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I,OAAO,OAAO,CAAC,SAAS,KAAK,WAAW,IAAI,OAAO,OAAO,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;QACvF,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAA;IAClD,CAAC;IAED,OAAO,OAAO,CAAA;AAChB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CAAC,OAAqB;IAI7C,IAAI,SAAS,IAAI,OAAO,IAAI,OAAO,OAAO,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChE,OAAO,EAAC,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,OAAO,CAAC,OAAO,EAAC,CAAA;IAC/C,CAAC;SAAM,IAAI,gBAAgB,IAAI,OAAO,IAAI,OAAO,OAAO,CAAC,cAAc,KAAK,QAAQ,EAAE,CAAC;QACrF,OAAO,EAAC,IAAI,EAAE,eAAe,EAAE,EAAE,EAAE,OAAO,CAAC,cAAc,EAAC,CAAA;IAC5D,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAA;AACvE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rejectOnApiError.d.ts","sourceRoot":"","sources":["../src/rejectOnApiError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,aAAa,CAAA;AAuB1C,wBAAgB,gBAAgB,IAAI,SAAS,CAsC5C"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { throughObj } from './util/streamHelpers.js';
|
|
2
|
+
function isErrorDocument(doc) {
|
|
3
|
+
return !('_id' in doc && doc._id) && 'error' in doc;
|
|
4
|
+
}
|
|
5
|
+
export function rejectOnApiError() {
|
|
6
|
+
return throughObj((doc, _enc, callback) => {
|
|
7
|
+
// check if the document passed contains a document attribute first, and return early.
|
|
8
|
+
if ('_id' in doc && doc._id) {
|
|
9
|
+
callback(null, doc);
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
if (isErrorDocument(doc)) {
|
|
13
|
+
// if we got a statusCode we can decorate the error with it
|
|
14
|
+
if (doc.statusCode) {
|
|
15
|
+
const err = doc.error;
|
|
16
|
+
const errorMessage = typeof err === 'string'
|
|
17
|
+
? err
|
|
18
|
+
: typeof err === 'object'
|
|
19
|
+
? (err.description ?? err.message)
|
|
20
|
+
: undefined;
|
|
21
|
+
callback(new Error(['Export', `HTTP ${doc.statusCode}`, errorMessage, doc.message]
|
|
22
|
+
.filter((part) => typeof part === 'string')
|
|
23
|
+
.join(': ')));
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
// no statusCode, just serialize and return the error
|
|
27
|
+
const error = doc.error;
|
|
28
|
+
const errorMessage = typeof error === 'object' ? (error.description ?? error.message) : undefined;
|
|
29
|
+
callback(new Error(errorMessage ?? JSON.stringify(doc)));
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
callback(null, doc);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=rejectOnApiError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rejectOnApiError.js","sourceRoot":"","sources":["../src/rejectOnApiError.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,UAAU,EAAC,MAAM,yBAAyB,CAAA;AAiBlD,SAAS,eAAe,CAAC,GAAoB;IAC3C,OAAO,CAAC,CAAC,KAAK,IAAI,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,IAAI,OAAO,IAAI,GAAG,CAAA;AACrD,CAAC;AAED,MAAM,UAAU,gBAAgB;IAC9B,OAAO,UAAU,CAAC,CAAC,GAAoB,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;QACzD,sFAAsF;QACtF,IAAI,KAAK,IAAI,GAAG,IAAI,GAAG,CAAC,GAAG,EAAE,CAAC;YAC5B,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;YACnB,OAAM;QACR,CAAC;QAED,IAAI,eAAe,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AAY,CAAA;AAmBpE,wBAAsB,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,cAAc,CAAC,CAiD1F"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { getIt } from 'get-it';
|
|
2
|
+
import { keepAlive, promise } from 'get-it/middleware';
|
|
3
|
+
import { delay } from './util/delay.js';
|
|
4
|
+
import { extractFirstError } from './util/extractFirstError.js';
|
|
5
|
+
import { tryThrowFriendlyError } from './util/friendlyError.js';
|
|
6
|
+
import { DEFAULT_RETRY_DELAY, DOCUMENT_STREAM_MAX_RETRIES, REQUEST_READ_TIMEOUT, } from './constants.js';
|
|
7
|
+
import { debug } from './debug.js';
|
|
8
|
+
const request = getIt([keepAlive(), promise({ onlyBody: true })]);
|
|
9
|
+
const CONNECTION_TIMEOUT = 15 * 1000; // 15 seconds
|
|
10
|
+
export async function requestStream(options) {
|
|
11
|
+
const maxRetries = options.maxRetries !== undefined ? options.maxRetries : DOCUMENT_STREAM_MAX_RETRIES;
|
|
12
|
+
const readTimeout = options.readTimeout !== undefined ? options.readTimeout : REQUEST_READ_TIMEOUT;
|
|
13
|
+
const retryDelayMs = options.retryDelayMs !== undefined ? options.retryDelayMs : DEFAULT_RETRY_DELAY;
|
|
14
|
+
let error;
|
|
15
|
+
let i = 0;
|
|
16
|
+
do {
|
|
17
|
+
i++;
|
|
18
|
+
try {
|
|
19
|
+
return await request({
|
|
20
|
+
...options,
|
|
21
|
+
stream: true,
|
|
22
|
+
maxRedirects: 0,
|
|
23
|
+
timeout: { connect: CONNECTION_TIMEOUT, socket: readTimeout },
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
const firstError = extractFirstError(err);
|
|
28
|
+
error = firstError !== null ? firstError : err;
|
|
29
|
+
if (maxRetries === 0) {
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
if (error.response?.statusCode && error.response.statusCode < 500) {
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
if (i < maxRetries) {
|
|
36
|
+
debug('Error, retrying after %d ms: %s', retryDelayMs, error.message);
|
|
37
|
+
await delay(retryDelayMs);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
} while (i < maxRetries);
|
|
41
|
+
await tryThrowFriendlyError(error);
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
43
|
+
if (!error) {
|
|
44
|
+
throw new Error(`Export: Failed to fetch ${options.url}: Unknown error`);
|
|
45
|
+
}
|
|
46
|
+
throw new Error(`Export: Failed to fetch ${options.url}: ${error.message}`);
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=requestStream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requestStream.js","sourceRoot":"","sources":["../src/requestStream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,QAAQ,CAAA;AAC5B,OAAO,EAAC,SAAS,EAAE,OAAO,EAAC,MAAM,mBAAmB,CAAA;AAEpD,OAAO,EAAC,KAAK,EAAC,MAAM,iBAAiB,CAAA;AACrC,OAAO,EAAC,iBAAiB,EAAC,MAAM,6BAA6B,CAAA;AAC7D,OAAO,EAAC,qBAAqB,EAAC,MAAM,yBAAyB,CAAA;AAC7D,OAAO,EACL,mBAAmB,EACnB,2BAA2B,EAC3B,oBAAoB,GACrB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAC,KAAK,EAAC,MAAM,YAAY,CAAA;AAchC,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,SAAS,EAAE,EAAE,OAAO,CAAC,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC,CAAC,CAEnC,CAAA;AAE3B,MAAM,kBAAkB,GAAG,EAAE,GAAG,IAAI,CAAA,CAAC,aAAa;AAElD,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,OAA6B;IAC/D,MAAM,UAAU,GACd,OAAO,CAAC,UAAU,KAAK,SAAS,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AG,UAAU,EAAC;IAExB,MAAM,qBAAqB,CAAC,KAAK,CAAC,CAAA;IAElC,uEAAuE;IACvE,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,2BAA2B,OAAO,CAAC,GAAG,iBAAiB,CAAC,CAAA;IAC1E,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,2BAA2B,OAAO,CAAC,GAAG,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;AAC7E,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stringifyStream.d.ts","sourceRoot":"","sources":["../src/stringifyStream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,aAAa,CAAA;AAI1C,wBAAgB,eAAe,IAAI,SAAS,CAE3C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stringifyStream.js","sourceRoot":"","sources":["../src/stringifyStream.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,UAAU,EAAC,MAAM,yBAAyB,CAAA;AAElD,MAAM,UAAU,eAAe;IAC7B,OAAO,UAAU,CAAC,CAAC,GAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAA;AACjG,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Safe JSON parser that is able to handle lines interrupted by an error object.
|
|
3
|
+
*
|
|
4
|
+
* This may occur when streaming NDJSON from the Export HTTP API.
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
* @see {@link https://github.com/sanity-io/sanity/pull/1787 | Initial pull request}
|
|
8
|
+
*/
|
|
9
|
+
export declare const tryParseJson: (line: string) => unknown;
|
|
10
|
+
//# sourceMappingURL=tryParseJson.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tryParseJson.d.ts","sourceRoot":"","sources":["../src/tryParseJson.ts"],"names":[],"mappings":"AAoCA;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,SAjCc,MAAM,KAAG,OAmC9C,CAAA"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
function createSafeJsonParser({ errorLabel }) {
|
|
2
|
+
return function safeJsonParser(line) {
|
|
3
|
+
try {
|
|
4
|
+
return JSON.parse(line);
|
|
5
|
+
}
|
|
6
|
+
catch (err) {
|
|
7
|
+
// Catch half-done lines with an error at the end
|
|
8
|
+
const errorPosition = line.lastIndexOf('{"error":');
|
|
9
|
+
if (errorPosition === -1) {
|
|
10
|
+
if (err instanceof Error) {
|
|
11
|
+
err.message = `${err.message} (${line})`;
|
|
12
|
+
}
|
|
13
|
+
throw err;
|
|
14
|
+
}
|
|
15
|
+
const errorJson = line.slice(errorPosition);
|
|
16
|
+
const errorLine = JSON.parse(errorJson);
|
|
17
|
+
const error = errorLine.error;
|
|
18
|
+
if (error && error.description) {
|
|
19
|
+
throw new Error(`${errorLabel}: ${error.description}\n\n${errorJson}\n`, { cause: err });
|
|
20
|
+
}
|
|
21
|
+
throw err;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Safe JSON parser that is able to handle lines interrupted by an error object.
|
|
27
|
+
*
|
|
28
|
+
* This may occur when streaming NDJSON from the Export HTTP API.
|
|
29
|
+
*
|
|
30
|
+
* @internal
|
|
31
|
+
* @see {@link https://github.com/sanity-io/sanity/pull/1787 | Initial pull request}
|
|
32
|
+
*/
|
|
33
|
+
export const tryParseJson = createSafeJsonParser({
|
|
34
|
+
errorLabel: 'Error streaming dataset',
|
|
35
|
+
});
|
|
36
|
+
//# sourceMappingURL=tryParseJson.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tryParseJson.js","sourceRoot":"","sources":["../src/tryParseJson.ts"],"names":[],"mappings":"AAUA,SAAS,oBAAoB,CAAC,EAAC,UAAU,EAAwB;IAC/D,OAAO,SAAS,cAAc,CAAC,IAAY;QACzC,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAY,CAAA;QACpC,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,iDAAiD;YACjD,MAAM,aAAa,GAAG,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,CAAA;YACnD,IAAI,aAAa,KAAK,CAAC,CAAC,EAAE,CAAC;gBACzB,IAAI,GAAG,YAAY,KAAK,EAAE,CAAC;oBACzB,GAAG,CAAC,OAAO,GAAG,GAAG,GAAG,CAAC,OAAO,KAAK,IAAI,GAAG,CAAA;gBAC1C,CAAC;gBACD,MAAM,GAAG,CAAA;YACX,CAAC;YAED,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAA;YAC3C,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAoB,CAAA;YAC1D,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAA;YAC7B,IAAI,KAAK,IAAI,KAAK,CAAC,WAAW,EAAE,CAAC;gBAC/B,MAAM,IAAI,KAAK,CAAC,GAAG,UAAU,KAAK,KAAK,CAAC,WAAW,OAAO,SAAS,IAAI,EAAE,EAAC,KAAK,EAAE,GAAG,EAAC,CAAC,CAAA;YACxF,CAAC;YAED,MAAM,GAAG,CAAA;QACX,CAAC;IACH,CAAC,CAAA;AACH,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,oBAAoB,CAAC;IAC/C,UAAU,EAAE,yBAAyB;CACtC,CAAC,CAAA"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import type { Writable } from 'node:stream';
|
|
2
|
+
/**
|
|
3
|
+
* The mode to use when exporting documents.
|
|
4
|
+
*
|
|
5
|
+
* - `"stream"` mode uses a continuous stream of documents from the source and will
|
|
6
|
+
* give a consistent snapshot of the dataset at the time the export started, but
|
|
7
|
+
* will struggle with very large datasets.
|
|
8
|
+
* - `"cursor"` mode uses paginated requests to fetch documents using a cursor, and
|
|
9
|
+
* will handle very large datasets better, but may give an inconsistent snapshot if
|
|
10
|
+
* the dataset is being modified during the export.
|
|
11
|
+
*
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export type ExportMode = 'stream' | 'cursor';
|
|
15
|
+
/**
|
|
16
|
+
* Minimal representation of a Sanity document.
|
|
17
|
+
*
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
export interface SanityDocument {
|
|
21
|
+
_id: string;
|
|
22
|
+
_type: string;
|
|
23
|
+
_rev?: string;
|
|
24
|
+
_createdAt?: string;
|
|
25
|
+
_updatedAt?: string;
|
|
26
|
+
[key: string]: unknown;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
export interface ExportProgress {
|
|
32
|
+
/** Description of the current export step */
|
|
33
|
+
step: string;
|
|
34
|
+
/** Number of documents processed so far */
|
|
35
|
+
current?: number;
|
|
36
|
+
/** Total number of documents, if known - otherwise `?` */
|
|
37
|
+
total?: number | '?';
|
|
38
|
+
/** Set to `true` if the progress update is a repeat of a previous one but with new values */
|
|
39
|
+
update?: boolean;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* @public
|
|
43
|
+
*/
|
|
44
|
+
export interface SanityClientLike {
|
|
45
|
+
getUrl: (path: string) => string;
|
|
46
|
+
config: () => {
|
|
47
|
+
token?: string;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The options used to configure an export operation.
|
|
52
|
+
*
|
|
53
|
+
* @public
|
|
54
|
+
*/
|
|
55
|
+
export type ExportOptions = {
|
|
56
|
+
/**
|
|
57
|
+
* An instance of `@sanity/client`, configured with the project ID and authentication
|
|
58
|
+
* token to be used for the export operation.
|
|
59
|
+
*/
|
|
60
|
+
client: SanityClientLike;
|
|
61
|
+
/**
|
|
62
|
+
* Either a filesystem path to write the output `tar.gz` file to, or a writable stream
|
|
63
|
+
*/
|
|
64
|
+
outputPath: string | Writable;
|
|
65
|
+
/**
|
|
66
|
+
* Whether or not to include asset files in the export
|
|
67
|
+
*/
|
|
68
|
+
assets?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Whether or not to export the documents "raw", meaning asset documents will be
|
|
71
|
+
* included as-is, referencing asset file URLs in the source dataset and project ID or
|
|
72
|
+
* media library ID. Also skips downloading assets. Generally this is only useful if
|
|
73
|
+
* importing to the same source and you do not want to download the assets and
|
|
74
|
+
* re-upload them to the same source.
|
|
75
|
+
*
|
|
76
|
+
* @note This will usually cause undesirable results if imported into another project
|
|
77
|
+
* or media library!
|
|
78
|
+
*/
|
|
79
|
+
raw?: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Whether or not to include draft documents in the export.
|
|
82
|
+
*/
|
|
83
|
+
drafts?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* An array of document type names to include in the export. If not specified, all types
|
|
86
|
+
* will be included.
|
|
87
|
+
*/
|
|
88
|
+
types?: string[] | undefined;
|
|
89
|
+
/**
|
|
90
|
+
* How many asset downloads to perform concurrently. Must be between 1 and 24 if specified.
|
|
91
|
+
*/
|
|
92
|
+
assetConcurrency?: number;
|
|
93
|
+
/**
|
|
94
|
+
* Maximum number of times to retry downloading a failed asset.
|
|
95
|
+
*
|
|
96
|
+
* @note Only certain errors are retried (like network errors and 5xx responses).
|
|
97
|
+
*/
|
|
98
|
+
maxAssetRetries?: number;
|
|
99
|
+
/**
|
|
100
|
+
* Maximum number of times to retry fetching documents from the source.
|
|
101
|
+
*
|
|
102
|
+
* @note Only certain errors are retried (like network errors and 5xx responses).
|
|
103
|
+
*/
|
|
104
|
+
maxRetries?: number;
|
|
105
|
+
/**
|
|
106
|
+
* Delay between retry attempts in milliseconds.
|
|
107
|
+
*/
|
|
108
|
+
retryDelayMs?: number;
|
|
109
|
+
/**
|
|
110
|
+
* Timeout for read operations in milliseconds.
|
|
111
|
+
*/
|
|
112
|
+
readTimeout?: number;
|
|
113
|
+
/**
|
|
114
|
+
* The mode to use when exporting documents, either `"stream"` or `"cursor"`.
|
|
115
|
+
*/
|
|
116
|
+
mode?: ExportMode;
|
|
117
|
+
/**
|
|
118
|
+
* Whether or not to compress the output tarball (gzip). Note that the output will
|
|
119
|
+
* still be a gzipped tarball even if this is set to `false`, setting it to `false`
|
|
120
|
+
* only sets the gzip compression level to 0 (no compression).
|
|
121
|
+
*/
|
|
122
|
+
compress?: boolean;
|
|
123
|
+
/**
|
|
124
|
+
* Whether or not to include an `assets.json` file in the export, mapping asset IDs to
|
|
125
|
+
* their custom metadata (like original filename, etc).
|
|
126
|
+
*/
|
|
127
|
+
assetsMap?: boolean;
|
|
128
|
+
/**
|
|
129
|
+
* Optional filter function to determine whether or not a document should be included
|
|
130
|
+
* in the export. Note that this is run after any built-in document filtering such as
|
|
131
|
+
* draft exclusion, document type filtering, etc.
|
|
132
|
+
*
|
|
133
|
+
* @param doc - The document to evaluate
|
|
134
|
+
* @returns Whether or not to include the document in the export
|
|
135
|
+
*/
|
|
136
|
+
filterDocument?: (doc: SanityDocument) => boolean;
|
|
137
|
+
/**
|
|
138
|
+
* Optional transform function to modify a document before it is included in the export.
|
|
139
|
+
* Note that this is run post-filtering, and post asset document processing.
|
|
140
|
+
*
|
|
141
|
+
* @param doc - The document to transform
|
|
142
|
+
* @returns The transformed document
|
|
143
|
+
*/
|
|
144
|
+
transformDocument?: (doc: SanityDocument) => SanityDocument;
|
|
145
|
+
/**
|
|
146
|
+
* Optional progress callback that will be called periodically during the export.
|
|
147
|
+
*
|
|
148
|
+
* @param progress - The current export progress
|
|
149
|
+
*/
|
|
150
|
+
onProgress?: (progress: ExportProgress) => void;
|
|
151
|
+
} & ExportSource;
|
|
152
|
+
/**
|
|
153
|
+
* The source of data to export, either a dataset name or a media library ID.
|
|
154
|
+
*
|
|
155
|
+
* @public
|
|
156
|
+
*/
|
|
157
|
+
export type ExportSource = {
|
|
158
|
+
/**
|
|
159
|
+
* The name of the dataset to export from.
|
|
160
|
+
*/
|
|
161
|
+
dataset: string;
|
|
162
|
+
} | {
|
|
163
|
+
/**
|
|
164
|
+
* The ID of the media library to export from.
|
|
165
|
+
*/
|
|
166
|
+
mediaLibraryId: string;
|
|
167
|
+
};
|
|
168
|
+
/**
|
|
169
|
+
* @public
|
|
170
|
+
*/
|
|
171
|
+
export interface ExportResult<T = string | Writable> {
|
|
172
|
+
/**
|
|
173
|
+
* The filesystem path or writable stream that was passed as `options.outputPath`.
|
|
174
|
+
*/
|
|
175
|
+
outputPath: T;
|
|
176
|
+
/**
|
|
177
|
+
* The number of documents exported.
|
|
178
|
+
*/
|
|
179
|
+
documentCount: number;
|
|
180
|
+
/**
|
|
181
|
+
* The number of assets exported.
|
|
182
|
+
*/
|
|
183
|
+
assetCount: number;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* @internal
|
|
187
|
+
*/
|
|
188
|
+
export type NormalizedExportOptions = ExportOptions & {
|
|
189
|
+
assets: boolean;
|
|
190
|
+
raw: boolean;
|
|
191
|
+
drafts: boolean;
|
|
192
|
+
maxAssetRetries: number;
|
|
193
|
+
maxRetries: number;
|
|
194
|
+
readTimeout: number;
|
|
195
|
+
mode: ExportMode;
|
|
196
|
+
compress: boolean;
|
|
197
|
+
assetsMap: boolean;
|
|
198
|
+
filterDocument: (doc: SanityDocument) => boolean;
|
|
199
|
+
transformDocument: (doc: SanityDocument) => SanityDocument;
|
|
200
|
+
};
|
|
201
|
+
/**
|
|
202
|
+
* @internal
|
|
203
|
+
*/
|
|
204
|
+
export interface AssetMetadata {
|
|
205
|
+
[key: string]: unknown;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* @internal
|
|
209
|
+
*/
|
|
210
|
+
export interface AssetMap {
|
|
211
|
+
[assetId: string]: AssetMetadata;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* @internal
|
|
215
|
+
*/
|
|
216
|
+
export interface RequestStreamOptions {
|
|
217
|
+
url: string;
|
|
218
|
+
headers?: Record<string, string>;
|
|
219
|
+
maxRetries?: number;
|
|
220
|
+
retryDelayMs?: number;
|
|
221
|
+
readTimeout?: number;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* @internal
|
|
225
|
+
*/
|
|
226
|
+
export interface ResponseStream extends NodeJS.ReadableStream {
|
|
227
|
+
statusCode?: number;
|
|
228
|
+
headers?: Record<string, string | string[] | undefined>;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* @internal
|
|
232
|
+
*/
|
|
233
|
+
export interface AssetDocument extends SanityDocument {
|
|
234
|
+
_type: 'sanity.imageAsset' | 'sanity.fileAsset';
|
|
235
|
+
url?: string;
|
|
236
|
+
path?: string;
|
|
237
|
+
assetId?: string;
|
|
238
|
+
extension?: string;
|
|
239
|
+
mimeType?: string;
|
|
240
|
+
}
|
|
241
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,aAAa,CAAA;AAEzC;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,QAAQ,CAAA;AAE5C;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,6CAA6C;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BAAoB;IACnC,GAAG,EAAE,MAAM,CAAA;IACX,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAChC,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,cAAe,SAAQ,MAAM,CAAC,cAAc;IAC3D,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,CAAA;CACxD;AAED;;GAEG;AACH,MAAM,WAAW,aAAc,SAAQ,cAAc;IACnD,KAAK,EAAE,mBAAmB,GAAG,kBAAkB,CAAA;IAC/C,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delay.d.ts","sourceRoot":"","sources":["../../src/util/delay.ts"],"names":[],"mappings":"AAAA,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE/C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delay.js","sourceRoot":"","sources":["../../src/util/delay.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,KAAK,CAAC,EAAU;IAC9B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAA;AAC1D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractFirstError.d.ts","sourceRoot":"","sources":["../../src/util/extractFirstError.ts"],"names":[],"mappings":"AAyBA,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAKvD"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
function isAggregateError(err) {
|
|
2
|
+
if (typeof err !== 'object' || err === null) {
|
|
3
|
+
return false;
|
|
4
|
+
}
|
|
5
|
+
if (err instanceof AggregateError) {
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
const record = err;
|
|
9
|
+
return (record.name === 'AggregateError' &&
|
|
10
|
+
Array.isArray(record.errors) &&
|
|
11
|
+
record.errors.length > 0 &&
|
|
12
|
+
typeof record.errors[0] === 'object' &&
|
|
13
|
+
record.errors[0] !== null &&
|
|
14
|
+
'message' in record.errors[0]);
|
|
15
|
+
}
|
|
16
|
+
export function extractFirstError(err) {
|
|
17
|
+
if (isAggregateError(err)) {
|
|
18
|
+
return err.errors[0];
|
|
19
|
+
}
|
|
20
|
+
return err;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=extractFirstError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractFirstError.js","sourceRoot":"","sources":["../../src/util/extractFirstError.ts"],"names":[],"mappings":"AAKA,SAAS,gBAAgB,CAAC,GAAY;IACpC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;QAC5C,OAAO,KAAK,CAAA;IACd,CAAC;IAED,IAAI,GAAG,YAAY,cAAc,EAAE,CAAC;QAClC,OAAO,IAAI,CAAA;IACb,CAAC;IAED,MAAM,MAAM,GAAG,GAA8B,CAAA;IAC7C,OAAO,CACL,MAAM,CAAC,IAAI,KAAK,gBAAgB;QAChC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC;QAC5B,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC;QACxB,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,QAAQ;QACpC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,IAAI;QACzB,SAAS,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAC9B,CAAA;AACH,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,GAAY;IAC5C,IAAI,gBAAgB,CAAC,GAAG,CAAC,EAAE,CAAC;QAC1B,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;IACtB,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"friendlyError.d.ts","sourceRoot":"","sources":["../../src/util/friendlyError.ts"],"names":[],"mappings":"AAgDA,wBAAsB,qBAAqB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CA0BvE"}
|