@sanity/client 6.11.3 → 6.11.4-canary.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/README.md +85 -4
  2. package/dist/_chunks/{browserMiddleware-1MULg59S.cjs → browserMiddleware-Pe3R-Bkh.cjs} +106 -20
  3. package/dist/_chunks/browserMiddleware-Pe3R-Bkh.cjs.map +1 -0
  4. package/dist/_chunks/{browserMiddleware-heyg-fDk.js → browserMiddleware-wklv-F5c.js} +108 -22
  5. package/dist/_chunks/browserMiddleware-wklv-F5c.js.map +1 -0
  6. package/dist/_chunks/{nodeMiddleware-CHxg1-zH.cjs → nodeMiddleware-7PkLkt-m.cjs} +107 -21
  7. package/dist/_chunks/nodeMiddleware-7PkLkt-m.cjs.map +1 -0
  8. package/dist/_chunks/{nodeMiddleware-u_fUUnxa.js → nodeMiddleware-LGORMZpx.js} +109 -23
  9. package/dist/_chunks/nodeMiddleware-LGORMZpx.js.map +1 -0
  10. package/dist/_chunks/stegaEncodeSourceMap-2y-qTNKB.cjs +230 -0
  11. package/dist/_chunks/stegaEncodeSourceMap-2y-qTNKB.cjs.map +1 -0
  12. package/dist/_chunks/stegaEncodeSourceMap-9L0STMBo.js +475 -0
  13. package/dist/_chunks/stegaEncodeSourceMap-9L0STMBo.js.map +1 -0
  14. package/dist/_chunks/stegaEncodeSourceMap-gXzb3LIV.js +226 -0
  15. package/dist/_chunks/stegaEncodeSourceMap-gXzb3LIV.js.map +1 -0
  16. package/dist/_chunks/stegaEncodeSourceMap-vNYIaMiu.cjs +479 -0
  17. package/dist/_chunks/stegaEncodeSourceMap-vNYIaMiu.cjs.map +1 -0
  18. package/dist/index.browser.cjs +1 -1
  19. package/dist/index.browser.js +2 -2
  20. package/dist/index.cjs +1 -1
  21. package/dist/index.d.ts +133 -0
  22. package/dist/index.js +2 -2
  23. package/dist/stega.browser.cjs +10 -700
  24. package/dist/stega.browser.cjs.map +1 -1
  25. package/dist/stega.browser.js +5 -693
  26. package/dist/stega.browser.js.map +1 -1
  27. package/dist/stega.cjs +10 -451
  28. package/dist/stega.cjs.js +3 -5
  29. package/dist/stega.cjs.map +1 -1
  30. package/dist/stega.d.ts +1302 -1455
  31. package/dist/stega.js +5 -444
  32. package/dist/stega.js.map +1 -1
  33. package/package.json +12 -7
  34. package/src/SanityClient.ts +40 -4
  35. package/src/config.ts +34 -12
  36. package/src/data/dataMethods.ts +37 -9
  37. package/src/stega/index.browser.ts +3 -6
  38. package/src/stega/index.ts +3 -6
  39. package/src/stega/shared.ts +1 -13
  40. package/src/stega/types.ts +11 -18
  41. package/src/types.ts +24 -0
  42. package/umd/sanityClient.js +1073 -20
  43. package/umd/sanityClient.min.js +4 -3
  44. package/dist/_chunks/browserMiddleware-1MULg59S.cjs.map +0 -1
  45. package/dist/_chunks/browserMiddleware-heyg-fDk.js.map +0 -1
  46. package/dist/_chunks/nodeMiddleware-CHxg1-zH.cjs.map +0 -1
  47. package/dist/_chunks/nodeMiddleware-u_fUUnxa.js.map +0 -1
  48. package/src/stega/SanityStegaClient.ts +0 -298
  49. package/src/stega/config.ts +0 -76
@@ -64,7 +64,7 @@
64
64
  var trim = function(string) {
65
65
  return string.replace(/^\s+|\s+$/g, '');
66
66
  }
67
- , isArray = function(arg) {
67
+ , isArray$3 = function(arg) {
68
68
  return Object.prototype.toString.call(arg) === '[object Array]';
69
69
  };
70
70
 
@@ -84,7 +84,7 @@
84
84
 
85
85
  if (typeof(result[key]) === 'undefined') {
86
86
  result[key] = value;
87
- } else if (isArray(result[key])) {
87
+ } else if (isArray$3(result[key])) {
88
88
  result[key].push(value);
89
89
  } else {
90
90
  result[key] = [ result[key], value ];
@@ -1464,6 +1464,44 @@
1464
1464
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
1465
1465
  }
1466
1466
 
1467
+ function __awaiter(thisArg, _arguments, P, generator) {
1468
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1469
+ return new (P || (P = Promise))(function (resolve, reject) {
1470
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
1471
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
1472
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
1473
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
1474
+ });
1475
+ }
1476
+
1477
+ function __generator(thisArg, body) {
1478
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
1479
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
1480
+ function verb(n) { return function (v) { return step([n, v]); }; }
1481
+ function step(op) {
1482
+ if (f) throw new TypeError("Generator is already executing.");
1483
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
1484
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
1485
+ if (y = 0, t) op = [op[0] & 2, t.value];
1486
+ switch (op[0]) {
1487
+ case 0: case 1: t = op; break;
1488
+ case 4: _.label++; return { value: op[1], done: false };
1489
+ case 5: _.label++; y = op[1]; op = [0]; continue;
1490
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
1491
+ default:
1492
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
1493
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
1494
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
1495
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
1496
+ if (t[2]) _.ops.pop();
1497
+ _.trys.pop(); continue;
1498
+ }
1499
+ op = body.call(thisArg, _);
1500
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
1501
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
1502
+ }
1503
+ }
1504
+
1467
1505
  function __values(o) {
1468
1506
  var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
1469
1507
  if (m) return m.call(o);
@@ -1503,6 +1541,30 @@
1503
1541
  return to.concat(ar || Array.prototype.slice.call(from));
1504
1542
  }
1505
1543
 
1544
+ function __await(v) {
1545
+ return this instanceof __await ? (this.v = v, this) : new __await(v);
1546
+ }
1547
+
1548
+ function __asyncGenerator(thisArg, _arguments, generator) {
1549
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
1550
+ var g = generator.apply(thisArg, _arguments || []), i, q = [];
1551
+ return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
1552
+ function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
1553
+ function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
1554
+ function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
1555
+ function fulfill(value) { resume("next", value); }
1556
+ function reject(value) { resume("throw", value); }
1557
+ function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
1558
+ }
1559
+
1560
+ function __asyncValues(o) {
1561
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
1562
+ var m = o[Symbol.asyncIterator], i;
1563
+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
1564
+ function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
1565
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
1566
+ }
1567
+
1506
1568
  typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
1507
1569
  var e = new Error(message);
1508
1570
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
@@ -1884,6 +1946,13 @@
1884
1946
  return x;
1885
1947
  }
1886
1948
 
1949
+ function pipe() {
1950
+ var fns = [];
1951
+ for (var _i = 0; _i < arguments.length; _i++) {
1952
+ fns[_i] = arguments[_i];
1953
+ }
1954
+ return pipeFromArray(fns);
1955
+ }
1887
1956
  function pipeFromArray(fns) {
1888
1957
  if (fns.length === 0) {
1889
1958
  return identity;
@@ -2067,6 +2136,348 @@
2067
2136
  return OperatorSubscriber;
2068
2137
  }(Subscriber));
2069
2138
 
2139
+ function last(arr) {
2140
+ return arr[arr.length - 1];
2141
+ }
2142
+ function popResultSelector(args) {
2143
+ return isFunction(last(args)) ? args.pop() : undefined;
2144
+ }
2145
+
2146
+ var isArrayLike = (function (x) { return x && typeof x.length === 'number' && typeof x !== 'function'; });
2147
+
2148
+ function isPromise(value) {
2149
+ return isFunction(value === null || value === void 0 ? void 0 : value.then);
2150
+ }
2151
+
2152
+ function isInteropObservable(input) {
2153
+ return isFunction(input[observable]);
2154
+ }
2155
+
2156
+ function isAsyncIterable(obj) {
2157
+ return Symbol.asyncIterator && isFunction(obj === null || obj === void 0 ? void 0 : obj[Symbol.asyncIterator]);
2158
+ }
2159
+
2160
+ function createInvalidObservableTypeError(input) {
2161
+ return new TypeError("You provided " + (input !== null && typeof input === 'object' ? 'an invalid object' : "'" + input + "'") + " where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.");
2162
+ }
2163
+
2164
+ function getSymbolIterator() {
2165
+ if (typeof Symbol !== 'function' || !Symbol.iterator) {
2166
+ return '@@iterator';
2167
+ }
2168
+ return Symbol.iterator;
2169
+ }
2170
+ var iterator = getSymbolIterator();
2171
+
2172
+ function isIterable(input) {
2173
+ return isFunction(input === null || input === void 0 ? void 0 : input[iterator]);
2174
+ }
2175
+
2176
+ function readableStreamLikeToAsyncGenerator(readableStream) {
2177
+ return __asyncGenerator(this, arguments, function readableStreamLikeToAsyncGenerator_1() {
2178
+ var reader, _a, value, done;
2179
+ return __generator(this, function (_b) {
2180
+ switch (_b.label) {
2181
+ case 0:
2182
+ reader = readableStream.getReader();
2183
+ _b.label = 1;
2184
+ case 1:
2185
+ _b.trys.push([1, , 9, 10]);
2186
+ _b.label = 2;
2187
+ case 2:
2188
+ return [4, __await(reader.read())];
2189
+ case 3:
2190
+ _a = _b.sent(), value = _a.value, done = _a.done;
2191
+ if (!done) return [3, 5];
2192
+ return [4, __await(void 0)];
2193
+ case 4: return [2, _b.sent()];
2194
+ case 5: return [4, __await(value)];
2195
+ case 6: return [4, _b.sent()];
2196
+ case 7:
2197
+ _b.sent();
2198
+ return [3, 2];
2199
+ case 8: return [3, 10];
2200
+ case 9:
2201
+ reader.releaseLock();
2202
+ return [7];
2203
+ case 10: return [2];
2204
+ }
2205
+ });
2206
+ });
2207
+ }
2208
+ function isReadableStreamLike(obj) {
2209
+ return isFunction(obj === null || obj === void 0 ? void 0 : obj.getReader);
2210
+ }
2211
+
2212
+ function innerFrom(input) {
2213
+ if (input instanceof Observable) {
2214
+ return input;
2215
+ }
2216
+ if (input != null) {
2217
+ if (isInteropObservable(input)) {
2218
+ return fromInteropObservable(input);
2219
+ }
2220
+ if (isArrayLike(input)) {
2221
+ return fromArrayLike(input);
2222
+ }
2223
+ if (isPromise(input)) {
2224
+ return fromPromise(input);
2225
+ }
2226
+ if (isAsyncIterable(input)) {
2227
+ return fromAsyncIterable(input);
2228
+ }
2229
+ if (isIterable(input)) {
2230
+ return fromIterable(input);
2231
+ }
2232
+ if (isReadableStreamLike(input)) {
2233
+ return fromReadableStreamLike(input);
2234
+ }
2235
+ }
2236
+ throw createInvalidObservableTypeError(input);
2237
+ }
2238
+ function fromInteropObservable(obj) {
2239
+ return new Observable(function (subscriber) {
2240
+ var obs = obj[observable]();
2241
+ if (isFunction(obs.subscribe)) {
2242
+ return obs.subscribe(subscriber);
2243
+ }
2244
+ throw new TypeError('Provided object does not correctly implement Symbol.observable');
2245
+ });
2246
+ }
2247
+ function fromArrayLike(array) {
2248
+ return new Observable(function (subscriber) {
2249
+ for (var i = 0; i < array.length && !subscriber.closed; i++) {
2250
+ subscriber.next(array[i]);
2251
+ }
2252
+ subscriber.complete();
2253
+ });
2254
+ }
2255
+ function fromPromise(promise) {
2256
+ return new Observable(function (subscriber) {
2257
+ promise
2258
+ .then(function (value) {
2259
+ if (!subscriber.closed) {
2260
+ subscriber.next(value);
2261
+ subscriber.complete();
2262
+ }
2263
+ }, function (err) { return subscriber.error(err); })
2264
+ .then(null, reportUnhandledError);
2265
+ });
2266
+ }
2267
+ function fromIterable(iterable) {
2268
+ return new Observable(function (subscriber) {
2269
+ var e_1, _a;
2270
+ try {
2271
+ for (var iterable_1 = __values(iterable), iterable_1_1 = iterable_1.next(); !iterable_1_1.done; iterable_1_1 = iterable_1.next()) {
2272
+ var value = iterable_1_1.value;
2273
+ subscriber.next(value);
2274
+ if (subscriber.closed) {
2275
+ return;
2276
+ }
2277
+ }
2278
+ }
2279
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2280
+ finally {
2281
+ try {
2282
+ if (iterable_1_1 && !iterable_1_1.done && (_a = iterable_1.return)) _a.call(iterable_1);
2283
+ }
2284
+ finally { if (e_1) throw e_1.error; }
2285
+ }
2286
+ subscriber.complete();
2287
+ });
2288
+ }
2289
+ function fromAsyncIterable(asyncIterable) {
2290
+ return new Observable(function (subscriber) {
2291
+ process$1(asyncIterable, subscriber).catch(function (err) { return subscriber.error(err); });
2292
+ });
2293
+ }
2294
+ function fromReadableStreamLike(readableStream) {
2295
+ return fromAsyncIterable(readableStreamLikeToAsyncGenerator(readableStream));
2296
+ }
2297
+ function process$1(asyncIterable, subscriber) {
2298
+ var asyncIterable_1, asyncIterable_1_1;
2299
+ var e_2, _a;
2300
+ return __awaiter(this, void 0, void 0, function () {
2301
+ var value, e_2_1;
2302
+ return __generator(this, function (_b) {
2303
+ switch (_b.label) {
2304
+ case 0:
2305
+ _b.trys.push([0, 5, 6, 11]);
2306
+ asyncIterable_1 = __asyncValues(asyncIterable);
2307
+ _b.label = 1;
2308
+ case 1: return [4, asyncIterable_1.next()];
2309
+ case 2:
2310
+ if (!(asyncIterable_1_1 = _b.sent(), !asyncIterable_1_1.done)) return [3, 4];
2311
+ value = asyncIterable_1_1.value;
2312
+ subscriber.next(value);
2313
+ if (subscriber.closed) {
2314
+ return [2];
2315
+ }
2316
+ _b.label = 3;
2317
+ case 3: return [3, 1];
2318
+ case 4: return [3, 11];
2319
+ case 5:
2320
+ e_2_1 = _b.sent();
2321
+ e_2 = { error: e_2_1 };
2322
+ return [3, 11];
2323
+ case 6:
2324
+ _b.trys.push([6, , 9, 10]);
2325
+ if (!(asyncIterable_1_1 && !asyncIterable_1_1.done && (_a = asyncIterable_1.return))) return [3, 8];
2326
+ return [4, _a.call(asyncIterable_1)];
2327
+ case 7:
2328
+ _b.sent();
2329
+ _b.label = 8;
2330
+ case 8: return [3, 10];
2331
+ case 9:
2332
+ if (e_2) throw e_2.error;
2333
+ return [7];
2334
+ case 10: return [7];
2335
+ case 11:
2336
+ subscriber.complete();
2337
+ return [2];
2338
+ }
2339
+ });
2340
+ });
2341
+ }
2342
+
2343
+ function executeSchedule(parentSubscription, scheduler, work, delay, repeat) {
2344
+ if (delay === void 0) { delay = 0; }
2345
+ if (repeat === void 0) { repeat = false; }
2346
+ var scheduleSubscription = scheduler.schedule(function () {
2347
+ work();
2348
+ if (repeat) {
2349
+ parentSubscription.add(this.schedule(null, delay));
2350
+ }
2351
+ else {
2352
+ this.unsubscribe();
2353
+ }
2354
+ }, delay);
2355
+ parentSubscription.add(scheduleSubscription);
2356
+ if (!repeat) {
2357
+ return scheduleSubscription;
2358
+ }
2359
+ }
2360
+
2361
+ function observeOn(scheduler, delay) {
2362
+ if (delay === void 0) { delay = 0; }
2363
+ return operate(function (source, subscriber) {
2364
+ source.subscribe(createOperatorSubscriber(subscriber, function (value) { return executeSchedule(subscriber, scheduler, function () { return subscriber.next(value); }, delay); }, function () { return executeSchedule(subscriber, scheduler, function () { return subscriber.complete(); }, delay); }, function (err) { return executeSchedule(subscriber, scheduler, function () { return subscriber.error(err); }, delay); }));
2365
+ });
2366
+ }
2367
+
2368
+ function subscribeOn(scheduler, delay) {
2369
+ if (delay === void 0) { delay = 0; }
2370
+ return operate(function (source, subscriber) {
2371
+ subscriber.add(scheduler.schedule(function () { return source.subscribe(subscriber); }, delay));
2372
+ });
2373
+ }
2374
+
2375
+ function scheduleObservable(input, scheduler) {
2376
+ return innerFrom(input).pipe(subscribeOn(scheduler), observeOn(scheduler));
2377
+ }
2378
+
2379
+ function schedulePromise(input, scheduler) {
2380
+ return innerFrom(input).pipe(subscribeOn(scheduler), observeOn(scheduler));
2381
+ }
2382
+
2383
+ function scheduleArray(input, scheduler) {
2384
+ return new Observable(function (subscriber) {
2385
+ var i = 0;
2386
+ return scheduler.schedule(function () {
2387
+ if (i === input.length) {
2388
+ subscriber.complete();
2389
+ }
2390
+ else {
2391
+ subscriber.next(input[i++]);
2392
+ if (!subscriber.closed) {
2393
+ this.schedule();
2394
+ }
2395
+ }
2396
+ });
2397
+ });
2398
+ }
2399
+
2400
+ function scheduleIterable(input, scheduler) {
2401
+ return new Observable(function (subscriber) {
2402
+ var iterator$1;
2403
+ executeSchedule(subscriber, scheduler, function () {
2404
+ iterator$1 = input[iterator]();
2405
+ executeSchedule(subscriber, scheduler, function () {
2406
+ var _a;
2407
+ var value;
2408
+ var done;
2409
+ try {
2410
+ (_a = iterator$1.next(), value = _a.value, done = _a.done);
2411
+ }
2412
+ catch (err) {
2413
+ subscriber.error(err);
2414
+ return;
2415
+ }
2416
+ if (done) {
2417
+ subscriber.complete();
2418
+ }
2419
+ else {
2420
+ subscriber.next(value);
2421
+ }
2422
+ }, 0, true);
2423
+ });
2424
+ return function () { return isFunction(iterator$1 === null || iterator$1 === void 0 ? void 0 : iterator$1.return) && iterator$1.return(); };
2425
+ });
2426
+ }
2427
+
2428
+ function scheduleAsyncIterable(input, scheduler) {
2429
+ if (!input) {
2430
+ throw new Error('Iterable cannot be null');
2431
+ }
2432
+ return new Observable(function (subscriber) {
2433
+ executeSchedule(subscriber, scheduler, function () {
2434
+ var iterator = input[Symbol.asyncIterator]();
2435
+ executeSchedule(subscriber, scheduler, function () {
2436
+ iterator.next().then(function (result) {
2437
+ if (result.done) {
2438
+ subscriber.complete();
2439
+ }
2440
+ else {
2441
+ subscriber.next(result.value);
2442
+ }
2443
+ });
2444
+ }, 0, true);
2445
+ });
2446
+ });
2447
+ }
2448
+
2449
+ function scheduleReadableStreamLike(input, scheduler) {
2450
+ return scheduleAsyncIterable(readableStreamLikeToAsyncGenerator(input), scheduler);
2451
+ }
2452
+
2453
+ function scheduled(input, scheduler) {
2454
+ if (input != null) {
2455
+ if (isInteropObservable(input)) {
2456
+ return scheduleObservable(input, scheduler);
2457
+ }
2458
+ if (isArrayLike(input)) {
2459
+ return scheduleArray(input, scheduler);
2460
+ }
2461
+ if (isPromise(input)) {
2462
+ return schedulePromise(input, scheduler);
2463
+ }
2464
+ if (isAsyncIterable(input)) {
2465
+ return scheduleAsyncIterable(input, scheduler);
2466
+ }
2467
+ if (isIterable(input)) {
2468
+ return scheduleIterable(input, scheduler);
2469
+ }
2470
+ if (isReadableStreamLike(input)) {
2471
+ return scheduleReadableStreamLike(input, scheduler);
2472
+ }
2473
+ }
2474
+ throw createInvalidObservableTypeError(input);
2475
+ }
2476
+
2477
+ function from(input, scheduler) {
2478
+ return scheduler ? scheduled(input, scheduler) : innerFrom(input);
2479
+ }
2480
+
2070
2481
  var EmptyError = createErrorClass(function (_super) { return function EmptyErrorImpl() {
2071
2482
  _super(this);
2072
2483
  this.name = 'EmptyError';
@@ -2108,6 +2519,62 @@
2108
2519
  });
2109
2520
  }
2110
2521
 
2522
+ var isArray$2 = Array.isArray;
2523
+ function callOrApply(fn, args) {
2524
+ return isArray$2(args) ? fn.apply(void 0, __spreadArray([], __read(args))) : fn(args);
2525
+ }
2526
+ function mapOneOrManyArgs(fn) {
2527
+ return map(function (args) { return callOrApply(fn, args); });
2528
+ }
2529
+
2530
+ function combineLatestInit(observables, scheduler, valueTransform) {
2531
+ if (valueTransform === void 0) { valueTransform = identity; }
2532
+ return function (subscriber) {
2533
+ maybeSchedule(scheduler, function () {
2534
+ var length = observables.length;
2535
+ var values = new Array(length);
2536
+ var active = length;
2537
+ var remainingFirstValues = length;
2538
+ var _loop_1 = function (i) {
2539
+ maybeSchedule(scheduler, function () {
2540
+ var source = from(observables[i], scheduler);
2541
+ var hasFirstValue = false;
2542
+ source.subscribe(createOperatorSubscriber(subscriber, function (value) {
2543
+ values[i] = value;
2544
+ if (!hasFirstValue) {
2545
+ hasFirstValue = true;
2546
+ remainingFirstValues--;
2547
+ }
2548
+ if (!remainingFirstValues) {
2549
+ subscriber.next(valueTransform(values.slice()));
2550
+ }
2551
+ }, function () {
2552
+ if (!--active) {
2553
+ subscriber.complete();
2554
+ }
2555
+ }));
2556
+ }, subscriber);
2557
+ };
2558
+ for (var i = 0; i < length; i++) {
2559
+ _loop_1(i);
2560
+ }
2561
+ }, subscriber);
2562
+ };
2563
+ }
2564
+ function maybeSchedule(scheduler, execute, subscription) {
2565
+ if (scheduler) {
2566
+ executeSchedule(subscription, scheduler, execute);
2567
+ }
2568
+ else {
2569
+ execute();
2570
+ }
2571
+ }
2572
+
2573
+ var isArray$1 = Array.isArray;
2574
+ function argsOrArgArray(args) {
2575
+ return args.length === 1 && isArray$1(args[0]) ? args[0] : args;
2576
+ }
2577
+
2111
2578
  function filter(predicate, thisArg) {
2112
2579
  return operate(function (source, subscriber) {
2113
2580
  var index = 0;
@@ -2115,6 +2582,29 @@
2115
2582
  });
2116
2583
  }
2117
2584
 
2585
+ function combineLatest() {
2586
+ var args = [];
2587
+ for (var _i = 0; _i < arguments.length; _i++) {
2588
+ args[_i] = arguments[_i];
2589
+ }
2590
+ var resultSelector = popResultSelector(args);
2591
+ return resultSelector
2592
+ ? pipe(combineLatest.apply(void 0, __spreadArray([], __read(args))), mapOneOrManyArgs(resultSelector))
2593
+ : operate(function (source, subscriber) {
2594
+ combineLatestInit(__spreadArray([source], __read(argsOrArgArray(args))))(subscriber);
2595
+ });
2596
+ }
2597
+
2598
+ function combineLatestWith() {
2599
+ var otherSources = [];
2600
+ for (var _i = 0; _i < arguments.length; _i++) {
2601
+ otherSources[_i] = arguments[_i];
2602
+ }
2603
+ return combineLatest.apply(void 0, __spreadArray([], __read(otherSources)));
2604
+ }
2605
+
2606
+ var s={0:8203,1:8204,2:8205,3:8290,4:8291,5:8288,6:65279,7:8289,8:119155,9:119156,a:119157,b:119158,c:119159,d:119160,e:119161,f:119162},c={0:8203,1:8204,2:8205,3:65279},d=new Array(4).fill(String.fromCodePoint(c[0])).join("");function E(t){let e=JSON.stringify(t);return `${d}${Array.from(e).map(r=>{let n=r.charCodeAt(0);if(n>255)throw new Error(`Only ASCII edit info can be encoded. Error attempting to encode ${e} on character ${r} (${n})`);return Array.from(n.toString(4).padStart(4,"0")).map(o=>String.fromCodePoint(c[o])).join("")}).join("")}`}function I(t){return Number.isNaN(Number(t))?Boolean(Date.parse(t)):!1}function x(t){try{new URL(t,t.startsWith("/")?"https://acme.com":void 0);}catch{return !1}return !0}function b(t,e,r="auto"){return r===!0||r==="auto"&&(I(t)||x(t))?t:`${t}${E(e)}`}Object.fromEntries(Object.entries(c).map(t=>t.reverse()));Object.fromEntries(Object.entries(s).map(t=>t.reverse()));var S=`${Object.values(s).map(t=>`\\u{${t.toString(16)}}`).join("")}`,f=new RegExp(`[${S}]{4,}`,"gu");function X(t){var e;return {cleaned:t.replace(f,""),encoded:((e=t.match(f))==null?void 0:e[0])||""}}
2607
+
2118
2608
  const MAX_ITEMS_IN_ERROR_MESSAGE = 5;
2119
2609
  class ClientError extends Error {
2120
2610
  constructor(res) {
@@ -2763,7 +3253,8 @@
2763
3253
  const defaultConfig = {
2764
3254
  apiHost: "https://api.sanity.io",
2765
3255
  apiVersion: "1",
2766
- useProjectHostname: true
3256
+ useProjectHostname: true,
3257
+ stega: { enabled: false }
2767
3258
  };
2768
3259
  const LOCALHOSTS = ["localhost", "127.0.0.1", "0.0.0.0"];
2769
3260
  const isLocal = (host) => LOCALHOSTS.indexOf(host) !== -1;
@@ -2790,11 +3281,21 @@
2790
3281
  }
2791
3282
  };
2792
3283
  const initConfig = (config, prevConfig) => {
2793
- const specifiedConfig = Object.assign({}, prevConfig, config);
3284
+ const specifiedConfig = {
3285
+ ...prevConfig,
3286
+ ...config,
3287
+ stega: {
3288
+ ...typeof prevConfig.stega === "boolean" ? { enabled: prevConfig.stega } : prevConfig.stega || defaultConfig.stega,
3289
+ ...typeof config.stega === "boolean" ? { enabled: config.stega } : config.stega || {}
3290
+ }
3291
+ };
2794
3292
  if (!specifiedConfig.apiVersion) {
2795
3293
  printNoApiVersionSpecifiedWarning();
2796
3294
  }
2797
- const newConfig = Object.assign({}, defaultConfig, specifiedConfig);
3295
+ const newConfig = {
3296
+ ...defaultConfig,
3297
+ ...specifiedConfig
3298
+ };
2798
3299
  const projectBased = newConfig.useProjectHostname;
2799
3300
  if (typeof Promise === "undefined") {
2800
3301
  const helpUrl = generateHelpUrl("js-client-promise-polyfill");
@@ -2806,14 +3307,25 @@
2806
3307
  if (typeof newConfig.perspective === "string") {
2807
3308
  validateApiPerspective(newConfig.perspective);
2808
3309
  }
2809
- if ("encodeSourceMapAtPath" in newConfig || "encodeSourceMap" in newConfig || "studioUrl" in newConfig || "logger" in newConfig) {
3310
+ if ("encodeSourceMap" in newConfig) {
3311
+ throw new Error(
3312
+ "It looks like you're using options meant for '@sanity/preview-kit/client'. 'encodeSourceMap' is not supported in '@sanity/client'. Did you mean 'stega.enabled'?"
3313
+ );
3314
+ }
3315
+ if ("encodeSourceMapAtPath" in newConfig) {
2810
3316
  throw new Error(
2811
- "It looks like you're using options meant for '@sanity/preview-kit/client', such as 'encodeSourceMapAtPath', 'encodeSourceMap', 'studioUrl' and 'logger'. Make sure you're using the right import."
3317
+ "It looks like you're using options meant for '@sanity/preview-kit/client'. 'encodeSourceMapAtPath' is not supported in '@sanity/client'. Did you mean 'stega.filter'?"
2812
3318
  );
2813
3319
  }
2814
- if ("stega" in newConfig && newConfig["stega"] !== void 0 && newConfig["stega"] !== false) {
3320
+ if (typeof newConfig.stega.enabled !== "boolean") {
3321
+ throw new Error("stega.enabled must be a boolean, received ".concat(newConfig.stega.enabled));
3322
+ }
3323
+ if (newConfig.stega.enabled && newConfig.stega.studioUrl === void 0) {
3324
+ throw new Error("stega.studioUrl must be defined when stega.enabled is true");
3325
+ }
3326
+ if (newConfig.stega.enabled && typeof newConfig.stega.studioUrl !== "string" && typeof newConfig.stega.studioUrl !== "function") {
2815
3327
  throw new Error(
2816
- "It looks like you're using options meant for '@sanity/client/stega'. Make sure you're using the right import. Or set 'stega' in 'createClient' to 'false'."
3328
+ "stega.studioUrl must be a string or a function, received ".concat(newConfig.stega.studioUrl)
2817
3329
  );
2818
3330
  }
2819
3331
  const isBrowser = typeof window !== "undefined" && window.location && window.location.hostname;
@@ -2874,6 +3386,20 @@
2874
3386
  });
2875
3387
  }
2876
3388
 
3389
+ function vercelStegaCleanAll(result) {
3390
+ try {
3391
+ return JSON.parse(
3392
+ JSON.stringify(result, (key, value) => {
3393
+ if (typeof value !== "string")
3394
+ return value;
3395
+ return X(value).cleaned;
3396
+ })
3397
+ );
3398
+ } catch {
3399
+ return result;
3400
+ }
3401
+ }
3402
+
2877
3403
  const encodeQueryString = ({
2878
3404
  query,
2879
3405
  params = {},
@@ -2915,21 +3441,38 @@
2915
3441
  return indexed;
2916
3442
  }, /* @__PURE__ */ Object.create(null));
2917
3443
  const getQuerySizeLimit = 11264;
2918
- function _fetch(client, httpRequest, query, params, options = {}) {
2919
- if ("stega" in options && options["stega"] !== void 0 && options["stega"] !== false) {
2920
- throw new Error(
2921
- "It looks like you're using options meant for '@sanity/client/stega'. Make sure you're using the right import. Or set 'stega' in 'fetch' to 'false'."
2922
- );
2923
- }
3444
+ function _fetch(client, httpRequest, _stega, query, _params, options = {}) {
3445
+ const stega = "stega" in options ? {
3446
+ ..._stega || {},
3447
+ ...typeof options.stega === "boolean" ? { enabled: options.stega } : options.stega || {}
3448
+ } : _stega;
3449
+ const params = stega.enabled ? vercelStegaCleanAll(_params) : _params;
2924
3450
  const mapResponse = options.filterResponse === false ? (res) => res : (res) => res.result;
2925
3451
  const { cache, next, ...opts } = {
2926
3452
  // Opt out of setting a `signal` on an internal `fetch` if one isn't provided.
2927
3453
  // This is necessary in React Server Components to avoid opting out of Request Memoization.
2928
3454
  useAbortSignal: typeof options.signal !== "undefined",
3455
+ // Set `resultSourceMap' when stega is enabled, as it's required for encoding.
3456
+ resultSourceMap: stega.enabled ? "withKeyArraySelector" : options.resultSourceMap,
2929
3457
  ...options
2930
3458
  };
2931
3459
  const reqOpts = typeof cache !== "undefined" || typeof next !== "undefined" ? { ...opts, fetch: { cache, next } } : opts;
2932
- return _dataRequest(client, httpRequest, "query", { query, params }, reqOpts).pipe(map(mapResponse));
3460
+ const $request = _dataRequest(client, httpRequest, "query", { query, params }, reqOpts);
3461
+ return stega.enabled ? $request.pipe(
3462
+ combineLatestWith(
3463
+ from(
3464
+ Promise.resolve().then(function () { return stegaEncodeSourceMap9L0STMBo; }).then(function (n) { return n.stegaEncodeSourceMap$1; }).then(
3465
+ ({ stegaEncodeSourceMap }) => stegaEncodeSourceMap
3466
+ )
3467
+ )
3468
+ ),
3469
+ map(
3470
+ ([res, stegaEncodeSourceMap]) => {
3471
+ const result = stegaEncodeSourceMap(res.result, res.resultSourceMap, stega);
3472
+ return mapResponse({ ...res, result });
3473
+ }
3474
+ )
3475
+ ) : $request.pipe(map(mapResponse));
2933
3476
  }
2934
3477
  function _getDocument(client, httpRequest, id, opts = {}) {
2935
3478
  const options = { uri: _getDataUrl(client, "doc", id), json: true, tag: opts.tag };
@@ -3670,10 +4213,25 @@
3670
4213
  * @param newConfig - New client configuration properties, shallowly merged with existing configuration
3671
4214
  */
3672
4215
  withConfig(newConfig) {
3673
- return new _ObservableSanityClient(__privateGet(this, _httpRequest), { ...this.config(), ...newConfig });
4216
+ const thisConfig = this.config();
4217
+ return new _ObservableSanityClient(__privateGet(this, _httpRequest), {
4218
+ ...this.config(),
4219
+ ...newConfig,
4220
+ stega: {
4221
+ ...thisConfig.stega || {},
4222
+ ...typeof (newConfig == null ? void 0 : newConfig.stega) === "boolean" ? { enabled: newConfig.stega } : (newConfig == null ? void 0 : newConfig.stega) || {}
4223
+ }
4224
+ });
3674
4225
  }
3675
4226
  fetch(query, params, options = {}) {
3676
- return _fetch(this, __privateGet(this, _httpRequest), query, params, options);
4227
+ return _fetch(
4228
+ this,
4229
+ __privateGet(this, _httpRequest),
4230
+ __privateGet(this, _clientConfig).stega,
4231
+ query,
4232
+ params,
4233
+ options
4234
+ );
3677
4235
  }
3678
4236
  /**
3679
4237
  * Fetch a single document with the given ID.
@@ -3805,10 +4363,27 @@
3805
4363
  * @param newConfig - New client configuration properties, shallowly merged with existing configuration
3806
4364
  */
3807
4365
  withConfig(newConfig) {
3808
- return new _SanityClient(__privateGet(this, _httpRequest2), { ...this.config(), ...newConfig });
4366
+ const thisConfig = this.config();
4367
+ return new _SanityClient(__privateGet(this, _httpRequest2), {
4368
+ ...thisConfig,
4369
+ ...newConfig,
4370
+ stega: {
4371
+ ...thisConfig.stega || {},
4372
+ ...typeof (newConfig == null ? void 0 : newConfig.stega) === "boolean" ? { enabled: newConfig.stega } : (newConfig == null ? void 0 : newConfig.stega) || {}
4373
+ }
4374
+ });
3809
4375
  }
3810
4376
  fetch(query, params, options = {}) {
3811
- return lastValueFrom(_fetch(this, __privateGet(this, _httpRequest2), query, params, options));
4377
+ return lastValueFrom(
4378
+ _fetch(
4379
+ this,
4380
+ __privateGet(this, _httpRequest2),
4381
+ __privateGet(this, _clientConfig2).stega,
4382
+ query,
4383
+ params,
4384
+ options
4385
+ )
4386
+ );
3812
4387
  }
3813
4388
  /**
3814
4389
  * Fetch a single document with the given ID.
@@ -3943,6 +4518,484 @@
3943
4518
  const createClient = exp.createClient;
3944
4519
  const deprecatedCreateClient = defineDeprecatedCreateClient(createClient);
3945
4520
 
4521
+ const reKeySegment = /_key\s*==\s*['"](.*)['"]/;
4522
+ function isKeySegment(segment) {
4523
+ if (typeof segment === "string") {
4524
+ return reKeySegment.test(segment.trim());
4525
+ }
4526
+ return typeof segment === "object" && "_key" in segment;
4527
+ }
4528
+ function toString(path) {
4529
+ if (!Array.isArray(path)) {
4530
+ throw new Error("Path is not an array");
4531
+ }
4532
+ return path.reduce((target, segment, i) => {
4533
+ const segmentType = typeof segment;
4534
+ if (segmentType === "number") {
4535
+ return "".concat(target, "[").concat(segment, "]");
4536
+ }
4537
+ if (segmentType === "string") {
4538
+ const separator = i === 0 ? "" : ".";
4539
+ return "".concat(target).concat(separator).concat(segment);
4540
+ }
4541
+ if (isKeySegment(segment) && segment._key) {
4542
+ return "".concat(target, '[_key=="').concat(segment._key, '"]');
4543
+ }
4544
+ if (Array.isArray(segment)) {
4545
+ const [from, to] = segment;
4546
+ return "".concat(target, "[").concat(from, ":").concat(to, "]");
4547
+ }
4548
+ throw new Error("Unsupported path segment `".concat(JSON.stringify(segment), "`"));
4549
+ }, "");
4550
+ }
4551
+
4552
+ const ESCAPE = {
4553
+ "\f": "\\f",
4554
+ "\n": "\\n",
4555
+ "\r": "\\r",
4556
+ " ": "\\t",
4557
+ "'": "\\'",
4558
+ "\\": "\\\\"
4559
+ };
4560
+ const UNESCAPE = {
4561
+ "\\f": "\f",
4562
+ "\\n": "\n",
4563
+ "\\r": "\r",
4564
+ "\\t": " ",
4565
+ "\\'": "'",
4566
+ "\\\\": "\\"
4567
+ };
4568
+ function jsonPath(path) {
4569
+ return "$".concat(path.map((segment) => {
4570
+ if (typeof segment === "string") {
4571
+ const escapedKey = segment.replace(/[\f\n\r\t'\\]/g, (match) => {
4572
+ return ESCAPE[match];
4573
+ });
4574
+ return "['".concat(escapedKey, "']");
4575
+ }
4576
+ if (typeof segment === "number") {
4577
+ return "[".concat(segment, "]");
4578
+ }
4579
+ if (segment._key !== "") {
4580
+ const escapedKey = segment._key.replace(/['\\]/g, (match) => {
4581
+ return ESCAPE[match];
4582
+ });
4583
+ return "[?(@._key=='".concat(escapedKey, "')]");
4584
+ }
4585
+ return "[".concat(segment._index, "]");
4586
+ }).join(""));
4587
+ }
4588
+ function parseJsonPath(path) {
4589
+ const parsed = [];
4590
+ const parseRe = /\['(.*?)'\]|\[(\d+)\]|\[\?\(@\._key=='(.*?)'\)\]/g;
4591
+ let match;
4592
+ while ((match = parseRe.exec(path)) !== null) {
4593
+ if (match[1] !== void 0) {
4594
+ const key = match[1].replace(/\\(\\|f|n|r|t|')/g, (m) => {
4595
+ return UNESCAPE[m];
4596
+ });
4597
+ parsed.push(key);
4598
+ continue;
4599
+ }
4600
+ if (match[2] !== void 0) {
4601
+ parsed.push(parseInt(match[2], 10));
4602
+ continue;
4603
+ }
4604
+ if (match[3] !== void 0) {
4605
+ const _key = match[3].replace(/\\(\\')/g, (m) => {
4606
+ return UNESCAPE[m];
4607
+ });
4608
+ parsed.push({
4609
+ _key,
4610
+ _index: -1
4611
+ });
4612
+ continue;
4613
+ }
4614
+ }
4615
+ return parsed;
4616
+ }
4617
+ function jsonPathToStudioPath(path) {
4618
+ return path.map((segment) => {
4619
+ if (typeof segment === "string") {
4620
+ return segment;
4621
+ }
4622
+ if (typeof segment === "number") {
4623
+ return segment;
4624
+ }
4625
+ if (segment._key !== "") {
4626
+ return { _key: segment._key };
4627
+ }
4628
+ if (segment._index !== -1) {
4629
+ return segment._index;
4630
+ }
4631
+ throw new Error("invalid segment:".concat(JSON.stringify(segment)));
4632
+ });
4633
+ }
4634
+ function jsonPathToMappingPath(path) {
4635
+ return path.map((segment) => {
4636
+ if (typeof segment === "string") {
4637
+ return segment;
4638
+ }
4639
+ if (typeof segment === "number") {
4640
+ return segment;
4641
+ }
4642
+ if (segment._index !== -1) {
4643
+ return segment._index;
4644
+ }
4645
+ throw new Error("invalid segment:".concat(JSON.stringify(segment)));
4646
+ });
4647
+ }
4648
+
4649
+ function resolveMapping(resultPath, csm) {
4650
+ if (!(csm == null ? void 0 : csm.mappings)) {
4651
+ return void 0;
4652
+ }
4653
+ const resultMappingPath = jsonPath(jsonPathToMappingPath(resultPath));
4654
+ if (csm.mappings[resultMappingPath] !== void 0) {
4655
+ return {
4656
+ mapping: csm.mappings[resultMappingPath],
4657
+ matchedPath: resultMappingPath,
4658
+ pathSuffix: ""
4659
+ };
4660
+ }
4661
+ const mappings = Object.entries(csm.mappings).filter(([key]) => resultMappingPath.startsWith(key)).sort(([key1], [key2]) => key2.length - key1.length);
4662
+ if (mappings.length == 0) {
4663
+ return void 0;
4664
+ }
4665
+ const [matchedPath, mapping] = mappings[0];
4666
+ const pathSuffix = resultMappingPath.substring(matchedPath.length);
4667
+ return { mapping, matchedPath, pathSuffix };
4668
+ }
4669
+
4670
+ function isArray(value) {
4671
+ return value !== null && Array.isArray(value);
4672
+ }
4673
+
4674
+ function isRecord(value) {
4675
+ return typeof value === "object" && value !== null;
4676
+ }
4677
+
4678
+ function walkMap(value, mappingFn, path = []) {
4679
+ if (isArray(value)) {
4680
+ return value.map((v, idx) => {
4681
+ if (isRecord(v)) {
4682
+ const _key = v["_key"];
4683
+ if (typeof _key === "string") {
4684
+ return walkMap(v, mappingFn, path.concat({ _key, _index: idx }));
4685
+ }
4686
+ }
4687
+ return walkMap(v, mappingFn, path.concat(idx));
4688
+ });
4689
+ }
4690
+ if (isRecord(value)) {
4691
+ return Object.fromEntries(
4692
+ Object.entries(value).map(([k, v]) => [k, walkMap(v, mappingFn, path.concat(k))])
4693
+ );
4694
+ }
4695
+ return mappingFn(value, path);
4696
+ }
4697
+
4698
+ function encodeIntoResult(result, csm, encoder) {
4699
+ return walkMap(result, (value, path) => {
4700
+ if (typeof value !== "string") {
4701
+ return value;
4702
+ }
4703
+ const resolveMappingResult = resolveMapping(path, csm);
4704
+ if (!resolveMappingResult) {
4705
+ return value;
4706
+ }
4707
+ const { mapping, matchedPath } = resolveMappingResult;
4708
+ if (mapping.type !== "value") {
4709
+ return value;
4710
+ }
4711
+ if (mapping.source.type !== "documentValue") {
4712
+ return value;
4713
+ }
4714
+ const sourceDocument = csm.documents[mapping.source.document];
4715
+ const sourcePath = csm.paths[mapping.source.path];
4716
+ const matchPathSegments = parseJsonPath(matchedPath);
4717
+ const sourcePathSegments = parseJsonPath(sourcePath);
4718
+ const fullSourceSegments = sourcePathSegments.concat(path.slice(matchPathSegments.length));
4719
+ return encoder({
4720
+ sourcePath: fullSourceSegments,
4721
+ sourceDocument,
4722
+ resultPath: path,
4723
+ value
4724
+ });
4725
+ });
4726
+ }
4727
+
4728
+ const DRAFTS_PREFIX = "drafts.";
4729
+ function getPublishedId(id) {
4730
+ if (id.startsWith(DRAFTS_PREFIX)) {
4731
+ return id.slice(DRAFTS_PREFIX.length);
4732
+ }
4733
+ return id;
4734
+ }
4735
+
4736
+ function createEditUrl(options) {
4737
+ const {
4738
+ baseUrl,
4739
+ workspace: _workspace = "default",
4740
+ tool: _tool = "default",
4741
+ id: _id,
4742
+ type,
4743
+ path
4744
+ } = options;
4745
+ if (!baseUrl) {
4746
+ throw new Error("baseUrl is required");
4747
+ }
4748
+ if (!path) {
4749
+ throw new Error("path is required");
4750
+ }
4751
+ if (!_id) {
4752
+ throw new Error("id is required");
4753
+ }
4754
+ if (baseUrl !== "/" && baseUrl.endsWith("/")) {
4755
+ throw new Error("baseUrl must not end with a slash");
4756
+ }
4757
+ const workspace = _workspace === "default" ? void 0 : _workspace;
4758
+ const tool = _tool === "default" ? void 0 : _tool;
4759
+ const id = getPublishedId(_id);
4760
+ const stringifiedPath = Array.isArray(path) ? toString(jsonPathToStudioPath(path)) : path;
4761
+ const searchParams = new URLSearchParams({
4762
+ baseUrl,
4763
+ id,
4764
+ type,
4765
+ path: stringifiedPath
4766
+ });
4767
+ if (workspace) {
4768
+ searchParams.set("workspace", workspace);
4769
+ }
4770
+ if (tool) {
4771
+ searchParams.set("tool", tool);
4772
+ }
4773
+ const segments = [baseUrl === "/" ? "" : baseUrl];
4774
+ if (workspace) {
4775
+ segments.push(workspace);
4776
+ }
4777
+ const routerParams = [
4778
+ "mode=presentation",
4779
+ "id=".concat(id),
4780
+ "type=".concat(type),
4781
+ "path=".concat(encodeURIComponent(stringifiedPath))
4782
+ ];
4783
+ if (tool) {
4784
+ routerParams.push("tool=".concat(tool));
4785
+ }
4786
+ segments.push("intent", "edit", "".concat(routerParams.join(";"), "?").concat(searchParams));
4787
+ return segments.join("/");
4788
+ }
4789
+
4790
+ function resolveStudioBaseRoute(studioUrl) {
4791
+ let baseUrl = typeof studioUrl === "string" ? studioUrl : studioUrl.baseUrl;
4792
+ if (baseUrl !== "/") {
4793
+ baseUrl = baseUrl.replace(/\/$/, "");
4794
+ }
4795
+ if (typeof studioUrl === "string") {
4796
+ return { baseUrl };
4797
+ }
4798
+ return { ...studioUrl, baseUrl };
4799
+ }
4800
+
4801
+ const filterDefault = ({ sourcePath, value }) => {
4802
+ if (isValidDate(value) || isValidURL(value)) {
4803
+ return false;
4804
+ }
4805
+ const endPath = sourcePath.at(-1);
4806
+ if (sourcePath.at(-2) === "slug" && endPath === "current") {
4807
+ return false;
4808
+ }
4809
+ if (typeof endPath === "string" && endPath.startsWith("_")) {
4810
+ return false;
4811
+ }
4812
+ if (typeof endPath === "number" && sourcePath.at(-2) === "marks") {
4813
+ return false;
4814
+ }
4815
+ if (endPath === "href" && typeof sourcePath.at(-2) === "number" && sourcePath.at(-3) === "markDefs") {
4816
+ return false;
4817
+ }
4818
+ if (endPath === "style" || endPath === "listItem") {
4819
+ return false;
4820
+ }
4821
+ if (sourcePath.some(
4822
+ (path) => path === "meta" || path === "metadata" || path === "openGraph" || path === "seo"
4823
+ )) {
4824
+ return false;
4825
+ }
4826
+ if (typeof endPath === "string" && denylist.has(endPath)) {
4827
+ return false;
4828
+ }
4829
+ return true;
4830
+ };
4831
+ const denylist = /* @__PURE__ */ new Set([
4832
+ "color",
4833
+ "colour",
4834
+ "currency",
4835
+ "email",
4836
+ "format",
4837
+ "gid",
4838
+ "hex",
4839
+ "href",
4840
+ "hsl",
4841
+ "hsla",
4842
+ "icon",
4843
+ "id",
4844
+ "index",
4845
+ "key",
4846
+ "language",
4847
+ "layout",
4848
+ "link",
4849
+ "linkAction",
4850
+ "locale",
4851
+ "lqip",
4852
+ "page",
4853
+ "path",
4854
+ "ref",
4855
+ "rgb",
4856
+ "rgba",
4857
+ "route",
4858
+ "secret",
4859
+ "slug",
4860
+ "status",
4861
+ "tag",
4862
+ "template",
4863
+ "theme",
4864
+ "type",
4865
+ "unit",
4866
+ "url",
4867
+ "username",
4868
+ "variant",
4869
+ "website"
4870
+ ]);
4871
+ function isValidDate(dateString) {
4872
+ return Number.isNaN(Number(dateString)) ? Boolean(Date.parse(dateString)) : false;
4873
+ }
4874
+ function isValidURL(url) {
4875
+ try {
4876
+ new URL(url, url.startsWith("/") ? "https://acme.com" : void 0);
4877
+ } catch {
4878
+ return false;
4879
+ }
4880
+ return true;
4881
+ }
4882
+
4883
+ const TRUNCATE_LENGTH = 20;
4884
+ function stegaEncodeSourceMap(result, resultSourceMap, config) {
4885
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
4886
+ const { filter, logger, enabled } = config;
4887
+ if (!enabled) {
4888
+ const msg = "config.enabled must be true, don't call this function otherwise";
4889
+ (_a = logger == null ? void 0 : logger.error) == null ? void 0 : _a.call(logger, "[@sanity/client/stega]: ".concat(msg), { result, resultSourceMap, config });
4890
+ throw new TypeError(msg);
4891
+ }
4892
+ if (!resultSourceMap) {
4893
+ (_b = logger == null ? void 0 : logger.error) == null ? void 0 : _b.call(logger, "[@sanity/client/stega]: Missing Content Source Map from response body", {
4894
+ result,
4895
+ resultSourceMap,
4896
+ config
4897
+ });
4898
+ return result;
4899
+ }
4900
+ if (!config.studioUrl) {
4901
+ const msg = "config.studioUrl must be defined";
4902
+ (_c = logger == null ? void 0 : logger.error) == null ? void 0 : _c.call(logger, "[@sanity/client/stega]: ".concat(msg), { result, resultSourceMap, config });
4903
+ throw new TypeError(msg);
4904
+ }
4905
+ const report = {
4906
+ encoded: [],
4907
+ skipped: []
4908
+ };
4909
+ const resultWithStega = encodeIntoResult(
4910
+ result,
4911
+ resultSourceMap,
4912
+ ({ sourcePath, sourceDocument, resultPath, value }) => {
4913
+ if ((typeof filter === "function" ? filter({ sourcePath, resultPath, filterDefault, sourceDocument, value }) : filterDefault({ sourcePath, resultPath, filterDefault, sourceDocument, value })) === false) {
4914
+ if (logger) {
4915
+ report.skipped.push({
4916
+ path: prettyPathForLogging(sourcePath),
4917
+ value: "".concat(value.slice(0, TRUNCATE_LENGTH)).concat(value.length > TRUNCATE_LENGTH ? "..." : ""),
4918
+ length: value.length
4919
+ });
4920
+ }
4921
+ return value;
4922
+ }
4923
+ if (logger) {
4924
+ report.encoded.push({
4925
+ path: prettyPathForLogging(sourcePath),
4926
+ value: "".concat(value.slice(0, TRUNCATE_LENGTH)).concat(value.length > TRUNCATE_LENGTH ? "..." : ""),
4927
+ length: value.length
4928
+ });
4929
+ }
4930
+ const { baseUrl, workspace, tool } = resolveStudioBaseRoute(
4931
+ typeof config.studioUrl === "function" ? config.studioUrl(sourceDocument) : config.studioUrl
4932
+ );
4933
+ if (!baseUrl)
4934
+ return value;
4935
+ const { _id: id, _type: type } = sourceDocument;
4936
+ return b(
4937
+ value,
4938
+ {
4939
+ origin: "sanity.io",
4940
+ href: createEditUrl({
4941
+ baseUrl,
4942
+ workspace,
4943
+ tool,
4944
+ id,
4945
+ type,
4946
+ path: sourcePath
4947
+ })
4948
+ },
4949
+ // We use custom logic to determine if we should skip encoding
4950
+ false
4951
+ );
4952
+ }
4953
+ );
4954
+ if (logger) {
4955
+ const isSkipping = report.skipped.length;
4956
+ const isEncoding = report.encoded.length;
4957
+ if (isSkipping || isEncoding) {
4958
+ (_d = (logger == null ? void 0 : logger.groupCollapsed) || logger.log) == null ? void 0 : _d(
4959
+ "[@sanity/client/stega]: Encoding source map into result"
4960
+ );
4961
+ (_e = logger.log) == null ? void 0 : _e.call(
4962
+ logger,
4963
+ "[@sanity/client/stega]: Paths encoded: ".concat(report.encoded.length, ", skipped: ").concat(report.skipped.length)
4964
+ );
4965
+ }
4966
+ if (report.encoded.length > 0) {
4967
+ (_f = logger == null ? void 0 : logger.log) == null ? void 0 : _f.call(logger, "[@sanity/client/stega]: Table of encoded paths");
4968
+ (_g = (logger == null ? void 0 : logger.table) || logger.log) == null ? void 0 : _g(report.encoded);
4969
+ }
4970
+ if (report.skipped.length > 0) {
4971
+ const skipped = /* @__PURE__ */ new Set();
4972
+ for (const { path } of report.skipped) {
4973
+ skipped.add(path.replace(reKeySegment, "0").replace(/\[\d+\]/g, "[]"));
4974
+ }
4975
+ (_h = logger == null ? void 0 : logger.log) == null ? void 0 : _h.call(logger, "[@sanity/client/stega]: List of skipped paths", [...skipped.values()]);
4976
+ }
4977
+ if (isSkipping || isEncoding) {
4978
+ (_i = logger == null ? void 0 : logger.groupEnd) == null ? void 0 : _i.call(logger);
4979
+ }
4980
+ }
4981
+ return resultWithStega;
4982
+ }
4983
+ function prettyPathForLogging(path) {
4984
+ return toString(jsonPathToStudioPath(path));
4985
+ }
4986
+
4987
+ var stegaEncodeSourceMap$1 = /*#__PURE__*/Object.freeze({
4988
+ __proto__: null,
4989
+ stegaEncodeSourceMap: stegaEncodeSourceMap
4990
+ });
4991
+
4992
+ var stegaEncodeSourceMap9L0STMBo = /*#__PURE__*/Object.freeze({
4993
+ __proto__: null,
4994
+ encodeIntoResult: encodeIntoResult,
4995
+ stegaEncodeSourceMap: stegaEncodeSourceMap,
4996
+ stegaEncodeSourceMap$1: stegaEncodeSourceMap$1
4997
+ });
4998
+
3946
4999
  var eventsource = {exports: {}};
3947
5000
 
3948
5001
  /** @license