@sanity/client 6.7.1 → 6.8.0-pink-lizard.1

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 (65) hide show
  1. package/README.md +79 -2
  2. package/dist/_chunks/browserMiddleware-Oa7zKwEN.js +1862 -0
  3. package/dist/_chunks/browserMiddleware-Oa7zKwEN.js.map +1 -0
  4. package/dist/_chunks/browserMiddleware-zle5A-pb.cjs +1877 -0
  5. package/dist/_chunks/browserMiddleware-zle5A-pb.cjs.map +1 -0
  6. package/dist/_chunks/createEditLink-FiifjNgi.cjs +222 -0
  7. package/dist/_chunks/createEditLink-FiifjNgi.cjs.map +1 -0
  8. package/dist/_chunks/createEditLink-f3l2nngi.js +212 -0
  9. package/dist/_chunks/createEditLink-f3l2nngi.js.map +1 -0
  10. package/dist/_chunks/nodeMiddleware-S6QZVGmT.cjs +1897 -0
  11. package/dist/_chunks/nodeMiddleware-S6QZVGmT.cjs.map +1 -0
  12. package/dist/_chunks/nodeMiddleware-XodpBhbR.js +1882 -0
  13. package/dist/_chunks/nodeMiddleware-XodpBhbR.js.map +1 -0
  14. package/dist/csm.cjs +71 -0
  15. package/dist/csm.cjs.map +1 -0
  16. package/dist/csm.d.ts +248 -0
  17. package/dist/csm.js +58 -0
  18. package/dist/csm.js.map +1 -0
  19. package/dist/index.browser.cjs +13 -1868
  20. package/dist/index.browser.cjs.map +1 -1
  21. package/dist/index.browser.js +3 -1858
  22. package/dist/index.browser.js.map +1 -1
  23. package/dist/index.cjs +13 -1888
  24. package/dist/index.cjs.js +2 -2
  25. package/dist/index.cjs.map +1 -1
  26. package/dist/index.js +3 -1878
  27. package/dist/index.js.map +1 -1
  28. package/dist/stega.browser.cjs +629 -0
  29. package/dist/stega.browser.cjs.map +1 -0
  30. package/dist/stega.browser.js +598 -0
  31. package/dist/stega.browser.js.map +1 -0
  32. package/dist/stega.cjs +424 -0
  33. package/dist/stega.cjs.js +21 -0
  34. package/dist/stega.cjs.map +1 -0
  35. package/dist/stega.d.ts +2872 -0
  36. package/dist/stega.js +393 -0
  37. package/dist/stega.js.map +1 -0
  38. package/package.json +42 -2
  39. package/src/config.ts +6 -0
  40. package/src/csm/applySourceDocuments.test.ts +820 -0
  41. package/src/csm/applySourceDocuments.ts +87 -0
  42. package/src/csm/createEditLink.ts +75 -0
  43. package/src/csm/getPublishedId.ts +12 -0
  44. package/src/csm/index.ts +9 -0
  45. package/src/csm/isArray.ts +3 -0
  46. package/src/csm/isRecord.ts +3 -0
  47. package/src/csm/jsonpath.test.ts +33 -0
  48. package/src/csm/jsonpath.ts +93 -0
  49. package/src/csm/resolveMapping.ts +41 -0
  50. package/src/csm/resolvedKeyedSourcePath.ts +23 -0
  51. package/src/csm/simplifyPath.ts +20 -0
  52. package/src/csm/types.ts +72 -0
  53. package/src/csm/walkMap.ts +30 -0
  54. package/src/stega/SanityStegaClient.ts +244 -0
  55. package/src/stega/config.ts +56 -0
  56. package/src/stega/encodeIntoResult.test.ts +268 -0
  57. package/src/stega/encodeIntoResult.ts +59 -0
  58. package/src/stega/filterDefault.ts +49 -0
  59. package/src/stega/index.browser.ts +19 -0
  60. package/src/stega/index.ts +19 -0
  61. package/src/stega/shared.ts +4 -0
  62. package/src/stega/stegaEncodeSourceMap.ts +128 -0
  63. package/src/stega/types.ts +139 -0
  64. package/umd/sanityClient.js +5 -1
  65. package/umd/sanityClient.min.js +1 -1
@@ -0,0 +1,629 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', {
4
+ value: true
5
+ });
6
+ var browserMiddleware = require('./_chunks/browserMiddleware-zle5A-pb.cjs');
7
+ var operators = require('rxjs/operators');
8
+ var stega = require('@vercel/stega');
9
+ var getIt = require('get-it');
10
+ const defaultStegaConfig = {
11
+ enabled: false,
12
+ filter: props => props.filterDefault(props),
13
+ vercelStegaCombineSkip: "auto"
14
+ };
15
+ function splitConfig(config) {
16
+ const {
17
+ stega = {},
18
+ ...clientConfig
19
+ } = config;
20
+ return {
21
+ clientConfig,
22
+ stegaConfig: stega
23
+ };
24
+ }
25
+ const initStegaConfig = (config, prevConfig) => {
26
+ const specifiedConfig = Object.assign({}, prevConfig, config);
27
+ const newConfig = Object.assign({}, defaultStegaConfig, specifiedConfig);
28
+ if ("encodeSourceMap" in newConfig) {
29
+ throw new Error("It looks like you're using options meant for '@sanity/preview-kit/client'. 'encodeSourceMap' is not supported in '@sanity/client/stega'. Did you mean 'enabled'?");
30
+ }
31
+ if ("encodeSourceMapAtPath" in newConfig) {
32
+ throw new Error("It looks like you're using options meant for '@sanity/preview-kit/client'. 'encodeSourceMapAtPath' is not supported in '@sanity/client/stega'. Did you mean 'filter'?");
33
+ }
34
+ if (typeof newConfig.enabled !== "boolean") {
35
+ throw new Error("config.enabled must be a boolean, received ".concat(newConfig.enabled));
36
+ }
37
+ if (newConfig.enabled && newConfig.studioUrl === void 0) {
38
+ throw new Error("config.studioUrl must be defined when config.enabled is true");
39
+ }
40
+ if (newConfig.enabled && typeof newConfig.studioUrl !== "string" && typeof newConfig.studioUrl !== "function") {
41
+ throw new Error("config.studioUrl must be a string or a function, received ".concat(newConfig.studioUrl));
42
+ }
43
+ return newConfig;
44
+ };
45
+ const DRAFTS_PREFIX = "drafts.";
46
+ function getPublishedId(id) {
47
+ if (id.startsWith(DRAFTS_PREFIX)) {
48
+ return id.slice(DRAFTS_PREFIX.length);
49
+ }
50
+ return id;
51
+ }
52
+ const ESCAPE = {
53
+ "\f": "\\f",
54
+ "\n": "\\n",
55
+ "\r": "\\r",
56
+ " ": "\\t",
57
+ "'": "\\'",
58
+ "\\": "\\\\"
59
+ };
60
+ const UNESCAPE = {
61
+ "\\f": "\f",
62
+ "\\n": "\n",
63
+ "\\r": "\r",
64
+ "\\t": " ",
65
+ "\\'": "'",
66
+ "\\\\": "\\"
67
+ };
68
+ function jsonPath(path, opts) {
69
+ return "$".concat(path.map(segment => {
70
+ if (typeof segment === "string") {
71
+ const escapedKey = segment.replace(/[\f\n\r\t'\\]/g, match => {
72
+ return ESCAPE[match];
73
+ });
74
+ return "['".concat(escapedKey, "']");
75
+ }
76
+ if (typeof segment === "number") {
77
+ return "[".concat(segment, "]");
78
+ }
79
+ if ((opts == null ? void 0 : opts.keyArraySelectors) && segment.key !== "") {
80
+ const escapedKey = segment.key.replace(/['\\]/g, match => {
81
+ return ESCAPE[match];
82
+ });
83
+ return "[?(@._key=='".concat(escapedKey, "')]");
84
+ }
85
+ return "[".concat(segment.index, "]");
86
+ }).join(""));
87
+ }
88
+ function parseJsonPath(path) {
89
+ const parsed = [];
90
+ const parseRe = /\['(.*?)'\]|\[(\d+)\]|\[\?\(@\._key=='(.*?)'\)\]/g;
91
+ let match;
92
+ while ((match = parseRe.exec(path)) !== null) {
93
+ if (match[1] !== void 0) {
94
+ const key = match[1].replace(/\\(\\|f|n|r|t|')/g, m => {
95
+ return UNESCAPE[m];
96
+ });
97
+ parsed.push(key);
98
+ continue;
99
+ }
100
+ if (match[2] !== void 0) {
101
+ parsed.push(parseInt(match[2], 10));
102
+ continue;
103
+ }
104
+ if (match[3] !== void 0) {
105
+ const key = match[3].replace(/\\(\\')/g, m => {
106
+ return UNESCAPE[m];
107
+ });
108
+ parsed.push({
109
+ key,
110
+ index: -1
111
+ });
112
+ continue;
113
+ }
114
+ }
115
+ return parsed;
116
+ }
117
+ function resolvedKeyedSourcePath(options) {
118
+ const {
119
+ keyedResultPath,
120
+ pathSuffix,
121
+ sourceBasePath
122
+ } = options;
123
+ const inferredResultPath = pathSuffix === void 0 ? [] : parseJsonPath(pathSuffix);
124
+ const inferredPath = keyedResultPath.slice(keyedResultPath.length - inferredResultPath.length);
125
+ const inferredPathSuffix = inferredPath.length ? jsonPath(inferredPath, {
126
+ keyArraySelectors: true
127
+ }).slice(1) : "";
128
+ return parseJsonPath(sourceBasePath + inferredPathSuffix);
129
+ }
130
+ function resolveMapping(resultPath, csm) {
131
+ if (!(csm == null ? void 0 : csm.mappings)) {
132
+ return void 0;
133
+ }
134
+ const resultJsonPath = jsonPath(resultPath);
135
+ if (csm.mappings[resultJsonPath] !== void 0) {
136
+ return {
137
+ mapping: csm.mappings[resultJsonPath],
138
+ matchedPath: resultJsonPath,
139
+ pathSuffix: ""
140
+ };
141
+ }
142
+ const mappings = Object.entries(csm.mappings).filter(_ref => {
143
+ let [key] = _ref;
144
+ return resultJsonPath.startsWith(key);
145
+ }).sort((_ref2, _ref3) => {
146
+ let [key1] = _ref2;
147
+ let [key2] = _ref3;
148
+ return key2.length - key1.length;
149
+ });
150
+ if (mappings.length == 0) {
151
+ return void 0;
152
+ }
153
+ const [matchedPath, mapping] = mappings[0];
154
+ const pathSuffix = resultJsonPath.substring(matchedPath.length);
155
+ return {
156
+ mapping,
157
+ matchedPath,
158
+ pathSuffix
159
+ };
160
+ }
161
+ function simplifyPath(path) {
162
+ return path.map((segment, index) => {
163
+ if (typeof segment === "number") {
164
+ return "[".concat(segment, "]");
165
+ }
166
+ if (typeof segment === "string") {
167
+ return index === 0 ? segment : ".".concat(segment);
168
+ }
169
+ return '[_key=="'.concat(segment.key, '"]');
170
+ }).join("");
171
+ }
172
+ function createEditLink(options) {
173
+ const {
174
+ studioUrl: resolveStudioUrl,
175
+ resultSourceMap: csm,
176
+ resultPath
177
+ } = options;
178
+ const {
179
+ mapping,
180
+ pathSuffix
181
+ } = resolveMapping(resultPath, csm) || {};
182
+ if (!mapping) {
183
+ return void 0;
184
+ }
185
+ if (mapping.source.type === "literal") {
186
+ return void 0;
187
+ }
188
+ if (mapping.source.type === "unknown") {
189
+ return void 0;
190
+ }
191
+ const sourceDoc = csm.documents[mapping.source.document];
192
+ const sourceBasePath = csm.paths[mapping.source.path];
193
+ if (sourceDoc && sourceBasePath) {
194
+ const studioUrl = typeof resolveStudioUrl === "function" ? resolveStudioUrl(sourceDoc, parseJsonPath(sourceBasePath)) : resolveStudioUrl;
195
+ if (!studioUrl) return void 0;
196
+ const _studioUrl = studioUrl.replace(/\/$/, "");
197
+ const _path = encodeURIComponent(simplifyPath(resolvedKeyedSourcePath({
198
+ keyedResultPath: parseJsonPath(sourceBasePath),
199
+ pathSuffix,
200
+ sourceBasePath
201
+ })));
202
+ const {
203
+ _id,
204
+ _type
205
+ } = sourceDoc;
206
+ const params = new URLSearchParams();
207
+ if (sourceDoc._projectId) {
208
+ params.set("projectId", sourceDoc._projectId);
209
+ }
210
+ if (sourceDoc._dataset) {
211
+ params.set("dataset", sourceDoc._dataset);
212
+ }
213
+ params.set("id", getPublishedId(sourceDoc._id));
214
+ params.set("type", sourceDoc._type);
215
+ params.set("path", decodeURIComponent(_path));
216
+ params.set("baseUrl", _studioUrl);
217
+ return "".concat(_studioUrl, "/intent/edit/id=").concat(getPublishedId(_id), ";type=").concat(_type, ";path=").concat(_path, "?").concat(params);
218
+ }
219
+ return void 0;
220
+ }
221
+ function isArray(value) {
222
+ return value !== null && Array.isArray(value);
223
+ }
224
+ function isRecord(value) {
225
+ return typeof value === "object" && value !== null;
226
+ }
227
+ function walkMap(value, mappingFn) {
228
+ let path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
229
+ if (isArray(value)) {
230
+ return value.map((v, idx) => {
231
+ if (isRecord(v)) {
232
+ const key = v["_key"];
233
+ if (typeof key === "string") {
234
+ return walkMap(v, mappingFn, path.concat({
235
+ key,
236
+ index: idx
237
+ }));
238
+ }
239
+ }
240
+ return walkMap(v, mappingFn, path.concat(idx));
241
+ });
242
+ }
243
+ if (isRecord(value)) {
244
+ return Object.fromEntries(Object.entries(value).map(_ref4 => {
245
+ let [k, v] = _ref4;
246
+ return [k, walkMap(v, mappingFn, path.concat(k))];
247
+ }));
248
+ }
249
+ return mappingFn(value, path);
250
+ }
251
+ function encodeIntoResult(result, csm, encoder, options) {
252
+ return walkMap(result, (value, path) => {
253
+ if (typeof value !== "string") {
254
+ return value;
255
+ }
256
+ const resolveMappingResult = resolveMapping(path, csm);
257
+ if (!resolveMappingResult) {
258
+ return value;
259
+ }
260
+ const {
261
+ mapping,
262
+ matchedPath,
263
+ pathSuffix
264
+ } = resolveMappingResult;
265
+ if (mapping.type !== "value") {
266
+ return value;
267
+ }
268
+ if (mapping.source.type !== "documentValue") {
269
+ return value;
270
+ }
271
+ const sourceDocument = csm.documents[mapping.source.document];
272
+ const sourcePath = csm.paths[mapping.source.path];
273
+ if (options == null ? void 0 : options.keyArraySelectors) {
274
+ const matchPathSegments = parseJsonPath(matchedPath);
275
+ const sourcePathSegments = parseJsonPath(sourcePath);
276
+ const fullSourceSegments = sourcePathSegments.concat(path.slice(matchPathSegments.length));
277
+ return encoder({
278
+ sourcePath: fullSourceSegments,
279
+ sourceDocument,
280
+ resultPath: path,
281
+ value
282
+ });
283
+ }
284
+ return encoder({
285
+ sourcePath: parseJsonPath(sourcePath + pathSuffix),
286
+ sourceDocument,
287
+ resultPath: path,
288
+ value
289
+ });
290
+ });
291
+ }
292
+ const filterDefault = _ref5 => {
293
+ let {
294
+ sourcePath
295
+ } = _ref5;
296
+ const endPath = sourcePath.at(-1);
297
+ if (sourcePath.at(-2) === "slug" && endPath === "current") {
298
+ return false;
299
+ }
300
+ if (typeof endPath === "string" && endPath.startsWith("_")) {
301
+ return false;
302
+ }
303
+ if (typeof endPath === "number" && sourcePath.at(-2) === "marks" && typeof sourcePath.at(-3) === "number" && sourcePath.at(-4) === "children" && typeof sourcePath.at(-5) === "number") {
304
+ return false;
305
+ }
306
+ if (endPath === "href" && typeof sourcePath.at(-2) === "number" && sourcePath.at(-3) === "markDefs" && typeof sourcePath.at(-4) === "number") {
307
+ return false;
308
+ }
309
+ if (typeof endPath === "string" && typeof sourcePath.at(-2) === "number") {
310
+ if (endPath === "style" || endPath === "listItem") {
311
+ return false;
312
+ }
313
+ }
314
+ return true;
315
+ };
316
+ const TRUNCATE_LENGTH = 20;
317
+ function stegaEncodeSourceMap(result, resultSourceMap, config) {
318
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
319
+ const {
320
+ filter,
321
+ vercelStegaCombineSkip,
322
+ logger,
323
+ studioUrl,
324
+ enabled
325
+ } = config;
326
+ if (!enabled) {
327
+ const msg = "config.enabled must be true, don't call this function otherwise";
328
+ (_a = logger == null ? void 0 : logger.error) == null ? void 0 : _a.call(logger, "[@sanity/client/stega]: ".concat(msg), {
329
+ result,
330
+ resultSourceMap,
331
+ config
332
+ });
333
+ throw new TypeError(msg);
334
+ }
335
+ if (!resultSourceMap) {
336
+ (_b = logger == null ? void 0 : logger.error) == null ? void 0 : _b.call(logger, "[@sanity/client/stega]: Missing Content Source Map from response body", {
337
+ result,
338
+ resultSourceMap,
339
+ config
340
+ });
341
+ return result;
342
+ }
343
+ if (!studioUrl) {
344
+ const msg = "config.studioUrl must be defined";
345
+ (_c = logger == null ? void 0 : logger.error) == null ? void 0 : _c.call(logger, "[@sanity/client/stega]: ".concat(msg), {
346
+ result,
347
+ resultSourceMap,
348
+ config
349
+ });
350
+ throw new TypeError(msg);
351
+ }
352
+ const report = {
353
+ encoded: [],
354
+ skipped: []
355
+ };
356
+ const resultWithStega = encodeIntoResult(result, resultSourceMap, _ref6 => {
357
+ let {
358
+ sourcePath,
359
+ sourceDocument,
360
+ resultPath,
361
+ value
362
+ } = _ref6;
363
+ if ((typeof filter === "function" ? filter({
364
+ sourcePath,
365
+ resultPath,
366
+ filterDefault,
367
+ sourceDocument,
368
+ value
369
+ }) : filterDefault({
370
+ sourcePath,
371
+ resultPath,
372
+ filterDefault,
373
+ sourceDocument,
374
+ value
375
+ })) === false) {
376
+ if (logger) {
377
+ report.skipped.push({
378
+ path: prettyPathForLogging(sourcePath),
379
+ value: "".concat(value.slice(0, TRUNCATE_LENGTH)).concat(value.length > TRUNCATE_LENGTH ? "..." : ""),
380
+ length: value.length
381
+ });
382
+ }
383
+ return value;
384
+ }
385
+ if (logger) {
386
+ report.encoded.push({
387
+ path: prettyPathForLogging(sourcePath),
388
+ value: "".concat(value.slice(0, TRUNCATE_LENGTH)).concat(value.length > TRUNCATE_LENGTH ? "..." : ""),
389
+ length: value.length
390
+ });
391
+ }
392
+ return stega.vercelStegaCombine(value, {
393
+ origin: "sanity.io",
394
+ href: createEditLink({
395
+ studioUrl,
396
+ resultSourceMap,
397
+ resultPath
398
+ })
399
+ }, vercelStegaCombineSkip);
400
+ }, {
401
+ keyArraySelectors: true
402
+ });
403
+ if (logger) {
404
+ const isSkipping = report.skipped.length;
405
+ const isEncoding = report.encoded.length;
406
+ if (isSkipping || isEncoding) {
407
+ (_d = (logger == null ? void 0 : logger.groupCollapsed) || logger.log) == null ? void 0 : _d("[@sanity/client/stega]: Encoding source map into result");
408
+ (_e = logger.log) == null ? void 0 : _e.call(logger, "[@sanity/client/stega]: Paths encoded: ".concat(report.encoded.length, ", skipped: ").concat(report.skipped.length));
409
+ }
410
+ if (report.encoded.length > 0) {
411
+ (_f = logger == null ? void 0 : logger.log) == null ? void 0 : _f.call(logger, "[@sanity/client/stega]: Table of encoded paths");
412
+ (_g = (logger == null ? void 0 : logger.table) || logger.log) == null ? void 0 : _g(report.encoded);
413
+ }
414
+ if (report.skipped.length > 0) {
415
+ const skipped = /* @__PURE__ */new Set();
416
+ for (const {
417
+ path
418
+ } of report.skipped) {
419
+ skipped.add(path.replace(/\[\d+\]/g, "[]"));
420
+ }
421
+ (_h = logger == null ? void 0 : logger.log) == null ? void 0 : _h.call(logger, "[@sanity/client/stega]: List of skipped paths", [...skipped.values()]);
422
+ }
423
+ if (isSkipping || isEncoding) {
424
+ (_i = logger == null ? void 0 : logger.groupEnd) == null ? void 0 : _i.call(logger);
425
+ }
426
+ }
427
+ return resultWithStega;
428
+ }
429
+ function prettyPathForLogging(path) {
430
+ return path.map((segment, index) => typeof segment === "number" ? "[".concat(segment, "]") : index > 0 ? ".".concat(segment) : segment).join("");
431
+ }
432
+ var __accessCheck = (obj, member, msg) => {
433
+ if (!member.has(obj)) throw TypeError("Cannot " + msg);
434
+ };
435
+ var __privateGet = (obj, member, getter) => {
436
+ __accessCheck(obj, member, "read from private field");
437
+ return getter ? getter.call(obj) : member.get(obj);
438
+ };
439
+ var __privateAdd = (obj, member, value) => {
440
+ if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
441
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
442
+ };
443
+ var __privateSet = (obj, member, value, setter) => {
444
+ __accessCheck(obj, member, "write to private field");
445
+ setter ? setter.call(obj, value) : member.set(obj, value);
446
+ return value;
447
+ };
448
+ var _httpRequest, _httpRequest2;
449
+ const _ObservableSanityStegaClient = class _ObservableSanityStegaClient extends browserMiddleware.ObservableSanityClient {
450
+ constructor(httpRequest) {
451
+ let config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : browserMiddleware.defaultConfig;
452
+ const {
453
+ clientConfig,
454
+ stegaConfig
455
+ } = splitConfig(config);
456
+ super(httpRequest, clientConfig);
457
+ /**
458
+ * Private properties
459
+ */
460
+ __privateAdd(this, _httpRequest, void 0);
461
+ __privateSet(this, _httpRequest, httpRequest);
462
+ this.stegaConfig = initStegaConfig(stegaConfig, defaultStegaConfig);
463
+ }
464
+ /**
465
+ * Clone the client - returns a new instance
466
+ */
467
+ clone() {
468
+ return new _ObservableSanityStegaClient(__privateGet(this, _httpRequest), this.config());
469
+ }
470
+ config(newConfig) {
471
+ if (newConfig === void 0) {
472
+ return {
473
+ ...super.config(),
474
+ stega: {
475
+ ...this.stegaConfig
476
+ }
477
+ };
478
+ }
479
+ super.config(newConfig);
480
+ const {
481
+ stegaConfig
482
+ } = splitConfig(newConfig);
483
+ this.stegaConfig = initStegaConfig(stegaConfig, this.stegaConfig || {});
484
+ return this;
485
+ }
486
+ /**
487
+ * Clone the client with a new (partial) configuration.
488
+ *
489
+ * @param newConfig - New client configuration properties, shallowly merged with existing configuration
490
+ */
491
+ withConfig(newConfig) {
492
+ return new _ObservableSanityStegaClient(__privateGet(this, _httpRequest), {
493
+ ...this.config(),
494
+ ...newConfig
495
+ });
496
+ }
497
+ fetch(query, params) {
498
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
499
+ const {
500
+ filterResponse: originalFilterResponse = true
501
+ } = options;
502
+ return super.fetch(query, params, Object.assign({}, options, {
503
+ filterResponse: false
504
+ })).pipe(operators.map(res => {
505
+ const {
506
+ result: _result,
507
+ resultSourceMap
508
+ } = res;
509
+ let result = _result;
510
+ if (this.stegaConfig.enabled) {
511
+ result = stegaEncodeSourceMap(_result, resultSourceMap, this.stegaConfig);
512
+ }
513
+ return originalFilterResponse ? result : {
514
+ ...res,
515
+ result
516
+ };
517
+ }));
518
+ }
519
+ };
520
+ _httpRequest = new WeakMap();
521
+ let ObservableSanityStegaClient = _ObservableSanityStegaClient;
522
+ const _SanityStegaClient = class _SanityStegaClient extends browserMiddleware.SanityClient {
523
+ constructor(httpRequest) {
524
+ let config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : browserMiddleware.defaultConfig;
525
+ const {
526
+ clientConfig,
527
+ stegaConfig
528
+ } = splitConfig(config);
529
+ super(httpRequest, clientConfig);
530
+ /**
531
+ * Private properties
532
+ */
533
+ __privateAdd(this, _httpRequest2, void 0);
534
+ __privateSet(this, _httpRequest2, httpRequest);
535
+ this.stegaConfig = initStegaConfig(stegaConfig, defaultStegaConfig);
536
+ this.observable = new ObservableSanityStegaClient(httpRequest, config);
537
+ }
538
+ /**
539
+ * Clone the client - returns a new instance
540
+ */
541
+ clone() {
542
+ return new _SanityStegaClient(__privateGet(this, _httpRequest2), this.config());
543
+ }
544
+ config(newConfig) {
545
+ if (newConfig === void 0) {
546
+ return {
547
+ ...super.config(),
548
+ stega: {
549
+ ...this.stegaConfig
550
+ }
551
+ };
552
+ }
553
+ super.config(newConfig);
554
+ const {
555
+ stegaConfig
556
+ } = splitConfig(newConfig);
557
+ this.stegaConfig = initStegaConfig(stegaConfig, {
558
+ ...(this.stegaConfig || {})
559
+ });
560
+ return this;
561
+ }
562
+ /**
563
+ * Clone the client with a new (partial) configuration.
564
+ *
565
+ * @param newConfig - New client configuration properties, shallowly merged with existing configuration
566
+ */
567
+ withConfig(newConfig) {
568
+ return new _SanityStegaClient(__privateGet(this, _httpRequest2), {
569
+ ...this.config(),
570
+ ...newConfig
571
+ });
572
+ }
573
+ fetch(query, params) {
574
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
575
+ const {
576
+ filterResponse: originalFilterResponse = true
577
+ } = options;
578
+ return super.fetch(query, params, Object.assign({}, options, {
579
+ filterResponse: false
580
+ })).then(res => {
581
+ const {
582
+ result: _result,
583
+ resultSourceMap
584
+ } = res;
585
+ let result = _result;
586
+ if (this.stegaConfig.enabled) {
587
+ result = stegaEncodeSourceMap(_result, resultSourceMap, this.stegaConfig);
588
+ }
589
+ return originalFilterResponse ? result : {
590
+ ...res,
591
+ result
592
+ };
593
+ });
594
+ }
595
+ };
596
+ _httpRequest2 = new WeakMap();
597
+ let SanityStegaClient = _SanityStegaClient;
598
+ const exp = browserMiddleware.defineCreateClientExports(browserMiddleware.envMiddleware, SanityStegaClient);
599
+ const requester = exp.requester;
600
+ const createClient = exp.createClient;
601
+ exports.BasePatch = browserMiddleware.BasePatch;
602
+ exports.BaseTransaction = browserMiddleware.BaseTransaction;
603
+ exports.ClientError = browserMiddleware.ClientError;
604
+ exports.ObservablePatch = browserMiddleware.ObservablePatch;
605
+ exports.ObservableSanityClient = browserMiddleware.ObservableSanityClient;
606
+ exports.ObservableTransaction = browserMiddleware.ObservableTransaction;
607
+ exports.Patch = browserMiddleware.Patch;
608
+ exports.SanityClient = browserMiddleware.SanityClient;
609
+ exports.ServerError = browserMiddleware.ServerError;
610
+ exports.Transaction = browserMiddleware.Transaction;
611
+ Object.defineProperty(exports, 'unstable__adapter', {
612
+ enumerable: true,
613
+ get: function () {
614
+ return getIt.adapter;
615
+ }
616
+ });
617
+ Object.defineProperty(exports, 'unstable__environment', {
618
+ enumerable: true,
619
+ get: function () {
620
+ return getIt.environment;
621
+ }
622
+ });
623
+ exports.ObservableSanityStegaClient = ObservableSanityStegaClient;
624
+ exports.SanityStegaClient = SanityStegaClient;
625
+ exports.createClient = createClient;
626
+ exports.encodeIntoResult = encodeIntoResult;
627
+ exports.requester = requester;
628
+ exports.stegaEncodeSourceMap = stegaEncodeSourceMap;
629
+ //# sourceMappingURL=stega.browser.cjs.map