@sanity/client 7.1.0-views.0 → 7.1.0-views.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 (80) hide show
  1. package/README.md +668 -40
  2. package/dist/_chunks-cjs/config.cjs +14 -0
  3. package/dist/_chunks-cjs/config.cjs.map +1 -1
  4. package/dist/_chunks-cjs/dataMethods.cjs +197 -32
  5. package/dist/_chunks-cjs/dataMethods.cjs.map +1 -1
  6. package/dist/_chunks-cjs/isRecord.cjs +6 -0
  7. package/dist/_chunks-cjs/isRecord.cjs.map +1 -0
  8. package/dist/_chunks-cjs/resolveEditInfo.cjs +3 -5
  9. package/dist/_chunks-cjs/resolveEditInfo.cjs.map +1 -1
  10. package/dist/_chunks-cjs/stegaClean.cjs +4 -0
  11. package/dist/_chunks-cjs/stegaClean.cjs.map +1 -1
  12. package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs +2 -5
  13. package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs.map +1 -1
  14. package/dist/_chunks-es/config.js +15 -1
  15. package/dist/_chunks-es/config.js.map +1 -1
  16. package/dist/_chunks-es/dataMethods.js +200 -33
  17. package/dist/_chunks-es/dataMethods.js.map +1 -1
  18. package/dist/_chunks-es/isRecord.js +7 -0
  19. package/dist/_chunks-es/isRecord.js.map +1 -0
  20. package/dist/_chunks-es/resolveEditInfo.js +1 -3
  21. package/dist/_chunks-es/resolveEditInfo.js.map +1 -1
  22. package/dist/_chunks-es/stegaClean.js +4 -0
  23. package/dist/_chunks-es/stegaClean.js.map +1 -1
  24. package/dist/_chunks-es/stegaEncodeSourceMap.js +1 -4
  25. package/dist/_chunks-es/stegaEncodeSourceMap.js.map +1 -1
  26. package/dist/index.browser.cjs +1019 -59
  27. package/dist/index.browser.cjs.map +1 -1
  28. package/dist/index.browser.d.cts +1948 -149
  29. package/dist/index.browser.d.ts +1948 -149
  30. package/dist/index.browser.js +1021 -60
  31. package/dist/index.browser.js.map +1 -1
  32. package/dist/index.cjs +825 -29
  33. package/dist/index.cjs.map +1 -1
  34. package/dist/index.d.cts +1948 -149
  35. package/dist/index.d.ts +1948 -149
  36. package/dist/index.js +826 -31
  37. package/dist/index.js.map +1 -1
  38. package/dist/stega.browser.d.cts +1948 -149
  39. package/dist/stega.browser.d.ts +1948 -149
  40. package/dist/stega.d.cts +1948 -149
  41. package/dist/stega.d.ts +1948 -149
  42. package/dist/views.cjs +13 -5
  43. package/dist/views.cjs.map +1 -1
  44. package/dist/views.d.cts +51 -36
  45. package/dist/views.d.ts +51 -36
  46. package/dist/views.js +14 -5
  47. package/dist/views.js.map +1 -1
  48. package/package.json +2 -1
  49. package/src/SanityClient.ts +652 -12
  50. package/src/agent/actions/AgentActionsClient.ts +29 -2
  51. package/src/agent/actions/commonTypes.ts +57 -17
  52. package/src/agent/actions/generate.ts +36 -2
  53. package/src/agent/actions/patch.ts +136 -0
  54. package/src/agent/actions/prompt.ts +145 -0
  55. package/src/agent/actions/transform.ts +105 -7
  56. package/src/agent/actions/translate.ts +5 -2
  57. package/src/config.ts +3 -1
  58. package/src/csm/walkMap.ts +1 -1
  59. package/src/data/dataMethods.ts +170 -12
  60. package/src/data/encodeQueryString.ts +1 -1
  61. package/src/data/eventsource.ts +16 -7
  62. package/src/data/listen.ts +10 -4
  63. package/src/data/live.ts +13 -5
  64. package/src/datasets/DatasetsClient.ts +4 -1
  65. package/src/defineCreateClient.ts +7 -1
  66. package/src/http/errors.ts +92 -27
  67. package/src/http/request.ts +3 -3
  68. package/src/http/requestOptions.ts +4 -0
  69. package/src/projects/ProjectsClient.ts +6 -2
  70. package/src/releases/ReleasesClient.ts +693 -0
  71. package/src/releases/createRelease.ts +53 -0
  72. package/src/types.ts +291 -10
  73. package/src/users/UsersClient.ts +7 -3
  74. package/src/util/codeFrame.ts +174 -0
  75. package/src/util/createVersionId.ts +79 -0
  76. package/src/{csm → util}/isRecord.ts +1 -1
  77. package/src/validators.ts +23 -1
  78. package/src/views/index.ts +51 -15
  79. package/umd/sanityClient.js +1067 -61
  80. package/umd/sanityClient.min.js +2 -2
@@ -1,16 +1,87 @@
1
1
  import { getIt } from "get-it";
2
2
  import { retry, jsonRequest, jsonResponse, progress, observable } from "get-it/middleware";
3
3
  import { Observable, from } from "rxjs";
4
+ import { isRecord } from "./isRecord.js";
5
+ import { getVersionFromId, isDraftId, getVersionId } from "@sanity/client/csm";
4
6
  import { combineLatestWith, map, filter } from "rxjs/operators";
5
- import { validateObject, validateInsert, requireDocumentId, validateDocumentId, resourceConfig, hasDataset, requestTag, printPreviewDraftsDeprecationWarning, validateApiPerspective, printCdnPreviewDraftsWarning } from "./config.js";
7
+ import { validateObject, validateInsert, requireDocumentId, validateDocumentId, requireDocumentType, resourceConfig, hasDataset, requestTag, printPreviewDraftsDeprecationWarning, validateApiPerspective, printCdnPreviewDraftsWarning } from "./config.js";
6
8
  import { stegaClean } from "./stegaClean.js";
9
+ const NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
10
+ function codeFrame(query, location2, message) {
11
+ const lines = query.split(NEWLINE), loc = {
12
+ start: columnToLine(location2.start, lines),
13
+ end: location2.end ? columnToLine(location2.end, lines) : void 0
14
+ }, { start, end, markerLines } = getMarkerLines(loc, lines), numberMaxWidth = `${end}`.length;
15
+ return query.split(NEWLINE, end).slice(start, end).map((line, index) => {
16
+ const number = start + 1 + index, gutter = ` ${` ${number}`.slice(-numberMaxWidth)} |`, hasMarker = markerLines[number], lastMarkerLine = !markerLines[number + 1];
17
+ if (!hasMarker)
18
+ return ` ${gutter}${line.length > 0 ? ` ${line}` : ""}`;
19
+ let markerLine = "";
20
+ if (Array.isArray(hasMarker)) {
21
+ const markerSpacing = line.slice(0, Math.max(hasMarker[0] - 1, 0)).replace(/[^\t]/g, " "), numberOfMarkers = hasMarker[1] || 1;
22
+ markerLine = [
23
+ `
24
+ `,
25
+ gutter.replace(/\d/g, " "),
26
+ " ",
27
+ markerSpacing,
28
+ "^".repeat(numberOfMarkers)
29
+ ].join(""), lastMarkerLine && message && (markerLine += " " + message);
30
+ }
31
+ return [">", gutter, line.length > 0 ? ` ${line}` : "", markerLine].join("");
32
+ }).join(`
33
+ `);
34
+ }
35
+ function getMarkerLines(loc, source) {
36
+ const startLoc = { ...loc.start }, endLoc = { ...startLoc, ...loc.end }, linesAbove = 2, linesBelow = 3, startLine = startLoc.line ?? -1, startColumn = startLoc.column ?? 0, endLine = endLoc.line, endColumn = endLoc.column;
37
+ let start = Math.max(startLine - (linesAbove + 1), 0), end = Math.min(source.length, endLine + linesBelow);
38
+ startLine === -1 && (start = 0), endLine === -1 && (end = source.length);
39
+ const lineDiff = endLine - startLine, markerLines = {};
40
+ if (lineDiff)
41
+ for (let i = 0; i <= lineDiff; i++) {
42
+ const lineNumber = i + startLine;
43
+ if (!startColumn)
44
+ markerLines[lineNumber] = !0;
45
+ else if (i === 0) {
46
+ const sourceLength = source[lineNumber - 1].length;
47
+ markerLines[lineNumber] = [startColumn, sourceLength - startColumn + 1];
48
+ } else if (i === lineDiff)
49
+ markerLines[lineNumber] = [0, endColumn];
50
+ else {
51
+ const sourceLength = source[lineNumber - i].length;
52
+ markerLines[lineNumber] = [0, sourceLength];
53
+ }
54
+ }
55
+ else
56
+ startColumn === endColumn ? startColumn ? markerLines[startLine] = [startColumn, 0] : markerLines[startLine] = !0 : markerLines[startLine] = [startColumn, endColumn - startColumn];
57
+ return { start, end, markerLines };
58
+ }
59
+ function columnToLine(column, lines) {
60
+ let offset = 0;
61
+ for (let i = 0; i < lines.length; i++) {
62
+ const lineLength = lines[i].length + 1;
63
+ if (offset + lineLength > column)
64
+ return {
65
+ line: i + 1,
66
+ // 1-based line
67
+ column: column - offset
68
+ // 0-based column
69
+ };
70
+ offset += lineLength;
71
+ }
72
+ return {
73
+ line: lines.length,
74
+ column: lines[lines.length - 1]?.length ?? 0
75
+ };
76
+ }
77
+ const MAX_ITEMS_IN_ERROR_MESSAGE = 5;
7
78
  class ClientError extends Error {
8
79
  response;
9
80
  statusCode = 400;
10
81
  responseBody;
11
82
  details;
12
- constructor(res) {
13
- const props = extractErrorProps(res);
83
+ constructor(res, context) {
84
+ const props = extractErrorProps(res, context);
14
85
  super(props.message), Object.assign(this, props);
15
86
  }
16
87
  }
@@ -24,7 +95,7 @@ class ServerError extends Error {
24
95
  super(props.message), Object.assign(this, props);
25
96
  }
26
97
  }
27
- function extractErrorProps(res) {
98
+ function extractErrorProps(res, context) {
28
99
  const body = res.body, props = {
29
100
  response: res,
30
101
  statusCode: res.statusCode,
@@ -32,34 +103,56 @@ function extractErrorProps(res) {
32
103
  message: "",
33
104
  details: void 0
34
105
  };
35
- if (body.error && body.message)
36
- return props.message = `${body.error} - ${body.message}`, props;
37
- if (isMutationError(body) || isActionError(body)) {
38
- const allItems = body.error.items || [], items = allItems.slice(0, 5).map((item) => item.error?.description).filter(Boolean);
106
+ if (!isRecord(body))
107
+ return props.message = httpErrorMessage(res, body), props;
108
+ const error = body.error;
109
+ if (typeof error == "string" && typeof body.message == "string")
110
+ return props.message = `${error} - ${body.message}`, props;
111
+ if (typeof error != "object" || error === null)
112
+ return typeof error == "string" ? props.message = error : typeof body.message == "string" ? props.message = body.message : props.message = httpErrorMessage(res, body), props;
113
+ if (isMutationError(error) || isActionError(error)) {
114
+ const allItems = error.items || [], items = allItems.slice(0, MAX_ITEMS_IN_ERROR_MESSAGE).map((item) => item.error?.description).filter(Boolean);
39
115
  let itemsStr = items.length ? `:
40
116
  - ${items.join(`
41
117
  - `)}` : "";
42
- return allItems.length > 5 && (itemsStr += `
43
- ...and ${allItems.length - 5} more`), props.message = `${body.error.description}${itemsStr}`, props.details = body.error, props;
118
+ return allItems.length > MAX_ITEMS_IN_ERROR_MESSAGE && (itemsStr += `
119
+ ...and ${allItems.length - MAX_ITEMS_IN_ERROR_MESSAGE} more`), props.message = `${error.description}${itemsStr}`, props.details = body.error, props;
120
+ }
121
+ if (isQueryParseError(error)) {
122
+ const tag = context?.options?.query?.tag;
123
+ return props.message = formatQueryParseError(error, tag), props.details = body.error, props;
44
124
  }
45
- return body.error && body.error.description ? (props.message = body.error.description, props.details = body.error, props) : (props.message = body.error || body.message || httpErrorMessage(res), props);
125
+ return "description" in error && typeof error.description == "string" ? (props.message = error.description, props.details = error, props) : (props.message = httpErrorMessage(res, body), props);
46
126
  }
47
- function isMutationError(body) {
48
- return isPlainObject(body) && isPlainObject(body.error) && body.error.type === "mutationError" && typeof body.error.description == "string";
127
+ function isMutationError(error) {
128
+ return "type" in error && error.type === "mutationError" && "description" in error && typeof error.description == "string";
49
129
  }
50
- function isActionError(body) {
51
- return isPlainObject(body) && isPlainObject(body.error) && body.error.type === "actionError" && typeof body.error.description == "string";
130
+ function isActionError(error) {
131
+ return "type" in error && error.type === "actionError" && "description" in error && typeof error.description == "string";
52
132
  }
53
- function isPlainObject(obj) {
54
- return typeof obj == "object" && obj !== null && !Array.isArray(obj);
133
+ function isQueryParseError(error) {
134
+ return isRecord(error) && error.type === "queryParseError" && typeof error.query == "string" && typeof error.start == "number" && typeof error.end == "number";
55
135
  }
56
- function httpErrorMessage(res) {
57
- const statusMessage = res.statusMessage ? ` ${res.statusMessage}` : "";
58
- return `${res.method}-request to ${res.url} resulted in HTTP ${res.statusCode}${statusMessage}`;
136
+ function formatQueryParseError(error, tag) {
137
+ const { query, start, end, description } = error;
138
+ if (!query || typeof start > "u")
139
+ return `GROQ query parse error: ${description}`;
140
+ const withTag = tag ? `
141
+
142
+ Tag: ${tag}` : "";
143
+ return `GROQ query parse error:
144
+ ${codeFrame(query, { start, end }, description)}${withTag}`;
145
+ }
146
+ function httpErrorMessage(res, body) {
147
+ const details = typeof body == "string" ? ` (${sliceWithEllipsis(body, 100)})` : "", statusMessage = res.statusMessage ? ` ${res.statusMessage}` : "";
148
+ return `${res.method}-request to ${res.url} resulted in HTTP ${res.statusCode}${statusMessage}${details}`;
59
149
  }
60
150
  function stringifyBody(body, res) {
61
151
  return (res.headers["content-type"] || "").toLowerCase().indexOf("application/json") !== -1 ? JSON.stringify(body, null, 2) : body;
62
152
  }
153
+ function sliceWithEllipsis(str, max) {
154
+ return str.length > max ? `${str.slice(0, max)}\u2026` : str;
155
+ }
63
156
  class CorsOriginError extends Error {
64
157
  projectId;
65
158
  addOriginUrl;
@@ -74,11 +167,11 @@ class CorsOriginError extends Error {
74
167
  }
75
168
  }
76
169
  const httpError = {
77
- onResponse: (res) => {
170
+ onResponse: (res, context) => {
78
171
  if (res.statusCode >= 500)
79
172
  throw new ServerError(res);
80
173
  if (res.statusCode >= 400)
81
- throw new ClientError(res);
174
+ throw new ClientError(res, context);
82
175
  return res;
83
176
  }
84
177
  };
@@ -446,7 +539,9 @@ class ObservableTransaction extends BaseTransaction {
446
539
  }
447
540
  const projectHeader = "X-Sanity-Project-ID";
448
541
  function requestOptions(config, overrides = {}) {
449
- const headers = {}, token = overrides.token || config.token;
542
+ const headers = {};
543
+ config.headers && Object.assign(headers, config.headers);
544
+ const token = overrides.token || config.token;
450
545
  token && (headers.Authorization = `Bearer ${token}`), !overrides.useGlobalApi && !config.useProjectHostname && config.projectId && (headers[projectHeader] = config.projectId);
451
546
  const withCredentials = !!(typeof overrides.withCredentials > "u" ? config.withCredentials : overrides.withCredentials), timeout = typeof overrides.timeout > "u" ? config.timeout : overrides.timeout;
452
547
  return Object.assign({}, overrides, {
@@ -466,7 +561,7 @@ const encodeQueryString = ({
466
561
  const searchParams = new URLSearchParams(), { tag, includeMutations, returnQuery, ...opts } = options;
467
562
  tag && searchParams.append("tag", tag), searchParams.append("query", query);
468
563
  for (const [key, value] of Object.entries(params))
469
- searchParams.append(`$${key}`, JSON.stringify(value));
564
+ value !== void 0 && searchParams.append(`$${key}`, JSON.stringify(value));
470
565
  for (const [key, value] of Object.entries(opts))
471
566
  value && searchParams.append(key, `${value}`);
472
567
  return returnQuery === !1 && searchParams.append("returnQuery", "false"), includeMutations === !1 && searchParams.append("includeMutations", "false"), `?${searchParams}`;
@@ -482,17 +577,25 @@ function _fetch(config, httpRequest, _stega, query, _params = {}, options = {})
482
577
  const stega = "stega" in options ? {
483
578
  ..._stega || {},
484
579
  ...typeof options.stega == "boolean" ? { enabled: options.stega } : options.stega || {}
485
- } : _stega, params = stega.enabled ? stegaClean(_params) : _params, mapResponse = options.filterResponse === !1 ? (res) => res : (res) => res.result, { cache, next, ...opts } = {
580
+ } : _stega, params = stega.enabled ? stegaClean(_params) : _params, mapResponse = options.filterResponse === !1 ? (res) => res : (res) => res.result, { cache, next, useEmulate, connections, ...opts } = {
486
581
  // Opt out of setting a `signal` on an internal `fetch` if one isn't provided.
487
582
  // This is necessary in React Server Components to avoid opting out of Request Memoization.
488
583
  useAbortSignal: typeof options.signal < "u",
489
584
  // Set `resultSourceMap' when stega is enabled, as it's required for encoding.
490
585
  resultSourceMap: stega.enabled ? "withKeyArraySelector" : options.resultSourceMap,
586
+ // Only use emulate if explicitly asked for
587
+ useEmulate: !1,
588
+ // Having connections is a special case for views
589
+ connections: void 0,
491
590
  ...options,
492
591
  // Default to not returning the query, unless `filterResponse` is `false`,
493
592
  // or `returnQuery` is explicitly set. `true` is the default in Content Lake, so skip if truthy
494
593
  returnQuery: options.filterResponse === !1 && options.returnQuery !== !1
495
- }, reqOpts = typeof cache < "u" || typeof next < "u" ? { ...opts, fetch: { cache, next } } : opts, $request = _dataRequest(config, httpRequest, "query", { query, params }, reqOpts);
594
+ }, reqOpts = typeof cache < "u" || typeof next < "u" ? { ...opts, fetch: { cache, next } } : opts, $request = _dataRequest(config, httpRequest, useEmulate ? "emulate" : "query", useEmulate ? {
595
+ query,
596
+ params,
597
+ connections
598
+ } : { query, params }, reqOpts);
496
599
  return stega.enabled ? $request.pipe(
497
600
  combineLatestWith(
498
601
  from(
@@ -512,8 +615,24 @@ function _fetch(config, httpRequest, _stega, query, _params = {}, options = {})
512
615
  ) : $request.pipe(map(mapResponse));
513
616
  }
514
617
  function _getDocument(config, httpRequest, id, opts = {}) {
515
- const options = {
516
- uri: _getDataUrl(config, "doc", id),
618
+ const docId = (() => {
619
+ if (!opts.releaseId)
620
+ return id;
621
+ const versionId = getVersionFromId(id);
622
+ if (!versionId) {
623
+ if (isDraftId(id))
624
+ throw new Error(
625
+ `The document ID (\`${id}\`) is a draft, but \`options.releaseId\` is set as \`${opts.releaseId}\``
626
+ );
627
+ return getVersionId(id, opts.releaseId);
628
+ }
629
+ if (versionId !== opts.releaseId)
630
+ throw new Error(
631
+ `The document ID (\`${id}\`) is already a version of \`${versionId}\` release, but this does not match the provided \`options.releaseId\` (\`${opts.releaseId}\`)`
632
+ );
633
+ return id;
634
+ })(), options = {
635
+ uri: _getDataUrl(config, "doc", docId),
517
636
  json: !0,
518
637
  tag: opts.tag,
519
638
  signal: opts.signal
@@ -538,12 +657,33 @@ function _getDocuments(config, httpRequest, ids, opts = {}) {
538
657
  })
539
658
  );
540
659
  }
660
+ function _getReleaseDocuments(config, httpRequest, releaseId, opts = {}) {
661
+ return _dataRequest(
662
+ config,
663
+ httpRequest,
664
+ "query",
665
+ {
666
+ query: "*[sanity::partOfRelease($releaseId)]",
667
+ params: {
668
+ releaseId
669
+ }
670
+ },
671
+ opts
672
+ );
673
+ }
541
674
  function _createIfNotExists(config, httpRequest, doc, options) {
542
675
  return requireDocumentId("createIfNotExists", doc), _create(config, httpRequest, doc, "createIfNotExists", options);
543
676
  }
544
677
  function _createOrReplace(config, httpRequest, doc, options) {
545
678
  return requireDocumentId("createOrReplace", doc), _create(config, httpRequest, doc, "createOrReplace", options);
546
679
  }
680
+ function _createVersion(config, httpRequest, doc, publishedId, options) {
681
+ return requireDocumentId("createVersion", doc), requireDocumentType("createVersion", doc), _action(config, httpRequest, {
682
+ actionType: "sanity.action.document.version.create",
683
+ publishedId,
684
+ document: doc
685
+ }, options);
686
+ }
547
687
  function _delete(config, httpRequest, selection, options) {
548
688
  return _dataRequest(
549
689
  config,
@@ -553,6 +693,26 @@ function _delete(config, httpRequest, selection, options) {
553
693
  options
554
694
  );
555
695
  }
696
+ function _discardVersion(config, httpRequest, versionId, purge = !1, options) {
697
+ return _action(config, httpRequest, {
698
+ actionType: "sanity.action.document.version.discard",
699
+ versionId,
700
+ purge
701
+ }, options);
702
+ }
703
+ function _replaceVersion(config, httpRequest, doc, options) {
704
+ return requireDocumentId("replaceVersion", doc), requireDocumentType("replaceVersion", doc), _action(config, httpRequest, {
705
+ actionType: "sanity.action.document.version.replace",
706
+ document: doc
707
+ }, options);
708
+ }
709
+ function _unpublishVersion(config, httpRequest, versionId, publishedId, options) {
710
+ return _action(config, httpRequest, {
711
+ actionType: "sanity.action.document.version.unpublish",
712
+ versionId,
713
+ publishedId
714
+ }, options);
715
+ }
556
716
  function _mutate(config, httpRequest, mutations, options) {
557
717
  let mut;
558
718
  mutations instanceof Patch || mutations instanceof ObservablePatch ? mut = { patch: mutations.serialize() } : mutations instanceof Transaction || mutations instanceof ObservableTransaction ? mut = mutations.serialize() : mut = mutations;
@@ -570,7 +730,7 @@ function _action(config, httpRequest, actions, options) {
570
730
  );
571
731
  }
572
732
  function _dataRequest(config, httpRequest, endpoint, body, options = {}) {
573
- const isMutation = endpoint === "mutate", isAction = endpoint === "actions", isQuery2 = endpoint === "query", strQuery = isMutation || isAction ? "" : encodeQueryString(body), useGet = !isMutation && !isAction && strQuery.length < getQuerySizeLimit, stringQuery = useGet ? strQuery : "", returnFirst = options.returnFirst, { timeout, token, tag, headers, returnQuery, lastLiveEventId, cacheMode } = options, uri = _getDataUrl(config, endpoint, stringQuery), reqOptions = {
733
+ const isMutation = endpoint === "mutate", isAction = endpoint === "actions", isQuery2 = endpoint === "query", isEmulate2 = endpoint === "emulate", strQuery = isMutation || isAction || isEmulate2 ? "" : encodeQueryString(body), useGet = !isMutation && !isAction && !isEmulate2 && strQuery.length < getQuerySizeLimit, stringQuery = useGet ? strQuery : "", returnFirst = options.returnFirst, { timeout, token, tag, headers, returnQuery, lastLiveEventId, cacheMode } = options, uri = _getDataUrl(config, endpoint, stringQuery), reqOptions = {
574
734
  method: useGet ? "GET" : "POST",
575
735
  uri,
576
736
  json: !0,
@@ -613,12 +773,12 @@ function _create(config, httpRequest, doc, op, options = {}) {
613
773
  const mutation = { [op]: doc }, opts = Object.assign({ returnFirst: !0, returnDocuments: !0 }, options);
614
774
  return _dataRequest(config, httpRequest, "mutate", { mutations: [mutation] }, opts);
615
775
  }
616
- const hasDataConfig = (config) => config.dataset !== void 0 && config.projectId !== void 0 || config["~experimental_resource"] !== void 0, isQuery = (config, uri) => hasDataConfig(config) && uri.startsWith(_getDataUrl(config, "query")), isViewQuery = (config, uri) => hasDataConfig(config) && uri.startsWith(_getDataUrl(config, "views")), isMutate = (config, uri) => hasDataConfig(config) && uri.startsWith(_getDataUrl(config, "mutate")), isDoc = (config, uri) => hasDataConfig(config) && uri.startsWith(_getDataUrl(config, "doc", "")), isListener = (config, uri) => hasDataConfig(config) && uri.startsWith(_getDataUrl(config, "listen")), isHistory = (config, uri) => hasDataConfig(config) && uri.startsWith(_getDataUrl(config, "history", "")), isData = (config, uri) => uri.startsWith("/data/") || isQuery(config, uri) || isMutate(config, uri) || isDoc(config, uri) || isListener(config, uri) || isHistory(config, uri) || isViewQuery(config, uri);
776
+ const hasDataConfig = (config) => config.dataset !== void 0 && config.projectId !== void 0 || config["~experimental_resource"] !== void 0, isQuery = (config, uri) => hasDataConfig(config) && uri.startsWith(_getDataUrl(config, "query")), isViewQuery = (config, uri) => hasDataConfig(config) && uri.startsWith(_getDataUrl(config, "views")), isEmulate = (config, uri) => hasDataConfig(config) && uri.startsWith(_getDataUrl(config, "emulate")), isMutate = (config, uri) => hasDataConfig(config) && uri.startsWith(_getDataUrl(config, "mutate")), isDoc = (config, uri) => hasDataConfig(config) && uri.startsWith(_getDataUrl(config, "doc", "")), isListener = (config, uri) => hasDataConfig(config) && uri.startsWith(_getDataUrl(config, "listen")), isHistory = (config, uri) => hasDataConfig(config) && uri.startsWith(_getDataUrl(config, "history", "")), isData = (config, uri) => uri.startsWith("/data/") || isQuery(config, uri) || isMutate(config, uri) || isDoc(config, uri) || isListener(config, uri) || isHistory(config, uri) || isViewQuery(config, uri) || isEmulate(config, uri);
617
777
  function _requestObservable(config, httpRequest, options) {
618
778
  const uri = options.url || options.uri, canUseCdn = typeof options.canUseCdn > "u" ? ["GET", "HEAD"].indexOf(options.method || "GET") >= 0 && isData(config, uri) : options.canUseCdn;
619
779
  let useCdn = (options.useCdn ?? config.useCdn) && canUseCdn;
620
780
  const tag = options.tag && config.requestTagPrefix ? [config.requestTagPrefix, options.tag].join(".") : options.tag || config.requestTagPrefix;
621
- if (tag && options.tag !== null && (options.query = { tag: requestTag(tag), ...options.query }), ["GET", "HEAD", "POST"].indexOf(options.method || "GET") >= 0 && isQuery(config, uri)) {
781
+ if (tag && options.tag !== null && (options.query = { tag: requestTag(tag), ...options.query }), ["GET", "HEAD", "POST"].indexOf(options.method || "GET") >= 0 && (isQuery(config, uri) || isEmulate(config, uri))) {
622
782
  const resultSourceMap = options.resultSourceMap ?? config.resultSourceMap;
623
783
  resultSourceMap !== void 0 && resultSourceMap !== !1 && (options.query = { resultSourceMap, ...options.query });
624
784
  const perspectiveOption = options.perspective || config.perspective;
@@ -653,7 +813,7 @@ function _getDataUrl(config, operation, path) {
653
813
  const catalog = hasDataset(config), baseUri = `/${operation}/${catalog}`;
654
814
  return `/data${path !== void 0 ? `${baseUri}/${path}` : baseUri}`.replace(/\/($|\?)/, "$1");
655
815
  }
656
- function _getUrl(config, uri, canUseCdn = !1, options = {}) {
816
+ function _getUrl(config, uri, canUseCdn = !1) {
657
817
  const { url, cdnUrl } = config;
658
818
  return `${canUseCdn ? cdnUrl : url}/${uri.replace(/^\//, "")}`;
659
819
  }
@@ -714,17 +874,24 @@ export {
714
874
  _create,
715
875
  _createIfNotExists,
716
876
  _createOrReplace,
877
+ _createVersion,
717
878
  _dataRequest,
718
879
  _delete,
880
+ _discardVersion,
719
881
  _fetch,
720
882
  _getDataUrl,
721
883
  _getDocument,
722
884
  _getDocuments,
885
+ _getReleaseDocuments,
723
886
  _getUrl,
724
887
  _mutate,
888
+ _replaceVersion,
725
889
  _request,
726
890
  _requestObservable,
891
+ _unpublishVersion,
727
892
  defineHttpRequest,
728
- encodeQueryString
893
+ encodeQueryString,
894
+ formatQueryParseError,
895
+ isQueryParseError
729
896
  };
730
897
  //# sourceMappingURL=dataMethods.js.map