@sanity/util 5.0.0-next-major.12 → 5.0.0-next-major.6

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": "5.0.0-next-major.12+dad441dd1a",
3
+ "version": "5.0.0-next-major.6+555be27666",
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": {
@@ -94,19 +95,19 @@
94
95
  "@sanity/client": "^7.13.1",
95
96
  "date-fns": "^4.1.0",
96
97
  "rxjs": "^7.8.2",
97
- "@sanity/types": "5.0.0-next-major.12+dad441dd1a"
98
+ "@sanity/types": "5.0.0-next-major.6+555be27666"
98
99
  },
99
100
  "devDependencies": {
100
- "@sanity/pkg-utils": "^10.0.0",
101
+ "@sanity/pkg-utils": "^10.1.2",
101
102
  "@types/node": "^24.3.0",
102
103
  "@typescript/native-preview": "7.0.0-dev.20251128.1",
103
104
  "eslint": "^9.39.1",
104
105
  "rimraf": "^5.0.10",
105
106
  "vitest": "^3.2.4",
106
- "@repo/eslint-config": "5.0.0-next-major.12+dad441dd1a",
107
- "@repo/tsconfig": "5.0.0-next-major.12+dad441dd1a",
108
- "@repo/package.config": "5.0.0-next-major.12+dad441dd1a",
109
- "@repo/test-config": "5.0.0-next-major.12+dad441dd1a"
107
+ "@repo/package.config": "5.0.0-next-major.6+555be27666",
108
+ "@repo/test-config": "5.0.0-next-major.6+555be27666",
109
+ "@repo/eslint-config": "5.0.0-next-major.6+555be27666",
110
+ "@repo/tsconfig": "5.0.0-next-major.6+555be27666"
110
111
  },
111
112
  "engines": {
112
113
  "node": ">=20.19 <22 || >=22.12"