@sanity/util 5.0.0-next.0-9b570ece82-202507150640 → 5.0.0-next.7
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/LICENSE +1 -1
- package/lib/client.js +9 -8
- package/lib/client.js.map +1 -1
- package/lib/concurrency-limiter.js +3 -3
- package/lib/concurrency-limiter.js.map +1 -1
- package/lib/content.js +11 -15
- package/lib/content.js.map +1 -1
- package/lib/{createSafeJsonParser.mjs → createSafeJsonParser.cjs} +5 -5
- package/lib/{createSafeJsonParser.mjs.map → createSafeJsonParser.cjs.map} +1 -1
- package/lib/createSafeJsonParser.js +4 -4
- package/lib/createSafeJsonParser.js.map +1 -1
- package/lib/fs.js +13 -15
- package/lib/fs.js.map +1 -1
- package/lib/index.js +1 -1
- package/lib/legacyDateFormat.js +160 -78
- package/lib/legacyDateFormat.js.map +1 -1
- package/lib/paths.js +25 -25
- package/lib/paths.js.map +1 -1
- package/package.json +18 -30
- package/lib/client.d.mts +0 -12
- package/lib/client.mjs +0 -64
- package/lib/client.mjs.map +0 -1
- package/lib/concurrency-limiter.d.mts +0 -22
- package/lib/concurrency-limiter.mjs +0 -32
- package/lib/concurrency-limiter.mjs.map +0 -1
- package/lib/content.d.mts +0 -39
- package/lib/content.mjs +0 -89
- package/lib/content.mjs.map +0 -1
- package/lib/fs.d.mts +0 -7
- package/lib/fs.mjs +0 -31
- package/lib/fs.mjs.map +0 -1
- package/lib/index.d.mts +0 -1
- package/lib/index.mjs +0 -2
- package/lib/index.mjs.map +0 -1
- package/lib/legacyDateFormat.d.mts +0 -39
- package/lib/legacyDateFormat.mjs +0 -213
- package/lib/legacyDateFormat.mjs.map +0 -1
- package/lib/paths.d.mts +0 -53
- package/lib/paths.mjs +0 -153
- package/lib/paths.mjs.map +0 -1
- /package/lib/{createSafeJsonParser.d.mts → createSafeJsonParser.d.cts} +0 -0
package/LICENSE
CHANGED
package/lib/client.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var rxjs = require("rxjs"), concurrencyLimiter = require("./concurrency-limiter.js");
|
|
1
|
+
import { from, switchMap, finalize } from "rxjs";
|
|
2
|
+
import { ConcurrencyLimiter } from "./concurrency-limiter.js";
|
|
4
3
|
function createClientConcurrencyLimiter(maxConcurrency) {
|
|
5
|
-
const limiter = new
|
|
4
|
+
const limiter = new ConcurrencyLimiter(maxConcurrency);
|
|
6
5
|
function wrapClient(client) {
|
|
7
6
|
return new Proxy(client, {
|
|
8
7
|
get: (target, property) => {
|
|
@@ -38,9 +37,9 @@ function createClientConcurrencyLimiter(maxConcurrency) {
|
|
|
38
37
|
get: (target, property) => {
|
|
39
38
|
switch (property) {
|
|
40
39
|
case "fetch":
|
|
41
|
-
return (...args) =>
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
return (...args) => from(limiter.ready()).pipe(
|
|
41
|
+
switchMap(() => target.fetch(...args)),
|
|
42
|
+
finalize(() => limiter.release())
|
|
44
43
|
);
|
|
45
44
|
case "clone":
|
|
46
45
|
return (...args) => wrapObservableClient(target.clone(...args));
|
|
@@ -59,5 +58,7 @@ function createClientConcurrencyLimiter(maxConcurrency) {
|
|
|
59
58
|
}
|
|
60
59
|
return wrapClient;
|
|
61
60
|
}
|
|
62
|
-
|
|
61
|
+
export {
|
|
62
|
+
createClientConcurrencyLimiter
|
|
63
|
+
};
|
|
63
64
|
//# sourceMappingURL=client.js.map
|
package/lib/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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":[
|
|
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;"}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
3
1
|
class ConcurrencyLimiter {
|
|
4
2
|
current = 0;
|
|
5
3
|
resolvers = [];
|
|
@@ -28,5 +26,7 @@ class ConcurrencyLimiter {
|
|
|
28
26
|
this.current = Math.max(0, this.current - 1);
|
|
29
27
|
};
|
|
30
28
|
}
|
|
31
|
-
|
|
29
|
+
export {
|
|
30
|
+
ConcurrencyLimiter
|
|
31
|
+
};
|
|
32
32
|
//# sourceMappingURL=concurrency-limiter.js.map
|
|
@@ -1 +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":"
|
|
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.js
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
3
|
-
var getRandomValues = require("get-random-values-esm");
|
|
4
|
-
function _interopDefaultCompat(e) {
|
|
5
|
-
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
6
|
-
}
|
|
7
|
-
var getRandomValues__default = /* @__PURE__ */ _interopDefaultCompat(getRandomValues), hasOwn = Object.prototype.hasOwnProperty.call.bind(Object.prototype.hasOwnProperty);
|
|
1
|
+
var hasOwn = Object.prototype.hasOwnProperty.call.bind(Object.prototype.hasOwnProperty);
|
|
8
2
|
function isDeepEmptyObject(value) {
|
|
9
3
|
for (const key in value)
|
|
10
4
|
if (!(key === "_type" || key === "_key") && hasOwn(value, key) && !isDeepEmpty(value[key]))
|
|
@@ -43,7 +37,7 @@ const getByteHexTable = /* @__PURE__ */ (() => {
|
|
|
43
37
|
})();
|
|
44
38
|
function whatwgRNG(length = 16) {
|
|
45
39
|
const rnds8 = new Uint8Array(length);
|
|
46
|
-
return
|
|
40
|
+
return crypto.getRandomValues(rnds8), rnds8;
|
|
47
41
|
}
|
|
48
42
|
function randomKey(length) {
|
|
49
43
|
const table = getByteHexTable();
|
|
@@ -82,11 +76,13 @@ function resolveTypeName(value) {
|
|
|
82
76
|
const obj = value;
|
|
83
77
|
return "_type" in obj && obj._type || jsType;
|
|
84
78
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
79
|
+
export {
|
|
80
|
+
isDeepEmpty,
|
|
81
|
+
isEmpty,
|
|
82
|
+
isEmptyArray,
|
|
83
|
+
isEmptyObject,
|
|
84
|
+
isShallowEmptyObject,
|
|
85
|
+
randomKey,
|
|
86
|
+
resolveTypeName
|
|
87
|
+
};
|
|
92
88
|
//# sourceMappingURL=content.js.map
|
package/lib/content.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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\n/**\n * @deprecated Use `isDeepEmpty` instead\n * todo: remove in v4\n */\nexport const isEmpty = isDeepEmpty\n\n/**\n * @deprecated Use `isDeepEmpty` instead\n * todo: remove in v4\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","
|
|
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\n/**\n * @deprecated Use `isDeepEmpty` instead\n * todo: remove in v4\n */\nexport const isEmpty = isDeepEmpty\n\n/**\n * @deprecated Use `isDeepEmpty` instead\n * todo: remove in v4\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,kBAMf,UAAU,aAMV,gBAAgB;AC5DtB,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;"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
1
3
|
function createSafeJsonParser({ errorLabel }) {
|
|
2
4
|
return function(line) {
|
|
3
5
|
try {
|
|
@@ -10,11 +12,9 @@ function createSafeJsonParser({ errorLabel }) {
|
|
|
10
12
|
throw error && error.description ? new Error(`${errorLabel}: ${error.description}
|
|
11
13
|
|
|
12
14
|
${errorJson}
|
|
13
|
-
|
|
15
|
+
`, { cause: err }) : err;
|
|
14
16
|
}
|
|
15
17
|
};
|
|
16
18
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
};
|
|
20
|
-
//# sourceMappingURL=createSafeJsonParser.mjs.map
|
|
19
|
+
exports.createSafeJsonParser = createSafeJsonParser;
|
|
20
|
+
//# sourceMappingURL=createSafeJsonParser.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createSafeJsonParser.
|
|
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;;"}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
3
1
|
function createSafeJsonParser({ errorLabel }) {
|
|
4
2
|
return function(line) {
|
|
5
3
|
try {
|
|
@@ -12,9 +10,11 @@ function createSafeJsonParser({ errorLabel }) {
|
|
|
12
10
|
throw error && error.description ? new Error(`${errorLabel}: ${error.description}
|
|
13
11
|
|
|
14
12
|
${errorJson}
|
|
15
|
-
|
|
13
|
+
`, { cause: err }) : err;
|
|
16
14
|
}
|
|
17
15
|
};
|
|
18
16
|
}
|
|
19
|
-
|
|
17
|
+
export {
|
|
18
|
+
createSafeJsonParser
|
|
19
|
+
};
|
|
20
20
|
//# sourceMappingURL=createSafeJsonParser.js.map
|
|
@@ -1 +1 @@
|
|
|
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
|
|
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.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
function _interopDefaultCompat(e) {
|
|
5
|
-
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
6
|
-
}
|
|
7
|
-
var fs__default = /* @__PURE__ */ _interopDefaultCompat(fs), os__default = /* @__PURE__ */ _interopDefaultCompat(os), path__default = /* @__PURE__ */ _interopDefaultCompat(path);
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
8
4
|
async function pathIsEmpty(dir) {
|
|
9
5
|
try {
|
|
10
|
-
return (await
|
|
6
|
+
return (await fs.readdir(absolutify(dir))).length === 0;
|
|
11
7
|
} catch (err) {
|
|
12
8
|
if (err.code === "ENOENT")
|
|
13
9
|
return !0;
|
|
@@ -17,17 +13,19 @@ async function pathIsEmpty(dir) {
|
|
|
17
13
|
function expandHome(filePath) {
|
|
18
14
|
if (filePath.charCodeAt(0) === 126) {
|
|
19
15
|
if (filePath.charCodeAt(1) === 43)
|
|
20
|
-
return
|
|
21
|
-
const home =
|
|
22
|
-
return home ?
|
|
16
|
+
return path.join(process.cwd(), filePath.slice(2));
|
|
17
|
+
const home = os.homedir();
|
|
18
|
+
return home ? path.join(home, filePath.slice(1)) : filePath;
|
|
23
19
|
}
|
|
24
20
|
return filePath;
|
|
25
21
|
}
|
|
26
22
|
function absolutify(dir) {
|
|
27
23
|
const pathName = expandHome(dir);
|
|
28
|
-
return
|
|
24
|
+
return path.isAbsolute(pathName) ? pathName : path.resolve(process.cwd(), pathName);
|
|
29
25
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
export {
|
|
27
|
+
absolutify,
|
|
28
|
+
expandHome,
|
|
29
|
+
pathIsEmpty
|
|
30
|
+
};
|
|
33
31
|
//# sourceMappingURL=fs.js.map
|
package/lib/fs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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":[
|
|
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
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
2
|
//# sourceMappingURL=index.js.map
|