@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.
- package/README.md +668 -40
- package/dist/_chunks-cjs/config.cjs +14 -0
- package/dist/_chunks-cjs/config.cjs.map +1 -1
- package/dist/_chunks-cjs/dataMethods.cjs +197 -32
- package/dist/_chunks-cjs/dataMethods.cjs.map +1 -1
- package/dist/_chunks-cjs/isRecord.cjs +6 -0
- package/dist/_chunks-cjs/isRecord.cjs.map +1 -0
- package/dist/_chunks-cjs/resolveEditInfo.cjs +3 -5
- package/dist/_chunks-cjs/resolveEditInfo.cjs.map +1 -1
- package/dist/_chunks-cjs/stegaClean.cjs +4 -0
- package/dist/_chunks-cjs/stegaClean.cjs.map +1 -1
- package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs +2 -5
- package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs.map +1 -1
- package/dist/_chunks-es/config.js +15 -1
- package/dist/_chunks-es/config.js.map +1 -1
- package/dist/_chunks-es/dataMethods.js +200 -33
- package/dist/_chunks-es/dataMethods.js.map +1 -1
- package/dist/_chunks-es/isRecord.js +7 -0
- package/dist/_chunks-es/isRecord.js.map +1 -0
- package/dist/_chunks-es/resolveEditInfo.js +1 -3
- package/dist/_chunks-es/resolveEditInfo.js.map +1 -1
- package/dist/_chunks-es/stegaClean.js +4 -0
- package/dist/_chunks-es/stegaClean.js.map +1 -1
- package/dist/_chunks-es/stegaEncodeSourceMap.js +1 -4
- package/dist/_chunks-es/stegaEncodeSourceMap.js.map +1 -1
- package/dist/index.browser.cjs +1019 -59
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +1948 -149
- package/dist/index.browser.d.ts +1948 -149
- package/dist/index.browser.js +1021 -60
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +825 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1948 -149
- package/dist/index.d.ts +1948 -149
- package/dist/index.js +826 -31
- package/dist/index.js.map +1 -1
- package/dist/stega.browser.d.cts +1948 -149
- package/dist/stega.browser.d.ts +1948 -149
- package/dist/stega.d.cts +1948 -149
- package/dist/stega.d.ts +1948 -149
- package/dist/views.cjs +13 -5
- package/dist/views.cjs.map +1 -1
- package/dist/views.d.cts +51 -36
- package/dist/views.d.ts +51 -36
- package/dist/views.js +14 -5
- package/dist/views.js.map +1 -1
- package/package.json +2 -1
- package/src/SanityClient.ts +652 -12
- package/src/agent/actions/AgentActionsClient.ts +29 -2
- package/src/agent/actions/commonTypes.ts +57 -17
- package/src/agent/actions/generate.ts +36 -2
- package/src/agent/actions/patch.ts +136 -0
- package/src/agent/actions/prompt.ts +145 -0
- package/src/agent/actions/transform.ts +105 -7
- package/src/agent/actions/translate.ts +5 -2
- package/src/config.ts +3 -1
- package/src/csm/walkMap.ts +1 -1
- package/src/data/dataMethods.ts +170 -12
- package/src/data/encodeQueryString.ts +1 -1
- package/src/data/eventsource.ts +16 -7
- package/src/data/listen.ts +10 -4
- package/src/data/live.ts +13 -5
- package/src/datasets/DatasetsClient.ts +4 -1
- package/src/defineCreateClient.ts +7 -1
- package/src/http/errors.ts +92 -27
- package/src/http/request.ts +3 -3
- package/src/http/requestOptions.ts +4 -0
- package/src/projects/ProjectsClient.ts +6 -2
- package/src/releases/ReleasesClient.ts +693 -0
- package/src/releases/createRelease.ts +53 -0
- package/src/types.ts +291 -10
- package/src/users/UsersClient.ts +7 -3
- package/src/util/codeFrame.ts +174 -0
- package/src/util/createVersionId.ts +79 -0
- package/src/{csm → util}/isRecord.ts +1 -1
- package/src/validators.ts +23 -1
- package/src/views/index.ts +51 -15
- package/umd/sanityClient.js +1067 -61
- package/umd/sanityClient.min.js +2 -2
package/dist/index.browser.js
CHANGED
|
@@ -1,16 +1,86 @@
|
|
|
1
1
|
import { getIt } from "get-it";
|
|
2
2
|
import { adapter, environment } from "get-it";
|
|
3
3
|
import { retry, jsonRequest, jsonResponse, progress, observable } from "get-it/middleware";
|
|
4
|
-
import { Observable, defer, of, isObservable, mergeMap, from, lastValueFrom, shareReplay, catchError, concat, throwError, timer, tap, finalize, share, merge, EMPTY } from "rxjs";
|
|
5
|
-
import { stegaClean } from "./_chunks-es/stegaClean.js";
|
|
4
|
+
import { Observable, defer, of, isObservable, mergeMap, from, lastValueFrom, shareReplay, catchError, concat, throwError, timer, tap, finalize, share, merge, EMPTY, map as map$1, firstValueFrom } from "rxjs";
|
|
5
|
+
import { isRecord, stegaClean } from "./_chunks-es/stegaClean.js";
|
|
6
6
|
import { combineLatestWith, map, filter, finalize as finalize$1 } from "rxjs/operators";
|
|
7
|
+
import { getVersionFromId, isDraftId, getVersionId, getDraftId, isVersionId, getPublishedId } from "@sanity/client/csm";
|
|
8
|
+
const NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
|
|
9
|
+
function codeFrame(query, location2, message) {
|
|
10
|
+
const lines = query.split(NEWLINE), loc = {
|
|
11
|
+
start: columnToLine(location2.start, lines),
|
|
12
|
+
end: location2.end ? columnToLine(location2.end, lines) : void 0
|
|
13
|
+
}, { start, end, markerLines } = getMarkerLines(loc, lines), numberMaxWidth = `${end}`.length;
|
|
14
|
+
return query.split(NEWLINE, end).slice(start, end).map((line, index) => {
|
|
15
|
+
const number = start + 1 + index, gutter = ` ${` ${number}`.slice(-numberMaxWidth)} |`, hasMarker = markerLines[number], lastMarkerLine = !markerLines[number + 1];
|
|
16
|
+
if (!hasMarker)
|
|
17
|
+
return ` ${gutter}${line.length > 0 ? ` ${line}` : ""}`;
|
|
18
|
+
let markerLine = "";
|
|
19
|
+
if (Array.isArray(hasMarker)) {
|
|
20
|
+
const markerSpacing = line.slice(0, Math.max(hasMarker[0] - 1, 0)).replace(/[^\t]/g, " "), numberOfMarkers = hasMarker[1] || 1;
|
|
21
|
+
markerLine = [
|
|
22
|
+
`
|
|
23
|
+
`,
|
|
24
|
+
gutter.replace(/\d/g, " "),
|
|
25
|
+
" ",
|
|
26
|
+
markerSpacing,
|
|
27
|
+
"^".repeat(numberOfMarkers)
|
|
28
|
+
].join(""), lastMarkerLine && message && (markerLine += " " + message);
|
|
29
|
+
}
|
|
30
|
+
return [">", gutter, line.length > 0 ? ` ${line}` : "", markerLine].join("");
|
|
31
|
+
}).join(`
|
|
32
|
+
`);
|
|
33
|
+
}
|
|
34
|
+
function getMarkerLines(loc, source) {
|
|
35
|
+
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;
|
|
36
|
+
let start = Math.max(startLine - (linesAbove + 1), 0), end = Math.min(source.length, endLine + linesBelow);
|
|
37
|
+
startLine === -1 && (start = 0), endLine === -1 && (end = source.length);
|
|
38
|
+
const lineDiff = endLine - startLine, markerLines = {};
|
|
39
|
+
if (lineDiff)
|
|
40
|
+
for (let i = 0; i <= lineDiff; i++) {
|
|
41
|
+
const lineNumber = i + startLine;
|
|
42
|
+
if (!startColumn)
|
|
43
|
+
markerLines[lineNumber] = !0;
|
|
44
|
+
else if (i === 0) {
|
|
45
|
+
const sourceLength = source[lineNumber - 1].length;
|
|
46
|
+
markerLines[lineNumber] = [startColumn, sourceLength - startColumn + 1];
|
|
47
|
+
} else if (i === lineDiff)
|
|
48
|
+
markerLines[lineNumber] = [0, endColumn];
|
|
49
|
+
else {
|
|
50
|
+
const sourceLength = source[lineNumber - i].length;
|
|
51
|
+
markerLines[lineNumber] = [0, sourceLength];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
else
|
|
55
|
+
startColumn === endColumn ? startColumn ? markerLines[startLine] = [startColumn, 0] : markerLines[startLine] = !0 : markerLines[startLine] = [startColumn, endColumn - startColumn];
|
|
56
|
+
return { start, end, markerLines };
|
|
57
|
+
}
|
|
58
|
+
function columnToLine(column, lines) {
|
|
59
|
+
let offset = 0;
|
|
60
|
+
for (let i = 0; i < lines.length; i++) {
|
|
61
|
+
const lineLength = lines[i].length + 1;
|
|
62
|
+
if (offset + lineLength > column)
|
|
63
|
+
return {
|
|
64
|
+
line: i + 1,
|
|
65
|
+
// 1-based line
|
|
66
|
+
column: column - offset
|
|
67
|
+
// 0-based column
|
|
68
|
+
};
|
|
69
|
+
offset += lineLength;
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
line: lines.length,
|
|
73
|
+
column: lines[lines.length - 1]?.length ?? 0
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
const MAX_ITEMS_IN_ERROR_MESSAGE = 5;
|
|
7
77
|
class ClientError extends Error {
|
|
8
78
|
response;
|
|
9
79
|
statusCode = 400;
|
|
10
80
|
responseBody;
|
|
11
81
|
details;
|
|
12
|
-
constructor(res) {
|
|
13
|
-
const props = extractErrorProps(res);
|
|
82
|
+
constructor(res, context) {
|
|
83
|
+
const props = extractErrorProps(res, context);
|
|
14
84
|
super(props.message), Object.assign(this, props);
|
|
15
85
|
}
|
|
16
86
|
}
|
|
@@ -24,7 +94,7 @@ class ServerError extends Error {
|
|
|
24
94
|
super(props.message), Object.assign(this, props);
|
|
25
95
|
}
|
|
26
96
|
}
|
|
27
|
-
function extractErrorProps(res) {
|
|
97
|
+
function extractErrorProps(res, context) {
|
|
28
98
|
const body = res.body, props = {
|
|
29
99
|
response: res,
|
|
30
100
|
statusCode: res.statusCode,
|
|
@@ -32,34 +102,56 @@ function extractErrorProps(res) {
|
|
|
32
102
|
message: "",
|
|
33
103
|
details: void 0
|
|
34
104
|
};
|
|
35
|
-
if (body
|
|
36
|
-
return props.message =
|
|
37
|
-
|
|
38
|
-
|
|
105
|
+
if (!isRecord(body))
|
|
106
|
+
return props.message = httpErrorMessage(res, body), props;
|
|
107
|
+
const error = body.error;
|
|
108
|
+
if (typeof error == "string" && typeof body.message == "string")
|
|
109
|
+
return props.message = `${error} - ${body.message}`, props;
|
|
110
|
+
if (typeof error != "object" || error === null)
|
|
111
|
+
return typeof error == "string" ? props.message = error : typeof body.message == "string" ? props.message = body.message : props.message = httpErrorMessage(res, body), props;
|
|
112
|
+
if (isMutationError(error) || isActionError(error)) {
|
|
113
|
+
const allItems = error.items || [], items = allItems.slice(0, MAX_ITEMS_IN_ERROR_MESSAGE).map((item) => item.error?.description).filter(Boolean);
|
|
39
114
|
let itemsStr = items.length ? `:
|
|
40
115
|
- ${items.join(`
|
|
41
116
|
- `)}` : "";
|
|
42
|
-
return allItems.length >
|
|
43
|
-
...and ${allItems.length -
|
|
117
|
+
return allItems.length > MAX_ITEMS_IN_ERROR_MESSAGE && (itemsStr += `
|
|
118
|
+
...and ${allItems.length - MAX_ITEMS_IN_ERROR_MESSAGE} more`), props.message = `${error.description}${itemsStr}`, props.details = body.error, props;
|
|
44
119
|
}
|
|
45
|
-
|
|
120
|
+
if (isQueryParseError(error)) {
|
|
121
|
+
const tag = context?.options?.query?.tag;
|
|
122
|
+
return props.message = formatQueryParseError(error, tag), props.details = body.error, props;
|
|
123
|
+
}
|
|
124
|
+
return "description" in error && typeof error.description == "string" ? (props.message = error.description, props.details = error, props) : (props.message = httpErrorMessage(res, body), props);
|
|
46
125
|
}
|
|
47
|
-
function isMutationError(
|
|
48
|
-
return
|
|
126
|
+
function isMutationError(error) {
|
|
127
|
+
return "type" in error && error.type === "mutationError" && "description" in error && typeof error.description == "string";
|
|
49
128
|
}
|
|
50
|
-
function isActionError(
|
|
51
|
-
return
|
|
129
|
+
function isActionError(error) {
|
|
130
|
+
return "type" in error && error.type === "actionError" && "description" in error && typeof error.description == "string";
|
|
52
131
|
}
|
|
53
|
-
function
|
|
54
|
-
return typeof
|
|
132
|
+
function isQueryParseError(error) {
|
|
133
|
+
return isRecord(error) && error.type === "queryParseError" && typeof error.query == "string" && typeof error.start == "number" && typeof error.end == "number";
|
|
55
134
|
}
|
|
56
|
-
function
|
|
57
|
-
const
|
|
58
|
-
|
|
135
|
+
function formatQueryParseError(error, tag) {
|
|
136
|
+
const { query, start, end, description } = error;
|
|
137
|
+
if (!query || typeof start > "u")
|
|
138
|
+
return `GROQ query parse error: ${description}`;
|
|
139
|
+
const withTag = tag ? `
|
|
140
|
+
|
|
141
|
+
Tag: ${tag}` : "";
|
|
142
|
+
return `GROQ query parse error:
|
|
143
|
+
${codeFrame(query, { start, end }, description)}${withTag}`;
|
|
144
|
+
}
|
|
145
|
+
function httpErrorMessage(res, body) {
|
|
146
|
+
const details = typeof body == "string" ? ` (${sliceWithEllipsis(body, 100)})` : "", statusMessage = res.statusMessage ? ` ${res.statusMessage}` : "";
|
|
147
|
+
return `${res.method}-request to ${res.url} resulted in HTTP ${res.statusCode}${statusMessage}${details}`;
|
|
59
148
|
}
|
|
60
149
|
function stringifyBody(body, res) {
|
|
61
150
|
return (res.headers["content-type"] || "").toLowerCase().indexOf("application/json") !== -1 ? JSON.stringify(body, null, 2) : body;
|
|
62
151
|
}
|
|
152
|
+
function sliceWithEllipsis(str, max) {
|
|
153
|
+
return str.length > max ? `${str.slice(0, max)}\u2026` : str;
|
|
154
|
+
}
|
|
63
155
|
class CorsOriginError extends Error {
|
|
64
156
|
projectId;
|
|
65
157
|
addOriginUrl;
|
|
@@ -74,11 +166,11 @@ class CorsOriginError extends Error {
|
|
|
74
166
|
}
|
|
75
167
|
}
|
|
76
168
|
const httpError = {
|
|
77
|
-
onResponse: (res) => {
|
|
169
|
+
onResponse: (res, context) => {
|
|
78
170
|
if (res.statusCode >= 500)
|
|
79
171
|
throw new ServerError(res);
|
|
80
172
|
if (res.statusCode >= 400)
|
|
81
|
-
throw new ClientError(res);
|
|
173
|
+
throw new ClientError(res, context);
|
|
82
174
|
return res;
|
|
83
175
|
}
|
|
84
176
|
};
|
|
@@ -135,6 +227,18 @@ const VALID_ASSET_TYPES = ["image", "file"], VALID_INSERT_LOCATIONS = ["before",
|
|
|
135
227
|
if (!doc._id)
|
|
136
228
|
throw new Error(`${op}() requires that the document contains an ID ("_id" property)`);
|
|
137
229
|
validateDocumentId(op, doc._id);
|
|
230
|
+
}, validateDocumentType = (op, type) => {
|
|
231
|
+
if (typeof type != "string")
|
|
232
|
+
throw new Error(`\`${op}()\`: \`${type}\` is not a valid document type`);
|
|
233
|
+
}, requireDocumentType = (op, doc) => {
|
|
234
|
+
if (!doc._type)
|
|
235
|
+
throw new Error(`\`${op}()\` requires that the document contains a type (\`_type\` property)`);
|
|
236
|
+
validateDocumentType(op, doc._type);
|
|
237
|
+
}, validateVersionIdMatch = (builtVersionId, document) => {
|
|
238
|
+
if (document._id && document._id !== builtVersionId)
|
|
239
|
+
throw new Error(
|
|
240
|
+
`The provided document ID (\`${document._id}\`) does not match the generated version ID (\`${builtVersionId}\`)`
|
|
241
|
+
);
|
|
138
242
|
}, validateInsert = (at, selector, items) => {
|
|
139
243
|
const signature = "insert(at, selector, items)";
|
|
140
244
|
if (VALID_INSERT_LOCATIONS.indexOf(at) === -1) {
|
|
@@ -177,6 +281,7 @@ const VALID_ASSET_TYPES = ["image", "file"], VALID_INSERT_LOCATIONS = ["before",
|
|
|
177
281
|
if (config["~experimental_resource"])
|
|
178
282
|
throw new Error(`\`${service}\` does not support resource-based operations`);
|
|
179
283
|
};
|
|
284
|
+
var ViewResourceType = /* @__PURE__ */ ((ViewResourceType2) => (ViewResourceType2.Dataset = "dataset", ViewResourceType2))(ViewResourceType || {});
|
|
180
285
|
function once(fn) {
|
|
181
286
|
let didCall = !1, returnValue;
|
|
182
287
|
return (...args) => (didCall || (returnValue = fn(...args), didCall = !0), returnValue);
|
|
@@ -328,7 +433,8 @@ function connectWithESInstance(es, events) {
|
|
|
328
433
|
return;
|
|
329
434
|
}
|
|
330
435
|
if (message.type === "channelError") {
|
|
331
|
-
|
|
436
|
+
const tag = new URL(es.url).searchParams.get("tag");
|
|
437
|
+
observer.error(new ChannelError(extractErrorMessage(event?.data, tag), event.data));
|
|
332
438
|
return;
|
|
333
439
|
}
|
|
334
440
|
if (message.type === "disconnect") {
|
|
@@ -367,8 +473,9 @@ function parseEvent(message) {
|
|
|
367
473
|
return [err, null];
|
|
368
474
|
}
|
|
369
475
|
}
|
|
370
|
-
function extractErrorMessage(err) {
|
|
371
|
-
|
|
476
|
+
function extractErrorMessage(err, tag) {
|
|
477
|
+
const error = err.error;
|
|
478
|
+
return error ? isQueryParseError(error) ? formatQueryParseError(error, tag) : error.description ? error.description : typeof error == "string" ? error : JSON.stringify(error, null, 2) : err.message || "Unknown listener error";
|
|
372
479
|
}
|
|
373
480
|
function isEmptyObject(data) {
|
|
374
481
|
for (const _ in data)
|
|
@@ -711,7 +818,9 @@ class ObservableTransaction extends BaseTransaction {
|
|
|
711
818
|
}
|
|
712
819
|
const projectHeader = "X-Sanity-Project-ID";
|
|
713
820
|
function requestOptions(config, overrides = {}) {
|
|
714
|
-
const headers = {}
|
|
821
|
+
const headers = {};
|
|
822
|
+
config.headers && Object.assign(headers, config.headers);
|
|
823
|
+
const token = overrides.token || config.token;
|
|
715
824
|
token && (headers.Authorization = `Bearer ${token}`), !overrides.useGlobalApi && !config.useProjectHostname && config.projectId && (headers[projectHeader] = config.projectId);
|
|
716
825
|
const withCredentials = !!(typeof overrides.withCredentials > "u" ? config.withCredentials : overrides.withCredentials), timeout = typeof overrides.timeout > "u" ? config.timeout : overrides.timeout;
|
|
717
826
|
return Object.assign({}, overrides, {
|
|
@@ -731,7 +840,7 @@ const encodeQueryString = ({
|
|
|
731
840
|
const searchParams = new URLSearchParams(), { tag, includeMutations, returnQuery, ...opts } = options;
|
|
732
841
|
tag && searchParams.append("tag", tag), searchParams.append("query", query);
|
|
733
842
|
for (const [key, value] of Object.entries(params))
|
|
734
|
-
searchParams.append(`$${key}`, JSON.stringify(value));
|
|
843
|
+
value !== void 0 && searchParams.append(`$${key}`, JSON.stringify(value));
|
|
735
844
|
for (const [key, value] of Object.entries(opts))
|
|
736
845
|
value && searchParams.append(key, `${value}`);
|
|
737
846
|
return returnQuery === !1 && searchParams.append("returnQuery", "false"), includeMutations === !1 && searchParams.append("includeMutations", "false"), `?${searchParams}`;
|
|
@@ -747,17 +856,25 @@ function _fetch(config, httpRequest, _stega, query, _params = {}, options = {})
|
|
|
747
856
|
const stega = "stega" in options ? {
|
|
748
857
|
..._stega || {},
|
|
749
858
|
...typeof options.stega == "boolean" ? { enabled: options.stega } : options.stega || {}
|
|
750
|
-
} : _stega, params = stega.enabled ? stegaClean(_params) : _params, mapResponse = options.filterResponse === !1 ? (res) => res : (res) => res.result, { cache, next, ...opts } = {
|
|
859
|
+
} : _stega, params = stega.enabled ? stegaClean(_params) : _params, mapResponse = options.filterResponse === !1 ? (res) => res : (res) => res.result, { cache, next, useEmulate, connections, ...opts } = {
|
|
751
860
|
// Opt out of setting a `signal` on an internal `fetch` if one isn't provided.
|
|
752
861
|
// This is necessary in React Server Components to avoid opting out of Request Memoization.
|
|
753
862
|
useAbortSignal: typeof options.signal < "u",
|
|
754
863
|
// Set `resultSourceMap' when stega is enabled, as it's required for encoding.
|
|
755
864
|
resultSourceMap: stega.enabled ? "withKeyArraySelector" : options.resultSourceMap,
|
|
865
|
+
// Only use emulate if explicitly asked for
|
|
866
|
+
useEmulate: !1,
|
|
867
|
+
// Having connections is a special case for views
|
|
868
|
+
connections: void 0,
|
|
756
869
|
...options,
|
|
757
870
|
// Default to not returning the query, unless `filterResponse` is `false`,
|
|
758
871
|
// or `returnQuery` is explicitly set. `true` is the default in Content Lake, so skip if truthy
|
|
759
872
|
returnQuery: options.filterResponse === !1 && options.returnQuery !== !1
|
|
760
|
-
}, reqOpts = typeof cache < "u" || typeof next < "u" ? { ...opts, fetch: { cache, next } } : opts, $request = _dataRequest(config, httpRequest, "
|
|
873
|
+
}, reqOpts = typeof cache < "u" || typeof next < "u" ? { ...opts, fetch: { cache, next } } : opts, $request = _dataRequest(config, httpRequest, useEmulate ? "emulate" : "query", useEmulate ? {
|
|
874
|
+
query,
|
|
875
|
+
params,
|
|
876
|
+
connections
|
|
877
|
+
} : { query, params }, reqOpts);
|
|
761
878
|
return stega.enabled ? $request.pipe(
|
|
762
879
|
combineLatestWith(
|
|
763
880
|
from(
|
|
@@ -777,8 +894,24 @@ function _fetch(config, httpRequest, _stega, query, _params = {}, options = {})
|
|
|
777
894
|
) : $request.pipe(map(mapResponse));
|
|
778
895
|
}
|
|
779
896
|
function _getDocument(config, httpRequest, id, opts = {}) {
|
|
780
|
-
const
|
|
781
|
-
|
|
897
|
+
const docId = (() => {
|
|
898
|
+
if (!opts.releaseId)
|
|
899
|
+
return id;
|
|
900
|
+
const versionId = getVersionFromId(id);
|
|
901
|
+
if (!versionId) {
|
|
902
|
+
if (isDraftId(id))
|
|
903
|
+
throw new Error(
|
|
904
|
+
`The document ID (\`${id}\`) is a draft, but \`options.releaseId\` is set as \`${opts.releaseId}\``
|
|
905
|
+
);
|
|
906
|
+
return getVersionId(id, opts.releaseId);
|
|
907
|
+
}
|
|
908
|
+
if (versionId !== opts.releaseId)
|
|
909
|
+
throw new Error(
|
|
910
|
+
`The document ID (\`${id}\`) is already a version of \`${versionId}\` release, but this does not match the provided \`options.releaseId\` (\`${opts.releaseId}\`)`
|
|
911
|
+
);
|
|
912
|
+
return id;
|
|
913
|
+
})(), options = {
|
|
914
|
+
uri: _getDataUrl(config, "doc", docId),
|
|
782
915
|
json: !0,
|
|
783
916
|
tag: opts.tag,
|
|
784
917
|
signal: opts.signal
|
|
@@ -803,12 +936,33 @@ function _getDocuments(config, httpRequest, ids, opts = {}) {
|
|
|
803
936
|
})
|
|
804
937
|
);
|
|
805
938
|
}
|
|
939
|
+
function _getReleaseDocuments(config, httpRequest, releaseId, opts = {}) {
|
|
940
|
+
return _dataRequest(
|
|
941
|
+
config,
|
|
942
|
+
httpRequest,
|
|
943
|
+
"query",
|
|
944
|
+
{
|
|
945
|
+
query: "*[sanity::partOfRelease($releaseId)]",
|
|
946
|
+
params: {
|
|
947
|
+
releaseId
|
|
948
|
+
}
|
|
949
|
+
},
|
|
950
|
+
opts
|
|
951
|
+
);
|
|
952
|
+
}
|
|
806
953
|
function _createIfNotExists(config, httpRequest, doc, options) {
|
|
807
954
|
return requireDocumentId("createIfNotExists", doc), _create(config, httpRequest, doc, "createIfNotExists", options);
|
|
808
955
|
}
|
|
809
956
|
function _createOrReplace(config, httpRequest, doc, options) {
|
|
810
957
|
return requireDocumentId("createOrReplace", doc), _create(config, httpRequest, doc, "createOrReplace", options);
|
|
811
958
|
}
|
|
959
|
+
function _createVersion(config, httpRequest, doc, publishedId, options) {
|
|
960
|
+
return requireDocumentId("createVersion", doc), requireDocumentType("createVersion", doc), _action(config, httpRequest, {
|
|
961
|
+
actionType: "sanity.action.document.version.create",
|
|
962
|
+
publishedId,
|
|
963
|
+
document: doc
|
|
964
|
+
}, options);
|
|
965
|
+
}
|
|
812
966
|
function _delete(config, httpRequest, selection, options) {
|
|
813
967
|
return _dataRequest(
|
|
814
968
|
config,
|
|
@@ -818,6 +972,26 @@ function _delete(config, httpRequest, selection, options) {
|
|
|
818
972
|
options
|
|
819
973
|
);
|
|
820
974
|
}
|
|
975
|
+
function _discardVersion(config, httpRequest, versionId, purge = !1, options) {
|
|
976
|
+
return _action(config, httpRequest, {
|
|
977
|
+
actionType: "sanity.action.document.version.discard",
|
|
978
|
+
versionId,
|
|
979
|
+
purge
|
|
980
|
+
}, options);
|
|
981
|
+
}
|
|
982
|
+
function _replaceVersion(config, httpRequest, doc, options) {
|
|
983
|
+
return requireDocumentId("replaceVersion", doc), requireDocumentType("replaceVersion", doc), _action(config, httpRequest, {
|
|
984
|
+
actionType: "sanity.action.document.version.replace",
|
|
985
|
+
document: doc
|
|
986
|
+
}, options);
|
|
987
|
+
}
|
|
988
|
+
function _unpublishVersion(config, httpRequest, versionId, publishedId, options) {
|
|
989
|
+
return _action(config, httpRequest, {
|
|
990
|
+
actionType: "sanity.action.document.version.unpublish",
|
|
991
|
+
versionId,
|
|
992
|
+
publishedId
|
|
993
|
+
}, options);
|
|
994
|
+
}
|
|
821
995
|
function _mutate(config, httpRequest, mutations, options) {
|
|
822
996
|
let mut;
|
|
823
997
|
mutations instanceof Patch || mutations instanceof ObservablePatch ? mut = { patch: mutations.serialize() } : mutations instanceof Transaction || mutations instanceof ObservableTransaction ? mut = mutations.serialize() : mut = mutations;
|
|
@@ -835,7 +1009,7 @@ function _action(config, httpRequest, actions, options) {
|
|
|
835
1009
|
);
|
|
836
1010
|
}
|
|
837
1011
|
function _dataRequest(config, httpRequest, endpoint, body, options = {}) {
|
|
838
|
-
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 = {
|
|
1012
|
+
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 = {
|
|
839
1013
|
method: useGet ? "GET" : "POST",
|
|
840
1014
|
uri,
|
|
841
1015
|
json: !0,
|
|
@@ -878,12 +1052,12 @@ function _create(config, httpRequest, doc, op, options = {}) {
|
|
|
878
1052
|
const mutation = { [op]: doc }, opts = Object.assign({ returnFirst: !0, returnDocuments: !0 }, options);
|
|
879
1053
|
return _dataRequest(config, httpRequest, "mutate", { mutations: [mutation] }, opts);
|
|
880
1054
|
}
|
|
881
|
-
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);
|
|
1055
|
+
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);
|
|
882
1056
|
function _requestObservable(config, httpRequest, options) {
|
|
883
1057
|
const uri = options.url || options.uri, canUseCdn = typeof options.canUseCdn > "u" ? ["GET", "HEAD"].indexOf(options.method || "GET") >= 0 && isData(config, uri) : options.canUseCdn;
|
|
884
1058
|
let useCdn = (options.useCdn ?? config.useCdn) && canUseCdn;
|
|
885
1059
|
const tag = options.tag && config.requestTagPrefix ? [config.requestTagPrefix, options.tag].join(".") : options.tag || config.requestTagPrefix;
|
|
886
|
-
if (tag && options.tag !== null && (options.query = { tag: requestTag(tag), ...options.query }), ["GET", "HEAD", "POST"].indexOf(options.method || "GET") >= 0 && isQuery(config, uri)) {
|
|
1060
|
+
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))) {
|
|
887
1061
|
const resultSourceMap = options.resultSourceMap ?? config.resultSourceMap;
|
|
888
1062
|
resultSourceMap !== void 0 && resultSourceMap !== !1 && (options.query = { resultSourceMap, ...options.query });
|
|
889
1063
|
const perspectiveOption = options.perspective || config.perspective;
|
|
@@ -918,7 +1092,7 @@ function _getDataUrl(config, operation, path) {
|
|
|
918
1092
|
const catalog = hasDataset(config), baseUri = `/${operation}/${catalog}`;
|
|
919
1093
|
return `/data${path !== void 0 ? `${baseUri}/${path}` : baseUri}`.replace(/\/($|\?)/, "$1");
|
|
920
1094
|
}
|
|
921
|
-
function _getUrl(config, uri, canUseCdn = !1
|
|
1095
|
+
function _getUrl(config, uri, canUseCdn = !1) {
|
|
922
1096
|
const { url, cdnUrl } = config;
|
|
923
1097
|
return `${canUseCdn ? cdnUrl : url}/${uri.replace(/^\//, "")}`;
|
|
924
1098
|
}
|
|
@@ -973,6 +1147,22 @@ function _generate(client, httpRequest, request) {
|
|
|
973
1147
|
body: request
|
|
974
1148
|
});
|
|
975
1149
|
}
|
|
1150
|
+
function _patch(client, httpRequest, request) {
|
|
1151
|
+
const dataset2 = hasDataset(client.config());
|
|
1152
|
+
return _request(client.config(), httpRequest, {
|
|
1153
|
+
method: "POST",
|
|
1154
|
+
uri: `/agent/action/patch/${dataset2}`,
|
|
1155
|
+
body: request
|
|
1156
|
+
});
|
|
1157
|
+
}
|
|
1158
|
+
function _prompt(client, httpRequest, request) {
|
|
1159
|
+
const dataset2 = hasDataset(client.config());
|
|
1160
|
+
return _request(client.config(), httpRequest, {
|
|
1161
|
+
method: "POST",
|
|
1162
|
+
uri: `/agent/action/prompt/${dataset2}`,
|
|
1163
|
+
body: request
|
|
1164
|
+
});
|
|
1165
|
+
}
|
|
976
1166
|
function _transform(client, httpRequest, request) {
|
|
977
1167
|
const dataset2 = hasDataset(client.config());
|
|
978
1168
|
return _request(client.config(), httpRequest, {
|
|
@@ -1044,6 +1234,21 @@ class AgentActionsClient {
|
|
|
1044
1234
|
translate(request) {
|
|
1045
1235
|
return lastValueFrom(_translate(this.#client, this.#httpRequest, request));
|
|
1046
1236
|
}
|
|
1237
|
+
/**
|
|
1238
|
+
* Run a raw instruction and return the result either as text or json
|
|
1239
|
+
* @param request - prompt request
|
|
1240
|
+
*/
|
|
1241
|
+
prompt(request) {
|
|
1242
|
+
return lastValueFrom(_prompt(this.#client, this.#httpRequest, request));
|
|
1243
|
+
}
|
|
1244
|
+
/**
|
|
1245
|
+
* Patch a document using a schema aware API.
|
|
1246
|
+
* Does not use an LLM, but uses the schema to ensure paths and values matches the schema.
|
|
1247
|
+
* @param request - instruction request
|
|
1248
|
+
*/
|
|
1249
|
+
patch(request) {
|
|
1250
|
+
return lastValueFrom(_patch(this.#client, this.#httpRequest, request));
|
|
1251
|
+
}
|
|
1047
1252
|
}
|
|
1048
1253
|
class ObservableAssetsClient {
|
|
1049
1254
|
#client;
|
|
@@ -1152,13 +1357,11 @@ const MAX_URL_LENGTH = 14800, possibleOptions = [
|
|
|
1152
1357
|
includeResult: !0
|
|
1153
1358
|
};
|
|
1154
1359
|
function _listen(query, params, opts = {}) {
|
|
1155
|
-
const { url, token, withCredentials, requestTagPrefix } = this.config(), tag = opts.tag && requestTagPrefix ? [requestTagPrefix, opts.tag].join(".") : opts.tag, options = { ...defaults(opts, defaultOptions), tag }, listenOpts = pick(options, possibleOptions), qs = encodeQueryString({ query, params, options: { tag, ...listenOpts } }), uri = `${url}${_getDataUrl(this.config(), "listen", qs)}`;
|
|
1360
|
+
const { url, token, withCredentials, requestTagPrefix, headers: configHeaders } = this.config(), tag = opts.tag && requestTagPrefix ? [requestTagPrefix, opts.tag].join(".") : opts.tag, options = { ...defaults(opts, defaultOptions), tag }, listenOpts = pick(options, possibleOptions), qs = encodeQueryString({ query, params, options: { tag, ...listenOpts } }), uri = `${url}${_getDataUrl(this.config(), "listen", qs)}`;
|
|
1156
1361
|
if (uri.length > MAX_URL_LENGTH)
|
|
1157
1362
|
return throwError(() => new Error("Query too large for listener"));
|
|
1158
1363
|
const listenFor = options.events ? options.events : ["mutation"], esOptions = {};
|
|
1159
|
-
return withCredentials && (esOptions.withCredentials = !0), token && (esOptions.headers = {
|
|
1160
|
-
Authorization: `Bearer ${token}`
|
|
1161
|
-
}), connectEventSource(() => (
|
|
1364
|
+
return withCredentials && (esOptions.withCredentials = !0), (token || configHeaders) && (esOptions.headers = {}, token && (esOptions.headers.Authorization = `Bearer ${token}`), configHeaders && Object.assign(esOptions.headers, configHeaders)), connectEventSource(() => (
|
|
1162
1365
|
// use polyfill if there is no global EventSource or if we need to set headers
|
|
1163
1366
|
(typeof EventSource > "u" || esOptions.headers ? eventSourcePolyfill : of(EventSource)).pipe(map((EventSource2) => new EventSource2(uri, esOptions)))
|
|
1164
1367
|
), listenFor).pipe(
|
|
@@ -1216,7 +1419,8 @@ class LiveClient {
|
|
|
1216
1419
|
apiVersion: _apiVersion,
|
|
1217
1420
|
token,
|
|
1218
1421
|
withCredentials,
|
|
1219
|
-
requestTagPrefix
|
|
1422
|
+
requestTagPrefix,
|
|
1423
|
+
headers: configHeaders
|
|
1220
1424
|
} = this.#client.config(), apiVersion = _apiVersion.replace(/^v/, "");
|
|
1221
1425
|
if (apiVersion !== "X" && apiVersion < requiredApiVersion)
|
|
1222
1426
|
throw new Error(
|
|
@@ -1229,9 +1433,7 @@ class LiveClient {
|
|
|
1229
1433
|
const path = _getDataUrl(this.#client.config(), "live/events"), url = new URL(this.#client.getUrl(path, !1)), tag = _tag && requestTagPrefix ? [requestTagPrefix, _tag].join(".") : _tag;
|
|
1230
1434
|
tag && url.searchParams.set("tag", tag), includeDrafts && url.searchParams.set("includeDrafts", "true");
|
|
1231
1435
|
const esOptions = {};
|
|
1232
|
-
includeDrafts && token && (esOptions.headers = {
|
|
1233
|
-
Authorization: `Bearer ${token}`
|
|
1234
|
-
}), includeDrafts && withCredentials && (esOptions.withCredentials = !0);
|
|
1436
|
+
includeDrafts && withCredentials && (esOptions.withCredentials = !0), (includeDrafts && token || configHeaders) && (esOptions.headers = {}, includeDrafts && token && (esOptions.headers.Authorization = `Bearer ${token}`), configHeaders && Object.assign(esOptions.headers, configHeaders));
|
|
1235
1437
|
const key = `${url.href}::${JSON.stringify(esOptions)}`, existing = eventsCache.get(key);
|
|
1236
1438
|
if (existing)
|
|
1237
1439
|
return existing;
|
|
@@ -1369,7 +1571,10 @@ class DatasetsClient {
|
|
|
1369
1571
|
*/
|
|
1370
1572
|
list() {
|
|
1371
1573
|
return resourceGuard("dataset", this.#client.config()), lastValueFrom(
|
|
1372
|
-
_request(this.#client.config(), this.#httpRequest, {
|
|
1574
|
+
_request(this.#client.config(), this.#httpRequest, {
|
|
1575
|
+
uri: "/datasets",
|
|
1576
|
+
tag: null
|
|
1577
|
+
})
|
|
1373
1578
|
);
|
|
1374
1579
|
}
|
|
1375
1580
|
}
|
|
@@ -1398,7 +1603,9 @@ class ObservableProjectsClient {
|
|
|
1398
1603
|
* @param projectId - ID of the project to fetch
|
|
1399
1604
|
*/
|
|
1400
1605
|
getById(projectId2) {
|
|
1401
|
-
return resourceGuard("projects", this.#client.config()), _request(this.#client.config(), this.#httpRequest, {
|
|
1606
|
+
return resourceGuard("projects", this.#client.config()), _request(this.#client.config(), this.#httpRequest, {
|
|
1607
|
+
uri: `/projects/${projectId2}`
|
|
1608
|
+
});
|
|
1402
1609
|
}
|
|
1403
1610
|
}
|
|
1404
1611
|
class ProjectsClient {
|
|
@@ -1419,7 +1626,518 @@ class ProjectsClient {
|
|
|
1419
1626
|
*/
|
|
1420
1627
|
getById(projectId2) {
|
|
1421
1628
|
return resourceGuard("projects", this.#client.config()), lastValueFrom(
|
|
1422
|
-
_request(this.#client.config(), this.#httpRequest, {
|
|
1629
|
+
_request(this.#client.config(), this.#httpRequest, {
|
|
1630
|
+
uri: `/projects/${projectId2}`
|
|
1631
|
+
})
|
|
1632
|
+
);
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
1635
|
+
let random = (bytes) => crypto.getRandomValues(new Uint8Array(bytes)), customRandom = (alphabet, defaultSize, getRandom) => {
|
|
1636
|
+
let mask = (2 << Math.log(alphabet.length - 1) / Math.LN2) - 1, step = -~(1.6 * mask * defaultSize / alphabet.length);
|
|
1637
|
+
return (size = defaultSize) => {
|
|
1638
|
+
let id = "";
|
|
1639
|
+
for (; ; ) {
|
|
1640
|
+
let bytes = getRandom(step), j = step | 0;
|
|
1641
|
+
for (; j--; )
|
|
1642
|
+
if (id += alphabet[bytes[j] & mask] || "", id.length === size) return id;
|
|
1643
|
+
}
|
|
1644
|
+
};
|
|
1645
|
+
}, customAlphabet = (alphabet, size = 21) => customRandom(alphabet, size, random);
|
|
1646
|
+
const generateReleaseId = customAlphabet(
|
|
1647
|
+
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
|
|
1648
|
+
8
|
|
1649
|
+
), getDocumentVersionId = (publishedId, releaseId) => releaseId ? getVersionId(publishedId, releaseId) : getDraftId(publishedId);
|
|
1650
|
+
function deriveDocumentVersionId(op, {
|
|
1651
|
+
releaseId,
|
|
1652
|
+
publishedId,
|
|
1653
|
+
document
|
|
1654
|
+
}) {
|
|
1655
|
+
if (publishedId && document._id) {
|
|
1656
|
+
const versionId = getDocumentVersionId(publishedId, releaseId);
|
|
1657
|
+
return validateVersionIdMatch(versionId, document), versionId;
|
|
1658
|
+
}
|
|
1659
|
+
if (document._id) {
|
|
1660
|
+
const isDraft = isDraftId(document._id), isVersion = isVersionId(document._id);
|
|
1661
|
+
if (!isDraft && !isVersion)
|
|
1662
|
+
throw new Error(
|
|
1663
|
+
`\`${op}()\` requires a document with an \`_id\` that is a version or draft ID`
|
|
1664
|
+
);
|
|
1665
|
+
if (releaseId) {
|
|
1666
|
+
if (isDraft)
|
|
1667
|
+
throw new Error(
|
|
1668
|
+
`\`${op}()\` was called with a document ID (\`${document._id}\`) that is a draft ID, but a release ID (\`${releaseId}\`) was also provided.`
|
|
1669
|
+
);
|
|
1670
|
+
const builtVersionId = getVersionFromId(document._id);
|
|
1671
|
+
if (builtVersionId !== releaseId)
|
|
1672
|
+
throw new Error(
|
|
1673
|
+
`\`${op}()\` was called with a document ID (\`${document._id}\`) that is a version ID, but the release ID (\`${releaseId}\`) does not match the document's version ID (\`${builtVersionId}\`).`
|
|
1674
|
+
);
|
|
1675
|
+
}
|
|
1676
|
+
return document._id;
|
|
1677
|
+
}
|
|
1678
|
+
if (publishedId)
|
|
1679
|
+
return getDocumentVersionId(publishedId, releaseId);
|
|
1680
|
+
throw new Error(`\`${op}()\` requires either a publishedId or a document with an \`_id\``);
|
|
1681
|
+
}
|
|
1682
|
+
const getArgs = (releaseOrOptions, maybeOptions) => {
|
|
1683
|
+
if (typeof releaseOrOptions == "object" && releaseOrOptions !== null && ("releaseId" in releaseOrOptions || "metadata" in releaseOrOptions)) {
|
|
1684
|
+
const { releaseId = generateReleaseId(), metadata = {} } = releaseOrOptions;
|
|
1685
|
+
return [releaseId, metadata, maybeOptions];
|
|
1686
|
+
}
|
|
1687
|
+
return [generateReleaseId(), {}, releaseOrOptions];
|
|
1688
|
+
}, createRelease = (releaseOrOptions, maybeOptions) => {
|
|
1689
|
+
const [releaseId, metadata, options] = getArgs(releaseOrOptions, maybeOptions), finalMetadata = {
|
|
1690
|
+
...metadata,
|
|
1691
|
+
releaseType: metadata.releaseType || "undecided"
|
|
1692
|
+
};
|
|
1693
|
+
return { action: {
|
|
1694
|
+
actionType: "sanity.action.release.create",
|
|
1695
|
+
releaseId,
|
|
1696
|
+
metadata: finalMetadata
|
|
1697
|
+
}, options };
|
|
1698
|
+
};
|
|
1699
|
+
class ObservableReleasesClient {
|
|
1700
|
+
#client;
|
|
1701
|
+
#httpRequest;
|
|
1702
|
+
constructor(client, httpRequest) {
|
|
1703
|
+
this.#client = client, this.#httpRequest = httpRequest;
|
|
1704
|
+
}
|
|
1705
|
+
/**
|
|
1706
|
+
* @public
|
|
1707
|
+
*
|
|
1708
|
+
* Retrieve a release by id.
|
|
1709
|
+
*
|
|
1710
|
+
* @category Releases
|
|
1711
|
+
*
|
|
1712
|
+
* @param params - Release action parameters:
|
|
1713
|
+
* - `releaseId` - The id of the release to retrieve.
|
|
1714
|
+
* @param options - Additional query options including abort signal and query tag.
|
|
1715
|
+
* @returns An observable that resolves to the release document {@link ReleaseDocument}.
|
|
1716
|
+
*
|
|
1717
|
+
* @example Retrieving a release by id
|
|
1718
|
+
* ```ts
|
|
1719
|
+
* client.observable.releases.get({releaseId: 'my-release'}).pipe(
|
|
1720
|
+
* tap((release) => console.log(release)),
|
|
1721
|
+
* // {
|
|
1722
|
+
* // _id: '_.releases.my-release',
|
|
1723
|
+
* // name: 'my-release'
|
|
1724
|
+
* // _type: 'system.release',
|
|
1725
|
+
* // metadata: {releaseType: 'asap'},
|
|
1726
|
+
* // _createdAt: '2021-01-01T00:00:00.000Z',
|
|
1727
|
+
* // ...
|
|
1728
|
+
* // }
|
|
1729
|
+
* ).subscribe()
|
|
1730
|
+
* ```
|
|
1731
|
+
*/
|
|
1732
|
+
get({ releaseId }, options) {
|
|
1733
|
+
return _getDocument(
|
|
1734
|
+
this.#client.config(),
|
|
1735
|
+
this.#httpRequest,
|
|
1736
|
+
`_.releases.${releaseId}`,
|
|
1737
|
+
options
|
|
1738
|
+
);
|
|
1739
|
+
}
|
|
1740
|
+
create(releaseOrOptions, maybeOptions) {
|
|
1741
|
+
const { action, options } = createRelease(releaseOrOptions, maybeOptions), { releaseId, metadata } = action;
|
|
1742
|
+
return _action(this.#client.config(), this.#httpRequest, action, options).pipe(
|
|
1743
|
+
map$1((actionResult) => ({
|
|
1744
|
+
...actionResult,
|
|
1745
|
+
releaseId,
|
|
1746
|
+
metadata
|
|
1747
|
+
}))
|
|
1748
|
+
);
|
|
1749
|
+
}
|
|
1750
|
+
/**
|
|
1751
|
+
* @public
|
|
1752
|
+
*
|
|
1753
|
+
* Edits an existing release, updating the metadata.
|
|
1754
|
+
*
|
|
1755
|
+
* @category Releases
|
|
1756
|
+
*
|
|
1757
|
+
* @param params - Release action parameters:
|
|
1758
|
+
* - `releaseId` - The id of the release to edit.
|
|
1759
|
+
* - `patch` - The patch operation to apply on the release metadata {@link PatchMutationOperation}.
|
|
1760
|
+
* @param options - Additional action options.
|
|
1761
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
1762
|
+
*/
|
|
1763
|
+
edit({ releaseId, patch }, options) {
|
|
1764
|
+
const editAction = {
|
|
1765
|
+
actionType: "sanity.action.release.edit",
|
|
1766
|
+
releaseId,
|
|
1767
|
+
patch
|
|
1768
|
+
};
|
|
1769
|
+
return _action(this.#client.config(), this.#httpRequest, editAction, options);
|
|
1770
|
+
}
|
|
1771
|
+
/**
|
|
1772
|
+
* @public
|
|
1773
|
+
*
|
|
1774
|
+
* Publishes all documents in a release at once. For larger releases the effect of the publish
|
|
1775
|
+
* will be visible immediately when querying but the removal of the `versions.<releasesId>.*`
|
|
1776
|
+
* documents and creation of the corresponding published documents with the new content may
|
|
1777
|
+
* take some time.
|
|
1778
|
+
*
|
|
1779
|
+
* During this period both the source and target documents are locked and cannot be
|
|
1780
|
+
* modified through any other means.
|
|
1781
|
+
*
|
|
1782
|
+
* @category Releases
|
|
1783
|
+
*
|
|
1784
|
+
* @param params - Release action parameters:
|
|
1785
|
+
* - `releaseId` - The id of the release to publish.
|
|
1786
|
+
* @param options - Additional action options.
|
|
1787
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
1788
|
+
*/
|
|
1789
|
+
publish({ releaseId }, options) {
|
|
1790
|
+
const publishAction = {
|
|
1791
|
+
actionType: "sanity.action.release.publish",
|
|
1792
|
+
releaseId
|
|
1793
|
+
};
|
|
1794
|
+
return _action(this.#client.config(), this.#httpRequest, publishAction, options);
|
|
1795
|
+
}
|
|
1796
|
+
/**
|
|
1797
|
+
* @public
|
|
1798
|
+
*
|
|
1799
|
+
* An archive action removes an active release. The documents that comprise the release
|
|
1800
|
+
* are deleted and therefore no longer queryable.
|
|
1801
|
+
*
|
|
1802
|
+
* While the documents remain in retention the last version can still be accessed using document history endpoint.
|
|
1803
|
+
*
|
|
1804
|
+
* @category Releases
|
|
1805
|
+
*
|
|
1806
|
+
* @param params - Release action parameters:
|
|
1807
|
+
* - `releaseId` - The id of the release to archive.
|
|
1808
|
+
* @param options - Additional action options.
|
|
1809
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
1810
|
+
*/
|
|
1811
|
+
archive({ releaseId }, options) {
|
|
1812
|
+
const archiveAction = {
|
|
1813
|
+
actionType: "sanity.action.release.archive",
|
|
1814
|
+
releaseId
|
|
1815
|
+
};
|
|
1816
|
+
return _action(this.#client.config(), this.#httpRequest, archiveAction, options);
|
|
1817
|
+
}
|
|
1818
|
+
/**
|
|
1819
|
+
* @public
|
|
1820
|
+
*
|
|
1821
|
+
* An unarchive action restores an archived release and all documents
|
|
1822
|
+
* with the content they had just prior to archiving.
|
|
1823
|
+
*
|
|
1824
|
+
* @category Releases
|
|
1825
|
+
*
|
|
1826
|
+
* @param params - Release action parameters:
|
|
1827
|
+
* - `releaseId` - The id of the release to unarchive.
|
|
1828
|
+
* @param options - Additional action options.
|
|
1829
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
1830
|
+
*/
|
|
1831
|
+
unarchive({ releaseId }, options) {
|
|
1832
|
+
const unarchiveAction = {
|
|
1833
|
+
actionType: "sanity.action.release.unarchive",
|
|
1834
|
+
releaseId
|
|
1835
|
+
};
|
|
1836
|
+
return _action(this.#client.config(), this.#httpRequest, unarchiveAction, options);
|
|
1837
|
+
}
|
|
1838
|
+
/**
|
|
1839
|
+
* @public
|
|
1840
|
+
*
|
|
1841
|
+
* A schedule action queues a release for publishing at the given future time.
|
|
1842
|
+
* The release is locked such that no documents in the release can be modified and
|
|
1843
|
+
* no documents that it references can be deleted as this would make the publish fail.
|
|
1844
|
+
* At the given time, the same logic as for the publish action is triggered.
|
|
1845
|
+
*
|
|
1846
|
+
* @category Releases
|
|
1847
|
+
*
|
|
1848
|
+
* @param params - Release action parameters:
|
|
1849
|
+
* - `releaseId` - The id of the release to schedule.
|
|
1850
|
+
* - `publishAt` - The serialised date and time to publish the release. If the `publishAt` is in the past, the release will be published immediately.
|
|
1851
|
+
* @param options - Additional action options.
|
|
1852
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
1853
|
+
*/
|
|
1854
|
+
schedule({ releaseId, publishAt }, options) {
|
|
1855
|
+
const scheduleAction = {
|
|
1856
|
+
actionType: "sanity.action.release.schedule",
|
|
1857
|
+
releaseId,
|
|
1858
|
+
publishAt
|
|
1859
|
+
};
|
|
1860
|
+
return _action(this.#client.config(), this.#httpRequest, scheduleAction, options);
|
|
1861
|
+
}
|
|
1862
|
+
/**
|
|
1863
|
+
* @public
|
|
1864
|
+
*
|
|
1865
|
+
* An unschedule action stops a release from being published.
|
|
1866
|
+
* The documents in the release are considered unlocked and can be edited again.
|
|
1867
|
+
* This may fail if another release is scheduled to be published after this one and
|
|
1868
|
+
* has a reference to a document created by this one.
|
|
1869
|
+
*
|
|
1870
|
+
* @category Releases
|
|
1871
|
+
*
|
|
1872
|
+
* @param params - Release action parameters:
|
|
1873
|
+
* - `releaseId` - The id of the release to unschedule.
|
|
1874
|
+
* @param options - Additional action options.
|
|
1875
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
1876
|
+
*/
|
|
1877
|
+
unschedule({ releaseId }, options) {
|
|
1878
|
+
const unscheduleAction = {
|
|
1879
|
+
actionType: "sanity.action.release.unschedule",
|
|
1880
|
+
releaseId
|
|
1881
|
+
};
|
|
1882
|
+
return _action(this.#client.config(), this.#httpRequest, unscheduleAction, options);
|
|
1883
|
+
}
|
|
1884
|
+
/**
|
|
1885
|
+
* @public
|
|
1886
|
+
*
|
|
1887
|
+
* A delete action removes a published or archived release.
|
|
1888
|
+
* The backing system document will be removed from the dataset.
|
|
1889
|
+
*
|
|
1890
|
+
* @category Releases
|
|
1891
|
+
*
|
|
1892
|
+
* @param params - Release action parameters:
|
|
1893
|
+
* - `releaseId` - The id of the release to delete.
|
|
1894
|
+
* @param options - Additional action options.
|
|
1895
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
1896
|
+
*/
|
|
1897
|
+
delete({ releaseId }, options) {
|
|
1898
|
+
const deleteAction = {
|
|
1899
|
+
actionType: "sanity.action.release.delete",
|
|
1900
|
+
releaseId
|
|
1901
|
+
};
|
|
1902
|
+
return _action(this.#client.config(), this.#httpRequest, deleteAction, options);
|
|
1903
|
+
}
|
|
1904
|
+
/**
|
|
1905
|
+
* @public
|
|
1906
|
+
*
|
|
1907
|
+
* Fetch the documents in a release by release id.
|
|
1908
|
+
*
|
|
1909
|
+
* @category Releases
|
|
1910
|
+
*
|
|
1911
|
+
* @param params - Release action parameters:
|
|
1912
|
+
* - `releaseId` - The id of the release to fetch documents for.
|
|
1913
|
+
* @param options - Additional mutation options {@link BaseMutationOptions}.
|
|
1914
|
+
* @returns An observable that resolves to the documents in the release.
|
|
1915
|
+
*/
|
|
1916
|
+
fetchDocuments({ releaseId }, options) {
|
|
1917
|
+
return _getReleaseDocuments(this.#client.config(), this.#httpRequest, releaseId, options);
|
|
1918
|
+
}
|
|
1919
|
+
}
|
|
1920
|
+
class ReleasesClient {
|
|
1921
|
+
#client;
|
|
1922
|
+
#httpRequest;
|
|
1923
|
+
constructor(client, httpRequest) {
|
|
1924
|
+
this.#client = client, this.#httpRequest = httpRequest;
|
|
1925
|
+
}
|
|
1926
|
+
/**
|
|
1927
|
+
* @public
|
|
1928
|
+
*
|
|
1929
|
+
* Retrieve a release by id.
|
|
1930
|
+
*
|
|
1931
|
+
* @category Releases
|
|
1932
|
+
*
|
|
1933
|
+
* @param params - Release action parameters:
|
|
1934
|
+
* - `releaseId` - The id of the release to retrieve.
|
|
1935
|
+
* @param options - Additional query options including abort signal and query tag.
|
|
1936
|
+
* @returns A promise that resolves to the release document {@link ReleaseDocument}.
|
|
1937
|
+
*
|
|
1938
|
+
* @example Retrieving a release by id
|
|
1939
|
+
* ```ts
|
|
1940
|
+
* const release = await client.releases.get({releaseId: 'my-release'})
|
|
1941
|
+
* console.log(release)
|
|
1942
|
+
* // {
|
|
1943
|
+
* // _id: '_.releases.my-release',
|
|
1944
|
+
* // name: 'my-release'
|
|
1945
|
+
* // _type: 'system.release',
|
|
1946
|
+
* // metadata: {releaseType: 'asap'},
|
|
1947
|
+
* // _createdAt: '2021-01-01T00:00:00.000Z',
|
|
1948
|
+
* // ...
|
|
1949
|
+
* // }
|
|
1950
|
+
* ```
|
|
1951
|
+
*/
|
|
1952
|
+
get({ releaseId }, options) {
|
|
1953
|
+
return lastValueFrom(
|
|
1954
|
+
_getDocument(
|
|
1955
|
+
this.#client.config(),
|
|
1956
|
+
this.#httpRequest,
|
|
1957
|
+
`_.releases.${releaseId}`,
|
|
1958
|
+
options
|
|
1959
|
+
)
|
|
1960
|
+
);
|
|
1961
|
+
}
|
|
1962
|
+
async create(releaseOrOptions, maybeOptions) {
|
|
1963
|
+
const { action, options } = createRelease(releaseOrOptions, maybeOptions), { releaseId, metadata } = action;
|
|
1964
|
+
return { ...await lastValueFrom(
|
|
1965
|
+
_action(this.#client.config(), this.#httpRequest, action, options)
|
|
1966
|
+
), releaseId, metadata };
|
|
1967
|
+
}
|
|
1968
|
+
/**
|
|
1969
|
+
* @public
|
|
1970
|
+
*
|
|
1971
|
+
* Edits an existing release, updating the metadata.
|
|
1972
|
+
*
|
|
1973
|
+
* @category Releases
|
|
1974
|
+
*
|
|
1975
|
+
* @param params - Release action parameters:
|
|
1976
|
+
* - `releaseId` - The id of the release to edit.
|
|
1977
|
+
* - `patch` - The patch operation to apply on the release metadata {@link PatchMutationOperation}.
|
|
1978
|
+
* @param options - Additional action options.
|
|
1979
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
1980
|
+
*/
|
|
1981
|
+
edit({ releaseId, patch }, options) {
|
|
1982
|
+
const editAction = {
|
|
1983
|
+
actionType: "sanity.action.release.edit",
|
|
1984
|
+
releaseId,
|
|
1985
|
+
patch
|
|
1986
|
+
};
|
|
1987
|
+
return lastValueFrom(_action(this.#client.config(), this.#httpRequest, editAction, options));
|
|
1988
|
+
}
|
|
1989
|
+
/**
|
|
1990
|
+
* @public
|
|
1991
|
+
*
|
|
1992
|
+
* Publishes all documents in a release at once. For larger releases the effect of the publish
|
|
1993
|
+
* will be visible immediately when querying but the removal of the `versions.<releasesId>.*`
|
|
1994
|
+
* documents and creation of the corresponding published documents with the new content may
|
|
1995
|
+
* take some time.
|
|
1996
|
+
*
|
|
1997
|
+
* During this period both the source and target documents are locked and cannot be
|
|
1998
|
+
* modified through any other means.
|
|
1999
|
+
*
|
|
2000
|
+
* @category Releases
|
|
2001
|
+
*
|
|
2002
|
+
* @param params - Release action parameters:
|
|
2003
|
+
* - `releaseId` - The id of the release to publish.
|
|
2004
|
+
* @param options - Additional action options.
|
|
2005
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
2006
|
+
*/
|
|
2007
|
+
publish({ releaseId }, options) {
|
|
2008
|
+
const publishAction = {
|
|
2009
|
+
actionType: "sanity.action.release.publish",
|
|
2010
|
+
releaseId
|
|
2011
|
+
};
|
|
2012
|
+
return lastValueFrom(_action(this.#client.config(), this.#httpRequest, publishAction, options));
|
|
2013
|
+
}
|
|
2014
|
+
/**
|
|
2015
|
+
* @public
|
|
2016
|
+
*
|
|
2017
|
+
* An archive action removes an active release. The documents that comprise the release
|
|
2018
|
+
* are deleted and therefore no longer queryable.
|
|
2019
|
+
*
|
|
2020
|
+
* While the documents remain in retention the last version can still be accessed using document history endpoint.
|
|
2021
|
+
*
|
|
2022
|
+
* @category Releases
|
|
2023
|
+
*
|
|
2024
|
+
* @param params - Release action parameters:
|
|
2025
|
+
* - `releaseId` - The id of the release to archive.
|
|
2026
|
+
* @param options - Additional action options.
|
|
2027
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
2028
|
+
*/
|
|
2029
|
+
archive({ releaseId }, options) {
|
|
2030
|
+
const archiveAction = {
|
|
2031
|
+
actionType: "sanity.action.release.archive",
|
|
2032
|
+
releaseId
|
|
2033
|
+
};
|
|
2034
|
+
return lastValueFrom(_action(this.#client.config(), this.#httpRequest, archiveAction, options));
|
|
2035
|
+
}
|
|
2036
|
+
/**
|
|
2037
|
+
* @public
|
|
2038
|
+
*
|
|
2039
|
+
* An unarchive action restores an archived release and all documents
|
|
2040
|
+
* with the content they had just prior to archiving.
|
|
2041
|
+
*
|
|
2042
|
+
* @category Releases
|
|
2043
|
+
*
|
|
2044
|
+
* @param params - Release action parameters:
|
|
2045
|
+
* - `releaseId` - The id of the release to unarchive.
|
|
2046
|
+
* @param options - Additional action options.
|
|
2047
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
2048
|
+
*/
|
|
2049
|
+
unarchive({ releaseId }, options) {
|
|
2050
|
+
const unarchiveAction = {
|
|
2051
|
+
actionType: "sanity.action.release.unarchive",
|
|
2052
|
+
releaseId
|
|
2053
|
+
};
|
|
2054
|
+
return lastValueFrom(
|
|
2055
|
+
_action(this.#client.config(), this.#httpRequest, unarchiveAction, options)
|
|
2056
|
+
);
|
|
2057
|
+
}
|
|
2058
|
+
/**
|
|
2059
|
+
* @public
|
|
2060
|
+
*
|
|
2061
|
+
* A schedule action queues a release for publishing at the given future time.
|
|
2062
|
+
* The release is locked such that no documents in the release can be modified and
|
|
2063
|
+
* no documents that it references can be deleted as this would make the publish fail.
|
|
2064
|
+
* At the given time, the same logic as for the publish action is triggered.
|
|
2065
|
+
*
|
|
2066
|
+
* @category Releases
|
|
2067
|
+
*
|
|
2068
|
+
* @param params - Release action parameters:
|
|
2069
|
+
* - `releaseId` - The id of the release to schedule.
|
|
2070
|
+
* - `publishAt` - The serialised date and time to publish the release. If the `publishAt` is in the past, the release will be published immediately.
|
|
2071
|
+
* @param options - Additional action options.
|
|
2072
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
2073
|
+
*/
|
|
2074
|
+
schedule({ releaseId, publishAt }, options) {
|
|
2075
|
+
const scheduleAction = {
|
|
2076
|
+
actionType: "sanity.action.release.schedule",
|
|
2077
|
+
releaseId,
|
|
2078
|
+
publishAt
|
|
2079
|
+
};
|
|
2080
|
+
return lastValueFrom(_action(this.#client.config(), this.#httpRequest, scheduleAction, options));
|
|
2081
|
+
}
|
|
2082
|
+
/**
|
|
2083
|
+
* @public
|
|
2084
|
+
*
|
|
2085
|
+
* An unschedule action stops a release from being published.
|
|
2086
|
+
* The documents in the release are considered unlocked and can be edited again.
|
|
2087
|
+
* This may fail if another release is scheduled to be published after this one and
|
|
2088
|
+
* has a reference to a document created by this one.
|
|
2089
|
+
*
|
|
2090
|
+
* @category Releases
|
|
2091
|
+
*
|
|
2092
|
+
* @param params - Release action parameters:
|
|
2093
|
+
* - `releaseId` - The id of the release to unschedule.
|
|
2094
|
+
* @param options - Additional action options.
|
|
2095
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
2096
|
+
*/
|
|
2097
|
+
unschedule({ releaseId }, options) {
|
|
2098
|
+
const unscheduleAction = {
|
|
2099
|
+
actionType: "sanity.action.release.unschedule",
|
|
2100
|
+
releaseId
|
|
2101
|
+
};
|
|
2102
|
+
return lastValueFrom(
|
|
2103
|
+
_action(this.#client.config(), this.#httpRequest, unscheduleAction, options)
|
|
2104
|
+
);
|
|
2105
|
+
}
|
|
2106
|
+
/**
|
|
2107
|
+
* @public
|
|
2108
|
+
*
|
|
2109
|
+
* A delete action removes a published or archived release.
|
|
2110
|
+
* The backing system document will be removed from the dataset.
|
|
2111
|
+
*
|
|
2112
|
+
* @category Releases
|
|
2113
|
+
*
|
|
2114
|
+
* @param params - Release action parameters:
|
|
2115
|
+
* - `releaseId` - The id of the release to delete.
|
|
2116
|
+
* @param options - Additional action options.
|
|
2117
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
2118
|
+
*/
|
|
2119
|
+
delete({ releaseId }, options) {
|
|
2120
|
+
const deleteAction = {
|
|
2121
|
+
actionType: "sanity.action.release.delete",
|
|
2122
|
+
releaseId
|
|
2123
|
+
};
|
|
2124
|
+
return lastValueFrom(_action(this.#client.config(), this.#httpRequest, deleteAction, options));
|
|
2125
|
+
}
|
|
2126
|
+
/**
|
|
2127
|
+
* @public
|
|
2128
|
+
*
|
|
2129
|
+
* Fetch the documents in a release by release id.
|
|
2130
|
+
*
|
|
2131
|
+
* @category Releases
|
|
2132
|
+
*
|
|
2133
|
+
* @param params - Release action parameters:
|
|
2134
|
+
* - `releaseId` - The id of the release to fetch documents for.
|
|
2135
|
+
* @param options - Additional mutation options {@link BaseMutationOptions}.
|
|
2136
|
+
* @returns A promise that resolves to the documents in the release.
|
|
2137
|
+
*/
|
|
2138
|
+
fetchDocuments({ releaseId }, options) {
|
|
2139
|
+
return lastValueFrom(
|
|
2140
|
+
_getReleaseDocuments(this.#client.config(), this.#httpRequest, releaseId, options)
|
|
1423
2141
|
);
|
|
1424
2142
|
}
|
|
1425
2143
|
}
|
|
@@ -1455,9 +2173,13 @@ class UsersClient {
|
|
|
1455
2173
|
*/
|
|
1456
2174
|
getById(id) {
|
|
1457
2175
|
return lastValueFrom(
|
|
1458
|
-
_request(
|
|
1459
|
-
|
|
1460
|
-
|
|
2176
|
+
_request(
|
|
2177
|
+
this.#client.config(),
|
|
2178
|
+
this.#httpRequest,
|
|
2179
|
+
{
|
|
2180
|
+
uri: `/users/${id}`
|
|
2181
|
+
}
|
|
2182
|
+
)
|
|
1461
2183
|
);
|
|
1462
2184
|
}
|
|
1463
2185
|
}
|
|
@@ -1468,6 +2190,7 @@ class ObservableSanityClient {
|
|
|
1468
2190
|
projects;
|
|
1469
2191
|
users;
|
|
1470
2192
|
agent;
|
|
2193
|
+
releases;
|
|
1471
2194
|
/**
|
|
1472
2195
|
* Private properties
|
|
1473
2196
|
*/
|
|
@@ -1480,7 +2203,7 @@ class ObservableSanityClient {
|
|
|
1480
2203
|
constructor(httpRequest, config = defaultConfig) {
|
|
1481
2204
|
this.config(config), this.#httpRequest = httpRequest, this.assets = new ObservableAssetsClient(this, this.#httpRequest), this.datasets = new ObservableDatasetsClient(this, this.#httpRequest), this.live = new LiveClient(this), this.projects = new ObservableProjectsClient(this, this.#httpRequest), this.users = new ObservableUsersClient(this, this.#httpRequest), this.agent = {
|
|
1482
2205
|
action: new ObservableAgentsActionClient(this, this.#httpRequest)
|
|
1483
|
-
};
|
|
2206
|
+
}, this.releases = new ObservableReleasesClient(this, this.#httpRequest);
|
|
1484
2207
|
}
|
|
1485
2208
|
/**
|
|
1486
2209
|
* Clone the client - returns a new instance
|
|
@@ -1545,17 +2268,132 @@ class ObservableSanityClient {
|
|
|
1545
2268
|
return _getDocuments(this.#clientConfig, this.#httpRequest, ids, options);
|
|
1546
2269
|
}
|
|
1547
2270
|
create(document, options) {
|
|
1548
|
-
return _create(
|
|
2271
|
+
return _create(
|
|
2272
|
+
this.#clientConfig,
|
|
2273
|
+
this.#httpRequest,
|
|
2274
|
+
document,
|
|
2275
|
+
"create",
|
|
2276
|
+
options
|
|
2277
|
+
);
|
|
1549
2278
|
}
|
|
1550
2279
|
createIfNotExists(document, options) {
|
|
1551
|
-
return _createIfNotExists(
|
|
2280
|
+
return _createIfNotExists(
|
|
2281
|
+
this.#clientConfig,
|
|
2282
|
+
this.#httpRequest,
|
|
2283
|
+
document,
|
|
2284
|
+
options
|
|
2285
|
+
);
|
|
1552
2286
|
}
|
|
1553
2287
|
createOrReplace(document, options) {
|
|
1554
2288
|
return _createOrReplace(this.#clientConfig, this.#httpRequest, document, options);
|
|
1555
2289
|
}
|
|
2290
|
+
createVersion({
|
|
2291
|
+
document,
|
|
2292
|
+
publishedId,
|
|
2293
|
+
releaseId
|
|
2294
|
+
}, options) {
|
|
2295
|
+
const documentVersionId = deriveDocumentVersionId("createVersion", {
|
|
2296
|
+
document,
|
|
2297
|
+
publishedId,
|
|
2298
|
+
releaseId
|
|
2299
|
+
}), documentVersion = { ...document, _id: documentVersionId }, versionPublishedId = publishedId || getPublishedId(document._id);
|
|
2300
|
+
return _createVersion(
|
|
2301
|
+
this.config(),
|
|
2302
|
+
this.#httpRequest,
|
|
2303
|
+
documentVersion,
|
|
2304
|
+
versionPublishedId,
|
|
2305
|
+
options
|
|
2306
|
+
);
|
|
2307
|
+
}
|
|
1556
2308
|
delete(selection, options) {
|
|
1557
2309
|
return _delete(this.#clientConfig, this.#httpRequest, selection, options);
|
|
1558
2310
|
}
|
|
2311
|
+
/**
|
|
2312
|
+
* @public
|
|
2313
|
+
*
|
|
2314
|
+
* Deletes the draft or release version of a document.
|
|
2315
|
+
*
|
|
2316
|
+
* @remarks
|
|
2317
|
+
* * Discarding a version with no `releaseId` will discard the draft version of the published document.
|
|
2318
|
+
* * If the draft or release version does not exist, any error will throw.
|
|
2319
|
+
*
|
|
2320
|
+
* @param params - Version action parameters:
|
|
2321
|
+
* - `releaseId` - The ID of the release to discard the document from.
|
|
2322
|
+
* - `publishedId` - The published ID of the document to discard.
|
|
2323
|
+
* @param purge - if `true` the document history is also discarded.
|
|
2324
|
+
* @param options - Additional action options.
|
|
2325
|
+
* @returns an observable that resolves to the `transactionId`.
|
|
2326
|
+
*
|
|
2327
|
+
* @example Discarding a release version of a document
|
|
2328
|
+
* ```ts
|
|
2329
|
+
* client.observable.discardVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
|
|
2330
|
+
* // The document with the ID `versions.myRelease.myDocument` will be discarded.
|
|
2331
|
+
* ```
|
|
2332
|
+
*
|
|
2333
|
+
* @example Discarding a draft version of a document
|
|
2334
|
+
* ```ts
|
|
2335
|
+
* client.observable.discardVersion({publishedId: 'myDocument'})
|
|
2336
|
+
* // The document with the ID `drafts.myDocument` will be discarded.
|
|
2337
|
+
* ```
|
|
2338
|
+
*/
|
|
2339
|
+
discardVersion({ releaseId, publishedId }, purge, options) {
|
|
2340
|
+
const documentVersionId = getDocumentVersionId(publishedId, releaseId);
|
|
2341
|
+
return _discardVersion(
|
|
2342
|
+
this.config(),
|
|
2343
|
+
this.#httpRequest,
|
|
2344
|
+
documentVersionId,
|
|
2345
|
+
purge,
|
|
2346
|
+
options
|
|
2347
|
+
);
|
|
2348
|
+
}
|
|
2349
|
+
replaceVersion({
|
|
2350
|
+
document,
|
|
2351
|
+
publishedId,
|
|
2352
|
+
releaseId
|
|
2353
|
+
}, options) {
|
|
2354
|
+
const documentVersionId = deriveDocumentVersionId("replaceVersion", {
|
|
2355
|
+
document,
|
|
2356
|
+
publishedId,
|
|
2357
|
+
releaseId
|
|
2358
|
+
}), documentVersion = { ...document, _id: documentVersionId };
|
|
2359
|
+
return _replaceVersion(
|
|
2360
|
+
this.config(),
|
|
2361
|
+
this.#httpRequest,
|
|
2362
|
+
documentVersion,
|
|
2363
|
+
options
|
|
2364
|
+
);
|
|
2365
|
+
}
|
|
2366
|
+
/**
|
|
2367
|
+
* @public
|
|
2368
|
+
*
|
|
2369
|
+
* Used to indicate when a document within a release should be unpublished when
|
|
2370
|
+
* the release is run.
|
|
2371
|
+
*
|
|
2372
|
+
* @remarks
|
|
2373
|
+
* * If the published document does not exist, an error will be thrown.
|
|
2374
|
+
*
|
|
2375
|
+
* @param params - Version action parameters:
|
|
2376
|
+
* - `releaseId` - The ID of the release to unpublish the document from.
|
|
2377
|
+
* - `publishedId` - The published ID of the document to unpublish.
|
|
2378
|
+
* @param options - Additional action options.
|
|
2379
|
+
* @returns an observable that resolves to the `transactionId`.
|
|
2380
|
+
*
|
|
2381
|
+
* @example Unpublishing a release version of a published document
|
|
2382
|
+
* ```ts
|
|
2383
|
+
* client.observable.unpublishVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
|
|
2384
|
+
* // The document with the ID `versions.myRelease.myDocument` will be unpublished. when `myRelease` is run.
|
|
2385
|
+
* ```
|
|
2386
|
+
*/
|
|
2387
|
+
unpublishVersion({ releaseId, publishedId }, options) {
|
|
2388
|
+
const versionId = getVersionId(publishedId, releaseId);
|
|
2389
|
+
return _unpublishVersion(
|
|
2390
|
+
this.config(),
|
|
2391
|
+
this.#httpRequest,
|
|
2392
|
+
versionId,
|
|
2393
|
+
publishedId,
|
|
2394
|
+
options
|
|
2395
|
+
);
|
|
2396
|
+
}
|
|
1559
2397
|
mutate(operations, options) {
|
|
1560
2398
|
return _mutate(this.#clientConfig, this.#httpRequest, operations, options);
|
|
1561
2399
|
}
|
|
@@ -1620,6 +2458,7 @@ class SanityClient {
|
|
|
1620
2458
|
projects;
|
|
1621
2459
|
users;
|
|
1622
2460
|
agent;
|
|
2461
|
+
releases;
|
|
1623
2462
|
/**
|
|
1624
2463
|
* Observable version of the Sanity client, with the same configuration as the promise-based one
|
|
1625
2464
|
*/
|
|
@@ -1636,7 +2475,7 @@ class SanityClient {
|
|
|
1636
2475
|
constructor(httpRequest, config = defaultConfig) {
|
|
1637
2476
|
this.config(config), this.#httpRequest = httpRequest, this.assets = new AssetsClient(this, this.#httpRequest), this.datasets = new DatasetsClient(this, this.#httpRequest), this.live = new LiveClient(this), this.projects = new ProjectsClient(this, this.#httpRequest), this.users = new UsersClient(this, this.#httpRequest), this.agent = {
|
|
1638
2477
|
action: new AgentActionsClient(this, this.#httpRequest)
|
|
1639
|
-
}, this.observable = new ObservableSanityClient(httpRequest, config);
|
|
2478
|
+
}, this.releases = new ReleasesClient(this, this.#httpRequest), this.observable = new ObservableSanityClient(httpRequest, config);
|
|
1640
2479
|
}
|
|
1641
2480
|
/**
|
|
1642
2481
|
* Clone the client - returns a new instance
|
|
@@ -1688,7 +2527,9 @@ class SanityClient {
|
|
|
1688
2527
|
* @param options - Request options
|
|
1689
2528
|
*/
|
|
1690
2529
|
getDocument(id, options) {
|
|
1691
|
-
return lastValueFrom(
|
|
2530
|
+
return lastValueFrom(
|
|
2531
|
+
_getDocument(this.#clientConfig, this.#httpRequest, id, options)
|
|
2532
|
+
);
|
|
1692
2533
|
}
|
|
1693
2534
|
/**
|
|
1694
2535
|
* Fetch multiple documents in one request.
|
|
@@ -1700,7 +2541,9 @@ class SanityClient {
|
|
|
1700
2541
|
* @param options - Request options
|
|
1701
2542
|
*/
|
|
1702
2543
|
getDocuments(ids, options) {
|
|
1703
|
-
return lastValueFrom(
|
|
2544
|
+
return lastValueFrom(
|
|
2545
|
+
_getDocuments(this.#clientConfig, this.#httpRequest, ids, options)
|
|
2546
|
+
);
|
|
1704
2547
|
}
|
|
1705
2548
|
create(document, options) {
|
|
1706
2549
|
return lastValueFrom(
|
|
@@ -1717,11 +2560,122 @@ class SanityClient {
|
|
|
1717
2560
|
_createOrReplace(this.#clientConfig, this.#httpRequest, document, options)
|
|
1718
2561
|
);
|
|
1719
2562
|
}
|
|
2563
|
+
createVersion({
|
|
2564
|
+
document,
|
|
2565
|
+
publishedId,
|
|
2566
|
+
releaseId
|
|
2567
|
+
}, options) {
|
|
2568
|
+
const documentVersionId = deriveDocumentVersionId("createVersion", {
|
|
2569
|
+
document,
|
|
2570
|
+
publishedId,
|
|
2571
|
+
releaseId
|
|
2572
|
+
}), documentVersion = { ...document, _id: documentVersionId }, versionPublishedId = publishedId || getPublishedId(document._id);
|
|
2573
|
+
return firstValueFrom(
|
|
2574
|
+
_createVersion(
|
|
2575
|
+
this.config(),
|
|
2576
|
+
this.#httpRequest,
|
|
2577
|
+
documentVersion,
|
|
2578
|
+
versionPublishedId,
|
|
2579
|
+
options
|
|
2580
|
+
)
|
|
2581
|
+
);
|
|
2582
|
+
}
|
|
1720
2583
|
delete(selection, options) {
|
|
1721
|
-
return lastValueFrom(
|
|
2584
|
+
return lastValueFrom(
|
|
2585
|
+
_delete(this.#clientConfig, this.#httpRequest, selection, options)
|
|
2586
|
+
);
|
|
2587
|
+
}
|
|
2588
|
+
/**
|
|
2589
|
+
* @public
|
|
2590
|
+
*
|
|
2591
|
+
* Deletes the draft or release version of a document.
|
|
2592
|
+
*
|
|
2593
|
+
* @remarks
|
|
2594
|
+
* * Discarding a version with no `releaseId` will discard the draft version of the published document.
|
|
2595
|
+
* * If the draft or release version does not exist, any error will throw.
|
|
2596
|
+
*
|
|
2597
|
+
* @param params - Version action parameters:
|
|
2598
|
+
* - `releaseId` - The ID of the release to discard the document from.
|
|
2599
|
+
* - `publishedId` - The published ID of the document to discard.
|
|
2600
|
+
* @param purge - if `true` the document history is also discarded.
|
|
2601
|
+
* @param options - Additional action options.
|
|
2602
|
+
* @returns a promise that resolves to the `transactionId`.
|
|
2603
|
+
*
|
|
2604
|
+
* @example Discarding a release version of a document
|
|
2605
|
+
* ```ts
|
|
2606
|
+
* client.discardVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
|
|
2607
|
+
* // The document with the ID `versions.myRelease.myDocument` will be discarded.
|
|
2608
|
+
* ```
|
|
2609
|
+
*
|
|
2610
|
+
* @example Discarding a draft version of a document
|
|
2611
|
+
* ```ts
|
|
2612
|
+
* client.discardVersion({publishedId: 'myDocument'})
|
|
2613
|
+
* // The document with the ID `drafts.myDocument` will be discarded.
|
|
2614
|
+
* ```
|
|
2615
|
+
*/
|
|
2616
|
+
discardVersion({ releaseId, publishedId }, purge, options) {
|
|
2617
|
+
const documentVersionId = getDocumentVersionId(publishedId, releaseId);
|
|
2618
|
+
return lastValueFrom(
|
|
2619
|
+
_discardVersion(
|
|
2620
|
+
this.config(),
|
|
2621
|
+
this.#httpRequest,
|
|
2622
|
+
documentVersionId,
|
|
2623
|
+
purge,
|
|
2624
|
+
options
|
|
2625
|
+
)
|
|
2626
|
+
);
|
|
2627
|
+
}
|
|
2628
|
+
replaceVersion({
|
|
2629
|
+
document,
|
|
2630
|
+
publishedId,
|
|
2631
|
+
releaseId
|
|
2632
|
+
}, options) {
|
|
2633
|
+
const documentVersionId = deriveDocumentVersionId("replaceVersion", {
|
|
2634
|
+
document,
|
|
2635
|
+
publishedId,
|
|
2636
|
+
releaseId
|
|
2637
|
+
}), documentVersion = { ...document, _id: documentVersionId };
|
|
2638
|
+
return firstValueFrom(
|
|
2639
|
+
_replaceVersion(this.config(), this.#httpRequest, documentVersion, options)
|
|
2640
|
+
);
|
|
2641
|
+
}
|
|
2642
|
+
/**
|
|
2643
|
+
* @public
|
|
2644
|
+
*
|
|
2645
|
+
* Used to indicate when a document within a release should be unpublished when
|
|
2646
|
+
* the release is run.
|
|
2647
|
+
*
|
|
2648
|
+
* @remarks
|
|
2649
|
+
* * If the published document does not exist, an error will be thrown.
|
|
2650
|
+
*
|
|
2651
|
+
* @param params - Version action parameters:
|
|
2652
|
+
* - `releaseId` - The ID of the release to unpublish the document from.
|
|
2653
|
+
* - `publishedId` - The published ID of the document to unpublish.
|
|
2654
|
+
* @param options - Additional action options.
|
|
2655
|
+
* @returns a promise that resolves to the `transactionId`.
|
|
2656
|
+
*
|
|
2657
|
+
* @example Unpublishing a release version of a published document
|
|
2658
|
+
* ```ts
|
|
2659
|
+
* await client.unpublishVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
|
|
2660
|
+
* // The document with the ID `versions.myRelease.myDocument` will be unpublished. when `myRelease` is run.
|
|
2661
|
+
* ```
|
|
2662
|
+
*/
|
|
2663
|
+
unpublishVersion({ releaseId, publishedId }, options) {
|
|
2664
|
+
const versionId = getVersionId(publishedId, releaseId);
|
|
2665
|
+
return lastValueFrom(
|
|
2666
|
+
_unpublishVersion(
|
|
2667
|
+
this.config(),
|
|
2668
|
+
this.#httpRequest,
|
|
2669
|
+
versionId,
|
|
2670
|
+
publishedId,
|
|
2671
|
+
options
|
|
2672
|
+
)
|
|
2673
|
+
);
|
|
1722
2674
|
}
|
|
1723
2675
|
mutate(operations, options) {
|
|
1724
|
-
return lastValueFrom(
|
|
2676
|
+
return lastValueFrom(
|
|
2677
|
+
_mutate(this.#clientConfig, this.#httpRequest, operations, options)
|
|
2678
|
+
);
|
|
1725
2679
|
}
|
|
1726
2680
|
/**
|
|
1727
2681
|
* Create a new buildable patch of operations to perform
|
|
@@ -1749,7 +2703,9 @@ class SanityClient {
|
|
|
1749
2703
|
* @param options - Action options
|
|
1750
2704
|
*/
|
|
1751
2705
|
action(operations, options) {
|
|
1752
|
-
return lastValueFrom(
|
|
2706
|
+
return lastValueFrom(
|
|
2707
|
+
_action(this.#clientConfig, this.#httpRequest, operations, options)
|
|
2708
|
+
);
|
|
1753
2709
|
}
|
|
1754
2710
|
/**
|
|
1755
2711
|
* Perform a request against the Sanity API
|
|
@@ -1772,7 +2728,9 @@ class SanityClient {
|
|
|
1772
2728
|
* @internal
|
|
1773
2729
|
*/
|
|
1774
2730
|
dataRequest(endpoint, body, options) {
|
|
1775
|
-
return lastValueFrom(
|
|
2731
|
+
return lastValueFrom(
|
|
2732
|
+
_dataRequest(this.#clientConfig, this.#httpRequest, endpoint, body, options)
|
|
2733
|
+
);
|
|
1776
2734
|
}
|
|
1777
2735
|
/**
|
|
1778
2736
|
* Get a Sanity API URL for the URI provided
|
|
@@ -1831,9 +2789,12 @@ export {
|
|
|
1831
2789
|
SanityClient,
|
|
1832
2790
|
ServerError,
|
|
1833
2791
|
Transaction,
|
|
2792
|
+
ViewResourceType,
|
|
1834
2793
|
connectEventSource,
|
|
1835
2794
|
createClient,
|
|
1836
2795
|
deprecatedCreateClient as default,
|
|
2796
|
+
formatQueryParseError,
|
|
2797
|
+
isQueryParseError,
|
|
1837
2798
|
requester,
|
|
1838
2799
|
adapter as unstable__adapter,
|
|
1839
2800
|
environment as unstable__environment,
|