@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.cjs
CHANGED
|
@@ -19,14 +19,83 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
19
19
|
mod
|
|
20
20
|
));
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
22
|
-
var getIt = require("get-it"), middleware = require("get-it/middleware"), rxjs = require("rxjs"), stegaClean = require("./_chunks-cjs/stegaClean.cjs"), operators = require("rxjs/operators");
|
|
22
|
+
var getIt = require("get-it"), middleware = require("get-it/middleware"), rxjs = require("rxjs"), stegaClean = require("./_chunks-cjs/stegaClean.cjs"), operators = require("rxjs/operators"), csm = require("@sanity/client/csm");
|
|
23
|
+
const NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
|
|
24
|
+
function codeFrame(query, location2, message) {
|
|
25
|
+
const lines = query.split(NEWLINE), loc = {
|
|
26
|
+
start: columnToLine(location2.start, lines),
|
|
27
|
+
end: location2.end ? columnToLine(location2.end, lines) : void 0
|
|
28
|
+
}, { start, end, markerLines } = getMarkerLines(loc, lines), numberMaxWidth = `${end}`.length;
|
|
29
|
+
return query.split(NEWLINE, end).slice(start, end).map((line, index) => {
|
|
30
|
+
const number = start + 1 + index, gutter = ` ${` ${number}`.slice(-numberMaxWidth)} |`, hasMarker = markerLines[number], lastMarkerLine = !markerLines[number + 1];
|
|
31
|
+
if (!hasMarker)
|
|
32
|
+
return ` ${gutter}${line.length > 0 ? ` ${line}` : ""}`;
|
|
33
|
+
let markerLine = "";
|
|
34
|
+
if (Array.isArray(hasMarker)) {
|
|
35
|
+
const markerSpacing = line.slice(0, Math.max(hasMarker[0] - 1, 0)).replace(/[^\t]/g, " "), numberOfMarkers = hasMarker[1] || 1;
|
|
36
|
+
markerLine = [
|
|
37
|
+
`
|
|
38
|
+
`,
|
|
39
|
+
gutter.replace(/\d/g, " "),
|
|
40
|
+
" ",
|
|
41
|
+
markerSpacing,
|
|
42
|
+
"^".repeat(numberOfMarkers)
|
|
43
|
+
].join(""), lastMarkerLine && message && (markerLine += " " + message);
|
|
44
|
+
}
|
|
45
|
+
return [">", gutter, line.length > 0 ? ` ${line}` : "", markerLine].join("");
|
|
46
|
+
}).join(`
|
|
47
|
+
`);
|
|
48
|
+
}
|
|
49
|
+
function getMarkerLines(loc, source) {
|
|
50
|
+
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;
|
|
51
|
+
let start = Math.max(startLine - (linesAbove + 1), 0), end = Math.min(source.length, endLine + linesBelow);
|
|
52
|
+
startLine === -1 && (start = 0), endLine === -1 && (end = source.length);
|
|
53
|
+
const lineDiff = endLine - startLine, markerLines = {};
|
|
54
|
+
if (lineDiff)
|
|
55
|
+
for (let i = 0; i <= lineDiff; i++) {
|
|
56
|
+
const lineNumber = i + startLine;
|
|
57
|
+
if (!startColumn)
|
|
58
|
+
markerLines[lineNumber] = !0;
|
|
59
|
+
else if (i === 0) {
|
|
60
|
+
const sourceLength = source[lineNumber - 1].length;
|
|
61
|
+
markerLines[lineNumber] = [startColumn, sourceLength - startColumn + 1];
|
|
62
|
+
} else if (i === lineDiff)
|
|
63
|
+
markerLines[lineNumber] = [0, endColumn];
|
|
64
|
+
else {
|
|
65
|
+
const sourceLength = source[lineNumber - i].length;
|
|
66
|
+
markerLines[lineNumber] = [0, sourceLength];
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else
|
|
70
|
+
startColumn === endColumn ? startColumn ? markerLines[startLine] = [startColumn, 0] : markerLines[startLine] = !0 : markerLines[startLine] = [startColumn, endColumn - startColumn];
|
|
71
|
+
return { start, end, markerLines };
|
|
72
|
+
}
|
|
73
|
+
function columnToLine(column, lines) {
|
|
74
|
+
let offset = 0;
|
|
75
|
+
for (let i = 0; i < lines.length; i++) {
|
|
76
|
+
const lineLength = lines[i].length + 1;
|
|
77
|
+
if (offset + lineLength > column)
|
|
78
|
+
return {
|
|
79
|
+
line: i + 1,
|
|
80
|
+
// 1-based line
|
|
81
|
+
column: column - offset
|
|
82
|
+
// 0-based column
|
|
83
|
+
};
|
|
84
|
+
offset += lineLength;
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
line: lines.length,
|
|
88
|
+
column: lines[lines.length - 1]?.length ?? 0
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
const MAX_ITEMS_IN_ERROR_MESSAGE = 5;
|
|
23
92
|
class ClientError extends Error {
|
|
24
93
|
response;
|
|
25
94
|
statusCode = 400;
|
|
26
95
|
responseBody;
|
|
27
96
|
details;
|
|
28
|
-
constructor(res) {
|
|
29
|
-
const props = extractErrorProps(res);
|
|
97
|
+
constructor(res, context) {
|
|
98
|
+
const props = extractErrorProps(res, context);
|
|
30
99
|
super(props.message), Object.assign(this, props);
|
|
31
100
|
}
|
|
32
101
|
}
|
|
@@ -40,7 +109,7 @@ class ServerError extends Error {
|
|
|
40
109
|
super(props.message), Object.assign(this, props);
|
|
41
110
|
}
|
|
42
111
|
}
|
|
43
|
-
function extractErrorProps(res) {
|
|
112
|
+
function extractErrorProps(res, context) {
|
|
44
113
|
const body = res.body, props = {
|
|
45
114
|
response: res,
|
|
46
115
|
statusCode: res.statusCode,
|
|
@@ -48,34 +117,56 @@ function extractErrorProps(res) {
|
|
|
48
117
|
message: "",
|
|
49
118
|
details: void 0
|
|
50
119
|
};
|
|
51
|
-
if (
|
|
52
|
-
return props.message =
|
|
53
|
-
|
|
54
|
-
|
|
120
|
+
if (!stegaClean.isRecord(body))
|
|
121
|
+
return props.message = httpErrorMessage(res, body), props;
|
|
122
|
+
const error = body.error;
|
|
123
|
+
if (typeof error == "string" && typeof body.message == "string")
|
|
124
|
+
return props.message = `${error} - ${body.message}`, props;
|
|
125
|
+
if (typeof error != "object" || error === null)
|
|
126
|
+
return typeof error == "string" ? props.message = error : typeof body.message == "string" ? props.message = body.message : props.message = httpErrorMessage(res, body), props;
|
|
127
|
+
if (isMutationError(error) || isActionError(error)) {
|
|
128
|
+
const allItems = error.items || [], items = allItems.slice(0, MAX_ITEMS_IN_ERROR_MESSAGE).map((item) => item.error?.description).filter(Boolean);
|
|
55
129
|
let itemsStr = items.length ? `:
|
|
56
130
|
- ${items.join(`
|
|
57
131
|
- `)}` : "";
|
|
58
|
-
return allItems.length >
|
|
59
|
-
...and ${allItems.length -
|
|
132
|
+
return allItems.length > MAX_ITEMS_IN_ERROR_MESSAGE && (itemsStr += `
|
|
133
|
+
...and ${allItems.length - MAX_ITEMS_IN_ERROR_MESSAGE} more`), props.message = `${error.description}${itemsStr}`, props.details = body.error, props;
|
|
60
134
|
}
|
|
61
|
-
|
|
135
|
+
if (isQueryParseError(error)) {
|
|
136
|
+
const tag = context?.options?.query?.tag;
|
|
137
|
+
return props.message = formatQueryParseError(error, tag), props.details = body.error, props;
|
|
138
|
+
}
|
|
139
|
+
return "description" in error && typeof error.description == "string" ? (props.message = error.description, props.details = error, props) : (props.message = httpErrorMessage(res, body), props);
|
|
62
140
|
}
|
|
63
|
-
function isMutationError(
|
|
64
|
-
return
|
|
141
|
+
function isMutationError(error) {
|
|
142
|
+
return "type" in error && error.type === "mutationError" && "description" in error && typeof error.description == "string";
|
|
65
143
|
}
|
|
66
|
-
function isActionError(
|
|
67
|
-
return
|
|
144
|
+
function isActionError(error) {
|
|
145
|
+
return "type" in error && error.type === "actionError" && "description" in error && typeof error.description == "string";
|
|
68
146
|
}
|
|
69
|
-
function
|
|
70
|
-
return typeof
|
|
147
|
+
function isQueryParseError(error) {
|
|
148
|
+
return stegaClean.isRecord(error) && error.type === "queryParseError" && typeof error.query == "string" && typeof error.start == "number" && typeof error.end == "number";
|
|
71
149
|
}
|
|
72
|
-
function
|
|
73
|
-
const
|
|
74
|
-
|
|
150
|
+
function formatQueryParseError(error, tag) {
|
|
151
|
+
const { query, start, end, description } = error;
|
|
152
|
+
if (!query || typeof start > "u")
|
|
153
|
+
return `GROQ query parse error: ${description}`;
|
|
154
|
+
const withTag = tag ? `
|
|
155
|
+
|
|
156
|
+
Tag: ${tag}` : "";
|
|
157
|
+
return `GROQ query parse error:
|
|
158
|
+
${codeFrame(query, { start, end }, description)}${withTag}`;
|
|
159
|
+
}
|
|
160
|
+
function httpErrorMessage(res, body) {
|
|
161
|
+
const details = typeof body == "string" ? ` (${sliceWithEllipsis(body, 100)})` : "", statusMessage = res.statusMessage ? ` ${res.statusMessage}` : "";
|
|
162
|
+
return `${res.method}-request to ${res.url} resulted in HTTP ${res.statusCode}${statusMessage}${details}`;
|
|
75
163
|
}
|
|
76
164
|
function stringifyBody(body, res) {
|
|
77
165
|
return (res.headers["content-type"] || "").toLowerCase().indexOf("application/json") !== -1 ? JSON.stringify(body, null, 2) : body;
|
|
78
166
|
}
|
|
167
|
+
function sliceWithEllipsis(str, max) {
|
|
168
|
+
return str.length > max ? `${str.slice(0, max)}\u2026` : str;
|
|
169
|
+
}
|
|
79
170
|
class CorsOriginError extends Error {
|
|
80
171
|
projectId;
|
|
81
172
|
addOriginUrl;
|
|
@@ -90,11 +181,11 @@ class CorsOriginError extends Error {
|
|
|
90
181
|
}
|
|
91
182
|
}
|
|
92
183
|
const httpError = {
|
|
93
|
-
onResponse: (res) => {
|
|
184
|
+
onResponse: (res, context) => {
|
|
94
185
|
if (res.statusCode >= 500)
|
|
95
186
|
throw new ServerError(res);
|
|
96
187
|
if (res.statusCode >= 400)
|
|
97
|
-
throw new ClientError(res);
|
|
188
|
+
throw new ClientError(res, context);
|
|
98
189
|
return res;
|
|
99
190
|
}
|
|
100
191
|
};
|
|
@@ -151,6 +242,18 @@ const VALID_ASSET_TYPES = ["image", "file"], VALID_INSERT_LOCATIONS = ["before",
|
|
|
151
242
|
if (!doc._id)
|
|
152
243
|
throw new Error(`${op}() requires that the document contains an ID ("_id" property)`);
|
|
153
244
|
validateDocumentId(op, doc._id);
|
|
245
|
+
}, validateDocumentType = (op, type) => {
|
|
246
|
+
if (typeof type != "string")
|
|
247
|
+
throw new Error(`\`${op}()\`: \`${type}\` is not a valid document type`);
|
|
248
|
+
}, requireDocumentType = (op, doc) => {
|
|
249
|
+
if (!doc._type)
|
|
250
|
+
throw new Error(`\`${op}()\` requires that the document contains a type (\`_type\` property)`);
|
|
251
|
+
validateDocumentType(op, doc._type);
|
|
252
|
+
}, validateVersionIdMatch = (builtVersionId, document) => {
|
|
253
|
+
if (document._id && document._id !== builtVersionId)
|
|
254
|
+
throw new Error(
|
|
255
|
+
`The provided document ID (\`${document._id}\`) does not match the generated version ID (\`${builtVersionId}\`)`
|
|
256
|
+
);
|
|
154
257
|
}, validateInsert = (at, selector, items) => {
|
|
155
258
|
const signature = "insert(at, selector, items)";
|
|
156
259
|
if (VALID_INSERT_LOCATIONS.indexOf(at) === -1) {
|
|
@@ -193,6 +296,7 @@ const VALID_ASSET_TYPES = ["image", "file"], VALID_INSERT_LOCATIONS = ["before",
|
|
|
193
296
|
if (config["~experimental_resource"])
|
|
194
297
|
throw new Error(`\`${service}\` does not support resource-based operations`);
|
|
195
298
|
};
|
|
299
|
+
var ViewResourceType = /* @__PURE__ */ ((ViewResourceType2) => (ViewResourceType2.Dataset = "dataset", ViewResourceType2))(ViewResourceType || {});
|
|
196
300
|
function once(fn) {
|
|
197
301
|
let didCall = !1, returnValue;
|
|
198
302
|
return (...args) => (didCall || (returnValue = fn(...args), didCall = !0), returnValue);
|
|
@@ -344,7 +448,8 @@ function connectWithESInstance(es, events) {
|
|
|
344
448
|
return;
|
|
345
449
|
}
|
|
346
450
|
if (message.type === "channelError") {
|
|
347
|
-
|
|
451
|
+
const tag = new URL(es.url).searchParams.get("tag");
|
|
452
|
+
observer.error(new ChannelError(extractErrorMessage(event?.data, tag), event.data));
|
|
348
453
|
return;
|
|
349
454
|
}
|
|
350
455
|
if (message.type === "disconnect") {
|
|
@@ -383,8 +488,9 @@ function parseEvent(message) {
|
|
|
383
488
|
return [err, null];
|
|
384
489
|
}
|
|
385
490
|
}
|
|
386
|
-
function extractErrorMessage(err) {
|
|
387
|
-
|
|
491
|
+
function extractErrorMessage(err, tag) {
|
|
492
|
+
const error = err.error;
|
|
493
|
+
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";
|
|
388
494
|
}
|
|
389
495
|
function isEmptyObject(data) {
|
|
390
496
|
for (const _ in data)
|
|
@@ -727,7 +833,9 @@ class ObservableTransaction extends BaseTransaction {
|
|
|
727
833
|
}
|
|
728
834
|
const projectHeader = "X-Sanity-Project-ID";
|
|
729
835
|
function requestOptions(config, overrides = {}) {
|
|
730
|
-
const headers = {}
|
|
836
|
+
const headers = {};
|
|
837
|
+
config.headers && Object.assign(headers, config.headers);
|
|
838
|
+
const token = overrides.token || config.token;
|
|
731
839
|
token && (headers.Authorization = `Bearer ${token}`), !overrides.useGlobalApi && !config.useProjectHostname && config.projectId && (headers[projectHeader] = config.projectId);
|
|
732
840
|
const withCredentials = !!(typeof overrides.withCredentials > "u" ? config.withCredentials : overrides.withCredentials), timeout = typeof overrides.timeout > "u" ? config.timeout : overrides.timeout;
|
|
733
841
|
return Object.assign({}, overrides, {
|
|
@@ -747,7 +855,7 @@ const encodeQueryString = ({
|
|
|
747
855
|
const searchParams = new URLSearchParams(), { tag, includeMutations, returnQuery, ...opts } = options;
|
|
748
856
|
tag && searchParams.append("tag", tag), searchParams.append("query", query);
|
|
749
857
|
for (const [key, value] of Object.entries(params))
|
|
750
|
-
searchParams.append(`$${key}`, JSON.stringify(value));
|
|
858
|
+
value !== void 0 && searchParams.append(`$${key}`, JSON.stringify(value));
|
|
751
859
|
for (const [key, value] of Object.entries(opts))
|
|
752
860
|
value && searchParams.append(key, `${value}`);
|
|
753
861
|
return returnQuery === !1 && searchParams.append("returnQuery", "false"), includeMutations === !1 && searchParams.append("includeMutations", "false"), `?${searchParams}`;
|
|
@@ -763,17 +871,25 @@ function _fetch(config, httpRequest, _stega, query, _params = {}, options = {})
|
|
|
763
871
|
const stega = "stega" in options ? {
|
|
764
872
|
..._stega || {},
|
|
765
873
|
...typeof options.stega == "boolean" ? { enabled: options.stega } : options.stega || {}
|
|
766
|
-
} : _stega, params = stega.enabled ? stegaClean.stegaClean(_params) : _params, mapResponse = options.filterResponse === !1 ? (res) => res : (res) => res.result, { cache, next, ...opts } = {
|
|
874
|
+
} : _stega, params = stega.enabled ? stegaClean.stegaClean(_params) : _params, mapResponse = options.filterResponse === !1 ? (res) => res : (res) => res.result, { cache, next, useEmulate, connections, ...opts } = {
|
|
767
875
|
// Opt out of setting a `signal` on an internal `fetch` if one isn't provided.
|
|
768
876
|
// This is necessary in React Server Components to avoid opting out of Request Memoization.
|
|
769
877
|
useAbortSignal: typeof options.signal < "u",
|
|
770
878
|
// Set `resultSourceMap' when stega is enabled, as it's required for encoding.
|
|
771
879
|
resultSourceMap: stega.enabled ? "withKeyArraySelector" : options.resultSourceMap,
|
|
880
|
+
// Only use emulate if explicitly asked for
|
|
881
|
+
useEmulate: !1,
|
|
882
|
+
// Having connections is a special case for views
|
|
883
|
+
connections: void 0,
|
|
772
884
|
...options,
|
|
773
885
|
// Default to not returning the query, unless `filterResponse` is `false`,
|
|
774
886
|
// or `returnQuery` is explicitly set. `true` is the default in Content Lake, so skip if truthy
|
|
775
887
|
returnQuery: options.filterResponse === !1 && options.returnQuery !== !1
|
|
776
|
-
}, reqOpts = typeof cache < "u" || typeof next < "u" ? { ...opts, fetch: { cache, next } } : opts, $request = _dataRequest(config, httpRequest, "
|
|
888
|
+
}, reqOpts = typeof cache < "u" || typeof next < "u" ? { ...opts, fetch: { cache, next } } : opts, $request = _dataRequest(config, httpRequest, useEmulate ? "emulate" : "query", useEmulate ? {
|
|
889
|
+
query,
|
|
890
|
+
params,
|
|
891
|
+
connections
|
|
892
|
+
} : { query, params }, reqOpts);
|
|
777
893
|
return stega.enabled ? $request.pipe(
|
|
778
894
|
operators.combineLatestWith(
|
|
779
895
|
rxjs.from(
|
|
@@ -795,8 +911,24 @@ function _fetch(config, httpRequest, _stega, query, _params = {}, options = {})
|
|
|
795
911
|
) : $request.pipe(operators.map(mapResponse));
|
|
796
912
|
}
|
|
797
913
|
function _getDocument(config, httpRequest, id, opts = {}) {
|
|
798
|
-
const
|
|
799
|
-
|
|
914
|
+
const docId = (() => {
|
|
915
|
+
if (!opts.releaseId)
|
|
916
|
+
return id;
|
|
917
|
+
const versionId = csm.getVersionFromId(id);
|
|
918
|
+
if (!versionId) {
|
|
919
|
+
if (csm.isDraftId(id))
|
|
920
|
+
throw new Error(
|
|
921
|
+
`The document ID (\`${id}\`) is a draft, but \`options.releaseId\` is set as \`${opts.releaseId}\``
|
|
922
|
+
);
|
|
923
|
+
return csm.getVersionId(id, opts.releaseId);
|
|
924
|
+
}
|
|
925
|
+
if (versionId !== opts.releaseId)
|
|
926
|
+
throw new Error(
|
|
927
|
+
`The document ID (\`${id}\`) is already a version of \`${versionId}\` release, but this does not match the provided \`options.releaseId\` (\`${opts.releaseId}\`)`
|
|
928
|
+
);
|
|
929
|
+
return id;
|
|
930
|
+
})(), options = {
|
|
931
|
+
uri: _getDataUrl(config, "doc", docId),
|
|
800
932
|
json: !0,
|
|
801
933
|
tag: opts.tag,
|
|
802
934
|
signal: opts.signal
|
|
@@ -821,12 +953,33 @@ function _getDocuments(config, httpRequest, ids, opts = {}) {
|
|
|
821
953
|
})
|
|
822
954
|
);
|
|
823
955
|
}
|
|
956
|
+
function _getReleaseDocuments(config, httpRequest, releaseId, opts = {}) {
|
|
957
|
+
return _dataRequest(
|
|
958
|
+
config,
|
|
959
|
+
httpRequest,
|
|
960
|
+
"query",
|
|
961
|
+
{
|
|
962
|
+
query: "*[sanity::partOfRelease($releaseId)]",
|
|
963
|
+
params: {
|
|
964
|
+
releaseId
|
|
965
|
+
}
|
|
966
|
+
},
|
|
967
|
+
opts
|
|
968
|
+
);
|
|
969
|
+
}
|
|
824
970
|
function _createIfNotExists(config, httpRequest, doc, options) {
|
|
825
971
|
return requireDocumentId("createIfNotExists", doc), _create(config, httpRequest, doc, "createIfNotExists", options);
|
|
826
972
|
}
|
|
827
973
|
function _createOrReplace(config, httpRequest, doc, options) {
|
|
828
974
|
return requireDocumentId("createOrReplace", doc), _create(config, httpRequest, doc, "createOrReplace", options);
|
|
829
975
|
}
|
|
976
|
+
function _createVersion(config, httpRequest, doc, publishedId, options) {
|
|
977
|
+
return requireDocumentId("createVersion", doc), requireDocumentType("createVersion", doc), _action(config, httpRequest, {
|
|
978
|
+
actionType: "sanity.action.document.version.create",
|
|
979
|
+
publishedId,
|
|
980
|
+
document: doc
|
|
981
|
+
}, options);
|
|
982
|
+
}
|
|
830
983
|
function _delete(config, httpRequest, selection, options) {
|
|
831
984
|
return _dataRequest(
|
|
832
985
|
config,
|
|
@@ -836,6 +989,26 @@ function _delete(config, httpRequest, selection, options) {
|
|
|
836
989
|
options
|
|
837
990
|
);
|
|
838
991
|
}
|
|
992
|
+
function _discardVersion(config, httpRequest, versionId, purge = !1, options) {
|
|
993
|
+
return _action(config, httpRequest, {
|
|
994
|
+
actionType: "sanity.action.document.version.discard",
|
|
995
|
+
versionId,
|
|
996
|
+
purge
|
|
997
|
+
}, options);
|
|
998
|
+
}
|
|
999
|
+
function _replaceVersion(config, httpRequest, doc, options) {
|
|
1000
|
+
return requireDocumentId("replaceVersion", doc), requireDocumentType("replaceVersion", doc), _action(config, httpRequest, {
|
|
1001
|
+
actionType: "sanity.action.document.version.replace",
|
|
1002
|
+
document: doc
|
|
1003
|
+
}, options);
|
|
1004
|
+
}
|
|
1005
|
+
function _unpublishVersion(config, httpRequest, versionId, publishedId, options) {
|
|
1006
|
+
return _action(config, httpRequest, {
|
|
1007
|
+
actionType: "sanity.action.document.version.unpublish",
|
|
1008
|
+
versionId,
|
|
1009
|
+
publishedId
|
|
1010
|
+
}, options);
|
|
1011
|
+
}
|
|
839
1012
|
function _mutate(config, httpRequest, mutations, options) {
|
|
840
1013
|
let mut;
|
|
841
1014
|
mutations instanceof Patch || mutations instanceof ObservablePatch ? mut = { patch: mutations.serialize() } : mutations instanceof Transaction || mutations instanceof ObservableTransaction ? mut = mutations.serialize() : mut = mutations;
|
|
@@ -853,7 +1026,7 @@ function _action(config, httpRequest, actions, options) {
|
|
|
853
1026
|
);
|
|
854
1027
|
}
|
|
855
1028
|
function _dataRequest(config, httpRequest, endpoint, body, options = {}) {
|
|
856
|
-
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 = {
|
|
1029
|
+
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 = {
|
|
857
1030
|
method: useGet ? "GET" : "POST",
|
|
858
1031
|
uri,
|
|
859
1032
|
json: !0,
|
|
@@ -896,12 +1069,12 @@ function _create(config, httpRequest, doc, op, options = {}) {
|
|
|
896
1069
|
const mutation = { [op]: doc }, opts = Object.assign({ returnFirst: !0, returnDocuments: !0 }, options);
|
|
897
1070
|
return _dataRequest(config, httpRequest, "mutate", { mutations: [mutation] }, opts);
|
|
898
1071
|
}
|
|
899
|
-
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);
|
|
1072
|
+
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);
|
|
900
1073
|
function _requestObservable(config, httpRequest, options) {
|
|
901
1074
|
const uri = options.url || options.uri, canUseCdn = typeof options.canUseCdn > "u" ? ["GET", "HEAD"].indexOf(options.method || "GET") >= 0 && isData(config, uri) : options.canUseCdn;
|
|
902
1075
|
let useCdn = (options.useCdn ?? config.useCdn) && canUseCdn;
|
|
903
1076
|
const tag = options.tag && config.requestTagPrefix ? [config.requestTagPrefix, options.tag].join(".") : options.tag || config.requestTagPrefix;
|
|
904
|
-
if (tag && options.tag !== null && (options.query = { tag: requestTag(tag), ...options.query }), ["GET", "HEAD", "POST"].indexOf(options.method || "GET") >= 0 && isQuery(config, uri)) {
|
|
1077
|
+
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))) {
|
|
905
1078
|
const resultSourceMap = options.resultSourceMap ?? config.resultSourceMap;
|
|
906
1079
|
resultSourceMap !== void 0 && resultSourceMap !== !1 && (options.query = { resultSourceMap, ...options.query });
|
|
907
1080
|
const perspectiveOption = options.perspective || config.perspective;
|
|
@@ -936,7 +1109,7 @@ function _getDataUrl(config, operation, path) {
|
|
|
936
1109
|
const catalog = hasDataset(config), baseUri = `/${operation}/${catalog}`;
|
|
937
1110
|
return `/data${path !== void 0 ? `${baseUri}/${path}` : baseUri}`.replace(/\/($|\?)/, "$1");
|
|
938
1111
|
}
|
|
939
|
-
function _getUrl(config, uri, canUseCdn = !1
|
|
1112
|
+
function _getUrl(config, uri, canUseCdn = !1) {
|
|
940
1113
|
const { url, cdnUrl } = config;
|
|
941
1114
|
return `${canUseCdn ? cdnUrl : url}/${uri.replace(/^\//, "")}`;
|
|
942
1115
|
}
|
|
@@ -991,6 +1164,22 @@ function _generate(client, httpRequest, request) {
|
|
|
991
1164
|
body: request
|
|
992
1165
|
});
|
|
993
1166
|
}
|
|
1167
|
+
function _patch(client, httpRequest, request) {
|
|
1168
|
+
const dataset2 = hasDataset(client.config());
|
|
1169
|
+
return _request(client.config(), httpRequest, {
|
|
1170
|
+
method: "POST",
|
|
1171
|
+
uri: `/agent/action/patch/${dataset2}`,
|
|
1172
|
+
body: request
|
|
1173
|
+
});
|
|
1174
|
+
}
|
|
1175
|
+
function _prompt(client, httpRequest, request) {
|
|
1176
|
+
const dataset2 = hasDataset(client.config());
|
|
1177
|
+
return _request(client.config(), httpRequest, {
|
|
1178
|
+
method: "POST",
|
|
1179
|
+
uri: `/agent/action/prompt/${dataset2}`,
|
|
1180
|
+
body: request
|
|
1181
|
+
});
|
|
1182
|
+
}
|
|
994
1183
|
function _transform(client, httpRequest, request) {
|
|
995
1184
|
const dataset2 = hasDataset(client.config());
|
|
996
1185
|
return _request(client.config(), httpRequest, {
|
|
@@ -1062,6 +1251,21 @@ class AgentActionsClient {
|
|
|
1062
1251
|
translate(request) {
|
|
1063
1252
|
return rxjs.lastValueFrom(_translate(this.#client, this.#httpRequest, request));
|
|
1064
1253
|
}
|
|
1254
|
+
/**
|
|
1255
|
+
* Run a raw instruction and return the result either as text or json
|
|
1256
|
+
* @param request - prompt request
|
|
1257
|
+
*/
|
|
1258
|
+
prompt(request) {
|
|
1259
|
+
return rxjs.lastValueFrom(_prompt(this.#client, this.#httpRequest, request));
|
|
1260
|
+
}
|
|
1261
|
+
/**
|
|
1262
|
+
* Patch a document using a schema aware API.
|
|
1263
|
+
* Does not use an LLM, but uses the schema to ensure paths and values matches the schema.
|
|
1264
|
+
* @param request - instruction request
|
|
1265
|
+
*/
|
|
1266
|
+
patch(request) {
|
|
1267
|
+
return rxjs.lastValueFrom(_patch(this.#client, this.#httpRequest, request));
|
|
1268
|
+
}
|
|
1065
1269
|
}
|
|
1066
1270
|
class ObservableAssetsClient {
|
|
1067
1271
|
#client;
|
|
@@ -1170,13 +1374,11 @@ const MAX_URL_LENGTH = 14800, possibleOptions = [
|
|
|
1170
1374
|
includeResult: !0
|
|
1171
1375
|
};
|
|
1172
1376
|
function _listen(query, params, opts = {}) {
|
|
1173
|
-
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)}`;
|
|
1377
|
+
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)}`;
|
|
1174
1378
|
if (uri.length > MAX_URL_LENGTH)
|
|
1175
1379
|
return rxjs.throwError(() => new Error("Query too large for listener"));
|
|
1176
1380
|
const listenFor = options.events ? options.events : ["mutation"], esOptions = {};
|
|
1177
|
-
return withCredentials && (esOptions.withCredentials = !0), token && (esOptions.headers = {
|
|
1178
|
-
Authorization: `Bearer ${token}`
|
|
1179
|
-
}), connectEventSource(() => (
|
|
1381
|
+
return withCredentials && (esOptions.withCredentials = !0), (token || configHeaders) && (esOptions.headers = {}, token && (esOptions.headers.Authorization = `Bearer ${token}`), configHeaders && Object.assign(esOptions.headers, configHeaders)), connectEventSource(() => (
|
|
1180
1382
|
// use polyfill if there is no global EventSource or if we need to set headers
|
|
1181
1383
|
(typeof EventSource > "u" || esOptions.headers ? eventSourcePolyfill : rxjs.of(EventSource)).pipe(operators.map((EventSource2) => new EventSource2(uri, esOptions)))
|
|
1182
1384
|
), listenFor).pipe(
|
|
@@ -1234,7 +1436,8 @@ class LiveClient {
|
|
|
1234
1436
|
apiVersion: _apiVersion,
|
|
1235
1437
|
token,
|
|
1236
1438
|
withCredentials,
|
|
1237
|
-
requestTagPrefix
|
|
1439
|
+
requestTagPrefix,
|
|
1440
|
+
headers: configHeaders
|
|
1238
1441
|
} = this.#client.config(), apiVersion = _apiVersion.replace(/^v/, "");
|
|
1239
1442
|
if (apiVersion !== "X" && apiVersion < requiredApiVersion)
|
|
1240
1443
|
throw new Error(
|
|
@@ -1247,9 +1450,7 @@ class LiveClient {
|
|
|
1247
1450
|
const path = _getDataUrl(this.#client.config(), "live/events"), url = new URL(this.#client.getUrl(path, !1)), tag = _tag && requestTagPrefix ? [requestTagPrefix, _tag].join(".") : _tag;
|
|
1248
1451
|
tag && url.searchParams.set("tag", tag), includeDrafts && url.searchParams.set("includeDrafts", "true");
|
|
1249
1452
|
const esOptions = {};
|
|
1250
|
-
includeDrafts && token && (esOptions.headers = {
|
|
1251
|
-
Authorization: `Bearer ${token}`
|
|
1252
|
-
}), includeDrafts && withCredentials && (esOptions.withCredentials = !0);
|
|
1453
|
+
includeDrafts && withCredentials && (esOptions.withCredentials = !0), (includeDrafts && token || configHeaders) && (esOptions.headers = {}, includeDrafts && token && (esOptions.headers.Authorization = `Bearer ${token}`), configHeaders && Object.assign(esOptions.headers, configHeaders));
|
|
1253
1454
|
const key = `${url.href}::${JSON.stringify(esOptions)}`, existing = eventsCache.get(key);
|
|
1254
1455
|
if (existing)
|
|
1255
1456
|
return existing;
|
|
@@ -1387,7 +1588,10 @@ class DatasetsClient {
|
|
|
1387
1588
|
*/
|
|
1388
1589
|
list() {
|
|
1389
1590
|
return resourceGuard("dataset", this.#client.config()), rxjs.lastValueFrom(
|
|
1390
|
-
_request(this.#client.config(), this.#httpRequest, {
|
|
1591
|
+
_request(this.#client.config(), this.#httpRequest, {
|
|
1592
|
+
uri: "/datasets",
|
|
1593
|
+
tag: null
|
|
1594
|
+
})
|
|
1391
1595
|
);
|
|
1392
1596
|
}
|
|
1393
1597
|
}
|
|
@@ -1416,7 +1620,9 @@ class ObservableProjectsClient {
|
|
|
1416
1620
|
* @param projectId - ID of the project to fetch
|
|
1417
1621
|
*/
|
|
1418
1622
|
getById(projectId2) {
|
|
1419
|
-
return resourceGuard("projects", this.#client.config()), _request(this.#client.config(), this.#httpRequest, {
|
|
1623
|
+
return resourceGuard("projects", this.#client.config()), _request(this.#client.config(), this.#httpRequest, {
|
|
1624
|
+
uri: `/projects/${projectId2}`
|
|
1625
|
+
});
|
|
1420
1626
|
}
|
|
1421
1627
|
}
|
|
1422
1628
|
class ProjectsClient {
|
|
@@ -1437,7 +1643,518 @@ class ProjectsClient {
|
|
|
1437
1643
|
*/
|
|
1438
1644
|
getById(projectId2) {
|
|
1439
1645
|
return resourceGuard("projects", this.#client.config()), rxjs.lastValueFrom(
|
|
1440
|
-
_request(this.#client.config(), this.#httpRequest, {
|
|
1646
|
+
_request(this.#client.config(), this.#httpRequest, {
|
|
1647
|
+
uri: `/projects/${projectId2}`
|
|
1648
|
+
})
|
|
1649
|
+
);
|
|
1650
|
+
}
|
|
1651
|
+
}
|
|
1652
|
+
let random = (bytes) => crypto.getRandomValues(new Uint8Array(bytes)), customRandom = (alphabet, defaultSize, getRandom) => {
|
|
1653
|
+
let mask = (2 << Math.log(alphabet.length - 1) / Math.LN2) - 1, step = -~(1.6 * mask * defaultSize / alphabet.length);
|
|
1654
|
+
return (size = defaultSize) => {
|
|
1655
|
+
let id = "";
|
|
1656
|
+
for (; ; ) {
|
|
1657
|
+
let bytes = getRandom(step), j = step | 0;
|
|
1658
|
+
for (; j--; )
|
|
1659
|
+
if (id += alphabet[bytes[j] & mask] || "", id.length === size) return id;
|
|
1660
|
+
}
|
|
1661
|
+
};
|
|
1662
|
+
}, customAlphabet = (alphabet, size = 21) => customRandom(alphabet, size, random);
|
|
1663
|
+
const generateReleaseId = customAlphabet(
|
|
1664
|
+
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
|
|
1665
|
+
8
|
|
1666
|
+
), getDocumentVersionId = (publishedId, releaseId) => releaseId ? csm.getVersionId(publishedId, releaseId) : csm.getDraftId(publishedId);
|
|
1667
|
+
function deriveDocumentVersionId(op, {
|
|
1668
|
+
releaseId,
|
|
1669
|
+
publishedId,
|
|
1670
|
+
document
|
|
1671
|
+
}) {
|
|
1672
|
+
if (publishedId && document._id) {
|
|
1673
|
+
const versionId = getDocumentVersionId(publishedId, releaseId);
|
|
1674
|
+
return validateVersionIdMatch(versionId, document), versionId;
|
|
1675
|
+
}
|
|
1676
|
+
if (document._id) {
|
|
1677
|
+
const isDraft = csm.isDraftId(document._id), isVersion = csm.isVersionId(document._id);
|
|
1678
|
+
if (!isDraft && !isVersion)
|
|
1679
|
+
throw new Error(
|
|
1680
|
+
`\`${op}()\` requires a document with an \`_id\` that is a version or draft ID`
|
|
1681
|
+
);
|
|
1682
|
+
if (releaseId) {
|
|
1683
|
+
if (isDraft)
|
|
1684
|
+
throw new Error(
|
|
1685
|
+
`\`${op}()\` was called with a document ID (\`${document._id}\`) that is a draft ID, but a release ID (\`${releaseId}\`) was also provided.`
|
|
1686
|
+
);
|
|
1687
|
+
const builtVersionId = csm.getVersionFromId(document._id);
|
|
1688
|
+
if (builtVersionId !== releaseId)
|
|
1689
|
+
throw new Error(
|
|
1690
|
+
`\`${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}\`).`
|
|
1691
|
+
);
|
|
1692
|
+
}
|
|
1693
|
+
return document._id;
|
|
1694
|
+
}
|
|
1695
|
+
if (publishedId)
|
|
1696
|
+
return getDocumentVersionId(publishedId, releaseId);
|
|
1697
|
+
throw new Error(`\`${op}()\` requires either a publishedId or a document with an \`_id\``);
|
|
1698
|
+
}
|
|
1699
|
+
const getArgs = (releaseOrOptions, maybeOptions) => {
|
|
1700
|
+
if (typeof releaseOrOptions == "object" && releaseOrOptions !== null && ("releaseId" in releaseOrOptions || "metadata" in releaseOrOptions)) {
|
|
1701
|
+
const { releaseId = generateReleaseId(), metadata = {} } = releaseOrOptions;
|
|
1702
|
+
return [releaseId, metadata, maybeOptions];
|
|
1703
|
+
}
|
|
1704
|
+
return [generateReleaseId(), {}, releaseOrOptions];
|
|
1705
|
+
}, createRelease = (releaseOrOptions, maybeOptions) => {
|
|
1706
|
+
const [releaseId, metadata, options] = getArgs(releaseOrOptions, maybeOptions), finalMetadata = {
|
|
1707
|
+
...metadata,
|
|
1708
|
+
releaseType: metadata.releaseType || "undecided"
|
|
1709
|
+
};
|
|
1710
|
+
return { action: {
|
|
1711
|
+
actionType: "sanity.action.release.create",
|
|
1712
|
+
releaseId,
|
|
1713
|
+
metadata: finalMetadata
|
|
1714
|
+
}, options };
|
|
1715
|
+
};
|
|
1716
|
+
class ObservableReleasesClient {
|
|
1717
|
+
#client;
|
|
1718
|
+
#httpRequest;
|
|
1719
|
+
constructor(client, httpRequest) {
|
|
1720
|
+
this.#client = client, this.#httpRequest = httpRequest;
|
|
1721
|
+
}
|
|
1722
|
+
/**
|
|
1723
|
+
* @public
|
|
1724
|
+
*
|
|
1725
|
+
* Retrieve a release by id.
|
|
1726
|
+
*
|
|
1727
|
+
* @category Releases
|
|
1728
|
+
*
|
|
1729
|
+
* @param params - Release action parameters:
|
|
1730
|
+
* - `releaseId` - The id of the release to retrieve.
|
|
1731
|
+
* @param options - Additional query options including abort signal and query tag.
|
|
1732
|
+
* @returns An observable that resolves to the release document {@link ReleaseDocument}.
|
|
1733
|
+
*
|
|
1734
|
+
* @example Retrieving a release by id
|
|
1735
|
+
* ```ts
|
|
1736
|
+
* client.observable.releases.get({releaseId: 'my-release'}).pipe(
|
|
1737
|
+
* tap((release) => console.log(release)),
|
|
1738
|
+
* // {
|
|
1739
|
+
* // _id: '_.releases.my-release',
|
|
1740
|
+
* // name: 'my-release'
|
|
1741
|
+
* // _type: 'system.release',
|
|
1742
|
+
* // metadata: {releaseType: 'asap'},
|
|
1743
|
+
* // _createdAt: '2021-01-01T00:00:00.000Z',
|
|
1744
|
+
* // ...
|
|
1745
|
+
* // }
|
|
1746
|
+
* ).subscribe()
|
|
1747
|
+
* ```
|
|
1748
|
+
*/
|
|
1749
|
+
get({ releaseId }, options) {
|
|
1750
|
+
return _getDocument(
|
|
1751
|
+
this.#client.config(),
|
|
1752
|
+
this.#httpRequest,
|
|
1753
|
+
`_.releases.${releaseId}`,
|
|
1754
|
+
options
|
|
1755
|
+
);
|
|
1756
|
+
}
|
|
1757
|
+
create(releaseOrOptions, maybeOptions) {
|
|
1758
|
+
const { action, options } = createRelease(releaseOrOptions, maybeOptions), { releaseId, metadata } = action;
|
|
1759
|
+
return _action(this.#client.config(), this.#httpRequest, action, options).pipe(
|
|
1760
|
+
rxjs.map((actionResult) => ({
|
|
1761
|
+
...actionResult,
|
|
1762
|
+
releaseId,
|
|
1763
|
+
metadata
|
|
1764
|
+
}))
|
|
1765
|
+
);
|
|
1766
|
+
}
|
|
1767
|
+
/**
|
|
1768
|
+
* @public
|
|
1769
|
+
*
|
|
1770
|
+
* Edits an existing release, updating the metadata.
|
|
1771
|
+
*
|
|
1772
|
+
* @category Releases
|
|
1773
|
+
*
|
|
1774
|
+
* @param params - Release action parameters:
|
|
1775
|
+
* - `releaseId` - The id of the release to edit.
|
|
1776
|
+
* - `patch` - The patch operation to apply on the release metadata {@link PatchMutationOperation}.
|
|
1777
|
+
* @param options - Additional action options.
|
|
1778
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
1779
|
+
*/
|
|
1780
|
+
edit({ releaseId, patch }, options) {
|
|
1781
|
+
const editAction = {
|
|
1782
|
+
actionType: "sanity.action.release.edit",
|
|
1783
|
+
releaseId,
|
|
1784
|
+
patch
|
|
1785
|
+
};
|
|
1786
|
+
return _action(this.#client.config(), this.#httpRequest, editAction, options);
|
|
1787
|
+
}
|
|
1788
|
+
/**
|
|
1789
|
+
* @public
|
|
1790
|
+
*
|
|
1791
|
+
* Publishes all documents in a release at once. For larger releases the effect of the publish
|
|
1792
|
+
* will be visible immediately when querying but the removal of the `versions.<releasesId>.*`
|
|
1793
|
+
* documents and creation of the corresponding published documents with the new content may
|
|
1794
|
+
* take some time.
|
|
1795
|
+
*
|
|
1796
|
+
* During this period both the source and target documents are locked and cannot be
|
|
1797
|
+
* modified through any other means.
|
|
1798
|
+
*
|
|
1799
|
+
* @category Releases
|
|
1800
|
+
*
|
|
1801
|
+
* @param params - Release action parameters:
|
|
1802
|
+
* - `releaseId` - The id of the release to publish.
|
|
1803
|
+
* @param options - Additional action options.
|
|
1804
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
1805
|
+
*/
|
|
1806
|
+
publish({ releaseId }, options) {
|
|
1807
|
+
const publishAction = {
|
|
1808
|
+
actionType: "sanity.action.release.publish",
|
|
1809
|
+
releaseId
|
|
1810
|
+
};
|
|
1811
|
+
return _action(this.#client.config(), this.#httpRequest, publishAction, options);
|
|
1812
|
+
}
|
|
1813
|
+
/**
|
|
1814
|
+
* @public
|
|
1815
|
+
*
|
|
1816
|
+
* An archive action removes an active release. The documents that comprise the release
|
|
1817
|
+
* are deleted and therefore no longer queryable.
|
|
1818
|
+
*
|
|
1819
|
+
* While the documents remain in retention the last version can still be accessed using document history endpoint.
|
|
1820
|
+
*
|
|
1821
|
+
* @category Releases
|
|
1822
|
+
*
|
|
1823
|
+
* @param params - Release action parameters:
|
|
1824
|
+
* - `releaseId` - The id of the release to archive.
|
|
1825
|
+
* @param options - Additional action options.
|
|
1826
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
1827
|
+
*/
|
|
1828
|
+
archive({ releaseId }, options) {
|
|
1829
|
+
const archiveAction = {
|
|
1830
|
+
actionType: "sanity.action.release.archive",
|
|
1831
|
+
releaseId
|
|
1832
|
+
};
|
|
1833
|
+
return _action(this.#client.config(), this.#httpRequest, archiveAction, options);
|
|
1834
|
+
}
|
|
1835
|
+
/**
|
|
1836
|
+
* @public
|
|
1837
|
+
*
|
|
1838
|
+
* An unarchive action restores an archived release and all documents
|
|
1839
|
+
* with the content they had just prior to archiving.
|
|
1840
|
+
*
|
|
1841
|
+
* @category Releases
|
|
1842
|
+
*
|
|
1843
|
+
* @param params - Release action parameters:
|
|
1844
|
+
* - `releaseId` - The id of the release to unarchive.
|
|
1845
|
+
* @param options - Additional action options.
|
|
1846
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
1847
|
+
*/
|
|
1848
|
+
unarchive({ releaseId }, options) {
|
|
1849
|
+
const unarchiveAction = {
|
|
1850
|
+
actionType: "sanity.action.release.unarchive",
|
|
1851
|
+
releaseId
|
|
1852
|
+
};
|
|
1853
|
+
return _action(this.#client.config(), this.#httpRequest, unarchiveAction, options);
|
|
1854
|
+
}
|
|
1855
|
+
/**
|
|
1856
|
+
* @public
|
|
1857
|
+
*
|
|
1858
|
+
* A schedule action queues a release for publishing at the given future time.
|
|
1859
|
+
* The release is locked such that no documents in the release can be modified and
|
|
1860
|
+
* no documents that it references can be deleted as this would make the publish fail.
|
|
1861
|
+
* At the given time, the same logic as for the publish action is triggered.
|
|
1862
|
+
*
|
|
1863
|
+
* @category Releases
|
|
1864
|
+
*
|
|
1865
|
+
* @param params - Release action parameters:
|
|
1866
|
+
* - `releaseId` - The id of the release to schedule.
|
|
1867
|
+
* - `publishAt` - The serialised date and time to publish the release. If the `publishAt` is in the past, the release will be published immediately.
|
|
1868
|
+
* @param options - Additional action options.
|
|
1869
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
1870
|
+
*/
|
|
1871
|
+
schedule({ releaseId, publishAt }, options) {
|
|
1872
|
+
const scheduleAction = {
|
|
1873
|
+
actionType: "sanity.action.release.schedule",
|
|
1874
|
+
releaseId,
|
|
1875
|
+
publishAt
|
|
1876
|
+
};
|
|
1877
|
+
return _action(this.#client.config(), this.#httpRequest, scheduleAction, options);
|
|
1878
|
+
}
|
|
1879
|
+
/**
|
|
1880
|
+
* @public
|
|
1881
|
+
*
|
|
1882
|
+
* An unschedule action stops a release from being published.
|
|
1883
|
+
* The documents in the release are considered unlocked and can be edited again.
|
|
1884
|
+
* This may fail if another release is scheduled to be published after this one and
|
|
1885
|
+
* has a reference to a document created by this one.
|
|
1886
|
+
*
|
|
1887
|
+
* @category Releases
|
|
1888
|
+
*
|
|
1889
|
+
* @param params - Release action parameters:
|
|
1890
|
+
* - `releaseId` - The id of the release to unschedule.
|
|
1891
|
+
* @param options - Additional action options.
|
|
1892
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
1893
|
+
*/
|
|
1894
|
+
unschedule({ releaseId }, options) {
|
|
1895
|
+
const unscheduleAction = {
|
|
1896
|
+
actionType: "sanity.action.release.unschedule",
|
|
1897
|
+
releaseId
|
|
1898
|
+
};
|
|
1899
|
+
return _action(this.#client.config(), this.#httpRequest, unscheduleAction, options);
|
|
1900
|
+
}
|
|
1901
|
+
/**
|
|
1902
|
+
* @public
|
|
1903
|
+
*
|
|
1904
|
+
* A delete action removes a published or archived release.
|
|
1905
|
+
* The backing system document will be removed from the dataset.
|
|
1906
|
+
*
|
|
1907
|
+
* @category Releases
|
|
1908
|
+
*
|
|
1909
|
+
* @param params - Release action parameters:
|
|
1910
|
+
* - `releaseId` - The id of the release to delete.
|
|
1911
|
+
* @param options - Additional action options.
|
|
1912
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
1913
|
+
*/
|
|
1914
|
+
delete({ releaseId }, options) {
|
|
1915
|
+
const deleteAction = {
|
|
1916
|
+
actionType: "sanity.action.release.delete",
|
|
1917
|
+
releaseId
|
|
1918
|
+
};
|
|
1919
|
+
return _action(this.#client.config(), this.#httpRequest, deleteAction, options);
|
|
1920
|
+
}
|
|
1921
|
+
/**
|
|
1922
|
+
* @public
|
|
1923
|
+
*
|
|
1924
|
+
* Fetch the documents in a release by release id.
|
|
1925
|
+
*
|
|
1926
|
+
* @category Releases
|
|
1927
|
+
*
|
|
1928
|
+
* @param params - Release action parameters:
|
|
1929
|
+
* - `releaseId` - The id of the release to fetch documents for.
|
|
1930
|
+
* @param options - Additional mutation options {@link BaseMutationOptions}.
|
|
1931
|
+
* @returns An observable that resolves to the documents in the release.
|
|
1932
|
+
*/
|
|
1933
|
+
fetchDocuments({ releaseId }, options) {
|
|
1934
|
+
return _getReleaseDocuments(this.#client.config(), this.#httpRequest, releaseId, options);
|
|
1935
|
+
}
|
|
1936
|
+
}
|
|
1937
|
+
class ReleasesClient {
|
|
1938
|
+
#client;
|
|
1939
|
+
#httpRequest;
|
|
1940
|
+
constructor(client, httpRequest) {
|
|
1941
|
+
this.#client = client, this.#httpRequest = httpRequest;
|
|
1942
|
+
}
|
|
1943
|
+
/**
|
|
1944
|
+
* @public
|
|
1945
|
+
*
|
|
1946
|
+
* Retrieve a release by id.
|
|
1947
|
+
*
|
|
1948
|
+
* @category Releases
|
|
1949
|
+
*
|
|
1950
|
+
* @param params - Release action parameters:
|
|
1951
|
+
* - `releaseId` - The id of the release to retrieve.
|
|
1952
|
+
* @param options - Additional query options including abort signal and query tag.
|
|
1953
|
+
* @returns A promise that resolves to the release document {@link ReleaseDocument}.
|
|
1954
|
+
*
|
|
1955
|
+
* @example Retrieving a release by id
|
|
1956
|
+
* ```ts
|
|
1957
|
+
* const release = await client.releases.get({releaseId: 'my-release'})
|
|
1958
|
+
* console.log(release)
|
|
1959
|
+
* // {
|
|
1960
|
+
* // _id: '_.releases.my-release',
|
|
1961
|
+
* // name: 'my-release'
|
|
1962
|
+
* // _type: 'system.release',
|
|
1963
|
+
* // metadata: {releaseType: 'asap'},
|
|
1964
|
+
* // _createdAt: '2021-01-01T00:00:00.000Z',
|
|
1965
|
+
* // ...
|
|
1966
|
+
* // }
|
|
1967
|
+
* ```
|
|
1968
|
+
*/
|
|
1969
|
+
get({ releaseId }, options) {
|
|
1970
|
+
return rxjs.lastValueFrom(
|
|
1971
|
+
_getDocument(
|
|
1972
|
+
this.#client.config(),
|
|
1973
|
+
this.#httpRequest,
|
|
1974
|
+
`_.releases.${releaseId}`,
|
|
1975
|
+
options
|
|
1976
|
+
)
|
|
1977
|
+
);
|
|
1978
|
+
}
|
|
1979
|
+
async create(releaseOrOptions, maybeOptions) {
|
|
1980
|
+
const { action, options } = createRelease(releaseOrOptions, maybeOptions), { releaseId, metadata } = action;
|
|
1981
|
+
return { ...await rxjs.lastValueFrom(
|
|
1982
|
+
_action(this.#client.config(), this.#httpRequest, action, options)
|
|
1983
|
+
), releaseId, metadata };
|
|
1984
|
+
}
|
|
1985
|
+
/**
|
|
1986
|
+
* @public
|
|
1987
|
+
*
|
|
1988
|
+
* Edits an existing release, updating the metadata.
|
|
1989
|
+
*
|
|
1990
|
+
* @category Releases
|
|
1991
|
+
*
|
|
1992
|
+
* @param params - Release action parameters:
|
|
1993
|
+
* - `releaseId` - The id of the release to edit.
|
|
1994
|
+
* - `patch` - The patch operation to apply on the release metadata {@link PatchMutationOperation}.
|
|
1995
|
+
* @param options - Additional action options.
|
|
1996
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
1997
|
+
*/
|
|
1998
|
+
edit({ releaseId, patch }, options) {
|
|
1999
|
+
const editAction = {
|
|
2000
|
+
actionType: "sanity.action.release.edit",
|
|
2001
|
+
releaseId,
|
|
2002
|
+
patch
|
|
2003
|
+
};
|
|
2004
|
+
return rxjs.lastValueFrom(_action(this.#client.config(), this.#httpRequest, editAction, options));
|
|
2005
|
+
}
|
|
2006
|
+
/**
|
|
2007
|
+
* @public
|
|
2008
|
+
*
|
|
2009
|
+
* Publishes all documents in a release at once. For larger releases the effect of the publish
|
|
2010
|
+
* will be visible immediately when querying but the removal of the `versions.<releasesId>.*`
|
|
2011
|
+
* documents and creation of the corresponding published documents with the new content may
|
|
2012
|
+
* take some time.
|
|
2013
|
+
*
|
|
2014
|
+
* During this period both the source and target documents are locked and cannot be
|
|
2015
|
+
* modified through any other means.
|
|
2016
|
+
*
|
|
2017
|
+
* @category Releases
|
|
2018
|
+
*
|
|
2019
|
+
* @param params - Release action parameters:
|
|
2020
|
+
* - `releaseId` - The id of the release to publish.
|
|
2021
|
+
* @param options - Additional action options.
|
|
2022
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
2023
|
+
*/
|
|
2024
|
+
publish({ releaseId }, options) {
|
|
2025
|
+
const publishAction = {
|
|
2026
|
+
actionType: "sanity.action.release.publish",
|
|
2027
|
+
releaseId
|
|
2028
|
+
};
|
|
2029
|
+
return rxjs.lastValueFrom(_action(this.#client.config(), this.#httpRequest, publishAction, options));
|
|
2030
|
+
}
|
|
2031
|
+
/**
|
|
2032
|
+
* @public
|
|
2033
|
+
*
|
|
2034
|
+
* An archive action removes an active release. The documents that comprise the release
|
|
2035
|
+
* are deleted and therefore no longer queryable.
|
|
2036
|
+
*
|
|
2037
|
+
* While the documents remain in retention the last version can still be accessed using document history endpoint.
|
|
2038
|
+
*
|
|
2039
|
+
* @category Releases
|
|
2040
|
+
*
|
|
2041
|
+
* @param params - Release action parameters:
|
|
2042
|
+
* - `releaseId` - The id of the release to archive.
|
|
2043
|
+
* @param options - Additional action options.
|
|
2044
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
2045
|
+
*/
|
|
2046
|
+
archive({ releaseId }, options) {
|
|
2047
|
+
const archiveAction = {
|
|
2048
|
+
actionType: "sanity.action.release.archive",
|
|
2049
|
+
releaseId
|
|
2050
|
+
};
|
|
2051
|
+
return rxjs.lastValueFrom(_action(this.#client.config(), this.#httpRequest, archiveAction, options));
|
|
2052
|
+
}
|
|
2053
|
+
/**
|
|
2054
|
+
* @public
|
|
2055
|
+
*
|
|
2056
|
+
* An unarchive action restores an archived release and all documents
|
|
2057
|
+
* with the content they had just prior to archiving.
|
|
2058
|
+
*
|
|
2059
|
+
* @category Releases
|
|
2060
|
+
*
|
|
2061
|
+
* @param params - Release action parameters:
|
|
2062
|
+
* - `releaseId` - The id of the release to unarchive.
|
|
2063
|
+
* @param options - Additional action options.
|
|
2064
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
2065
|
+
*/
|
|
2066
|
+
unarchive({ releaseId }, options) {
|
|
2067
|
+
const unarchiveAction = {
|
|
2068
|
+
actionType: "sanity.action.release.unarchive",
|
|
2069
|
+
releaseId
|
|
2070
|
+
};
|
|
2071
|
+
return rxjs.lastValueFrom(
|
|
2072
|
+
_action(this.#client.config(), this.#httpRequest, unarchiveAction, options)
|
|
2073
|
+
);
|
|
2074
|
+
}
|
|
2075
|
+
/**
|
|
2076
|
+
* @public
|
|
2077
|
+
*
|
|
2078
|
+
* A schedule action queues a release for publishing at the given future time.
|
|
2079
|
+
* The release is locked such that no documents in the release can be modified and
|
|
2080
|
+
* no documents that it references can be deleted as this would make the publish fail.
|
|
2081
|
+
* At the given time, the same logic as for the publish action is triggered.
|
|
2082
|
+
*
|
|
2083
|
+
* @category Releases
|
|
2084
|
+
*
|
|
2085
|
+
* @param params - Release action parameters:
|
|
2086
|
+
* - `releaseId` - The id of the release to schedule.
|
|
2087
|
+
* - `publishAt` - The serialised date and time to publish the release. If the `publishAt` is in the past, the release will be published immediately.
|
|
2088
|
+
* @param options - Additional action options.
|
|
2089
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
2090
|
+
*/
|
|
2091
|
+
schedule({ releaseId, publishAt }, options) {
|
|
2092
|
+
const scheduleAction = {
|
|
2093
|
+
actionType: "sanity.action.release.schedule",
|
|
2094
|
+
releaseId,
|
|
2095
|
+
publishAt
|
|
2096
|
+
};
|
|
2097
|
+
return rxjs.lastValueFrom(_action(this.#client.config(), this.#httpRequest, scheduleAction, options));
|
|
2098
|
+
}
|
|
2099
|
+
/**
|
|
2100
|
+
* @public
|
|
2101
|
+
*
|
|
2102
|
+
* An unschedule action stops a release from being published.
|
|
2103
|
+
* The documents in the release are considered unlocked and can be edited again.
|
|
2104
|
+
* This may fail if another release is scheduled to be published after this one and
|
|
2105
|
+
* has a reference to a document created by this one.
|
|
2106
|
+
*
|
|
2107
|
+
* @category Releases
|
|
2108
|
+
*
|
|
2109
|
+
* @param params - Release action parameters:
|
|
2110
|
+
* - `releaseId` - The id of the release to unschedule.
|
|
2111
|
+
* @param options - Additional action options.
|
|
2112
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
2113
|
+
*/
|
|
2114
|
+
unschedule({ releaseId }, options) {
|
|
2115
|
+
const unscheduleAction = {
|
|
2116
|
+
actionType: "sanity.action.release.unschedule",
|
|
2117
|
+
releaseId
|
|
2118
|
+
};
|
|
2119
|
+
return rxjs.lastValueFrom(
|
|
2120
|
+
_action(this.#client.config(), this.#httpRequest, unscheduleAction, options)
|
|
2121
|
+
);
|
|
2122
|
+
}
|
|
2123
|
+
/**
|
|
2124
|
+
* @public
|
|
2125
|
+
*
|
|
2126
|
+
* A delete action removes a published or archived release.
|
|
2127
|
+
* The backing system document will be removed from the dataset.
|
|
2128
|
+
*
|
|
2129
|
+
* @category Releases
|
|
2130
|
+
*
|
|
2131
|
+
* @param params - Release action parameters:
|
|
2132
|
+
* - `releaseId` - The id of the release to delete.
|
|
2133
|
+
* @param options - Additional action options.
|
|
2134
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
2135
|
+
*/
|
|
2136
|
+
delete({ releaseId }, options) {
|
|
2137
|
+
const deleteAction = {
|
|
2138
|
+
actionType: "sanity.action.release.delete",
|
|
2139
|
+
releaseId
|
|
2140
|
+
};
|
|
2141
|
+
return rxjs.lastValueFrom(_action(this.#client.config(), this.#httpRequest, deleteAction, options));
|
|
2142
|
+
}
|
|
2143
|
+
/**
|
|
2144
|
+
* @public
|
|
2145
|
+
*
|
|
2146
|
+
* Fetch the documents in a release by release id.
|
|
2147
|
+
*
|
|
2148
|
+
* @category Releases
|
|
2149
|
+
*
|
|
2150
|
+
* @param params - Release action parameters:
|
|
2151
|
+
* - `releaseId` - The id of the release to fetch documents for.
|
|
2152
|
+
* @param options - Additional mutation options {@link BaseMutationOptions}.
|
|
2153
|
+
* @returns A promise that resolves to the documents in the release.
|
|
2154
|
+
*/
|
|
2155
|
+
fetchDocuments({ releaseId }, options) {
|
|
2156
|
+
return rxjs.lastValueFrom(
|
|
2157
|
+
_getReleaseDocuments(this.#client.config(), this.#httpRequest, releaseId, options)
|
|
1441
2158
|
);
|
|
1442
2159
|
}
|
|
1443
2160
|
}
|
|
@@ -1473,9 +2190,13 @@ class UsersClient {
|
|
|
1473
2190
|
*/
|
|
1474
2191
|
getById(id) {
|
|
1475
2192
|
return rxjs.lastValueFrom(
|
|
1476
|
-
_request(
|
|
1477
|
-
|
|
1478
|
-
|
|
2193
|
+
_request(
|
|
2194
|
+
this.#client.config(),
|
|
2195
|
+
this.#httpRequest,
|
|
2196
|
+
{
|
|
2197
|
+
uri: `/users/${id}`
|
|
2198
|
+
}
|
|
2199
|
+
)
|
|
1479
2200
|
);
|
|
1480
2201
|
}
|
|
1481
2202
|
}
|
|
@@ -1486,6 +2207,7 @@ class ObservableSanityClient {
|
|
|
1486
2207
|
projects;
|
|
1487
2208
|
users;
|
|
1488
2209
|
agent;
|
|
2210
|
+
releases;
|
|
1489
2211
|
/**
|
|
1490
2212
|
* Private properties
|
|
1491
2213
|
*/
|
|
@@ -1498,7 +2220,7 @@ class ObservableSanityClient {
|
|
|
1498
2220
|
constructor(httpRequest, config = defaultConfig) {
|
|
1499
2221
|
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 = {
|
|
1500
2222
|
action: new ObservableAgentsActionClient(this, this.#httpRequest)
|
|
1501
|
-
};
|
|
2223
|
+
}, this.releases = new ObservableReleasesClient(this, this.#httpRequest);
|
|
1502
2224
|
}
|
|
1503
2225
|
/**
|
|
1504
2226
|
* Clone the client - returns a new instance
|
|
@@ -1563,17 +2285,132 @@ class ObservableSanityClient {
|
|
|
1563
2285
|
return _getDocuments(this.#clientConfig, this.#httpRequest, ids, options);
|
|
1564
2286
|
}
|
|
1565
2287
|
create(document, options) {
|
|
1566
|
-
return _create(
|
|
2288
|
+
return _create(
|
|
2289
|
+
this.#clientConfig,
|
|
2290
|
+
this.#httpRequest,
|
|
2291
|
+
document,
|
|
2292
|
+
"create",
|
|
2293
|
+
options
|
|
2294
|
+
);
|
|
1567
2295
|
}
|
|
1568
2296
|
createIfNotExists(document, options) {
|
|
1569
|
-
return _createIfNotExists(
|
|
2297
|
+
return _createIfNotExists(
|
|
2298
|
+
this.#clientConfig,
|
|
2299
|
+
this.#httpRequest,
|
|
2300
|
+
document,
|
|
2301
|
+
options
|
|
2302
|
+
);
|
|
1570
2303
|
}
|
|
1571
2304
|
createOrReplace(document, options) {
|
|
1572
2305
|
return _createOrReplace(this.#clientConfig, this.#httpRequest, document, options);
|
|
1573
2306
|
}
|
|
2307
|
+
createVersion({
|
|
2308
|
+
document,
|
|
2309
|
+
publishedId,
|
|
2310
|
+
releaseId
|
|
2311
|
+
}, options) {
|
|
2312
|
+
const documentVersionId = deriveDocumentVersionId("createVersion", {
|
|
2313
|
+
document,
|
|
2314
|
+
publishedId,
|
|
2315
|
+
releaseId
|
|
2316
|
+
}), documentVersion = { ...document, _id: documentVersionId }, versionPublishedId = publishedId || csm.getPublishedId(document._id);
|
|
2317
|
+
return _createVersion(
|
|
2318
|
+
this.config(),
|
|
2319
|
+
this.#httpRequest,
|
|
2320
|
+
documentVersion,
|
|
2321
|
+
versionPublishedId,
|
|
2322
|
+
options
|
|
2323
|
+
);
|
|
2324
|
+
}
|
|
1574
2325
|
delete(selection, options) {
|
|
1575
2326
|
return _delete(this.#clientConfig, this.#httpRequest, selection, options);
|
|
1576
2327
|
}
|
|
2328
|
+
/**
|
|
2329
|
+
* @public
|
|
2330
|
+
*
|
|
2331
|
+
* Deletes the draft or release version of a document.
|
|
2332
|
+
*
|
|
2333
|
+
* @remarks
|
|
2334
|
+
* * Discarding a version with no `releaseId` will discard the draft version of the published document.
|
|
2335
|
+
* * If the draft or release version does not exist, any error will throw.
|
|
2336
|
+
*
|
|
2337
|
+
* @param params - Version action parameters:
|
|
2338
|
+
* - `releaseId` - The ID of the release to discard the document from.
|
|
2339
|
+
* - `publishedId` - The published ID of the document to discard.
|
|
2340
|
+
* @param purge - if `true` the document history is also discarded.
|
|
2341
|
+
* @param options - Additional action options.
|
|
2342
|
+
* @returns an observable that resolves to the `transactionId`.
|
|
2343
|
+
*
|
|
2344
|
+
* @example Discarding a release version of a document
|
|
2345
|
+
* ```ts
|
|
2346
|
+
* client.observable.discardVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
|
|
2347
|
+
* // The document with the ID `versions.myRelease.myDocument` will be discarded.
|
|
2348
|
+
* ```
|
|
2349
|
+
*
|
|
2350
|
+
* @example Discarding a draft version of a document
|
|
2351
|
+
* ```ts
|
|
2352
|
+
* client.observable.discardVersion({publishedId: 'myDocument'})
|
|
2353
|
+
* // The document with the ID `drafts.myDocument` will be discarded.
|
|
2354
|
+
* ```
|
|
2355
|
+
*/
|
|
2356
|
+
discardVersion({ releaseId, publishedId }, purge, options) {
|
|
2357
|
+
const documentVersionId = getDocumentVersionId(publishedId, releaseId);
|
|
2358
|
+
return _discardVersion(
|
|
2359
|
+
this.config(),
|
|
2360
|
+
this.#httpRequest,
|
|
2361
|
+
documentVersionId,
|
|
2362
|
+
purge,
|
|
2363
|
+
options
|
|
2364
|
+
);
|
|
2365
|
+
}
|
|
2366
|
+
replaceVersion({
|
|
2367
|
+
document,
|
|
2368
|
+
publishedId,
|
|
2369
|
+
releaseId
|
|
2370
|
+
}, options) {
|
|
2371
|
+
const documentVersionId = deriveDocumentVersionId("replaceVersion", {
|
|
2372
|
+
document,
|
|
2373
|
+
publishedId,
|
|
2374
|
+
releaseId
|
|
2375
|
+
}), documentVersion = { ...document, _id: documentVersionId };
|
|
2376
|
+
return _replaceVersion(
|
|
2377
|
+
this.config(),
|
|
2378
|
+
this.#httpRequest,
|
|
2379
|
+
documentVersion,
|
|
2380
|
+
options
|
|
2381
|
+
);
|
|
2382
|
+
}
|
|
2383
|
+
/**
|
|
2384
|
+
* @public
|
|
2385
|
+
*
|
|
2386
|
+
* Used to indicate when a document within a release should be unpublished when
|
|
2387
|
+
* the release is run.
|
|
2388
|
+
*
|
|
2389
|
+
* @remarks
|
|
2390
|
+
* * If the published document does not exist, an error will be thrown.
|
|
2391
|
+
*
|
|
2392
|
+
* @param params - Version action parameters:
|
|
2393
|
+
* - `releaseId` - The ID of the release to unpublish the document from.
|
|
2394
|
+
* - `publishedId` - The published ID of the document to unpublish.
|
|
2395
|
+
* @param options - Additional action options.
|
|
2396
|
+
* @returns an observable that resolves to the `transactionId`.
|
|
2397
|
+
*
|
|
2398
|
+
* @example Unpublishing a release version of a published document
|
|
2399
|
+
* ```ts
|
|
2400
|
+
* client.observable.unpublishVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
|
|
2401
|
+
* // The document with the ID `versions.myRelease.myDocument` will be unpublished. when `myRelease` is run.
|
|
2402
|
+
* ```
|
|
2403
|
+
*/
|
|
2404
|
+
unpublishVersion({ releaseId, publishedId }, options) {
|
|
2405
|
+
const versionId = csm.getVersionId(publishedId, releaseId);
|
|
2406
|
+
return _unpublishVersion(
|
|
2407
|
+
this.config(),
|
|
2408
|
+
this.#httpRequest,
|
|
2409
|
+
versionId,
|
|
2410
|
+
publishedId,
|
|
2411
|
+
options
|
|
2412
|
+
);
|
|
2413
|
+
}
|
|
1577
2414
|
mutate(operations, options) {
|
|
1578
2415
|
return _mutate(this.#clientConfig, this.#httpRequest, operations, options);
|
|
1579
2416
|
}
|
|
@@ -1638,6 +2475,7 @@ class SanityClient {
|
|
|
1638
2475
|
projects;
|
|
1639
2476
|
users;
|
|
1640
2477
|
agent;
|
|
2478
|
+
releases;
|
|
1641
2479
|
/**
|
|
1642
2480
|
* Observable version of the Sanity client, with the same configuration as the promise-based one
|
|
1643
2481
|
*/
|
|
@@ -1654,7 +2492,7 @@ class SanityClient {
|
|
|
1654
2492
|
constructor(httpRequest, config = defaultConfig) {
|
|
1655
2493
|
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 = {
|
|
1656
2494
|
action: new AgentActionsClient(this, this.#httpRequest)
|
|
1657
|
-
}, this.observable = new ObservableSanityClient(httpRequest, config);
|
|
2495
|
+
}, this.releases = new ReleasesClient(this, this.#httpRequest), this.observable = new ObservableSanityClient(httpRequest, config);
|
|
1658
2496
|
}
|
|
1659
2497
|
/**
|
|
1660
2498
|
* Clone the client - returns a new instance
|
|
@@ -1706,7 +2544,9 @@ class SanityClient {
|
|
|
1706
2544
|
* @param options - Request options
|
|
1707
2545
|
*/
|
|
1708
2546
|
getDocument(id, options) {
|
|
1709
|
-
return rxjs.lastValueFrom(
|
|
2547
|
+
return rxjs.lastValueFrom(
|
|
2548
|
+
_getDocument(this.#clientConfig, this.#httpRequest, id, options)
|
|
2549
|
+
);
|
|
1710
2550
|
}
|
|
1711
2551
|
/**
|
|
1712
2552
|
* Fetch multiple documents in one request.
|
|
@@ -1718,7 +2558,9 @@ class SanityClient {
|
|
|
1718
2558
|
* @param options - Request options
|
|
1719
2559
|
*/
|
|
1720
2560
|
getDocuments(ids, options) {
|
|
1721
|
-
return rxjs.lastValueFrom(
|
|
2561
|
+
return rxjs.lastValueFrom(
|
|
2562
|
+
_getDocuments(this.#clientConfig, this.#httpRequest, ids, options)
|
|
2563
|
+
);
|
|
1722
2564
|
}
|
|
1723
2565
|
create(document, options) {
|
|
1724
2566
|
return rxjs.lastValueFrom(
|
|
@@ -1735,11 +2577,122 @@ class SanityClient {
|
|
|
1735
2577
|
_createOrReplace(this.#clientConfig, this.#httpRequest, document, options)
|
|
1736
2578
|
);
|
|
1737
2579
|
}
|
|
2580
|
+
createVersion({
|
|
2581
|
+
document,
|
|
2582
|
+
publishedId,
|
|
2583
|
+
releaseId
|
|
2584
|
+
}, options) {
|
|
2585
|
+
const documentVersionId = deriveDocumentVersionId("createVersion", {
|
|
2586
|
+
document,
|
|
2587
|
+
publishedId,
|
|
2588
|
+
releaseId
|
|
2589
|
+
}), documentVersion = { ...document, _id: documentVersionId }, versionPublishedId = publishedId || csm.getPublishedId(document._id);
|
|
2590
|
+
return rxjs.firstValueFrom(
|
|
2591
|
+
_createVersion(
|
|
2592
|
+
this.config(),
|
|
2593
|
+
this.#httpRequest,
|
|
2594
|
+
documentVersion,
|
|
2595
|
+
versionPublishedId,
|
|
2596
|
+
options
|
|
2597
|
+
)
|
|
2598
|
+
);
|
|
2599
|
+
}
|
|
1738
2600
|
delete(selection, options) {
|
|
1739
|
-
return rxjs.lastValueFrom(
|
|
2601
|
+
return rxjs.lastValueFrom(
|
|
2602
|
+
_delete(this.#clientConfig, this.#httpRequest, selection, options)
|
|
2603
|
+
);
|
|
2604
|
+
}
|
|
2605
|
+
/**
|
|
2606
|
+
* @public
|
|
2607
|
+
*
|
|
2608
|
+
* Deletes the draft or release version of a document.
|
|
2609
|
+
*
|
|
2610
|
+
* @remarks
|
|
2611
|
+
* * Discarding a version with no `releaseId` will discard the draft version of the published document.
|
|
2612
|
+
* * If the draft or release version does not exist, any error will throw.
|
|
2613
|
+
*
|
|
2614
|
+
* @param params - Version action parameters:
|
|
2615
|
+
* - `releaseId` - The ID of the release to discard the document from.
|
|
2616
|
+
* - `publishedId` - The published ID of the document to discard.
|
|
2617
|
+
* @param purge - if `true` the document history is also discarded.
|
|
2618
|
+
* @param options - Additional action options.
|
|
2619
|
+
* @returns a promise that resolves to the `transactionId`.
|
|
2620
|
+
*
|
|
2621
|
+
* @example Discarding a release version of a document
|
|
2622
|
+
* ```ts
|
|
2623
|
+
* client.discardVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
|
|
2624
|
+
* // The document with the ID `versions.myRelease.myDocument` will be discarded.
|
|
2625
|
+
* ```
|
|
2626
|
+
*
|
|
2627
|
+
* @example Discarding a draft version of a document
|
|
2628
|
+
* ```ts
|
|
2629
|
+
* client.discardVersion({publishedId: 'myDocument'})
|
|
2630
|
+
* // The document with the ID `drafts.myDocument` will be discarded.
|
|
2631
|
+
* ```
|
|
2632
|
+
*/
|
|
2633
|
+
discardVersion({ releaseId, publishedId }, purge, options) {
|
|
2634
|
+
const documentVersionId = getDocumentVersionId(publishedId, releaseId);
|
|
2635
|
+
return rxjs.lastValueFrom(
|
|
2636
|
+
_discardVersion(
|
|
2637
|
+
this.config(),
|
|
2638
|
+
this.#httpRequest,
|
|
2639
|
+
documentVersionId,
|
|
2640
|
+
purge,
|
|
2641
|
+
options
|
|
2642
|
+
)
|
|
2643
|
+
);
|
|
2644
|
+
}
|
|
2645
|
+
replaceVersion({
|
|
2646
|
+
document,
|
|
2647
|
+
publishedId,
|
|
2648
|
+
releaseId
|
|
2649
|
+
}, options) {
|
|
2650
|
+
const documentVersionId = deriveDocumentVersionId("replaceVersion", {
|
|
2651
|
+
document,
|
|
2652
|
+
publishedId,
|
|
2653
|
+
releaseId
|
|
2654
|
+
}), documentVersion = { ...document, _id: documentVersionId };
|
|
2655
|
+
return rxjs.firstValueFrom(
|
|
2656
|
+
_replaceVersion(this.config(), this.#httpRequest, documentVersion, options)
|
|
2657
|
+
);
|
|
2658
|
+
}
|
|
2659
|
+
/**
|
|
2660
|
+
* @public
|
|
2661
|
+
*
|
|
2662
|
+
* Used to indicate when a document within a release should be unpublished when
|
|
2663
|
+
* the release is run.
|
|
2664
|
+
*
|
|
2665
|
+
* @remarks
|
|
2666
|
+
* * If the published document does not exist, an error will be thrown.
|
|
2667
|
+
*
|
|
2668
|
+
* @param params - Version action parameters:
|
|
2669
|
+
* - `releaseId` - The ID of the release to unpublish the document from.
|
|
2670
|
+
* - `publishedId` - The published ID of the document to unpublish.
|
|
2671
|
+
* @param options - Additional action options.
|
|
2672
|
+
* @returns a promise that resolves to the `transactionId`.
|
|
2673
|
+
*
|
|
2674
|
+
* @example Unpublishing a release version of a published document
|
|
2675
|
+
* ```ts
|
|
2676
|
+
* await client.unpublishVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
|
|
2677
|
+
* // The document with the ID `versions.myRelease.myDocument` will be unpublished. when `myRelease` is run.
|
|
2678
|
+
* ```
|
|
2679
|
+
*/
|
|
2680
|
+
unpublishVersion({ releaseId, publishedId }, options) {
|
|
2681
|
+
const versionId = csm.getVersionId(publishedId, releaseId);
|
|
2682
|
+
return rxjs.lastValueFrom(
|
|
2683
|
+
_unpublishVersion(
|
|
2684
|
+
this.config(),
|
|
2685
|
+
this.#httpRequest,
|
|
2686
|
+
versionId,
|
|
2687
|
+
publishedId,
|
|
2688
|
+
options
|
|
2689
|
+
)
|
|
2690
|
+
);
|
|
1740
2691
|
}
|
|
1741
2692
|
mutate(operations, options) {
|
|
1742
|
-
return rxjs.lastValueFrom(
|
|
2693
|
+
return rxjs.lastValueFrom(
|
|
2694
|
+
_mutate(this.#clientConfig, this.#httpRequest, operations, options)
|
|
2695
|
+
);
|
|
1743
2696
|
}
|
|
1744
2697
|
/**
|
|
1745
2698
|
* Create a new buildable patch of operations to perform
|
|
@@ -1767,7 +2720,9 @@ class SanityClient {
|
|
|
1767
2720
|
* @param options - Action options
|
|
1768
2721
|
*/
|
|
1769
2722
|
action(operations, options) {
|
|
1770
|
-
return rxjs.lastValueFrom(
|
|
2723
|
+
return rxjs.lastValueFrom(
|
|
2724
|
+
_action(this.#clientConfig, this.#httpRequest, operations, options)
|
|
2725
|
+
);
|
|
1771
2726
|
}
|
|
1772
2727
|
/**
|
|
1773
2728
|
* Perform a request against the Sanity API
|
|
@@ -1790,7 +2745,9 @@ class SanityClient {
|
|
|
1790
2745
|
* @internal
|
|
1791
2746
|
*/
|
|
1792
2747
|
dataRequest(endpoint, body, options) {
|
|
1793
|
-
return rxjs.lastValueFrom(
|
|
2748
|
+
return rxjs.lastValueFrom(
|
|
2749
|
+
_dataRequest(this.#clientConfig, this.#httpRequest, endpoint, body, options)
|
|
2750
|
+
);
|
|
1794
2751
|
}
|
|
1795
2752
|
/**
|
|
1796
2753
|
* Get a Sanity API URL for the URI provided
|
|
@@ -1860,9 +2817,12 @@ exports.Patch = Patch;
|
|
|
1860
2817
|
exports.SanityClient = SanityClient;
|
|
1861
2818
|
exports.ServerError = ServerError;
|
|
1862
2819
|
exports.Transaction = Transaction;
|
|
2820
|
+
exports.ViewResourceType = ViewResourceType;
|
|
1863
2821
|
exports.connectEventSource = connectEventSource;
|
|
1864
2822
|
exports.createClient = createClient;
|
|
1865
2823
|
exports.default = deprecatedCreateClient;
|
|
2824
|
+
exports.formatQueryParseError = formatQueryParseError;
|
|
2825
|
+
exports.isQueryParseError = isQueryParseError;
|
|
1866
2826
|
exports.requester = requester;
|
|
1867
2827
|
exports.validateApiPerspective = validateApiPerspective;
|
|
1868
2828
|
//# sourceMappingURL=index.browser.cjs.map
|