@sanity/util 4.20.1-next.9 → 4.20.2-fix-babel-traverse-bug.2.03a7495fed
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.
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
3
|
+
function createSafeJsonParser({ errorLabel }) {
|
|
4
|
+
return function(line) {
|
|
5
|
+
try {
|
|
6
|
+
return JSON.parse(line);
|
|
7
|
+
} catch (err) {
|
|
8
|
+
const errorPosition = line.lastIndexOf('{"error":');
|
|
9
|
+
if (errorPosition === -1)
|
|
10
|
+
throw err.message = `${err.message} (${line})`, err;
|
|
11
|
+
const errorJson = line.slice(errorPosition), errorLine = JSON.parse(errorJson), error = errorLine && errorLine.error;
|
|
12
|
+
throw error && error.description ? new Error(`${errorLabel}: ${error.description}
|
|
13
|
+
|
|
14
|
+
${errorJson}
|
|
15
|
+
`, { cause: err }) : err;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
exports.createSafeJsonParser = createSafeJsonParser;
|
|
20
|
+
//# sourceMappingURL=createSafeJsonParser.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createSafeJsonParser.cjs","sources":["../src/createSafeJsonParser.ts"],"sourcesContent":["interface Options {\n errorLabel: string\n}\n\ntype Parser<Type> = (line: string) => Type\n\n/**\n * Create a safe JSON parser that is able to handle lines interrupted by an error object.\n *\n * This may occur when streaming NDJSON from the Export HTTP API.\n *\n * @internal\n * @see {@link https://github.com/sanity-io/sanity/pull/1787 | Initial pull request}\n */\nexport function createSafeJsonParser<Type>({errorLabel}: Options): Parser<Type> {\n return function safeJsonParser(line) {\n try {\n return JSON.parse(line)\n } catch (err) {\n // Catch half-done lines with an error at the end\n const errorPosition = line.lastIndexOf('{\"error\":')\n if (errorPosition === -1) {\n err.message = `${err.message} (${line})`\n throw err\n }\n\n const errorJson = line.slice(errorPosition)\n const errorLine = JSON.parse(errorJson)\n const error = errorLine && errorLine.error\n if (error && error.description) {\n throw new Error(`${errorLabel}: ${error.description}\\n\\n${errorJson}\\n`, {cause: err})\n }\n\n throw err\n }\n }\n}\n"],"names":[],"mappings":";;AAcO,SAAS,qBAA2B,EAAC,cAAoC;AAC9E,SAAO,SAAwB,MAAM;AACnC,QAAI;AACF,aAAO,KAAK,MAAM,IAAI;AAAA,IACxB,SAAS,KAAK;AAEZ,YAAM,gBAAgB,KAAK,YAAY,WAAW;AAClD,UAAI,kBAAkB;AACpB,cAAA,IAAI,UAAU,GAAG,IAAI,OAAO,KAAK,IAAI,KAC/B;AAGR,YAAM,YAAY,KAAK,MAAM,aAAa,GACpC,YAAY,KAAK,MAAM,SAAS,GAChC,QAAQ,aAAa,UAAU;AACrC,YAAI,SAAS,MAAM,cACX,IAAI,MAAM,GAAG,UAAU,KAAK,MAAM,WAAW;AAAA;AAAA,EAAO,SAAS;AAAA,GAAM,EAAC,OAAO,IAAA,CAAI,IAGjF;AAAA,IACR;AAAA,EACF;AACF;;"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a 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 function createSafeJsonParser<Type>({errorLabel}: Options): Parser<Type>
|
|
10
|
+
|
|
11
|
+
declare interface Options {
|
|
12
|
+
errorLabel: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
declare type Parser<Type> = (line: string) => Type
|
|
16
|
+
|
|
17
|
+
export {}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/util",
|
|
3
|
-
"version": "4.20.
|
|
3
|
+
"version": "4.20.2-fix-babel-traverse-bug.2.03a7495fed",
|
|
4
4
|
"description": "Utilities shared across projects of Sanity",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
},
|
|
47
47
|
"./createSafeJsonParser": {
|
|
48
48
|
"source": "./src/_exports/createSafeJsonParser.ts",
|
|
49
|
+
"require": "./lib/createSafeJsonParser.cjs",
|
|
49
50
|
"default": "./lib/createSafeJsonParser.js"
|
|
50
51
|
},
|
|
51
52
|
"./legacyDateFormat": {
|
|
@@ -88,35 +89,37 @@
|
|
|
88
89
|
"files": [
|
|
89
90
|
"lib"
|
|
90
91
|
],
|
|
92
|
+
"scripts": {
|
|
93
|
+
"build": "pnpm clean && pkg-utils build --strict --check --clean",
|
|
94
|
+
"check:types": "(cd ../../.. && tsgo --project packages/@sanity/util/tsconfig.lib.json --erasableSyntaxOnly)",
|
|
95
|
+
"clean": "rimraf client.js concurrency-limiter.js content.js createSafeJsonParser.js fs.js legacyDateFormat.js lib paths.js",
|
|
96
|
+
"lint": "eslint .",
|
|
97
|
+
"prepublishOnly": "turbo run build",
|
|
98
|
+
"test": "vitest run",
|
|
99
|
+
"watch": "pkg-utils watch"
|
|
100
|
+
},
|
|
91
101
|
"dependencies": {
|
|
92
102
|
"@date-fns/tz": "^1.4.1",
|
|
93
103
|
"@date-fns/utc": "^2.1.1",
|
|
94
104
|
"@sanity/client": "^7.13.1",
|
|
105
|
+
"@sanity/types": "4.20.2-fix-babel-traverse-bug.2.03a7495fed",
|
|
95
106
|
"date-fns": "^4.1.0",
|
|
96
|
-
"rxjs": "^7.8.2"
|
|
97
|
-
"@sanity/types": "4.20.1-next.9+eedec5b4bf"
|
|
107
|
+
"rxjs": "^7.8.2"
|
|
98
108
|
},
|
|
99
109
|
"devDependencies": {
|
|
110
|
+
"@repo/eslint-config": "4.20.1",
|
|
111
|
+
"@repo/package.config": "4.20.1",
|
|
112
|
+
"@repo/test-config": "4.20.1",
|
|
113
|
+
"@repo/tsconfig": "4.20.1",
|
|
100
114
|
"@sanity/pkg-utils": "^10.0.0",
|
|
101
115
|
"@types/node": "^24.3.0",
|
|
102
116
|
"@typescript/native-preview": "7.0.0-dev.20251128.1",
|
|
103
117
|
"eslint": "^9.39.1",
|
|
104
118
|
"rimraf": "^5.0.10",
|
|
105
|
-
"vitest": "^3.2.4"
|
|
106
|
-
"@repo/eslint-config": "4.20.1-next.9+eedec5b4bf",
|
|
107
|
-
"@repo/package.config": "4.20.1-next.9+eedec5b4bf",
|
|
108
|
-
"@repo/test-config": "4.20.1-next.9+eedec5b4bf",
|
|
109
|
-
"@repo/tsconfig": "4.20.1-next.9+eedec5b4bf"
|
|
119
|
+
"vitest": "^3.2.4"
|
|
110
120
|
},
|
|
111
121
|
"engines": {
|
|
112
122
|
"node": ">=20.19 <22 || >=22.12"
|
|
113
123
|
},
|
|
114
|
-
"
|
|
115
|
-
|
|
116
|
-
"check:types": "(cd ../../.. && tsgo --project packages/@sanity/util/tsconfig.lib.json --erasableSyntaxOnly)",
|
|
117
|
-
"clean": "rimraf client.js concurrency-limiter.js content.js createSafeJsonParser.js fs.js legacyDateFormat.js lib paths.js",
|
|
118
|
-
"lint": "eslint .",
|
|
119
|
-
"test": "vitest run",
|
|
120
|
-
"watch": "pkg-utils watch"
|
|
121
|
-
}
|
|
122
|
-
}
|
|
124
|
+
"gitHead": "03a7495fedf58733966c95ebba37d1c358cdd327"
|
|
125
|
+
}
|