@sanity/util 6.7.0-next.36 → 6.7.0-next.4

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/lib/client.d.ts CHANGED
@@ -5,5 +5,4 @@ import { SanityClient } from "@sanity/client";
5
5
  * that same state if the `clone` `config` or `withConfig` methods are called.
6
6
  */
7
7
  declare function createClientConcurrencyLimiter(maxConcurrency: number): (input: SanityClient) => SanityClient;
8
- export { createClientConcurrencyLimiter };
9
- //# sourceMappingURL=client.d.ts.map
8
+ export { createClientConcurrencyLimiter };
package/lib/client.js CHANGED
@@ -1,50 +1,64 @@
1
- import { t as ConcurrencyLimiter } from "./concurrency-limiter-C6gDjN0m.js";
2
- import { finalize, from, switchMap } from "rxjs";
3
- /**
4
- * Decorates a sanity client to limit the concurrency of `client.fetch`
5
- * requests. Keeps the concurrency limit state and returns wrapped clients with
6
- * that same state if the `clone` `config` or `withConfig` methods are called.
7
- */
1
+ import { from, switchMap, finalize } from "rxjs";
2
+ import { ConcurrencyLimiter } from "./concurrency-limiter.js";
8
3
  function createClientConcurrencyLimiter(maxConcurrency) {
9
- let limiter = new ConcurrencyLimiter(maxConcurrency);
10
- function wrapClient(client) {
11
- return new Proxy(client, { get: (target, property) => {
12
- switch (property) {
13
- case "fetch": return async (...args) => {
14
- await limiter.ready();
15
- try {
16
- return await target.fetch(...args);
17
- } finally {
18
- limiter.release();
19
- }
20
- };
21
- case "clone": return (...args) => wrapClient(target.clone(...args));
22
- case "config": return (...args) => {
23
- let result = target.config(...args);
24
- return args[0] ? wrapClient(result) : result;
25
- };
26
- case "withConfig": return (...args) => wrapClient(target.withConfig(...args));
27
- case "observable": return wrapObservableClient(target.observable);
28
- default: return target[property];
29
- }
30
- } });
31
- }
32
- function wrapObservableClient(observableSanityClient) {
33
- return new Proxy(observableSanityClient, { get: (target, property) => {
34
- switch (property) {
35
- case "fetch": return (...args) => from(limiter.ready()).pipe(switchMap(() => target.fetch(...args)), finalize(() => limiter.release()));
36
- case "clone": return (...args) => wrapObservableClient(target.clone(...args));
37
- case "config": return (...args) => {
38
- let result = target.config(...args);
39
- return args[0] ? wrapObservableClient(result) : result;
40
- };
41
- case "withConfig": return (...args) => wrapObservableClient(target.withConfig(...args));
42
- default: return target[property];
43
- }
44
- } });
45
- }
46
- return wrapClient;
4
+ const limiter = new ConcurrencyLimiter(maxConcurrency);
5
+ function wrapClient(client) {
6
+ return new Proxy(client, {
7
+ get: (target, property) => {
8
+ switch (property) {
9
+ case "fetch":
10
+ return async (...args) => {
11
+ await limiter.ready();
12
+ try {
13
+ return await target.fetch(...args);
14
+ } finally {
15
+ limiter.release();
16
+ }
17
+ };
18
+ case "clone":
19
+ return (...args) => wrapClient(target.clone(...args));
20
+ case "config":
21
+ return (...args) => {
22
+ const result = target.config(...args);
23
+ return args[0] ? wrapClient(result) : result;
24
+ };
25
+ case "withConfig":
26
+ return (...args) => wrapClient(target.withConfig(...args));
27
+ case "observable":
28
+ return wrapObservableClient(target.observable);
29
+ default:
30
+ return target[property];
31
+ }
32
+ }
33
+ });
34
+ }
35
+ function wrapObservableClient(observableSanityClient) {
36
+ return new Proxy(observableSanityClient, {
37
+ get: (target, property) => {
38
+ switch (property) {
39
+ case "fetch":
40
+ return (...args) => from(limiter.ready()).pipe(
41
+ switchMap(() => target.fetch(...args)),
42
+ finalize(() => limiter.release())
43
+ );
44
+ case "clone":
45
+ return (...args) => wrapObservableClient(target.clone(...args));
46
+ case "config":
47
+ return (...args) => {
48
+ const result = target.config(...args);
49
+ return args[0] ? wrapObservableClient(result) : result;
50
+ };
51
+ case "withConfig":
52
+ return (...args) => wrapObservableClient(target.withConfig(...args));
53
+ default:
54
+ return target[property];
55
+ }
56
+ }
57
+ });
58
+ }
59
+ return wrapClient;
47
60
  }
48
- export { createClientConcurrencyLimiter };
49
-
50
- //# sourceMappingURL=client.js.map
61
+ export {
62
+ createClientConcurrencyLimiter
63
+ };
64
+ //# sourceMappingURL=client.js.map
package/lib/client.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","names":[],"sources":["../src/client/concurrency-limiter/createClientConcurrencyLimiter.ts"],"sourcesContent":["import {type ObservableSanityClient, type SanityClient} from '@sanity/client'\nimport {finalize, from, switchMap} from 'rxjs'\n\nimport {ConcurrencyLimiter} from '../../concurrency-limiter'\n\n/**\n * Decorates a sanity client to limit the concurrency of `client.fetch`\n * requests. Keeps the concurrency limit state and returns wrapped clients with\n * that same state if the `clone` `config` or `withConfig` methods are called.\n */\nexport function createClientConcurrencyLimiter(\n maxConcurrency: number,\n): (input: SanityClient) => SanityClient {\n const limiter = new ConcurrencyLimiter(maxConcurrency)\n\n function wrapClient(client: SanityClient): SanityClient {\n return new Proxy(client, {\n get: (target, property) => {\n switch (property) {\n case 'fetch': {\n return async (...args: Parameters<SanityClient['fetch']>) => {\n await limiter.ready()\n try {\n // note we want to await before we return so the finally block\n // will run after the promise has been fulfilled or rejected\n return await target.fetch(...args)\n } finally {\n limiter.release()\n }\n }\n }\n case 'clone': {\n return (...args: Parameters<SanityClient['clone']>) => {\n return wrapClient(target.clone(...args))\n }\n }\n case 'config': {\n return (...args: Parameters<SanityClient['config']>) => {\n const result = target.config(...args)\n\n // if there is a config, it returns a client so we need to wrap again\n if (args[0]) return wrapClient(result)\n return result\n }\n }\n case 'withConfig': {\n return (...args: Parameters<SanityClient['withConfig']>) => {\n return wrapClient(target.withConfig(...args))\n }\n }\n case 'observable': {\n return wrapObservableClient(target.observable)\n }\n default: {\n return target[property as keyof SanityClient]\n }\n }\n },\n })\n }\n\n function wrapObservableClient(\n observableSanityClient: ObservableSanityClient,\n ): ObservableSanityClient {\n return new Proxy(observableSanityClient, {\n get: (target, property) => {\n switch (property) {\n case 'fetch': {\n return (...args: Parameters<ObservableSanityClient['fetch']>) =>\n from(limiter.ready()).pipe(\n switchMap(() => target.fetch(...args)),\n finalize(() => limiter.release()),\n )\n }\n case 'clone': {\n return (...args: Parameters<ObservableSanityClient['clone']>) => {\n return wrapObservableClient(target.clone(...args))\n }\n }\n case 'config': {\n return (...args: Parameters<ObservableSanityClient['config']>) => {\n const result = target.config(...args)\n\n // if there is a config, it returns a client so we need to wrap again\n if (args[0]) return wrapObservableClient(result)\n return result\n }\n }\n case 'withConfig': {\n return (...args: Parameters<ObservableSanityClient['withConfig']>) => {\n return wrapObservableClient(target.withConfig(...args))\n }\n }\n default: {\n return target[property as keyof ObservableSanityClient]\n }\n }\n },\n })\n }\n\n return wrapClient\n}\n"],"mappings":";;;;;;;AAUA,SAAgB,+BACd,gBACuC;CACvC,IAAM,UAAU,IAAI,mBAAmB,cAAc;CAErD,SAAS,WAAW,QAAoC;EACtD,OAAO,IAAI,MAAM,QAAQ,EACvB,MAAM,QAAQ,aAAa;GACzB,QAAQ,UAAR;IACE,KAAK,SACH,OAAO,OAAO,GAAG,SAA4C;KAC3D,MAAM,QAAQ,MAAM;KACpB,IAAI;MAGF,OAAO,MAAM,OAAO,MAAM,GAAG,IAAI;KACnC,UAAU;MACR,QAAQ,QAAQ;KAClB;IACF;IAEF,KAAK,SACH,QAAQ,GAAG,SACF,WAAW,OAAO,MAAM,GAAG,IAAI,CAAC;IAG3C,KAAK,UACH,QAAQ,GAAG,SAA6C;KACtD,IAAM,SAAS,OAAO,OAAO,GAAG,IAAI;KAIpC,OADI,KAAK,KAAW,WAAW,MAAM,IAC9B;IACT;IAEF,KAAK,cACH,QAAQ,GAAG,SACF,WAAW,OAAO,WAAW,GAAG,IAAI,CAAC;IAGhD,KAAK,cACH,OAAO,qBAAqB,OAAO,UAAU;IAE/C,SACE,OAAO,OAAO;GAElB;EACF,EACF,CAAC;CACH;CAEA,SAAS,qBACP,wBACwB;EACxB,OAAO,IAAI,MAAM,wBAAwB,EACvC,MAAM,QAAQ,aAAa;GACzB,QAAQ,UAAR;IACE,KAAK,SACH,QAAQ,GAAG,SACT,KAAK,QAAQ,MAAM,CAAC,CAAC,CAAC,KACpB,gBAAgB,OAAO,MAAM,GAAG,IAAI,CAAC,GACrC,eAAe,QAAQ,QAAQ,CAAC,CAClC;IAEJ,KAAK,SACH,QAAQ,GAAG,SACF,qBAAqB,OAAO,MAAM,GAAG,IAAI,CAAC;IAGrD,KAAK,UACH,QAAQ,GAAG,SAAuD;KAChE,IAAM,SAAS,OAAO,OAAO,GAAG,IAAI;KAIpC,OADI,KAAK,KAAW,qBAAqB,MAAM,IACxC;IACT;IAEF,KAAK,cACH,QAAQ,GAAG,SACF,qBAAqB,OAAO,WAAW,GAAG,IAAI,CAAC;IAG1D,SACE,OAAO,OAAO;GAElB;EACF,EACF,CAAC;CACH;CAEA,OAAO;AACT"}
1
+ {"version":3,"file":"client.js","sources":["../src/client/concurrency-limiter/createClientConcurrencyLimiter.ts"],"sourcesContent":["import {type ObservableSanityClient, type SanityClient} from '@sanity/client'\nimport {finalize, from, switchMap} from 'rxjs'\n\nimport {ConcurrencyLimiter} from '../../concurrency-limiter'\n\n/**\n * Decorates a sanity client to limit the concurrency of `client.fetch`\n * requests. Keeps the concurrency limit state and returns wrapped clients with\n * that same state if the `clone` `config` or `withConfig` methods are called.\n */\nexport function createClientConcurrencyLimiter(\n maxConcurrency: number,\n): (input: SanityClient) => SanityClient {\n const limiter = new ConcurrencyLimiter(maxConcurrency)\n\n function wrapClient(client: SanityClient): SanityClient {\n return new Proxy(client, {\n get: (target, property) => {\n switch (property) {\n case 'fetch': {\n return async (...args: Parameters<SanityClient['fetch']>) => {\n await limiter.ready()\n try {\n // note we want to await before we return so the finally block\n // will run after the promise has been fulfilled or rejected\n return await target.fetch(...args)\n } finally {\n limiter.release()\n }\n }\n }\n case 'clone': {\n return (...args: Parameters<SanityClient['clone']>) => {\n return wrapClient(target.clone(...args))\n }\n }\n case 'config': {\n return (...args: Parameters<SanityClient['config']>) => {\n const result = target.config(...args)\n\n // if there is a config, it returns a client so we need to wrap again\n if (args[0]) return wrapClient(result)\n return result\n }\n }\n case 'withConfig': {\n return (...args: Parameters<SanityClient['withConfig']>) => {\n return wrapClient(target.withConfig(...args))\n }\n }\n case 'observable': {\n return wrapObservableClient(target.observable)\n }\n default: {\n return target[property as keyof SanityClient]\n }\n }\n },\n })\n }\n\n function wrapObservableClient(\n observableSanityClient: ObservableSanityClient,\n ): ObservableSanityClient {\n return new Proxy(observableSanityClient, {\n get: (target, property) => {\n switch (property) {\n case 'fetch': {\n return (...args: Parameters<ObservableSanityClient['fetch']>) =>\n from(limiter.ready()).pipe(\n switchMap(() => target.fetch(...args)),\n finalize(() => limiter.release()),\n )\n }\n case 'clone': {\n return (...args: Parameters<ObservableSanityClient['clone']>) => {\n return wrapObservableClient(target.clone(...args))\n }\n }\n case 'config': {\n return (...args: Parameters<ObservableSanityClient['config']>) => {\n const result = target.config(...args)\n\n // if there is a config, it returns a client so we need to wrap again\n if (args[0]) return wrapObservableClient(result)\n return result\n }\n }\n case 'withConfig': {\n return (...args: Parameters<ObservableSanityClient['withConfig']>) => {\n return wrapObservableClient(target.withConfig(...args))\n }\n }\n default: {\n return target[property as keyof ObservableSanityClient]\n }\n }\n },\n })\n }\n\n return wrapClient\n}\n"],"names":[],"mappings":";;AAUO,SAAS,+BACd,gBACuC;AACvC,QAAM,UAAU,IAAI,mBAAmB,cAAc;AAErD,WAAS,WAAW,QAAoC;AACtD,WAAO,IAAI,MAAM,QAAQ;AAAA,MACvB,KAAK,CAAC,QAAQ,aAAa;AACzB,gBAAQ,UAAA;AAAA,UACN,KAAK;AACH,mBAAO,UAAU,SAA4C;AAC3D,oBAAM,QAAQ,MAAA;AACd,kBAAI;AAGF,uBAAO,MAAM,OAAO,MAAM,GAAG,IAAI;AAAA,cACnC,UAAA;AACE,wBAAQ,QAAA;AAAA,cACV;AAAA,YACF;AAAA,UAEF,KAAK;AACH,mBAAO,IAAI,SACF,WAAW,OAAO,MAAM,GAAG,IAAI,CAAC;AAAA,UAG3C,KAAK;AACH,mBAAO,IAAI,SAA6C;AACtD,oBAAM,SAAS,OAAO,OAAO,GAAG,IAAI;AAGpC,qBAAI,KAAK,CAAC,IAAU,WAAW,MAAM,IAC9B;AAAA,YACT;AAAA,UAEF,KAAK;AACH,mBAAO,IAAI,SACF,WAAW,OAAO,WAAW,GAAG,IAAI,CAAC;AAAA,UAGhD,KAAK;AACH,mBAAO,qBAAqB,OAAO,UAAU;AAAA,UAE/C;AACE,mBAAO,OAAO,QAA8B;AAAA,QAAA;AAAA,MAGlD;AAAA,IAAA,CACD;AAAA,EACH;AAEA,WAAS,qBACP,wBACwB;AACxB,WAAO,IAAI,MAAM,wBAAwB;AAAA,MACvC,KAAK,CAAC,QAAQ,aAAa;AACzB,gBAAQ,UAAA;AAAA,UACN,KAAK;AACH,mBAAO,IAAI,SACT,KAAK,QAAQ,MAAA,CAAO,EAAE;AAAA,cACpB,UAAU,MAAM,OAAO,MAAM,GAAG,IAAI,CAAC;AAAA,cACrC,SAAS,MAAM,QAAQ,QAAA,CAAS;AAAA,YAAA;AAAA,UAGtC,KAAK;AACH,mBAAO,IAAI,SACF,qBAAqB,OAAO,MAAM,GAAG,IAAI,CAAC;AAAA,UAGrD,KAAK;AACH,mBAAO,IAAI,SAAuD;AAChE,oBAAM,SAAS,OAAO,OAAO,GAAG,IAAI;AAGpC,qBAAI,KAAK,CAAC,IAAU,qBAAqB,MAAM,IACxC;AAAA,YACT;AAAA,UAEF,KAAK;AACH,mBAAO,IAAI,SACF,qBAAqB,OAAO,WAAW,GAAG,IAAI,CAAC;AAAA,UAG1D;AACE,mBAAO,OAAO,QAAwC;AAAA,QAAA;AAAA,MAG5D;AAAA,IAAA,CACD;AAAA,EACH;AAEA,SAAO;AACT;"}
@@ -18,5 +18,4 @@ declare class ConcurrencyLimiter {
18
18
  */
19
19
  release: () => void;
20
20
  }
21
- export { ConcurrencyLimiter };
22
- //# sourceMappingURL=concurrency-limiter.d.ts.map
21
+ export { ConcurrencyLimiter };
@@ -1,2 +1,32 @@
1
- import { t as ConcurrencyLimiter } from "./concurrency-limiter-C6gDjN0m.js";
2
- export { ConcurrencyLimiter };
1
+ class ConcurrencyLimiter {
2
+ current = 0;
3
+ resolvers = [];
4
+ max;
5
+ constructor(max) {
6
+ this.max = max;
7
+ }
8
+ /**
9
+ * Indicates when a slot for a new operation is ready.
10
+ * If under the limit, it resolves immediately; otherwise, it waits until a slot is free.
11
+ */
12
+ ready = () => this.max === 1 / 0 ? Promise.resolve() : this.current < this.max ? (this.current++, Promise.resolve()) : new Promise((resolve) => {
13
+ this.resolvers.push(resolve);
14
+ });
15
+ /**
16
+ * Releases a slot, decrementing the current count of operations if nothing is in the queue.
17
+ * If there are operations waiting, it allows the next one in the queue to proceed.
18
+ */
19
+ release = () => {
20
+ if (this.max === 1 / 0) return;
21
+ const nextResolver = this.resolvers.shift();
22
+ if (nextResolver) {
23
+ nextResolver();
24
+ return;
25
+ }
26
+ this.current = Math.max(0, this.current - 1);
27
+ };
28
+ }
29
+ export {
30
+ ConcurrencyLimiter
31
+ };
32
+ //# sourceMappingURL=concurrency-limiter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"concurrency-limiter.js","sources":["../src/concurrency-limiter.ts"],"sourcesContent":["/**\n * ConcurrencyLimiter manages the number of concurrent operations that can be performed.\n * It ensures that the number of operations does not exceed a specified maximum limit.\n */\nexport class ConcurrencyLimiter {\n current = 0\n resolvers: Array<() => void> = []\n public max: number\n constructor(max: number) {\n this.max = max\n }\n\n /**\n * Indicates when a slot for a new operation is ready.\n * If under the limit, it resolves immediately; otherwise, it waits until a slot is free.\n */\n ready = (): Promise<void> => {\n if (this.max === Infinity) return Promise.resolve()\n\n if (this.current < this.max) {\n this.current++\n return Promise.resolve()\n }\n\n return new Promise<void>((resolve) => {\n this.resolvers.push(resolve)\n })\n }\n\n /**\n * Releases a slot, decrementing the current count of operations if nothing is in the queue.\n * If there are operations waiting, it allows the next one in the queue to proceed.\n */\n release = (): void => {\n if (this.max === Infinity) return\n\n const nextResolver = this.resolvers.shift()\n if (nextResolver) {\n nextResolver()\n return\n }\n\n this.current = Math.max(0, this.current - 1)\n }\n}\n"],"names":[],"mappings":"AAIO,MAAM,mBAAmB;AAAA,EAC9B,UAAU;AAAA,EACV,YAA+B,CAAA;AAAA,EACxB;AAAA,EACP,YAAY,KAAa;AACvB,SAAK,MAAM;AAAA,EACb;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,QAAQ,MACF,KAAK,QAAQ,QAAiB,QAAQ,QAAA,IAEtC,KAAK,UAAU,KAAK,OACtB,KAAK,WACE,QAAQ,aAGV,IAAI,QAAc,CAAC,YAAY;AACpC,SAAK,UAAU,KAAK,OAAO;AAAA,EAC7B,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA,EAOH,UAAU,MAAY;AACpB,QAAI,KAAK,QAAQ,MAAU;AAE3B,UAAM,eAAe,KAAK,UAAU,MAAA;AACpC,QAAI,cAAc;AAChB,mBAAA;AACA;AAAA,IACF;AAEA,SAAK,UAAU,KAAK,IAAI,GAAG,KAAK,UAAU,CAAC;AAAA,EAC7C;AACF;"}
package/lib/content.d.ts CHANGED
@@ -33,5 +33,4 @@ declare function isShallowEmptyObject(value: {
33
33
  }): boolean;
34
34
  declare function randomKey(length?: number): string;
35
35
  declare function resolveTypeName(value: unknown): string;
36
- export { isDeepEmpty, isEmpty, isEmptyArray, isEmptyObject, isShallowEmptyObject, randomKey, resolveTypeName };
37
- //# sourceMappingURL=content.d.ts.map
36
+ export { isDeepEmpty, isEmpty, isEmptyArray, isEmptyObject, isShallowEmptyObject, randomKey, resolveTypeName };
package/lib/content.js CHANGED
@@ -1,75 +1,88 @@
1
- var hasOwn_default = Object.prototype.hasOwnProperty.call.bind(Object.prototype.hasOwnProperty);
1
+ var hasOwn = Object.prototype.hasOwnProperty.call.bind(Object.prototype.hasOwnProperty);
2
2
  function isDeepEmptyObject(value) {
3
- for (let key in value) if (key !== "_type" && key !== "_key" && hasOwn_default(value, key) && !isDeepEmpty(value[key])) return !1;
4
- return !0;
3
+ for (const key in value)
4
+ if (!(key === "_type" || key === "_key") && hasOwn(value, key) && !isDeepEmpty(value[key]))
5
+ return !1;
6
+ return !0;
5
7
  }
6
8
  function isDeepEmptyArray(value) {
7
- for (let i = 0; i < value.length; i++) if (!isDeepEmpty(value[i])) return !1;
8
- return !0;
9
+ for (let i = 0; i < value.length; i++)
10
+ if (!isDeepEmpty(value[i]))
11
+ return !1;
12
+ return !0;
9
13
  }
10
- /**
11
- * Looks at the value and determines if it is deeply empty while not considering _type and _key attributes on objects.
12
- * A value will be considered deeply empty if it is:
13
- * - undefined or null
14
- * - an object where all property values are deeply empty
15
- * - an array where all items are deeply empty
16
- * @param value - the value to check for deep emptiness
17
- */
18
14
  function isDeepEmpty(value) {
19
- if (value == null) return !0;
20
- let type = typeof value;
21
- return Array.isArray(value) ? isDeepEmptyArray(value) : type === "object" && isDeepEmptyObject(value);
15
+ if (value == null)
16
+ return !0;
17
+ const type = typeof value;
18
+ return Array.isArray(value) ? isDeepEmptyArray(value) : type === "object" ? isDeepEmptyObject(value) : !1;
22
19
  }
23
- /**
24
- * @deprecated Use `isDeepEmpty` instead
25
- * todo: remove in v4
26
- */
27
20
  const isEmptyArray = isDeepEmptyArray, isEmpty = isDeepEmpty, isEmptyObject = isDeepEmptyObject;
28
21
  function isShallowEmptyObject(value) {
29
- for (let key in value) if (key !== "_type" && key !== "_key" && hasOwn_default(value, key) && value[key] !== void 0) return !1;
30
- return !0;
22
+ for (const key in value)
23
+ if (!(key === "_type" || key === "_key") && hasOwn(value, key) && value[key] !== void 0)
24
+ return !1;
25
+ return !0;
31
26
  }
32
- const getByteHexTable = (() => {
33
- let table;
34
- return () => {
35
- if (table) return table;
36
- table = [];
37
- for (let i = 0; i < 256; ++i) table[i] = (i + 256).toString(16).slice(1);
38
- return table;
39
- };
27
+ const getByteHexTable = /* @__PURE__ */ (() => {
28
+ let table;
29
+ return () => {
30
+ if (table)
31
+ return table;
32
+ table = [];
33
+ for (let i = 0; i < 256; ++i)
34
+ table[i] = (i + 256).toString(16).slice(1);
35
+ return table;
36
+ };
40
37
  })();
41
38
  function whatwgRNG(length = 16) {
42
- let rnds8 = new Uint8Array(length);
43
- return crypto.getRandomValues(rnds8), rnds8;
39
+ const rnds8 = new Uint8Array(length);
40
+ return crypto.getRandomValues(rnds8), rnds8;
44
41
  }
45
42
  function randomKey(length) {
46
- let table = getByteHexTable();
47
- return whatwgRNG(length).reduce((str, n) => str + table[n], "").slice(0, length);
43
+ const table = getByteHexTable();
44
+ return whatwgRNG(length).reduce((str, n) => str + table[n], "").slice(0, length);
48
45
  }
49
46
  const toString = Object.prototype.toString;
50
47
  function resolveJSType(val) {
51
- switch (toString.call(val)) {
52
- case "[object Function]": return "function";
53
- case "[object Date]": return "date";
54
- case "[object RegExp]": return "regexp";
55
- case "[object Arguments]": return "arguments";
56
- case "[object Array]": return "array";
57
- case "[object String]": return "string";
58
- default:
59
- }
60
- if (typeof val == "object" && val && typeof val.length == "number") try {
61
- if (typeof val.callee == "function") return "arguments";
62
- } catch (ex) {
63
- if (ex instanceof TypeError) return "arguments";
64
- }
65
- return val === null ? "null" : val === void 0 ? "undefined" : val && val.nodeType === 1 ? "element" : val === Object(val) ? "object" : typeof val;
48
+ switch (toString.call(val)) {
49
+ case "[object Function]":
50
+ return "function";
51
+ case "[object Date]":
52
+ return "date";
53
+ case "[object RegExp]":
54
+ return "regexp";
55
+ case "[object Arguments]":
56
+ return "arguments";
57
+ case "[object Array]":
58
+ return "array";
59
+ case "[object String]":
60
+ return "string";
61
+ }
62
+ if (typeof val == "object" && val && typeof val.length == "number")
63
+ try {
64
+ if (typeof val.callee == "function")
65
+ return "arguments";
66
+ } catch (ex) {
67
+ if (ex instanceof TypeError)
68
+ return "arguments";
69
+ }
70
+ return val === null ? "null" : val === void 0 ? "undefined" : val && val.nodeType === 1 ? "element" : val === Object(val) ? "object" : typeof val;
66
71
  }
67
72
  function resolveTypeName(value) {
68
- let jsType = resolveJSType(value);
69
- if (jsType !== "object") return jsType;
70
- let obj = value;
71
- return "_type" in obj && obj._type || jsType;
73
+ const jsType = resolveJSType(value);
74
+ if (jsType !== "object")
75
+ return jsType;
76
+ const obj = value;
77
+ return "_type" in obj && obj._type || jsType;
72
78
  }
73
- export { isDeepEmpty, isEmpty, isEmptyArray, isEmptyObject, isShallowEmptyObject, randomKey, resolveTypeName };
74
-
75
- //# sourceMappingURL=content.js.map
79
+ export {
80
+ isDeepEmpty,
81
+ isEmpty,
82
+ isEmptyArray,
83
+ isEmptyObject,
84
+ isShallowEmptyObject,
85
+ randomKey,
86
+ resolveTypeName
87
+ };
88
+ //# sourceMappingURL=content.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"content.js","names":["hasOwn","hasOwn"],"sources":["../src/content/hasOwn.ts","../src/content/isDeepEmpty.ts","../src/content/isShallowEmptyObject.ts","../src/content/randomKey.ts","../src/content/resolveJSType.ts","../src/content/resolveTypeName.ts"],"sourcesContent":["export default Object.prototype.hasOwnProperty.call.bind(Object.prototype.hasOwnProperty)\n","import hasOwn from './hasOwn'\n\nfunction isDeepEmptyObject(value: {[key: string]: any}): boolean {\n for (const key in value) {\n if (key === '_type' || key === '_key') {\n continue\n }\n if (hasOwn(value, key) && !isDeepEmpty(value[key])) {\n return false\n }\n }\n return true\n}\n\nfunction isDeepEmptyArray(value: unknown[]): boolean {\n for (let i = 0; i < value.length; i++) {\n if (!isDeepEmpty(value[i])) {\n return false\n }\n }\n return true\n}\n\n/**\n * Looks at the value and determines if it is deeply empty while not considering _type and _key attributes on objects.\n * A value will be considered deeply empty if it is:\n * - undefined or null\n * - an object where all property values are deeply empty\n * - an array where all items are deeply empty\n * @param value - the value to check for deep emptiness\n */\nexport function isDeepEmpty(value: unknown): boolean {\n if (value === undefined || value === null) {\n return true\n }\n const type = typeof value\n\n if (Array.isArray(value)) {\n return isDeepEmptyArray(value)\n }\n if (type === 'object') {\n return isDeepEmptyObject(value)\n }\n return false\n}\n\n/**\n * @deprecated Use `isDeepEmpty` instead\n * todo: remove in v4\n */\nexport const isEmptyArray = isDeepEmptyArray\n/* oxlint-disable tsdoc/syntax */\n/**\n * @deprecated Use `isDeepEmpty` instead\n * todo: remove in v4\n * @alias\n */\nexport const isEmpty = isDeepEmpty\n/* oxlint-enable tsdoc/syntax */\n\n/**\n * @deprecated Use `isDeepEmpty` instead\n * todo: remove in v4\n *\n */\nexport const isEmptyObject = isDeepEmptyObject\n","import hasOwn from './hasOwn'\n\nexport function isShallowEmptyObject(value: {[key: string]: unknown}): boolean {\n for (const key in value) {\n if (key === '_type' || key === '_key') {\n continue\n }\n if (hasOwn(value, key) && value[key] !== undefined) {\n return false\n }\n }\n return true\n}\n","const getByteHexTable = (() => {\n let table: string[]\n return () => {\n if (table) {\n return table\n }\n\n table = []\n for (let i = 0; i < 256; ++i) {\n table[i] = (i + 0x100).toString(16).slice(1)\n }\n return table\n }\n})()\n\n// WHATWG crypto RNG - https://w3c.github.io/webcrypto/Overview.html\nfunction whatwgRNG(length = 16) {\n const rnds8 = new Uint8Array(length)\n crypto.getRandomValues(rnds8)\n return rnds8\n}\n\nexport function randomKey(length?: number): string {\n const table = getByteHexTable()\n return whatwgRNG(length)\n .reduce((str, n) => str + table[n], '')\n .slice(0, length)\n}\n","const toString = Object.prototype.toString\n// Copied from https://github.com/ForbesLindesay/type-of, but inlined to have fine grained control\n\nexport function resolveJSType(val: unknown) {\n switch (toString.call(val)) {\n case '[object Function]':\n return 'function'\n case '[object Date]':\n return 'date'\n case '[object RegExp]':\n return 'regexp'\n case '[object Arguments]':\n return 'arguments'\n case '[object Array]':\n return 'array'\n case '[object String]':\n return 'string'\n default:\n }\n\n if (typeof val == 'object' && val && typeof (val as any).length == 'number') {\n try {\n if (typeof (val as any).callee == 'function') {\n return 'arguments'\n }\n } catch (ex) {\n if (ex instanceof TypeError) {\n return 'arguments'\n }\n }\n }\n\n if (val === null) {\n return 'null'\n }\n\n if (val === undefined) {\n return 'undefined'\n }\n\n if (val && (val as any).nodeType === 1) {\n return 'element'\n }\n\n if (val === Object(val)) {\n return 'object'\n }\n\n return typeof val\n}\n","import {resolveJSType} from './resolveJSType'\n\nexport function resolveTypeName(value: unknown): string {\n const jsType = resolveJSType(value)\n if (jsType !== 'object') {\n return jsType\n }\n\n const obj = value as Record<string, unknown> & {_type?: string}\n return ('_type' in obj && obj._type) || jsType\n}\n"],"mappings":"AAAA,IAAA,iBAAe,OAAO,UAAU,eAAe,KAAK,KAAK,OAAO,UAAU,cAAc;ACExF,SAAS,kBAAkB,OAAsC;CAC/D,KAAK,IAAM,OAAO,OACZ,YAAQ,WAAW,QAAQ,UAG3BA,eAAO,OAAO,GAAG,KAAK,CAAC,YAAY,MAAM,IAAI,GAC/C,OAAO;CAGX,OAAO;AACT;AAEA,SAAS,iBAAiB,OAA2B;CACnD,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAChC,IAAI,CAAC,YAAY,MAAM,EAAE,GACvB,OAAO;CAGX,OAAO;AACT;;;;;;;;;AAUA,SAAgB,YAAY,OAAyB;CACnD,IAAI,SAAiC,MACnC,OAAO;CAET,IAAM,OAAO,OAAO;CAQpB,OANI,MAAM,QAAQ,KAAK,IACd,iBAAiB,KAAK,IAE3B,SAAS,YACJ,kBAAkB,KAAK;AAGlC;;;;;AAMA,MAAa,eAAe,kBAOf,UAAU,aAQV,gBAAgB;AC/D7B,SAAgB,qBAAqB,OAA0C;CAC7E,KAAK,IAAM,OAAO,OACZ,YAAQ,WAAW,QAAQ,UAG3BC,eAAO,OAAO,GAAG,KAAK,MAAM,SAAS,KAAA,GACvC,OAAO;CAGX,OAAO;AACT;ACZA,MAAM,yBAAyB;CAC7B,IAAI;CACJ,aAAa;EACX,IAAI,OACF,OAAO;EAGT,QAAQ,CAAC;EACT,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,EAAE,GACzB,MAAM,MAAM,IAAI,IAAA,CAAO,SAAS,EAAE,CAAC,CAAC,MAAM,CAAC;EAE7C,OAAO;CACT;AACF,EAAA,CAAG;AAGH,SAAS,UAAU,SAAS,IAAI;CAC9B,IAAM,QAAQ,IAAI,WAAW,MAAM;CAEnC,OADA,OAAO,gBAAgB,KAAK,GACrB;AACT;AAEA,SAAgB,UAAU,QAAyB;CACjD,IAAM,QAAQ,gBAAgB;CAC9B,OAAO,UAAU,MAAM,CAAC,CACrB,QAAQ,KAAK,MAAM,MAAM,MAAM,IAAI,EAAE,CAAC,CACtC,MAAM,GAAG,MAAM;AACpB;AC3BA,MAAM,WAAW,OAAO,UAAU;AAGlC,SAAgB,cAAc,KAAc;CAC1C,QAAQ,SAAS,KAAK,GAAG,GAAzB;EACE,KAAK,qBACH,OAAO;EACT,KAAK,iBACH,OAAO;EACT,KAAK,mBACH,OAAO;EACT,KAAK,sBACH,OAAO;EACT,KAAK,kBACH,OAAO;EACT,KAAK,mBACH,OAAO;EACT;CACF;CAEA,IAAI,OAAO,OAAO,YAAY,OAAO,OAAQ,IAAY,UAAU,UACjE,IAAI;EACF,IAAI,OAAQ,IAAY,UAAU,YAChC,OAAO;CAEX,SAAS,IAAI;EACX,IAAI,cAAc,WAChB,OAAO;CAEX;CAmBF,OAhBI,QAAQ,OACH,SAGL,QAAQ,KAAA,IACH,cAGL,OAAQ,IAAY,aAAa,IAC5B,YAGL,QAAQ,OAAO,GAAG,IACb,WAGF,OAAO;AAChB;AC/CA,SAAgB,gBAAgB,OAAwB;CACtD,IAAM,SAAS,cAAc,KAAK;CAClC,IAAI,WAAW,UACb,OAAO;CAGT,IAAM,MAAM;CACZ,OAAQ,WAAW,OAAO,IAAI,SAAU;AAC1C"}
1
+ {"version":3,"file":"content.js","sources":["../src/content/hasOwn.ts","../src/content/isDeepEmpty.ts","../src/content/isShallowEmptyObject.ts","../src/content/randomKey.ts","../src/content/resolveJSType.ts","../src/content/resolveTypeName.ts"],"sourcesContent":["export default Object.prototype.hasOwnProperty.call.bind(Object.prototype.hasOwnProperty)\n","import hasOwn from './hasOwn'\n\nfunction isDeepEmptyObject(value: {[key: string]: any}): boolean {\n for (const key in value) {\n if (key === '_type' || key === '_key') {\n continue\n }\n if (hasOwn(value, key) && !isDeepEmpty(value[key])) {\n return false\n }\n }\n return true\n}\n\nfunction isDeepEmptyArray(value: unknown[]): boolean {\n for (let i = 0; i < value.length; i++) {\n if (!isDeepEmpty(value[i])) {\n return false\n }\n }\n return true\n}\n\n/**\n * Looks at the value and determines if it is deeply empty while not considering _type and _key attributes on objects.\n * A value will be considered deeply empty if it is:\n * - undefined or null\n * - an object where all property values are deeply empty\n * - an array where all items are deeply empty\n * @param value - the value to check for deep emptiness\n */\nexport function isDeepEmpty(value: unknown): boolean {\n if (value === undefined || value === null) {\n return true\n }\n const type = typeof value\n\n if (Array.isArray(value)) {\n return isDeepEmptyArray(value)\n }\n if (type === 'object') {\n return isDeepEmptyObject(value)\n }\n return false\n}\n\n/**\n * @deprecated Use `isDeepEmpty` instead\n * todo: remove in v4\n */\nexport const isEmptyArray = isDeepEmptyArray\n/* oxlint-disable tsdoc/syntax */\n/**\n * @deprecated Use `isDeepEmpty` instead\n * todo: remove in v4\n * @alias\n */\nexport const isEmpty = isDeepEmpty\n/* oxlint-enable tsdoc/syntax */\n\n/**\n * @deprecated Use `isDeepEmpty` instead\n * todo: remove in v4\n *\n */\nexport const isEmptyObject = isDeepEmptyObject\n","import hasOwn from './hasOwn'\n\nexport function isShallowEmptyObject(value: {[key: string]: unknown}): boolean {\n for (const key in value) {\n if (key === '_type' || key === '_key') {\n continue\n }\n if (hasOwn(value, key) && value[key] !== undefined) {\n return false\n }\n }\n return true\n}\n","const getByteHexTable = (() => {\n let table: string[]\n return () => {\n if (table) {\n return table\n }\n\n table = []\n for (let i = 0; i < 256; ++i) {\n table[i] = (i + 0x100).toString(16).slice(1)\n }\n return table\n }\n})()\n\n// WHATWG crypto RNG - https://w3c.github.io/webcrypto/Overview.html\nfunction whatwgRNG(length = 16) {\n const rnds8 = new Uint8Array(length)\n crypto.getRandomValues(rnds8)\n return rnds8\n}\n\nexport function randomKey(length?: number): string {\n const table = getByteHexTable()\n return whatwgRNG(length)\n .reduce((str, n) => str + table[n], '')\n .slice(0, length)\n}\n","const toString = Object.prototype.toString\n// Copied from https://github.com/ForbesLindesay/type-of, but inlined to have fine grained control\n\nexport function resolveJSType(val: unknown) {\n switch (toString.call(val)) {\n case '[object Function]':\n return 'function'\n case '[object Date]':\n return 'date'\n case '[object RegExp]':\n return 'regexp'\n case '[object Arguments]':\n return 'arguments'\n case '[object Array]':\n return 'array'\n case '[object String]':\n return 'string'\n default:\n }\n\n if (typeof val == 'object' && val && typeof (val as any).length == 'number') {\n try {\n if (typeof (val as any).callee == 'function') {\n return 'arguments'\n }\n } catch (ex) {\n if (ex instanceof TypeError) {\n return 'arguments'\n }\n }\n }\n\n if (val === null) {\n return 'null'\n }\n\n if (val === undefined) {\n return 'undefined'\n }\n\n if (val && (val as any).nodeType === 1) {\n return 'element'\n }\n\n if (val === Object(val)) {\n return 'object'\n }\n\n return typeof val\n}\n","import {resolveJSType} from './resolveJSType'\n\nexport function resolveTypeName(value: unknown): string {\n const jsType = resolveJSType(value)\n if (jsType !== 'object') {\n return jsType\n }\n\n const obj = value as Record<string, unknown> & {_type?: string}\n return ('_type' in obj && obj._type) || jsType\n}\n"],"names":[],"mappings":"AAAA,IAAA,SAAe,OAAO,UAAU,eAAe,KAAK,KAAK,OAAO,UAAU,cAAc;ACExF,SAAS,kBAAkB,OAAsC;AAC/D,aAAW,OAAO;AAChB,QAAI,EAAA,QAAQ,WAAW,QAAQ,WAG3B,OAAO,OAAO,GAAG,KAAK,CAAC,YAAY,MAAM,GAAG,CAAC;AAC/C,aAAO;AAGX,SAAO;AACT;AAEA,SAAS,iBAAiB,OAA2B;AACnD,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ;AAChC,QAAI,CAAC,YAAY,MAAM,CAAC,CAAC;AACvB,aAAO;AAGX,SAAO;AACT;AAUO,SAAS,YAAY,OAAyB;AACnD,MAA2B,SAAU;AACnC,WAAO;AAET,QAAM,OAAO,OAAO;AAEpB,SAAI,MAAM,QAAQ,KAAK,IACd,iBAAiB,KAAK,IAE3B,SAAS,WACJ,kBAAkB,KAAK,IAEzB;AACT;AAMO,MAAM,eAAe,kBAOf,UAAU,aAQV,gBAAgB;AC/DtB,SAAS,qBAAqB,OAA0C;AAC7E,aAAW,OAAO;AAChB,QAAI,EAAA,QAAQ,WAAW,QAAQ,WAG3B,OAAO,OAAO,GAAG,KAAK,MAAM,GAAG,MAAM;AACvC,aAAO;AAGX,SAAO;AACT;ACZA,MAAM,kBAAmB,uBAAM;AAC7B,MAAI;AACJ,SAAO,MAAM;AACX,QAAI;AACF,aAAO;AAGT,YAAQ,CAAA;AACR,aAAS,IAAI,GAAG,IAAI,KAAK,EAAE;AACzB,YAAM,CAAC,KAAK,IAAI,KAAO,SAAS,EAAE,EAAE,MAAM,CAAC;AAE7C,WAAO;AAAA,EACT;AACF,GAAA;AAGA,SAAS,UAAU,SAAS,IAAI;AAC9B,QAAM,QAAQ,IAAI,WAAW,MAAM;AACnC,SAAA,OAAO,gBAAgB,KAAK,GACrB;AACT;AAEO,SAAS,UAAU,QAAyB;AACjD,QAAM,QAAQ,gBAAA;AACd,SAAO,UAAU,MAAM,EACpB,OAAO,CAAC,KAAK,MAAM,MAAM,MAAM,CAAC,GAAG,EAAE,EACrC,MAAM,GAAG,MAAM;AACpB;AC3BA,MAAM,WAAW,OAAO,UAAU;AAG3B,SAAS,cAAc,KAAc;AAC1C,UAAQ,SAAS,KAAK,GAAG,GAAA;AAAA,IACvB,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,EACT;AAGF,MAAI,OAAO,OAAO,YAAY,OAAO,OAAQ,IAAY,UAAU;AACjE,QAAI;AACF,UAAI,OAAQ,IAAY,UAAU;AAChC,eAAO;AAAA,IAEX,SAAS,IAAI;AACX,UAAI,cAAc;AAChB,eAAO;AAAA,IAEX;AAGF,SAAI,QAAQ,OACH,SAGL,QAAQ,SACH,cAGL,OAAQ,IAAY,aAAa,IAC5B,YAGL,QAAQ,OAAO,GAAG,IACb,WAGF,OAAO;AAChB;AC/CO,SAAS,gBAAgB,OAAwB;AACtD,QAAM,SAAS,cAAc,KAAK;AAClC,MAAI,WAAW;AACb,WAAO;AAGT,QAAM,MAAM;AACZ,SAAQ,WAAW,OAAO,IAAI,SAAU;AAC1C;"}
@@ -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,14 @@
1
+ interface Options {
2
+ errorLabel: string;
3
+ }
4
+ type Parser<Type> = (line: string) => Type;
5
+ /**
6
+ * Create a safe JSON parser that is able to handle lines interrupted by an error object.
7
+ *
8
+ * This may occur when streaming NDJSON from the Export HTTP API.
9
+ *
10
+ * @internal
11
+ * @see {@link https://github.com/sanity-io/sanity/pull/1787 | Initial pull request}
12
+ */
13
+ declare function createSafeJsonParser<Type>({ errorLabel }: Options): Parser<Type>;
14
+ export { createSafeJsonParser };
@@ -11,5 +11,4 @@ type Parser<Type> = (line: string) => Type;
11
11
  * @see {@link https://github.com/sanity-io/sanity/pull/1787 | Initial pull request}
12
12
  */
13
13
  declare function createSafeJsonParser<Type>({ errorLabel }: Options): Parser<Type>;
14
- export { createSafeJsonParser };
15
- //# sourceMappingURL=createSafeJsonParser.d.ts.map
14
+ export { createSafeJsonParser };
@@ -1,23 +1,20 @@
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
1
  function createSafeJsonParser({ errorLabel }) {
10
- return function(line) {
11
- try {
12
- return JSON.parse(line);
13
- } catch (err) {
14
- let errorPosition = line.lastIndexOf("{\"error\":");
15
- if (errorPosition === -1) throw err.message = `${err.message} (${line})`, err;
16
- let errorJson = line.slice(errorPosition), errorLine = JSON.parse(errorJson), error = errorLine && errorLine.error;
17
- throw error && error.description ? Error(`${errorLabel}: ${error.description}\n\n${errorJson}\n`, { cause: err }) : err;
18
- }
19
- };
20
- }
21
- export { createSafeJsonParser };
2
+ return function(line) {
3
+ try {
4
+ return JSON.parse(line);
5
+ } catch (err) {
6
+ const errorPosition = line.lastIndexOf('{"error":');
7
+ if (errorPosition === -1)
8
+ throw err.message = `${err.message} (${line})`, err;
9
+ const errorJson = line.slice(errorPosition), errorLine = JSON.parse(errorJson), error = errorLine && errorLine.error;
10
+ throw error && error.description ? new Error(`${errorLabel}: ${error.description}
22
11
 
23
- //# sourceMappingURL=createSafeJsonParser.js.map
12
+ ${errorJson}
13
+ `, { cause: err }) : err;
14
+ }
15
+ };
16
+ }
17
+ export {
18
+ createSafeJsonParser
19
+ };
20
+ //# sourceMappingURL=createSafeJsonParser.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"createSafeJsonParser.js","names":[],"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"],"mappings":";;;;;;;;AAcA,SAAgB,qBAA2B,EAAC,cAAoC;CAC9E,OAAO,SAAwB,MAAM;EACnC,IAAI;GACF,OAAO,KAAK,MAAM,IAAI;EACxB,SAAS,KAAK;GAEZ,IAAM,gBAAgB,KAAK,YAAY,aAAW;GAClD,IAAI,kBAAkB,IAEpB,MADA,IAAI,UAAU,GAAG,IAAI,QAAQ,IAAI,KAAK,IAChC;GAGR,IAAM,YAAY,KAAK,MAAM,aAAa,GACpC,YAAY,KAAK,MAAM,SAAS,GAChC,QAAQ,aAAa,UAAU;GAKrC,MAJI,SAAS,MAAM,cACP,MAAM,GAAG,WAAW,IAAI,MAAM,YAAY,MAAM,UAAU,KAAK,EAAC,OAAO,IAAG,CAAC,IAGjF;EACR;CACF;AACF"}
1
+ {"version":3,"file":"createSafeJsonParser.js","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;"}
package/lib/fs.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  declare function pathIsEmpty(dir: string): Promise<boolean>;
2
2
  declare function expandHome(filePath: string): string;
3
3
  declare function absolutify(dir: string): string;
4
- export { absolutify, expandHome, pathIsEmpty };
5
- //# sourceMappingURL=fs.d.ts.map
4
+ export { absolutify, expandHome, pathIsEmpty };
package/lib/fs.js CHANGED
@@ -2,25 +2,30 @@ import fs from "node:fs/promises";
2
2
  import os from "node:os";
3
3
  import path from "node:path";
4
4
  async function pathIsEmpty(dir) {
5
- try {
6
- return (await fs.readdir(absolutify(dir))).length === 0;
7
- } catch (err) {
8
- if (err.code === "ENOENT") return !0;
9
- throw err;
10
- }
5
+ try {
6
+ return (await fs.readdir(absolutify(dir))).length === 0;
7
+ } catch (err) {
8
+ if (err.code === "ENOENT")
9
+ return !0;
10
+ throw err;
11
+ }
11
12
  }
12
13
  function expandHome(filePath) {
13
- if (filePath.charCodeAt(0) === 126) {
14
- if (filePath.charCodeAt(1) === 43) return path.join(process.cwd(), filePath.slice(2));
15
- let home = os.homedir();
16
- return home ? path.join(home, filePath.slice(1)) : filePath;
17
- }
18
- return filePath;
14
+ if (filePath.charCodeAt(0) === 126) {
15
+ if (filePath.charCodeAt(1) === 43)
16
+ return path.join(process.cwd(), filePath.slice(2));
17
+ const home = os.homedir();
18
+ return home ? path.join(home, filePath.slice(1)) : filePath;
19
+ }
20
+ return filePath;
19
21
  }
20
22
  function absolutify(dir) {
21
- let pathName = expandHome(dir);
22
- return path.isAbsolute(pathName) ? pathName : path.resolve(process.cwd(), pathName);
23
+ const pathName = expandHome(dir);
24
+ return path.isAbsolute(pathName) ? pathName : path.resolve(process.cwd(), pathName);
23
25
  }
24
- export { absolutify, expandHome, pathIsEmpty };
25
-
26
- //# sourceMappingURL=fs.js.map
26
+ export {
27
+ absolutify,
28
+ expandHome,
29
+ pathIsEmpty
30
+ };
31
+ //# sourceMappingURL=fs.js.map
package/lib/fs.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"fs.js","names":[],"sources":["../src/fsTools.ts"],"sourcesContent":["import fs from 'node:fs/promises'\nimport os from 'node:os'\nimport path from 'node:path'\n\nexport async function pathIsEmpty(dir: string): Promise<boolean> {\n try {\n const content = await fs.readdir(absolutify(dir))\n return content.length === 0\n } catch (err) {\n if (err.code === 'ENOENT') {\n return true\n }\n\n throw err\n }\n}\n\nexport function expandHome(filePath: string): string {\n if (\n filePath.charCodeAt(0) === 126\n /* ~ */\n ) {\n if (\n filePath.charCodeAt(1) === 43\n /* + */\n ) {\n return path.join(process.cwd(), filePath.slice(2))\n }\n\n const home = os.homedir()\n return home ? path.join(home, filePath.slice(1)) : filePath\n }\n\n return filePath\n}\n\nexport function absolutify(dir: string): string {\n const pathName = expandHome(dir)\n return path.isAbsolute(pathName) ? pathName : path.resolve(process.cwd(), pathName)\n}\n"],"mappings":";;;AAIA,eAAsB,YAAY,KAA+B;CAC/D,IAAI;EAEF,QAAO,MADe,GAAG,QAAQ,WAAW,GAAG,CAAC,EAAA,CACjC,WAAW;CAC5B,SAAS,KAAK;EACZ,IAAI,IAAI,SAAS,UACf,OAAO;EAGT,MAAM;CACR;AACF;AAEA,SAAgB,WAAW,UAA0B;CACnD,IACE,SAAS,WAAW,CAAC,MAAM,KAE3B;EACA,IACE,SAAS,WAAW,CAAC,MAAM,IAG3B,OAAO,KAAK,KAAK,QAAQ,IAAI,GAAG,SAAS,MAAM,CAAC,CAAC;EAGnD,IAAM,OAAO,GAAG,QAAQ;EACxB,OAAO,OAAO,KAAK,KAAK,MAAM,SAAS,MAAM,CAAC,CAAC,IAAI;CACrD;CAEA,OAAO;AACT;AAEA,SAAgB,WAAW,KAAqB;CAC9C,IAAM,WAAW,WAAW,GAAG;CAC/B,OAAO,KAAK,WAAW,QAAQ,IAAI,WAAW,KAAK,QAAQ,QAAQ,IAAI,GAAG,QAAQ;AACpF"}
1
+ {"version":3,"file":"fs.js","sources":["../src/fsTools.ts"],"sourcesContent":["import fs from 'node:fs/promises'\nimport os from 'node:os'\nimport path from 'node:path'\n\nexport async function pathIsEmpty(dir: string): Promise<boolean> {\n try {\n const content = await fs.readdir(absolutify(dir))\n return content.length === 0\n } catch (err) {\n if (err.code === 'ENOENT') {\n return true\n }\n\n throw err\n }\n}\n\nexport function expandHome(filePath: string): string {\n if (\n filePath.charCodeAt(0) === 126\n /* ~ */\n ) {\n if (\n filePath.charCodeAt(1) === 43\n /* + */\n ) {\n return path.join(process.cwd(), filePath.slice(2))\n }\n\n const home = os.homedir()\n return home ? path.join(home, filePath.slice(1)) : filePath\n }\n\n return filePath\n}\n\nexport function absolutify(dir: string): string {\n const pathName = expandHome(dir)\n return path.isAbsolute(pathName) ? pathName : path.resolve(process.cwd(), pathName)\n}\n"],"names":[],"mappings":";;;AAIA,eAAsB,YAAY,KAA+B;AAC/D,MAAI;AAEF,YADgB,MAAM,GAAG,QAAQ,WAAW,GAAG,CAAC,GACjC,WAAW;AAAA,EAC5B,SAAS,KAAK;AACZ,QAAI,IAAI,SAAS;AACf,aAAO;AAGT,UAAM;AAAA,EACR;AACF;AAEO,SAAS,WAAW,UAA0B;AACnD,MACE,SAAS,WAAW,CAAC,MAAM,KAE3B;AACA,QACE,SAAS,WAAW,CAAC,MAAM;AAG3B,aAAO,KAAK,KAAK,QAAQ,IAAA,GAAO,SAAS,MAAM,CAAC,CAAC;AAGnD,UAAM,OAAO,GAAG,QAAA;AAChB,WAAO,OAAO,KAAK,KAAK,MAAM,SAAS,MAAM,CAAC,CAAC,IAAI;AAAA,EACrD;AAEA,SAAO;AACT;AAEO,SAAS,WAAW,KAAqB;AAC9C,QAAM,WAAW,WAAW,GAAG;AAC/B,SAAO,KAAK,WAAW,QAAQ,IAAI,WAAW,KAAK,QAAQ,QAAQ,IAAA,GAAO,QAAQ;AACpF;"}
package/lib/index.js CHANGED
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -18,5 +18,4 @@ declare function format(input: Date, dateFormat: string, options?: {
18
18
  }): string;
19
19
  declare function parse(dateString: string, dateFormat?: string, timeZone?: string): ParseResult;
20
20
  declare function isValidTimeZoneString(timeZone: string): boolean;
21
- export { DEFAULT_DATE_FORMAT, DEFAULT_TIME_FORMAT, ParseResult, format, isValidTimeZoneString, parse, sanitizeLocale };
22
- //# sourceMappingURL=legacyDateFormat.d.ts.map
21
+ export { DEFAULT_DATE_FORMAT, DEFAULT_TIME_FORMAT, ParseResult, format, isValidTimeZoneString, parse, sanitizeLocale };