@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
@@ -2,699 +2,11 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var browserMiddleware = require('./_chunks/browserMiddleware-1MULg59S.cjs');
6
- var operators = require('rxjs/operators');
7
- var stega = require('@vercel/stega');
5
+ var browserMiddleware = require('./_chunks/browserMiddleware-Pe3R-Bkh.cjs');
6
+ var stegaEncodeSourceMap = require('./_chunks/stegaEncodeSourceMap-vNYIaMiu.cjs');
8
7
  var getIt = require('get-it');
9
8
 
10
- const defaultStegaConfig = {
11
- enabled: false,
12
- filter: (props) => props.filterDefault(props)
13
- };
14
- function splitConfig(config) {
15
- const { stega = {}, ...clientConfig } = config;
16
- return { clientConfig, stegaConfig: typeof stega === "boolean" ? { enabled: stega } : stega };
17
- }
18
- const initStegaConfig = (config, prevConfig) => {
19
- const specifiedConfig = Object.assign({}, prevConfig, config);
20
- const newConfig = Object.assign({}, defaultStegaConfig, specifiedConfig);
21
- if ("encodeSourceMap" in newConfig) {
22
- throw new Error(
23
- "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'?"
24
- );
25
- }
26
- if ("encodeSourceMapAtPath" in newConfig) {
27
- throw new Error(
28
- "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'?"
29
- );
30
- }
31
- if (typeof newConfig.enabled !== "boolean") {
32
- throw new Error("config.enabled must be a boolean, received ".concat(newConfig.enabled));
33
- }
34
- if (newConfig.enabled && newConfig.studioUrl === void 0) {
35
- throw new Error("config.studioUrl must be defined when config.enabled is true");
36
- }
37
- if (newConfig.enabled && typeof newConfig.studioUrl !== "string" && typeof newConfig.studioUrl !== "function") {
38
- throw new Error(
39
- "config.studioUrl must be a string or a function, received ".concat(newConfig.studioUrl)
40
- );
41
- }
42
- return newConfig;
43
- };
44
- function splitStegaConfigFromFetchOptions(options, initializedStegaConfig) {
45
- const { stega = {}, ...fetchOptions } = options;
46
- const stegaConfig = initStegaConfig(
47
- typeof stega === "boolean" ? { enabled: stega } : stega,
48
- initializedStegaConfig
49
- );
50
- return { fetchOptions, stegaConfig };
51
- }
52
-
53
- const DRAFTS_PREFIX = "drafts.";
54
- function getPublishedId(id) {
55
- if (id.startsWith(DRAFTS_PREFIX)) {
56
- return id.slice(DRAFTS_PREFIX.length);
57
- }
58
- return id;
59
- }
60
-
61
- const reKeySegment = /_key\s*==\s*['"](.*)['"]/;
62
- function isKeySegment(segment) {
63
- if (typeof segment === "string") {
64
- return reKeySegment.test(segment.trim());
65
- }
66
- return typeof segment === "object" && "_key" in segment;
67
- }
68
- function toString(path) {
69
- if (!Array.isArray(path)) {
70
- throw new Error("Path is not an array");
71
- }
72
- return path.reduce((target, segment, i) => {
73
- const segmentType = typeof segment;
74
- if (segmentType === "number") {
75
- return "".concat(target, "[").concat(segment, "]");
76
- }
77
- if (segmentType === "string") {
78
- const separator = i === 0 ? "" : ".";
79
- return "".concat(target).concat(separator).concat(segment);
80
- }
81
- if (isKeySegment(segment) && segment._key) {
82
- return "".concat(target, '[_key=="').concat(segment._key, '"]');
83
- }
84
- if (Array.isArray(segment)) {
85
- const [from, to] = segment;
86
- return "".concat(target, "[").concat(from, ":").concat(to, "]");
87
- }
88
- throw new Error("Unsupported path segment `".concat(JSON.stringify(segment), "`"));
89
- }, "");
90
- }
91
-
92
- const ESCAPE = {
93
- "\f": "\\f",
94
- "\n": "\\n",
95
- "\r": "\\r",
96
- " ": "\\t",
97
- "'": "\\'",
98
- "\\": "\\\\"
99
- };
100
- const UNESCAPE = {
101
- "\\f": "\f",
102
- "\\n": "\n",
103
- "\\r": "\r",
104
- "\\t": " ",
105
- "\\'": "'",
106
- "\\\\": "\\"
107
- };
108
- function jsonPath(path) {
109
- return "$".concat(path.map((segment) => {
110
- if (typeof segment === "string") {
111
- const escapedKey = segment.replace(/[\f\n\r\t'\\]/g, (match) => {
112
- return ESCAPE[match];
113
- });
114
- return "['".concat(escapedKey, "']");
115
- }
116
- if (typeof segment === "number") {
117
- return "[".concat(segment, "]");
118
- }
119
- if (segment._key !== "") {
120
- const escapedKey = segment._key.replace(/['\\]/g, (match) => {
121
- return ESCAPE[match];
122
- });
123
- return "[?(@._key=='".concat(escapedKey, "')]");
124
- }
125
- return "[".concat(segment._index, "]");
126
- }).join(""));
127
- }
128
- function parseJsonPath(path) {
129
- const parsed = [];
130
- const parseRe = /\['(.*?)'\]|\[(\d+)\]|\[\?\(@\._key=='(.*?)'\)\]/g;
131
- let match;
132
- while ((match = parseRe.exec(path)) !== null) {
133
- if (match[1] !== void 0) {
134
- const key = match[1].replace(/\\(\\|f|n|r|t|')/g, (m) => {
135
- return UNESCAPE[m];
136
- });
137
- parsed.push(key);
138
- continue;
139
- }
140
- if (match[2] !== void 0) {
141
- parsed.push(parseInt(match[2], 10));
142
- continue;
143
- }
144
- if (match[3] !== void 0) {
145
- const _key = match[3].replace(/\\(\\')/g, (m) => {
146
- return UNESCAPE[m];
147
- });
148
- parsed.push({
149
- _key,
150
- _index: -1
151
- });
152
- continue;
153
- }
154
- }
155
- return parsed;
156
- }
157
- function jsonPathToStudioPath(path) {
158
- return path.map((segment) => {
159
- if (typeof segment === "string") {
160
- return segment;
161
- }
162
- if (typeof segment === "number") {
163
- return segment;
164
- }
165
- if (segment._key !== "") {
166
- return { _key: segment._key };
167
- }
168
- if (segment._index !== -1) {
169
- return segment._index;
170
- }
171
- throw new Error("invalid segment:".concat(JSON.stringify(segment)));
172
- });
173
- }
174
- function jsonPathToMappingPath(path) {
175
- return path.map((segment) => {
176
- if (typeof segment === "string") {
177
- return segment;
178
- }
179
- if (typeof segment === "number") {
180
- return segment;
181
- }
182
- if (segment._index !== -1) {
183
- return segment._index;
184
- }
185
- throw new Error("invalid segment:".concat(JSON.stringify(segment)));
186
- });
187
- }
188
-
189
- function createEditUrl(options) {
190
- const {
191
- baseUrl,
192
- workspace: _workspace = "default",
193
- tool: _tool = "default",
194
- id: _id,
195
- type,
196
- path
197
- } = options;
198
- if (!baseUrl) {
199
- throw new Error("baseUrl is required");
200
- }
201
- if (!path) {
202
- throw new Error("path is required");
203
- }
204
- if (!_id) {
205
- throw new Error("id is required");
206
- }
207
- if (baseUrl !== "/" && baseUrl.endsWith("/")) {
208
- throw new Error("baseUrl must not end with a slash");
209
- }
210
- const workspace = _workspace === "default" ? void 0 : _workspace;
211
- const tool = _tool === "default" ? void 0 : _tool;
212
- const id = getPublishedId(_id);
213
- const stringifiedPath = Array.isArray(path) ? toString(jsonPathToStudioPath(path)) : path;
214
- const searchParams = new URLSearchParams({
215
- baseUrl,
216
- id,
217
- type,
218
- path: stringifiedPath
219
- });
220
- if (workspace) {
221
- searchParams.set("workspace", workspace);
222
- }
223
- if (tool) {
224
- searchParams.set("tool", tool);
225
- }
226
- const segments = [baseUrl === "/" ? "" : baseUrl];
227
- if (workspace) {
228
- segments.push(workspace);
229
- }
230
- const routerParams = [
231
- "mode=presentation",
232
- "id=".concat(id),
233
- "type=".concat(type),
234
- "path=".concat(encodeURIComponent(stringifiedPath))
235
- ];
236
- if (tool) {
237
- routerParams.push("tool=".concat(tool));
238
- }
239
- segments.push("intent", "edit", "".concat(routerParams.join(";"), "?").concat(searchParams));
240
- return segments.join("/");
241
- }
242
-
243
- function resolveMapping(resultPath, csm) {
244
- if (!(csm == null ? void 0 : csm.mappings)) {
245
- return void 0;
246
- }
247
- const resultMappingPath = jsonPath(jsonPathToMappingPath(resultPath));
248
- if (csm.mappings[resultMappingPath] !== void 0) {
249
- return {
250
- mapping: csm.mappings[resultMappingPath],
251
- matchedPath: resultMappingPath,
252
- pathSuffix: ""
253
- };
254
- }
255
- const mappings = Object.entries(csm.mappings).filter(([key]) => resultMappingPath.startsWith(key)).sort(([key1], [key2]) => key2.length - key1.length);
256
- if (mappings.length == 0) {
257
- return void 0;
258
- }
259
- const [matchedPath, mapping] = mappings[0];
260
- const pathSuffix = resultMappingPath.substring(matchedPath.length);
261
- return { mapping, matchedPath, pathSuffix };
262
- }
263
-
264
- function resolveStudioBaseRoute(studioUrl) {
265
- let baseUrl = typeof studioUrl === "string" ? studioUrl : studioUrl.baseUrl;
266
- if (baseUrl !== "/") {
267
- baseUrl = baseUrl.replace(/\/$/, "");
268
- }
269
- if (typeof studioUrl === "string") {
270
- return { baseUrl };
271
- }
272
- return { ...studioUrl, baseUrl };
273
- }
274
-
275
- function isArray(value) {
276
- return value !== null && Array.isArray(value);
277
- }
278
-
279
- function isRecord(value) {
280
- return typeof value === "object" && value !== null;
281
- }
282
-
283
- function walkMap(value, mappingFn, path = []) {
284
- if (isArray(value)) {
285
- return value.map((v, idx) => {
286
- if (isRecord(v)) {
287
- const _key = v["_key"];
288
- if (typeof _key === "string") {
289
- return walkMap(v, mappingFn, path.concat({ _key, _index: idx }));
290
- }
291
- }
292
- return walkMap(v, mappingFn, path.concat(idx));
293
- });
294
- }
295
- if (isRecord(value)) {
296
- return Object.fromEntries(
297
- Object.entries(value).map(([k, v]) => [k, walkMap(v, mappingFn, path.concat(k))])
298
- );
299
- }
300
- return mappingFn(value, path);
301
- }
302
-
303
- function encodeIntoResult(result, csm, encoder) {
304
- return walkMap(result, (value, path) => {
305
- if (typeof value !== "string") {
306
- return value;
307
- }
308
- const resolveMappingResult = resolveMapping(path, csm);
309
- if (!resolveMappingResult) {
310
- return value;
311
- }
312
- const { mapping, matchedPath } = resolveMappingResult;
313
- if (mapping.type !== "value") {
314
- return value;
315
- }
316
- if (mapping.source.type !== "documentValue") {
317
- return value;
318
- }
319
- const sourceDocument = csm.documents[mapping.source.document];
320
- const sourcePath = csm.paths[mapping.source.path];
321
- const matchPathSegments = parseJsonPath(matchedPath);
322
- const sourcePathSegments = parseJsonPath(sourcePath);
323
- const fullSourceSegments = sourcePathSegments.concat(path.slice(matchPathSegments.length));
324
- return encoder({
325
- sourcePath: fullSourceSegments,
326
- sourceDocument,
327
- resultPath: path,
328
- value
329
- });
330
- });
331
- }
332
-
333
- const filterDefault = ({ sourcePath, value }) => {
334
- if (isValidDate(value) || isValidURL(value)) {
335
- return false;
336
- }
337
- const endPath = sourcePath.at(-1);
338
- if (sourcePath.at(-2) === "slug" && endPath === "current") {
339
- return false;
340
- }
341
- if (typeof endPath === "string" && endPath.startsWith("_")) {
342
- return false;
343
- }
344
- if (typeof endPath === "number" && sourcePath.at(-2) === "marks") {
345
- return false;
346
- }
347
- if (endPath === "href" && typeof sourcePath.at(-2) === "number" && sourcePath.at(-3) === "markDefs") {
348
- return false;
349
- }
350
- if (endPath === "style" || endPath === "listItem") {
351
- return false;
352
- }
353
- if (sourcePath.some(
354
- (path) => path === "meta" || path === "metadata" || path === "openGraph" || path === "seo"
355
- )) {
356
- return false;
357
- }
358
- if (typeof endPath === "string" && denylist.has(endPath)) {
359
- return false;
360
- }
361
- return true;
362
- };
363
- const denylist = /* @__PURE__ */ new Set([
364
- "color",
365
- "colour",
366
- "currency",
367
- "email",
368
- "format",
369
- "gid",
370
- "hex",
371
- "href",
372
- "hsl",
373
- "hsla",
374
- "icon",
375
- "id",
376
- "index",
377
- "key",
378
- "language",
379
- "layout",
380
- "link",
381
- "linkAction",
382
- "locale",
383
- "lqip",
384
- "page",
385
- "path",
386
- "ref",
387
- "rgb",
388
- "rgba",
389
- "route",
390
- "secret",
391
- "slug",
392
- "status",
393
- "tag",
394
- "template",
395
- "theme",
396
- "type",
397
- "unit",
398
- "url",
399
- "username",
400
- "variant",
401
- "website"
402
- ]);
403
- function isValidDate(dateString) {
404
- return Number.isNaN(Number(dateString)) ? Boolean(Date.parse(dateString)) : false;
405
- }
406
- function isValidURL(url) {
407
- try {
408
- new URL(url, url.startsWith("/") ? "https://acme.com" : void 0);
409
- } catch {
410
- return false;
411
- }
412
- return true;
413
- }
414
-
415
- const TRUNCATE_LENGTH = 20;
416
- function stegaEncodeSourceMap(result, resultSourceMap, config) {
417
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
418
- const { filter, logger, enabled } = config;
419
- if (!enabled) {
420
- const msg = "config.enabled must be true, don't call this function otherwise";
421
- (_a = logger == null ? void 0 : logger.error) == null ? void 0 : _a.call(logger, "[@sanity/client/stega]: ".concat(msg), { result, resultSourceMap, config });
422
- throw new TypeError(msg);
423
- }
424
- if (!resultSourceMap) {
425
- (_b = logger == null ? void 0 : logger.error) == null ? void 0 : _b.call(logger, "[@sanity/client/stega]: Missing Content Source Map from response body", {
426
- result,
427
- resultSourceMap,
428
- config
429
- });
430
- return result;
431
- }
432
- if (!config.studioUrl) {
433
- const msg = "config.studioUrl must be defined";
434
- (_c = logger == null ? void 0 : logger.error) == null ? void 0 : _c.call(logger, "[@sanity/client/stega]: ".concat(msg), { result, resultSourceMap, config });
435
- throw new TypeError(msg);
436
- }
437
- const report = {
438
- encoded: [],
439
- skipped: []
440
- };
441
- const resultWithStega = encodeIntoResult(
442
- result,
443
- resultSourceMap,
444
- ({ sourcePath, sourceDocument, resultPath, value }) => {
445
- if ((typeof filter === "function" ? filter({ sourcePath, resultPath, filterDefault, sourceDocument, value }) : filterDefault({ sourcePath, resultPath, filterDefault, sourceDocument, value })) === false) {
446
- if (logger) {
447
- report.skipped.push({
448
- path: prettyPathForLogging(sourcePath),
449
- value: "".concat(value.slice(0, TRUNCATE_LENGTH)).concat(value.length > TRUNCATE_LENGTH ? "..." : ""),
450
- length: value.length
451
- });
452
- }
453
- return value;
454
- }
455
- if (logger) {
456
- report.encoded.push({
457
- path: prettyPathForLogging(sourcePath),
458
- value: "".concat(value.slice(0, TRUNCATE_LENGTH)).concat(value.length > TRUNCATE_LENGTH ? "..." : ""),
459
- length: value.length
460
- });
461
- }
462
- const { baseUrl, workspace, tool } = resolveStudioBaseRoute(
463
- typeof config.studioUrl === "function" ? config.studioUrl(sourceDocument) : config.studioUrl
464
- );
465
- if (!baseUrl)
466
- return value;
467
- const { _id: id, _type: type } = sourceDocument;
468
- return stega.vercelStegaCombine(
469
- value,
470
- {
471
- origin: "sanity.io",
472
- href: createEditUrl({
473
- baseUrl,
474
- workspace,
475
- tool,
476
- id,
477
- type,
478
- path: sourcePath
479
- })
480
- },
481
- // We use custom logic to determine if we should skip encoding
482
- false
483
- );
484
- }
485
- );
486
- if (logger) {
487
- const isSkipping = report.skipped.length;
488
- const isEncoding = report.encoded.length;
489
- if (isSkipping || isEncoding) {
490
- (_d = (logger == null ? void 0 : logger.groupCollapsed) || logger.log) == null ? void 0 : _d(
491
- "[@sanity/client/stega]: Encoding source map into result"
492
- );
493
- (_e = logger.log) == null ? void 0 : _e.call(
494
- logger,
495
- "[@sanity/client/stega]: Paths encoded: ".concat(report.encoded.length, ", skipped: ").concat(report.skipped.length)
496
- );
497
- }
498
- if (report.encoded.length > 0) {
499
- (_f = logger == null ? void 0 : logger.log) == null ? void 0 : _f.call(logger, "[@sanity/client/stega]: Table of encoded paths");
500
- (_g = (logger == null ? void 0 : logger.table) || logger.log) == null ? void 0 : _g(report.encoded);
501
- }
502
- if (report.skipped.length > 0) {
503
- const skipped = /* @__PURE__ */ new Set();
504
- for (const { path } of report.skipped) {
505
- skipped.add(path.replace(reKeySegment, "0").replace(/\[\d+\]/g, "[]"));
506
- }
507
- (_h = logger == null ? void 0 : logger.log) == null ? void 0 : _h.call(logger, "[@sanity/client/stega]: List of skipped paths", [...skipped.values()]);
508
- }
509
- if (isSkipping || isEncoding) {
510
- (_i = logger == null ? void 0 : logger.groupEnd) == null ? void 0 : _i.call(logger);
511
- }
512
- }
513
- return resultWithStega;
514
- }
515
- function prettyPathForLogging(path) {
516
- return toString(jsonPathToStudioPath(path));
517
- }
518
-
519
- function vercelStegaCleanAll(result) {
520
- try {
521
- return JSON.parse(
522
- JSON.stringify(result, (key, value) => {
523
- if (typeof value !== "string")
524
- return value;
525
- return stega.vercelStegaSplit(value).cleaned;
526
- })
527
- );
528
- } catch {
529
- return result;
530
- }
531
- }
532
-
533
- var __accessCheck = (obj, member, msg) => {
534
- if (!member.has(obj))
535
- throw TypeError("Cannot " + msg);
536
- };
537
- var __privateGet = (obj, member, getter) => {
538
- __accessCheck(obj, member, "read from private field");
539
- return getter ? getter.call(obj) : member.get(obj);
540
- };
541
- var __privateAdd = (obj, member, value) => {
542
- if (member.has(obj))
543
- throw TypeError("Cannot add the same private member more than once");
544
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
545
- };
546
- var __privateSet = (obj, member, value, setter) => {
547
- __accessCheck(obj, member, "write to private field");
548
- setter ? setter.call(obj, value) : member.set(obj, value);
549
- return value;
550
- };
551
- var _httpRequest, _httpRequest2;
552
- const _ObservableSanityStegaClient = class _ObservableSanityStegaClient extends browserMiddleware.ObservableSanityClient {
553
- constructor(httpRequest, config = browserMiddleware.defaultConfig) {
554
- const { clientConfig, stegaConfig } = splitConfig(config);
555
- super(httpRequest, clientConfig);
556
- /**
557
- * Private properties
558
- */
559
- __privateAdd(this, _httpRequest, void 0);
560
- __privateSet(this, _httpRequest, httpRequest);
561
- this.stegaConfig = initStegaConfig(stegaConfig, defaultStegaConfig);
562
- }
563
- /**
564
- * Clone the client - returns a new instance
565
- */
566
- clone() {
567
- return new _ObservableSanityStegaClient(__privateGet(this, _httpRequest), this.config());
568
- }
569
- config(newConfig) {
570
- if (newConfig === void 0) {
571
- return { ...super.config(), stega: { ...this.stegaConfig } };
572
- }
573
- const { clientConfig, stegaConfig } = splitConfig(newConfig);
574
- super.config(clientConfig);
575
- this.stegaConfig = initStegaConfig(stegaConfig, this.stegaConfig || {});
576
- return this;
577
- }
578
- /**
579
- * Clone the client with a new (partial) configuration.
580
- *
581
- * @param newConfig - New client configuration properties, shallowly merged with existing configuration
582
- */
583
- withConfig(newConfig) {
584
- const thisConfig = this.config();
585
- const { stegaConfig } = splitConfig(newConfig || {});
586
- return new _ObservableSanityStegaClient(__privateGet(this, _httpRequest), {
587
- ...thisConfig,
588
- ...newConfig,
589
- stega: {
590
- ...thisConfig.stega || {},
591
- ...stegaConfig || {}
592
- }
593
- });
594
- }
595
- fetch(query, _params, _options = {}) {
596
- const { stegaConfig, fetchOptions: options } = splitStegaConfigFromFetchOptions(
597
- _options,
598
- this.stegaConfig
599
- );
600
- const params = _params ? vercelStegaCleanAll(_params) : _params;
601
- if (!stegaConfig.enabled) {
602
- return super.fetch(query, params, options);
603
- }
604
- const { filterResponse: originalFilterResponse = true } = options;
605
- return super.fetch(
606
- query,
607
- params,
608
- Object.assign({}, options, {
609
- filterResponse: false,
610
- resultSourceMap: "withKeyArraySelector"
611
- })
612
- ).pipe(
613
- operators.map((res) => {
614
- const { result: _result, resultSourceMap } = res;
615
- const result = stegaEncodeSourceMap(_result, resultSourceMap, stegaConfig);
616
- return originalFilterResponse ? result : { ...res, result };
617
- })
618
- );
619
- }
620
- };
621
- _httpRequest = new WeakMap();
622
- let ObservableSanityStegaClient = _ObservableSanityStegaClient;
623
- const _SanityStegaClient = class _SanityStegaClient extends browserMiddleware.SanityClient {
624
- constructor(httpRequest, config = browserMiddleware.defaultConfig) {
625
- const { clientConfig, stegaConfig } = splitConfig(config);
626
- super(httpRequest, clientConfig);
627
- /**
628
- * Private properties
629
- */
630
- __privateAdd(this, _httpRequest2, void 0);
631
- __privateSet(this, _httpRequest2, httpRequest);
632
- this.stegaConfig = initStegaConfig(stegaConfig, defaultStegaConfig);
633
- this.observable = new ObservableSanityStegaClient(httpRequest, config);
634
- }
635
- /**
636
- * Clone the client - returns a new instance
637
- */
638
- clone() {
639
- return new _SanityStegaClient(__privateGet(this, _httpRequest2), this.config());
640
- }
641
- config(newConfig) {
642
- if (newConfig === void 0) {
643
- return { ...super.config(), stega: { ...this.stegaConfig } };
644
- }
645
- const { clientConfig, stegaConfig } = splitConfig(newConfig);
646
- super.config(clientConfig);
647
- this.stegaConfig = initStegaConfig(stegaConfig, { ...this.stegaConfig || {} });
648
- return this;
649
- }
650
- /**
651
- * Clone the client with a new (partial) configuration.
652
- *
653
- * @param newConfig - New client configuration properties, shallowly merged with existing configuration
654
- */
655
- withConfig(newConfig) {
656
- const thisConfig = this.config();
657
- const { stegaConfig } = splitConfig(newConfig || {});
658
- return new _SanityStegaClient(__privateGet(this, _httpRequest2), {
659
- ...thisConfig,
660
- ...newConfig,
661
- stega: {
662
- ...thisConfig.stega || {},
663
- ...stegaConfig || {}
664
- }
665
- });
666
- }
667
- fetch(query, _params, _options = {}) {
668
- const { stegaConfig, fetchOptions: options } = splitStegaConfigFromFetchOptions(
669
- _options,
670
- this.stegaConfig
671
- );
672
- const params = _params ? vercelStegaCleanAll(_params) : _params;
673
- if (!stegaConfig.enabled) {
674
- return super.fetch(query, params, options);
675
- }
676
- const { filterResponse: originalFilterResponse = true } = options;
677
- return super.fetch(
678
- query,
679
- params,
680
- Object.assign({}, options, {
681
- filterResponse: false,
682
- resultSourceMap: "withKeyArraySelector"
683
- })
684
- ).then((res) => {
685
- const { result: _result, resultSourceMap } = res;
686
- const result = stegaEncodeSourceMap(_result, resultSourceMap, stegaConfig);
687
- return originalFilterResponse ? result : { ...res, result };
688
- });
689
- }
690
- };
691
- _httpRequest2 = new WeakMap();
692
- let SanityStegaClient = _SanityStegaClient;
693
-
694
- const exp = browserMiddleware.defineCreateClientExports(
695
- browserMiddleware.envMiddleware,
696
- SanityStegaClient
697
- );
9
+ const exp = browserMiddleware.defineCreateClientExports(browserMiddleware.envMiddleware, browserMiddleware.SanityClient);
698
10
  const requester = exp.requester;
699
11
  const createClient = exp.createClient;
700
12
 
@@ -708,19 +20,17 @@ exports.Patch = browserMiddleware.Patch;
708
20
  exports.SanityClient = browserMiddleware.SanityClient;
709
21
  exports.ServerError = browserMiddleware.ServerError;
710
22
  exports.Transaction = browserMiddleware.Transaction;
23
+ exports.vercelStegaCleanAll = browserMiddleware.vercelStegaCleanAll;
24
+ exports.encodeIntoResult = stegaEncodeSourceMap.encodeIntoResult;
25
+ exports.stegaEncodeSourceMap = stegaEncodeSourceMap.stegaEncodeSourceMap;
711
26
  Object.defineProperty(exports, "unstable__adapter", {
712
- enumerable: true,
713
- get: function () { return getIt.adapter; }
27
+ enumerable: true,
28
+ get: function () { return getIt.adapter; }
714
29
  });
715
30
  Object.defineProperty(exports, "unstable__environment", {
716
- enumerable: true,
717
- get: function () { return getIt.environment; }
31
+ enumerable: true,
32
+ get: function () { return getIt.environment; }
718
33
  });
719
- exports.ObservableSanityStegaClient = ObservableSanityStegaClient;
720
- exports.SanityStegaClient = SanityStegaClient;
721
34
  exports.createClient = createClient;
722
- exports.encodeIntoResult = encodeIntoResult;
723
35
  exports.requester = requester;
724
- exports.stegaEncodeSourceMap = stegaEncodeSourceMap;
725
- exports.vercelStegaCleanAll = vercelStegaCleanAll;
726
36
  //# sourceMappingURL=stega.browser.cjs.map