@sanity/client 8.1.0 → 8.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +171 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +438 -101
- package/dist/index.js.map +1 -1
- package/dist/index.node.d.ts +734 -10
- package/dist/index.node.js +409 -59
- package/dist/index.node.js.map +1 -1
- package/dist/media-library.d.ts +1 -1
- package/dist/{types-BODIEY7F.d.ts → types-0x2hPfhJ.d.ts} +735 -11
- package/package.json +1 -2
- package/src/SanityClient.ts +20 -0
- package/src/collaboration/CollaborationCommentsClient.ts +387 -0
- package/src/collaboration/comments.ts +313 -0
- package/src/collaboration/types.ts +303 -0
- package/src/data/dataMethods.ts +7 -1
- package/src/data/listen.ts +20 -5
- package/src/functions/FunctionsClient.ts +52 -9
- package/src/functions/invoke.ts +47 -6
- package/src/types.ts +240 -1
- package/src/util/createVersionId.ts +15 -5
package/dist/index.js
CHANGED
|
@@ -7,7 +7,6 @@ import { Observable, catchError, concat, defer, finalize, isObservable, lastValu
|
|
|
7
7
|
import { getDraftId, getPublishedId, getVersionFromId, getVersionId, isDraftId, isVersionId } from "@sanity/client/csm";
|
|
8
8
|
import { filter, finalize as finalize$1, map as map$1, mergeAll } from "rxjs/operators";
|
|
9
9
|
import { EventSource } from "eventsource";
|
|
10
|
-
import { customAlphabet } from "nanoid";
|
|
11
10
|
/**
|
|
12
11
|
* A string constant containing the experimental API version warning message.
|
|
13
12
|
* Use this with the `ignoreWarnings` option to suppress warnings when using experimental API versions.
|
|
@@ -338,41 +337,41 @@ var BasePatch = class {
|
|
|
338
337
|
_set(op, props) {
|
|
339
338
|
return this._assign(op, props, !1);
|
|
340
339
|
}
|
|
341
|
-
}, _client$
|
|
340
|
+
}, _client$11 = /* @__PURE__ */ new WeakMap(), ObservablePatch = class ObservablePatch extends BasePatch {
|
|
342
341
|
constructor(selection, operations, client) {
|
|
343
|
-
super(selection, operations), _classPrivateFieldInitSpec(this, _client$
|
|
342
|
+
super(selection, operations), _classPrivateFieldInitSpec(this, _client$11, void 0), _classPrivateFieldSet2(_client$11, this, client);
|
|
344
343
|
}
|
|
345
344
|
/**
|
|
346
345
|
* Clones the patch
|
|
347
346
|
*/
|
|
348
347
|
clone() {
|
|
349
|
-
return new ObservablePatch(this.selection, { ...this.operations }, _classPrivateFieldGet2(_client$
|
|
348
|
+
return new ObservablePatch(this.selection, { ...this.operations }, _classPrivateFieldGet2(_client$11, this));
|
|
350
349
|
}
|
|
351
350
|
commit(options) {
|
|
352
|
-
if (!_classPrivateFieldGet2(_client$
|
|
351
|
+
if (!_classPrivateFieldGet2(_client$11, this)) throw Error("No `client` passed to patch, either provide one or pass the patch to a clients `mutate()` method");
|
|
353
352
|
let returnFirst = typeof this.selection == "string", opts = Object.assign({
|
|
354
353
|
returnFirst,
|
|
355
354
|
returnDocuments: !0
|
|
356
355
|
}, options);
|
|
357
|
-
return _classPrivateFieldGet2(_client$
|
|
356
|
+
return _classPrivateFieldGet2(_client$11, this).mutate({ patch: this.serialize() }, opts);
|
|
358
357
|
}
|
|
359
|
-
}, _client2$
|
|
358
|
+
}, _client2$10 = /* @__PURE__ */ new WeakMap(), Patch = class Patch extends BasePatch {
|
|
360
359
|
constructor(selection, operations, client) {
|
|
361
|
-
super(selection, operations), _classPrivateFieldInitSpec(this, _client2$
|
|
360
|
+
super(selection, operations), _classPrivateFieldInitSpec(this, _client2$10, void 0), _classPrivateFieldSet2(_client2$10, this, client);
|
|
362
361
|
}
|
|
363
362
|
/**
|
|
364
363
|
* Clones the patch
|
|
365
364
|
*/
|
|
366
365
|
clone() {
|
|
367
|
-
return new Patch(this.selection, { ...this.operations }, _classPrivateFieldGet2(_client2$
|
|
366
|
+
return new Patch(this.selection, { ...this.operations }, _classPrivateFieldGet2(_client2$10, this));
|
|
368
367
|
}
|
|
369
368
|
commit(options) {
|
|
370
|
-
if (!_classPrivateFieldGet2(_client2$
|
|
369
|
+
if (!_classPrivateFieldGet2(_client2$10, this)) throw Error("No `client` passed to patch, either provide one or pass the patch to a clients `mutate()` method");
|
|
371
370
|
let returnFirst = typeof this.selection == "string", opts = Object.assign({
|
|
372
371
|
returnFirst,
|
|
373
372
|
returnDocuments: !0
|
|
374
373
|
}, options);
|
|
375
|
-
return _classPrivateFieldGet2(_client2$
|
|
374
|
+
return _classPrivateFieldGet2(_client2$10, this).mutate({ patch: this.serialize() }, opts);
|
|
376
375
|
}
|
|
377
376
|
};
|
|
378
377
|
const defaultMutateOptions = { returnDocuments: !1 };
|
|
@@ -443,30 +442,30 @@ var BaseTransaction = class {
|
|
|
443
442
|
_add(mut) {
|
|
444
443
|
return this.operations.push(mut), this;
|
|
445
444
|
}
|
|
446
|
-
}, _client$
|
|
445
|
+
}, _client$10 = /* @__PURE__ */ new WeakMap(), Transaction = class Transaction extends BaseTransaction {
|
|
447
446
|
constructor(operations, client, transactionId) {
|
|
448
|
-
super(operations, transactionId), _classPrivateFieldInitSpec(this, _client$
|
|
447
|
+
super(operations, transactionId), _classPrivateFieldInitSpec(this, _client$10, void 0), _classPrivateFieldSet2(_client$10, this, client);
|
|
449
448
|
}
|
|
450
449
|
/**
|
|
451
450
|
* Clones the transaction
|
|
452
451
|
*/
|
|
453
452
|
clone() {
|
|
454
|
-
return new Transaction([...this.operations], _classPrivateFieldGet2(_client$
|
|
453
|
+
return new Transaction([...this.operations], _classPrivateFieldGet2(_client$10, this), this.trxId);
|
|
455
454
|
}
|
|
456
455
|
commit(options) {
|
|
457
|
-
if (!_classPrivateFieldGet2(_client$
|
|
458
|
-
return _classPrivateFieldGet2(_client$
|
|
456
|
+
if (!_classPrivateFieldGet2(_client$10, this)) throw Error("No `client` passed to transaction, either provide one or pass the transaction to a clients `mutate()` method");
|
|
457
|
+
return _classPrivateFieldGet2(_client$10, this).mutate(this.serialize(), Object.assign({ transactionId: this.trxId }, defaultMutateOptions, options || {}));
|
|
459
458
|
}
|
|
460
459
|
patch(patchOrDocumentId, patchOps) {
|
|
461
460
|
let isBuilder = typeof patchOps == "function", isPatch = typeof patchOrDocumentId != "string" && patchOrDocumentId instanceof Patch, isMutationSelection = typeof patchOrDocumentId == "object" && ("query" in patchOrDocumentId || "id" in patchOrDocumentId);
|
|
462
461
|
if (isPatch) return this._add({ patch: patchOrDocumentId.serialize() });
|
|
463
462
|
if (isBuilder) {
|
|
464
|
-
let patch = patchOps(new Patch(patchOrDocumentId, {}, _classPrivateFieldGet2(_client$
|
|
463
|
+
let patch = patchOps(new Patch(patchOrDocumentId, {}, _classPrivateFieldGet2(_client$10, this)));
|
|
465
464
|
if (!(patch instanceof Patch)) throw Error("function passed to `patch()` must return the patch");
|
|
466
465
|
return this._add({ patch: patch.serialize() });
|
|
467
466
|
}
|
|
468
467
|
if (isMutationSelection) {
|
|
469
|
-
let patch = new Patch(patchOrDocumentId, patchOps || {}, _classPrivateFieldGet2(_client$
|
|
468
|
+
let patch = new Patch(patchOrDocumentId, patchOps || {}, _classPrivateFieldGet2(_client$10, this));
|
|
470
469
|
return this._add({ patch: patch.serialize() });
|
|
471
470
|
}
|
|
472
471
|
return this._add({ patch: {
|
|
@@ -474,25 +473,25 @@ var BaseTransaction = class {
|
|
|
474
473
|
...patchOps
|
|
475
474
|
} });
|
|
476
475
|
}
|
|
477
|
-
}, _client2$
|
|
476
|
+
}, _client2$9 = /* @__PURE__ */ new WeakMap(), ObservableTransaction = class ObservableTransaction extends BaseTransaction {
|
|
478
477
|
constructor(operations, client, transactionId) {
|
|
479
|
-
super(operations, transactionId), _classPrivateFieldInitSpec(this, _client2$
|
|
478
|
+
super(operations, transactionId), _classPrivateFieldInitSpec(this, _client2$9, void 0), _classPrivateFieldSet2(_client2$9, this, client);
|
|
480
479
|
}
|
|
481
480
|
/**
|
|
482
481
|
* Clones the transaction
|
|
483
482
|
*/
|
|
484
483
|
clone() {
|
|
485
|
-
return new ObservableTransaction([...this.operations], _classPrivateFieldGet2(_client2$
|
|
484
|
+
return new ObservableTransaction([...this.operations], _classPrivateFieldGet2(_client2$9, this), this.trxId);
|
|
486
485
|
}
|
|
487
486
|
commit(options) {
|
|
488
|
-
if (!_classPrivateFieldGet2(_client2$
|
|
489
|
-
return _classPrivateFieldGet2(_client2$
|
|
487
|
+
if (!_classPrivateFieldGet2(_client2$9, this)) throw Error("No `client` passed to transaction, either provide one or pass the transaction to a clients `mutate()` method");
|
|
488
|
+
return _classPrivateFieldGet2(_client2$9, this).mutate(this.serialize(), Object.assign({ transactionId: this.trxId }, defaultMutateOptions, options || {}));
|
|
490
489
|
}
|
|
491
490
|
patch(patchOrDocumentId, patchOps) {
|
|
492
491
|
let isBuilder = typeof patchOps == "function";
|
|
493
492
|
if (typeof patchOrDocumentId != "string" && patchOrDocumentId instanceof ObservablePatch) return this._add({ patch: patchOrDocumentId.serialize() });
|
|
494
493
|
if (isBuilder) {
|
|
495
|
-
let patch = patchOps(new ObservablePatch(patchOrDocumentId, {}, _classPrivateFieldGet2(_client2$
|
|
494
|
+
let patch = patchOps(new ObservablePatch(patchOrDocumentId, {}, _classPrivateFieldGet2(_client2$9, this)));
|
|
496
495
|
if (!(patch instanceof ObservablePatch)) throw Error("function passed to `patch()` must return the patch");
|
|
497
496
|
return this._add({ patch: patch.serialize() });
|
|
498
497
|
}
|
|
@@ -604,7 +603,7 @@ function _fetchRequest(_stega, _params, options) {
|
|
|
604
603
|
}
|
|
605
604
|
/** @internal */
|
|
606
605
|
function _fetchObservable(client, httpRequest, _stega, query, _params = {}, options = {}) {
|
|
607
|
-
return _observe(options.signal, (signal) => _fetch(client, httpRequest, _stega, query, _params, {
|
|
606
|
+
return _observe(options.signal, (signal) => _fetch$1(client, httpRequest, _stega, query, _params, {
|
|
608
607
|
...options,
|
|
609
608
|
signal
|
|
610
609
|
}));
|
|
@@ -614,7 +613,7 @@ function _fetchObservable(client, httpRequest, _stega, query, _params = {}, opti
|
|
|
614
613
|
*
|
|
615
614
|
* @internal
|
|
616
615
|
*/
|
|
617
|
-
function _fetch(client, httpRequest, _stega, query, _params = {}, options = {}) {
|
|
616
|
+
function _fetch$1(client, httpRequest, _stega, query, _params = {}, options = {}) {
|
|
618
617
|
let { stega, params, mapResponse, reqOpts } = _fetchRequest(_stega, _params, options), request = _dataRequest(client, httpRequest, "query", {
|
|
619
618
|
query,
|
|
620
619
|
params
|
|
@@ -767,7 +766,7 @@ function _createVersionFromBaseObservable(client, httpRequest, publishedId, base
|
|
|
767
766
|
}
|
|
768
767
|
/** @internal */
|
|
769
768
|
function _deleteObservable(client, httpRequest, selection, options) {
|
|
770
|
-
return _observe(options?.signal, (signal) => _delete(client, httpRequest, selection, {
|
|
769
|
+
return _observe(options?.signal, (signal) => _delete$1(client, httpRequest, selection, {
|
|
771
770
|
...options,
|
|
772
771
|
signal
|
|
773
772
|
}));
|
|
@@ -872,7 +871,7 @@ function _dataRequest(client, httpRequest, endpoint, body, options = {}) {
|
|
|
872
871
|
* @internal
|
|
873
872
|
*/
|
|
874
873
|
function _createObservable(client, httpRequest, doc, op, options = {}) {
|
|
875
|
-
return _observe(options.signal, (signal) => _create(client, httpRequest, doc, op, {
|
|
874
|
+
return _observe(options.signal, (signal) => _create$1(client, httpRequest, doc, op, {
|
|
876
875
|
...options,
|
|
877
876
|
signal
|
|
878
877
|
}));
|
|
@@ -882,7 +881,7 @@ function _createObservable(client, httpRequest, doc, op, options = {}) {
|
|
|
882
881
|
*
|
|
883
882
|
* @internal
|
|
884
883
|
*/
|
|
885
|
-
function _create(client, httpRequest, doc, op, options = {}) {
|
|
884
|
+
function _create$1(client, httpRequest, doc, op, options = {}) {
|
|
886
885
|
let mutation = { [op]: doc }, opts = Object.assign({
|
|
887
886
|
returnFirst: !0,
|
|
888
887
|
returnDocuments: !0
|
|
@@ -919,7 +918,7 @@ function _mutate(client, httpRequest, mutations, options) {
|
|
|
919
918
|
*
|
|
920
919
|
* @internal
|
|
921
920
|
*/
|
|
922
|
-
function _delete(client, httpRequest, selection, options) {
|
|
921
|
+
function _delete$1(client, httpRequest, selection, options) {
|
|
923
922
|
return _dataRequest(client, httpRequest, "mutate", { mutations: [{ delete: getSelection(selection) }] }, options);
|
|
924
923
|
}
|
|
925
924
|
/**
|
|
@@ -928,7 +927,7 @@ function _delete(client, httpRequest, selection, options) {
|
|
|
928
927
|
* @internal
|
|
929
928
|
*/
|
|
930
929
|
function _createIfNotExists(client, httpRequest, doc, options) {
|
|
931
|
-
return requireDocumentId("createIfNotExists", doc), _create(client, httpRequest, doc, "createIfNotExists", options);
|
|
930
|
+
return requireDocumentId("createIfNotExists", doc), _create$1(client, httpRequest, doc, "createIfNotExists", options);
|
|
932
931
|
}
|
|
933
932
|
/**
|
|
934
933
|
* Promise-based sibling of {@link _createOrReplaceObservable}.
|
|
@@ -936,7 +935,7 @@ function _createIfNotExists(client, httpRequest, doc, options) {
|
|
|
936
935
|
* @internal
|
|
937
936
|
*/
|
|
938
937
|
function _createOrReplace(client, httpRequest, doc, options) {
|
|
939
|
-
return requireDocumentId("createOrReplace", doc), _create(client, httpRequest, doc, "createOrReplace", options);
|
|
938
|
+
return requireDocumentId("createOrReplace", doc), _create$1(client, httpRequest, doc, "createOrReplace", options);
|
|
940
939
|
}
|
|
941
940
|
/**
|
|
942
941
|
* Promise-based sibling of {@link _createVersionObservable}.
|
|
@@ -1240,62 +1239,62 @@ function _translate(client, httpRequest, request) {
|
|
|
1240
1239
|
body: request
|
|
1241
1240
|
});
|
|
1242
1241
|
}
|
|
1243
|
-
var _client$
|
|
1242
|
+
var _client$9 = /* @__PURE__ */ new WeakMap(), _httpRequest$8 = /* @__PURE__ */ new WeakMap(), ObservableAgentsActionClient = class {
|
|
1244
1243
|
constructor(client, httpRequest) {
|
|
1245
|
-
_classPrivateFieldInitSpec(this, _client$
|
|
1244
|
+
_classPrivateFieldInitSpec(this, _client$9, void 0), _classPrivateFieldInitSpec(this, _httpRequest$8, void 0), _classPrivateFieldSet2(_client$9, this, client), _classPrivateFieldSet2(_httpRequest$8, this, httpRequest);
|
|
1246
1245
|
}
|
|
1247
1246
|
/**
|
|
1248
1247
|
* Run an instruction to generate content in a target document.
|
|
1249
1248
|
* @param request - instruction request
|
|
1250
1249
|
*/
|
|
1251
1250
|
generate(request) {
|
|
1252
|
-
return _generateObservable(_classPrivateFieldGet2(_client$
|
|
1251
|
+
return _generateObservable(_classPrivateFieldGet2(_client$9, this), _classPrivateFieldGet2(_httpRequest$8, this), request);
|
|
1253
1252
|
}
|
|
1254
1253
|
/**
|
|
1255
1254
|
* Transform a target document based on a source.
|
|
1256
1255
|
* @param request - translation request
|
|
1257
1256
|
*/
|
|
1258
1257
|
transform(request) {
|
|
1259
|
-
return _transformObservable(_classPrivateFieldGet2(_client$
|
|
1258
|
+
return _transformObservable(_classPrivateFieldGet2(_client$9, this), _classPrivateFieldGet2(_httpRequest$8, this), request);
|
|
1260
1259
|
}
|
|
1261
1260
|
/**
|
|
1262
1261
|
* Translate a target document based on a source.
|
|
1263
1262
|
* @param request - translation request
|
|
1264
1263
|
*/
|
|
1265
1264
|
translate(request) {
|
|
1266
|
-
return _translateObservable(_classPrivateFieldGet2(_client$
|
|
1265
|
+
return _translateObservable(_classPrivateFieldGet2(_client$9, this), _classPrivateFieldGet2(_httpRequest$8, this), request);
|
|
1267
1266
|
}
|
|
1268
|
-
}, _client2$
|
|
1267
|
+
}, _client2$8 = /* @__PURE__ */ new WeakMap(), _httpRequest2$9 = /* @__PURE__ */ new WeakMap(), AgentActionsClient = class {
|
|
1269
1268
|
constructor(client, httpRequest) {
|
|
1270
|
-
_classPrivateFieldInitSpec(this, _client2$
|
|
1269
|
+
_classPrivateFieldInitSpec(this, _client2$8, void 0), _classPrivateFieldInitSpec(this, _httpRequest2$9, void 0), _classPrivateFieldSet2(_client2$8, this, client), _classPrivateFieldSet2(_httpRequest2$9, this, httpRequest);
|
|
1271
1270
|
}
|
|
1272
1271
|
/**
|
|
1273
1272
|
* Run an instruction to generate content in a target document.
|
|
1274
1273
|
* @param request - instruction request
|
|
1275
1274
|
*/
|
|
1276
1275
|
generate(request) {
|
|
1277
|
-
return _generate(_classPrivateFieldGet2(_client2$
|
|
1276
|
+
return _generate(_classPrivateFieldGet2(_client2$8, this), _classPrivateFieldGet2(_httpRequest2$9, this), request);
|
|
1278
1277
|
}
|
|
1279
1278
|
/**
|
|
1280
1279
|
* Transform a target document based on a source.
|
|
1281
1280
|
* @param request - translation request
|
|
1282
1281
|
*/
|
|
1283
1282
|
transform(request) {
|
|
1284
|
-
return _transform(_classPrivateFieldGet2(_client2$
|
|
1283
|
+
return _transform(_classPrivateFieldGet2(_client2$8, this), _classPrivateFieldGet2(_httpRequest2$9, this), request);
|
|
1285
1284
|
}
|
|
1286
1285
|
/**
|
|
1287
1286
|
* Translate a target document based on a source.
|
|
1288
1287
|
* @param request - translation request
|
|
1289
1288
|
*/
|
|
1290
1289
|
translate(request) {
|
|
1291
|
-
return _translate(_classPrivateFieldGet2(_client2$
|
|
1290
|
+
return _translate(_classPrivateFieldGet2(_client2$8, this), _classPrivateFieldGet2(_httpRequest2$9, this), request);
|
|
1292
1291
|
}
|
|
1293
1292
|
/**
|
|
1294
1293
|
* Run a raw instruction and return the result either as text or json
|
|
1295
1294
|
* @param request - prompt request
|
|
1296
1295
|
*/
|
|
1297
1296
|
prompt(request) {
|
|
1298
|
-
return _prompt(_classPrivateFieldGet2(_client2$
|
|
1297
|
+
return _prompt(_classPrivateFieldGet2(_client2$8, this), _classPrivateFieldGet2(_httpRequest2$9, this), request);
|
|
1299
1298
|
}
|
|
1300
1299
|
/**
|
|
1301
1300
|
* Patch a document using a schema aware API.
|
|
@@ -1303,21 +1302,21 @@ var _client$8 = /* @__PURE__ */ new WeakMap(), _httpRequest$7 = /* @__PURE__ */
|
|
|
1303
1302
|
* @param request - instruction request
|
|
1304
1303
|
*/
|
|
1305
1304
|
patch(request) {
|
|
1306
|
-
return _patch(_classPrivateFieldGet2(_client2$
|
|
1305
|
+
return _patch(_classPrivateFieldGet2(_client2$8, this), _classPrivateFieldGet2(_httpRequest2$9, this), request);
|
|
1307
1306
|
}
|
|
1308
|
-
}, _client$
|
|
1307
|
+
}, _client$8 = /* @__PURE__ */ new WeakMap(), _httpRequest2$8 = /* @__PURE__ */ new WeakMap(), ObservableAssetsClient = class {
|
|
1309
1308
|
constructor(client, httpRequest) {
|
|
1310
|
-
_classPrivateFieldInitSpec(this, _client$
|
|
1309
|
+
_classPrivateFieldInitSpec(this, _client$8, void 0), _classPrivateFieldInitSpec(this, _httpRequest2$8, void 0), _classPrivateFieldSet2(_client$8, this, client), _classPrivateFieldSet2(_httpRequest2$8, this, httpRequest);
|
|
1311
1310
|
}
|
|
1312
1311
|
upload(assetType, body, options) {
|
|
1313
|
-
return _upload(_classPrivateFieldGet2(_client$
|
|
1312
|
+
return _upload(_classPrivateFieldGet2(_client$8, this), _classPrivateFieldGet2(_httpRequest2$8, this), assetType, body, options);
|
|
1314
1313
|
}
|
|
1315
|
-
}, _client2$
|
|
1314
|
+
}, _client2$7 = /* @__PURE__ */ new WeakMap(), _httpRequest3 = /* @__PURE__ */ new WeakMap(), AssetsClient = class {
|
|
1316
1315
|
constructor(client, httpRequest) {
|
|
1317
|
-
_classPrivateFieldInitSpec(this, _client2$
|
|
1316
|
+
_classPrivateFieldInitSpec(this, _client2$7, void 0), _classPrivateFieldInitSpec(this, _httpRequest3, void 0), _classPrivateFieldSet2(_client2$7, this, client), _classPrivateFieldSet2(_httpRequest3, this, httpRequest);
|
|
1318
1317
|
}
|
|
1319
1318
|
upload(assetType, body, options) {
|
|
1320
|
-
let observable = _upload(_classPrivateFieldGet2(_client2$
|
|
1319
|
+
let observable = _upload(_classPrivateFieldGet2(_client2$7, this), _classPrivateFieldGet2(_httpRequest3, this), assetType, body, options);
|
|
1321
1320
|
return lastValueFrom(observable.pipe(filter((event) => event.type === "response"), map$1((event) => pluckUploadedAsset(event.body))));
|
|
1322
1321
|
}
|
|
1323
1322
|
};
|
|
@@ -1458,6 +1457,7 @@ function resolveEventSourceFetch(config, options = {}) {
|
|
|
1458
1457
|
function pickBaseFetch(config) {
|
|
1459
1458
|
return config.resolveFetch ? config.resolveFetch(typeof config.proxy == "string" ? config.proxy : void 0) : globalThis.fetch.bind(globalThis);
|
|
1460
1459
|
}
|
|
1460
|
+
/** @internal */
|
|
1461
1461
|
const possibleOptions = [
|
|
1462
1462
|
"includePreviousRevision",
|
|
1463
1463
|
"includeResult",
|
|
@@ -1469,8 +1469,8 @@ const possibleOptions = [
|
|
|
1469
1469
|
"tag"
|
|
1470
1470
|
], defaultOptions = { includeResult: !0 };
|
|
1471
1471
|
/** @public */
|
|
1472
|
-
function _listen(query, params, opts = {}) {
|
|
1473
|
-
let
|
|
1472
|
+
function _listen$1(query, params, opts = {}) {
|
|
1473
|
+
let { url, requestTagPrefix } = this.config(), tag = opts.tag && requestTagPrefix ? [requestTagPrefix, opts.tag].join(".") : opts.tag, options = {
|
|
1474
1474
|
...defaults_default(opts, defaultOptions),
|
|
1475
1475
|
tag
|
|
1476
1476
|
}, listenOpts = pick(options, possibleOptions), qs = encodeQueryString({
|
|
@@ -1482,7 +1482,12 @@ function _listen(query, params, opts = {}) {
|
|
|
1482
1482
|
}
|
|
1483
1483
|
}), uri = `${url}${_getDataUrl(this, "listen", qs)}`;
|
|
1484
1484
|
if (uri.length > 14800) return throwError(() => /* @__PURE__ */ Error("Query too large for listener"));
|
|
1485
|
-
let listenFor = options.events ? options.events : ["mutation"]
|
|
1485
|
+
let listenFor = options.events ? options.events : ["mutation"];
|
|
1486
|
+
return _connectListenEventSource(this, uri, listenFor);
|
|
1487
|
+
}
|
|
1488
|
+
/** @internal */
|
|
1489
|
+
function _connectListenEventSource(client, uri, listenFor) {
|
|
1490
|
+
let config = client.config(), { token, withCredentials, headers: configHeaders } = config, headers = {};
|
|
1486
1491
|
token && (headers.Authorization = `Bearer ${token}`), configHeaders && Object.assign(headers, configHeaders);
|
|
1487
1492
|
let initEventSource = () => new EventSource(uri, { fetch: resolveEventSourceFetch(config, {
|
|
1488
1493
|
headers: Object.keys(headers).length ? headers : void 0,
|
|
@@ -1493,6 +1498,347 @@ function _listen(query, params, opts = {}) {
|
|
|
1493
1498
|
..."data" in event ? event.data : {}
|
|
1494
1499
|
})));
|
|
1495
1500
|
}
|
|
1501
|
+
/** @internal */
|
|
1502
|
+
const possibleRequestOptions = [
|
|
1503
|
+
"headers",
|
|
1504
|
+
"signal",
|
|
1505
|
+
"tag",
|
|
1506
|
+
"timeout",
|
|
1507
|
+
"token"
|
|
1508
|
+
];
|
|
1509
|
+
function commentUrl(id) {
|
|
1510
|
+
if (!id) throw Error("Comment ID must be provided");
|
|
1511
|
+
return `/collaboration/comments/${encodeURIComponent(id)}`;
|
|
1512
|
+
}
|
|
1513
|
+
function resolveCommentResource(client) {
|
|
1514
|
+
let { resource, projectId, dataset } = client.config();
|
|
1515
|
+
if (resource) return resource;
|
|
1516
|
+
if (projectId && dataset) return {
|
|
1517
|
+
type: "dataset",
|
|
1518
|
+
id: `${projectId}.${dataset}`
|
|
1519
|
+
};
|
|
1520
|
+
throw Error("`resource` or `projectId` and `dataset` must be configured to use collaboration comments");
|
|
1521
|
+
}
|
|
1522
|
+
function resourceQuery(client) {
|
|
1523
|
+
let { collaboration } = client.config(), organizationId = collaboration?.organizationId;
|
|
1524
|
+
if (!organizationId) throw Error("`collaboration.organizationId` must be configured to use collaboration comments");
|
|
1525
|
+
let resource = resolveCommentResource(client);
|
|
1526
|
+
return {
|
|
1527
|
+
organizationId,
|
|
1528
|
+
resourceId: resource.id,
|
|
1529
|
+
resourceType: resource.type
|
|
1530
|
+
};
|
|
1531
|
+
}
|
|
1532
|
+
/** @internal */
|
|
1533
|
+
function _getTargetDocumentRef(client, documentId) {
|
|
1534
|
+
if (!documentId) throw Error("Document ID must be provided");
|
|
1535
|
+
let resource = resolveCommentResource(client);
|
|
1536
|
+
return `${resource.type}:${resource.id}:${getPublishedId(documentId)}`;
|
|
1537
|
+
}
|
|
1538
|
+
function write(client, httpRequest, method, url, body, options = {}) {
|
|
1539
|
+
return _requestObservable(client, httpRequest, {
|
|
1540
|
+
method,
|
|
1541
|
+
url,
|
|
1542
|
+
body,
|
|
1543
|
+
query: {
|
|
1544
|
+
...resourceQuery(client),
|
|
1545
|
+
...options.transactionId ? { transactionId: options.transactionId } : {}
|
|
1546
|
+
},
|
|
1547
|
+
...pick(options, possibleRequestOptions)
|
|
1548
|
+
});
|
|
1549
|
+
}
|
|
1550
|
+
/**
|
|
1551
|
+
* `commentId` picks the written comment out of the results: a status update
|
|
1552
|
+
* cascades to the comment's replies, and the API leaves the results unordered.
|
|
1553
|
+
* Creates pass the requested `_id`, which is undefined when the API assigns
|
|
1554
|
+
* one, and always come back with a single result.
|
|
1555
|
+
*/
|
|
1556
|
+
function writeDocument(commentId, ...args) {
|
|
1557
|
+
return write(...args).pipe(map$1(({ results }) => {
|
|
1558
|
+
let result = commentId ? results.find(({ id }) => id === commentId) : results[0];
|
|
1559
|
+
if (!result?.document) throw Error("Comment write did not return a comment document");
|
|
1560
|
+
return result.document;
|
|
1561
|
+
}));
|
|
1562
|
+
}
|
|
1563
|
+
function writeMutationResult(...args) {
|
|
1564
|
+
return write(...args).pipe(map$1(({ transactionId, results }) => ({
|
|
1565
|
+
transactionId,
|
|
1566
|
+
documentIds: results.map((result) => result.id),
|
|
1567
|
+
results
|
|
1568
|
+
})));
|
|
1569
|
+
}
|
|
1570
|
+
/** @internal */
|
|
1571
|
+
function _create(client, httpRequest, body, options) {
|
|
1572
|
+
return writeDocument(body._id, client, httpRequest, "POST", "/collaboration/comments", body, options);
|
|
1573
|
+
}
|
|
1574
|
+
/** @internal */
|
|
1575
|
+
function _update(client, httpRequest, id, body, options) {
|
|
1576
|
+
return writeDocument(id, client, httpRequest, "PATCH", commentUrl(id), body, options);
|
|
1577
|
+
}
|
|
1578
|
+
/** @internal */
|
|
1579
|
+
function _delete(client, httpRequest, id, options) {
|
|
1580
|
+
return writeMutationResult(client, httpRequest, "DELETE", commentUrl(id), void 0, options);
|
|
1581
|
+
}
|
|
1582
|
+
/** @internal */
|
|
1583
|
+
function _addReaction(client, httpRequest, id, shortName, options) {
|
|
1584
|
+
return writeDocument(id, client, httpRequest, "POST", `${commentUrl(id)}/reactions`, { shortName }, options);
|
|
1585
|
+
}
|
|
1586
|
+
/** @internal */
|
|
1587
|
+
function _removeReaction(client, httpRequest, id, shortName, options) {
|
|
1588
|
+
return writeDocument(id, client, httpRequest, "DELETE", `${commentUrl(id)}/reactions/${encodeURIComponent(shortName)}`, void 0, options);
|
|
1589
|
+
}
|
|
1590
|
+
/** @internal */
|
|
1591
|
+
function _fetch(client, httpRequest, query, params, options) {
|
|
1592
|
+
let search = resourceQuery(client);
|
|
1593
|
+
return _requestObservable(client, httpRequest, {
|
|
1594
|
+
...encodeQueryString({
|
|
1595
|
+
query,
|
|
1596
|
+
params
|
|
1597
|
+
}).length < 11264 ? {
|
|
1598
|
+
method: "GET",
|
|
1599
|
+
url: `/collaboration/comments/query${encodeQueryString({
|
|
1600
|
+
query,
|
|
1601
|
+
params,
|
|
1602
|
+
options: search
|
|
1603
|
+
})}`
|
|
1604
|
+
} : {
|
|
1605
|
+
method: "POST",
|
|
1606
|
+
url: "/collaboration/comments/query",
|
|
1607
|
+
query: search,
|
|
1608
|
+
body: {
|
|
1609
|
+
query,
|
|
1610
|
+
params: params ?? {}
|
|
1611
|
+
}
|
|
1612
|
+
},
|
|
1613
|
+
...pick(options || {}, possibleRequestOptions)
|
|
1614
|
+
}).pipe(map$1((response) => response.result));
|
|
1615
|
+
}
|
|
1616
|
+
/** @internal */
|
|
1617
|
+
function _listen(client, query, params, options) {
|
|
1618
|
+
let opts = options ?? {}, { requestTagPrefix } = client.config(), tag = opts.tag && requestTagPrefix ? [requestTagPrefix, opts.tag].join(".") : opts.tag, listenOpts = pick({
|
|
1619
|
+
...defaults_default(opts, defaultOptions),
|
|
1620
|
+
tag
|
|
1621
|
+
}, possibleOptions), qs = encodeQueryString({
|
|
1622
|
+
query,
|
|
1623
|
+
params,
|
|
1624
|
+
options: {
|
|
1625
|
+
...listenOpts,
|
|
1626
|
+
...resourceQuery(client)
|
|
1627
|
+
}
|
|
1628
|
+
}), uri = `${client.getUrl("/collaboration/comments/listen")}${qs}`;
|
|
1629
|
+
return uri.length > 14800 ? throwError(() => /* @__PURE__ */ Error("Query too large for listener")) : _connectListenEventSource(client, uri, opts.events ? opts.events : ["mutation"]);
|
|
1630
|
+
}
|
|
1631
|
+
var _client$7 = /* @__PURE__ */ new WeakMap(), _httpRequest$7 = /* @__PURE__ */ new WeakMap(), ObservableCollaborationCommentsClient = class {
|
|
1632
|
+
constructor(client, httpRequest) {
|
|
1633
|
+
_classPrivateFieldInitSpec(this, _client$7, void 0), _classPrivateFieldInitSpec(this, _httpRequest$7, void 0), _classPrivateFieldSet2(_client$7, this, client), _classPrivateFieldSet2(_httpRequest$7, this, httpRequest);
|
|
1634
|
+
}
|
|
1635
|
+
/**
|
|
1636
|
+
* Create a comment or reply on the configured resource.
|
|
1637
|
+
*
|
|
1638
|
+
* A top-level comment requires `target`; a reply requires `parentCommentId` (never both).
|
|
1639
|
+
* Replies inherit `target`, `status`, and `threadId` from the parent comment.
|
|
1640
|
+
*
|
|
1641
|
+
* @param body - Comment to create
|
|
1642
|
+
* @param options - Optional request options
|
|
1643
|
+
* @returns The created comment
|
|
1644
|
+
*/
|
|
1645
|
+
create(body, options) {
|
|
1646
|
+
return _create(_classPrivateFieldGet2(_client$7, this), _classPrivateFieldGet2(_httpRequest$7, this), body, options);
|
|
1647
|
+
}
|
|
1648
|
+
/**
|
|
1649
|
+
* Update an existing comment.
|
|
1650
|
+
*
|
|
1651
|
+
* Updating `status` cascades to the comment's replies.
|
|
1652
|
+
*
|
|
1653
|
+
* @param id - Comment document ID
|
|
1654
|
+
* @param body - Fields to update
|
|
1655
|
+
* @param options - Optional request options
|
|
1656
|
+
* @returns The updated comment
|
|
1657
|
+
*/
|
|
1658
|
+
update(id, body, options) {
|
|
1659
|
+
return _update(_classPrivateFieldGet2(_client$7, this), _classPrivateFieldGet2(_httpRequest$7, this), id, body, options);
|
|
1660
|
+
}
|
|
1661
|
+
/**
|
|
1662
|
+
* Delete a comment and its replies.
|
|
1663
|
+
*
|
|
1664
|
+
* @param id - Comment document ID
|
|
1665
|
+
* @param options - Optional request options
|
|
1666
|
+
* @returns Mutation result, where `documentIds` covers the comment and every deleted reply
|
|
1667
|
+
*/
|
|
1668
|
+
delete(id, options) {
|
|
1669
|
+
return _delete(_classPrivateFieldGet2(_client$7, this), _classPrivateFieldGet2(_httpRequest$7, this), id, options);
|
|
1670
|
+
}
|
|
1671
|
+
/**
|
|
1672
|
+
* Add the current user's reaction to a comment.
|
|
1673
|
+
*
|
|
1674
|
+
* @param id - Comment document ID
|
|
1675
|
+
* @param shortName - Emoji short name, for example `:+1:`
|
|
1676
|
+
* @param options - Optional request options
|
|
1677
|
+
* @returns The comment, with the reaction applied
|
|
1678
|
+
*/
|
|
1679
|
+
addReaction(id, shortName, options) {
|
|
1680
|
+
return _addReaction(_classPrivateFieldGet2(_client$7, this), _classPrivateFieldGet2(_httpRequest$7, this), id, shortName, options);
|
|
1681
|
+
}
|
|
1682
|
+
/**
|
|
1683
|
+
* Remove the current user's reaction from a comment.
|
|
1684
|
+
*
|
|
1685
|
+
* @param id - Comment document ID
|
|
1686
|
+
* @param shortName - Emoji short name, for example `:+1:`
|
|
1687
|
+
* @param options - Optional request options
|
|
1688
|
+
* @returns The comment, with the reaction removed
|
|
1689
|
+
*/
|
|
1690
|
+
removeReaction(id, shortName, options) {
|
|
1691
|
+
return _removeReaction(_classPrivateFieldGet2(_client$7, this), _classPrivateFieldGet2(_httpRequest$7, this), id, shortName, options);
|
|
1692
|
+
}
|
|
1693
|
+
/**
|
|
1694
|
+
* Build the global document reference used by `target.document._ref`, for use in
|
|
1695
|
+
* queries and listeners.
|
|
1696
|
+
*
|
|
1697
|
+
* The reference is built from the configured `resource` and the published ID of
|
|
1698
|
+
* the given document ID, since comment references always use published IDs.
|
|
1699
|
+
*
|
|
1700
|
+
* @example
|
|
1701
|
+
* ```ts
|
|
1702
|
+
* client.collaboration.comments.listen(
|
|
1703
|
+
* '*[_type == "sanity.comment" && target.document._ref == $ref]',
|
|
1704
|
+
* {ref: client.collaboration.comments.getTargetDocumentRef('doc-1')},
|
|
1705
|
+
* )
|
|
1706
|
+
* ```
|
|
1707
|
+
*
|
|
1708
|
+
* @param documentId - Document ID, in published, draft or version form
|
|
1709
|
+
* @returns Global document reference, of the form `resourceType:resourceId:documentId`
|
|
1710
|
+
*/
|
|
1711
|
+
getTargetDocumentRef(documentId) {
|
|
1712
|
+
return _getTargetDocumentRef(_classPrivateFieldGet2(_client$7, this), documentId);
|
|
1713
|
+
}
|
|
1714
|
+
/**
|
|
1715
|
+
* Fetch comments on the configured resource.
|
|
1716
|
+
*
|
|
1717
|
+
* Takes the same `query` and `params` as `client.fetch`, and switches from a
|
|
1718
|
+
* GET to a POST for queries too large for the request URL in the same way,
|
|
1719
|
+
* but queries the comments endpoint, which accepts none of the query options
|
|
1720
|
+
* `client.fetch` does (`perspective`, `useCdn`, `filterResponse`,
|
|
1721
|
+
* `resultSourceMap`, stega).
|
|
1722
|
+
*
|
|
1723
|
+
* The query runs against the organization store, which is not scoped to
|
|
1724
|
+
* comments, so filter on `_type == "sanity.comment"`.
|
|
1725
|
+
*
|
|
1726
|
+
* @param query - GROQ-query to perform
|
|
1727
|
+
* @param params - Optional query parameters
|
|
1728
|
+
* @param options - Optional request options
|
|
1729
|
+
*/
|
|
1730
|
+
fetch(query, params, options) {
|
|
1731
|
+
return _fetch(_classPrivateFieldGet2(_client$7, this), _classPrivateFieldGet2(_httpRequest$7, this), query, params, options);
|
|
1732
|
+
}
|
|
1733
|
+
listen(query, params, options) {
|
|
1734
|
+
return _listen(_classPrivateFieldGet2(_client$7, this), query, params, options);
|
|
1735
|
+
}
|
|
1736
|
+
}, _client2$6 = /* @__PURE__ */ new WeakMap(), _httpRequest2$7 = /* @__PURE__ */ new WeakMap(), CollaborationCommentsClient = class {
|
|
1737
|
+
constructor(client, httpRequest) {
|
|
1738
|
+
_classPrivateFieldInitSpec(this, _client2$6, void 0), _classPrivateFieldInitSpec(this, _httpRequest2$7, void 0), _classPrivateFieldSet2(_client2$6, this, client), _classPrivateFieldSet2(_httpRequest2$7, this, httpRequest);
|
|
1739
|
+
}
|
|
1740
|
+
/**
|
|
1741
|
+
* Create a comment or reply on the configured resource.
|
|
1742
|
+
*
|
|
1743
|
+
* A top-level comment requires `target`; a reply requires `parentCommentId` (never both).
|
|
1744
|
+
* Replies inherit `target`, `status`, and `threadId` from the parent comment.
|
|
1745
|
+
*
|
|
1746
|
+
* @param body - Comment to create
|
|
1747
|
+
* @param options - Optional request options
|
|
1748
|
+
* @returns The created comment
|
|
1749
|
+
*/
|
|
1750
|
+
create(body, options) {
|
|
1751
|
+
return lastValueFrom(_create(_classPrivateFieldGet2(_client2$6, this), _classPrivateFieldGet2(_httpRequest2$7, this), body, options));
|
|
1752
|
+
}
|
|
1753
|
+
/**
|
|
1754
|
+
* Update an existing comment.
|
|
1755
|
+
*
|
|
1756
|
+
* Updating `status` cascades to the comment's replies.
|
|
1757
|
+
*
|
|
1758
|
+
* @param id - Comment document ID
|
|
1759
|
+
* @param body - Fields to update
|
|
1760
|
+
* @param options - Optional request options
|
|
1761
|
+
* @returns The updated comment
|
|
1762
|
+
*/
|
|
1763
|
+
update(id, body, options) {
|
|
1764
|
+
return lastValueFrom(_update(_classPrivateFieldGet2(_client2$6, this), _classPrivateFieldGet2(_httpRequest2$7, this), id, body, options));
|
|
1765
|
+
}
|
|
1766
|
+
/**
|
|
1767
|
+
* Delete a comment and its replies.
|
|
1768
|
+
*
|
|
1769
|
+
* @param id - Comment document ID
|
|
1770
|
+
* @param options - Optional request options
|
|
1771
|
+
* @returns Mutation result, where `documentIds` covers the comment and every deleted reply
|
|
1772
|
+
*/
|
|
1773
|
+
delete(id, options) {
|
|
1774
|
+
return lastValueFrom(_delete(_classPrivateFieldGet2(_client2$6, this), _classPrivateFieldGet2(_httpRequest2$7, this), id, options));
|
|
1775
|
+
}
|
|
1776
|
+
/**
|
|
1777
|
+
* Add the current user's reaction to a comment.
|
|
1778
|
+
*
|
|
1779
|
+
* @param id - Comment document ID
|
|
1780
|
+
* @param shortName - Emoji short name, for example `:+1:`
|
|
1781
|
+
* @param options - Optional request options
|
|
1782
|
+
* @returns The comment, with the reaction applied
|
|
1783
|
+
*/
|
|
1784
|
+
addReaction(id, shortName, options) {
|
|
1785
|
+
return lastValueFrom(_addReaction(_classPrivateFieldGet2(_client2$6, this), _classPrivateFieldGet2(_httpRequest2$7, this), id, shortName, options));
|
|
1786
|
+
}
|
|
1787
|
+
/**
|
|
1788
|
+
* Remove the current user's reaction from a comment.
|
|
1789
|
+
*
|
|
1790
|
+
* @param id - Comment document ID
|
|
1791
|
+
* @param shortName - Emoji short name, for example `:+1:`
|
|
1792
|
+
* @param options - Optional request options
|
|
1793
|
+
* @returns The comment, with the reaction removed
|
|
1794
|
+
*/
|
|
1795
|
+
removeReaction(id, shortName, options) {
|
|
1796
|
+
return lastValueFrom(_removeReaction(_classPrivateFieldGet2(_client2$6, this), _classPrivateFieldGet2(_httpRequest2$7, this), id, shortName, options));
|
|
1797
|
+
}
|
|
1798
|
+
/**
|
|
1799
|
+
* Build the global document reference used by `target.document._ref`, for use in
|
|
1800
|
+
* queries and listeners.
|
|
1801
|
+
*
|
|
1802
|
+
* The reference is built from the configured `resource` and the published ID of
|
|
1803
|
+
* the given document ID, since comment references always use published IDs.
|
|
1804
|
+
*
|
|
1805
|
+
* @example
|
|
1806
|
+
* ```ts
|
|
1807
|
+
* const comments = await client.collaboration.comments.fetch(
|
|
1808
|
+
* '*[_type == "sanity.comment" && target.document._ref == $ref]',
|
|
1809
|
+
* {ref: client.collaboration.comments.getTargetDocumentRef('doc-1')},
|
|
1810
|
+
* )
|
|
1811
|
+
* ```
|
|
1812
|
+
*
|
|
1813
|
+
* @param documentId - Document ID, in published, draft or version form
|
|
1814
|
+
* @returns Global document reference, of the form `resourceType:resourceId:documentId`
|
|
1815
|
+
*/
|
|
1816
|
+
getTargetDocumentRef(documentId) {
|
|
1817
|
+
return _getTargetDocumentRef(_classPrivateFieldGet2(_client2$6, this), documentId);
|
|
1818
|
+
}
|
|
1819
|
+
/**
|
|
1820
|
+
* Fetch comments on the configured resource.
|
|
1821
|
+
*
|
|
1822
|
+
* Takes the same `query` and `params` as `client.fetch`, and switches from a
|
|
1823
|
+
* GET to a POST for queries too large for the request URL in the same way,
|
|
1824
|
+
* but queries the comments endpoint, which accepts none of the query options
|
|
1825
|
+
* `client.fetch` does (`perspective`, `useCdn`, `filterResponse`,
|
|
1826
|
+
* `resultSourceMap`, stega).
|
|
1827
|
+
*
|
|
1828
|
+
* The query runs against the organization store, which is not scoped to
|
|
1829
|
+
* comments, so filter on `_type == "sanity.comment"`.
|
|
1830
|
+
*
|
|
1831
|
+
* @param query - GROQ-query to perform
|
|
1832
|
+
* @param params - Optional query parameters
|
|
1833
|
+
* @param options - Optional request options
|
|
1834
|
+
*/
|
|
1835
|
+
fetch(query, params, options) {
|
|
1836
|
+
return lastValueFrom(_fetch(_classPrivateFieldGet2(_client2$6, this), _classPrivateFieldGet2(_httpRequest2$7, this), query, params, options));
|
|
1837
|
+
}
|
|
1838
|
+
listen(query, params, options) {
|
|
1839
|
+
return _listen(_classPrivateFieldGet2(_client2$6, this), query, params, options);
|
|
1840
|
+
}
|
|
1841
|
+
};
|
|
1496
1842
|
/**
|
|
1497
1843
|
* A variant of share that takes a predicate function to determine which value to replay to new subscribers
|
|
1498
1844
|
* @param configOrPredicate - Predicate function to determine which value to replay
|
|
@@ -1795,7 +2141,11 @@ function _modify(client, httpRequest, method, name, options) {
|
|
|
1795
2141
|
});
|
|
1796
2142
|
}
|
|
1797
2143
|
/** Function resource types in a blueprint are namespaced under this prefix. */
|
|
1798
|
-
const
|
|
2144
|
+
const SYNC_INVOCABLE_FUNCTION_TYPES = ["sanity.function.pubsub"], ASYNC_INVOCABLE_FUNCTION_TYPES = [
|
|
2145
|
+
"sanity.function.durable",
|
|
2146
|
+
"sanity.function.pubsub",
|
|
2147
|
+
"sanity.function.queue"
|
|
2148
|
+
], INVOCABLE_FUNCTION_TYPES = [.../* @__PURE__ */ new Set([...SYNC_INVOCABLE_FUNCTION_TYPES, ...ASYNC_INVOCABLE_FUNCTION_TYPES])], scopeHeaders = (config, request) => {
|
|
1799
2149
|
let organizationId = request?.organizationId || config.organizationId;
|
|
1800
2150
|
if (organizationId) return {
|
|
1801
2151
|
"X-Sanity-Scope-Type": "organization",
|
|
@@ -1819,7 +2169,7 @@ const scopeHeaders = (config, request) => {
|
|
|
1819
2169
|
*
|
|
1820
2170
|
* @internal
|
|
1821
2171
|
*/
|
|
1822
|
-
function _resolveFunctionId(client, httpRequest, functionName, stackId, headers, request) {
|
|
2172
|
+
function _resolveFunctionId(client, httpRequest, functionName, stackId, headers, request, sync) {
|
|
1823
2173
|
return _requestObservable(client, httpRequest, {
|
|
1824
2174
|
method: "GET",
|
|
1825
2175
|
url: `/blueprints/stacks/${stackId}`,
|
|
@@ -1829,17 +2179,19 @@ function _resolveFunctionId(client, httpRequest, functionName, stackId, headers,
|
|
|
1829
2179
|
let match = (stack?.resources || []).find((resource) => resource.type?.startsWith("sanity.function.") && resource.name === functionName);
|
|
1830
2180
|
if (!match) throw Error(`Function "${functionName}" not found in stack "${stackId}"`);
|
|
1831
2181
|
if (!match.externalId) throw Error(`Function "${functionName}" is declared in stack "${stackId}" but is not deployed`);
|
|
1832
|
-
if (match.type
|
|
2182
|
+
if (!INVOCABLE_FUNCTION_TYPES.includes(match.type)) throw Error(`Function invocation is not supported for ${match.type}`);
|
|
2183
|
+
if (sync && !SYNC_INVOCABLE_FUNCTION_TYPES.includes(match.type)) throw Error(`Synchronous function invocation is not supported for ${match.type}`);
|
|
2184
|
+
if (!sync && !ASYNC_INVOCABLE_FUNCTION_TYPES.includes(match.type)) throw Error(`Asynchronous function invocation is not supported for ${match.type}`);
|
|
1833
2185
|
return match.externalId;
|
|
1834
2186
|
}));
|
|
1835
2187
|
}
|
|
1836
2188
|
/** @internal */
|
|
1837
|
-
function _invoke(client, httpRequest, functionName, request) {
|
|
2189
|
+
function _invoke(client, httpRequest, functionName, request, options) {
|
|
1838
2190
|
return defer(() => {
|
|
1839
|
-
let config = client.config(), headers = scopeHeaders(config, request);
|
|
1840
|
-
return _resolveFunctionId(client, httpRequest, functionName,
|
|
2191
|
+
let config = client.config(), headers = scopeHeaders(config, request), stackId = resolveStackId(config, request), sync = options?.sync ?? !1;
|
|
2192
|
+
return _resolveFunctionId(client, httpRequest, functionName, stackId, headers, request, sync).pipe(mergeMap((functionId) => _requestObservable(client, httpRequest, {
|
|
1841
2193
|
method: "POST",
|
|
1842
|
-
url: `/functions/${functionId}/invoke`,
|
|
2194
|
+
url: `/functions/${functionId}/invoke${sync ? "?sync=true" : ""}`,
|
|
1843
2195
|
headers,
|
|
1844
2196
|
body: { event: { data: request?.event?.data ?? {} } },
|
|
1845
2197
|
timeout: request?.timeout,
|
|
@@ -1851,42 +2203,15 @@ var _client$4 = /* @__PURE__ */ new WeakMap(), _httpRequest$5 = /* @__PURE__ */
|
|
|
1851
2203
|
constructor(client, httpRequest) {
|
|
1852
2204
|
_classPrivateFieldInitSpec(this, _client$4, void 0), _classPrivateFieldInitSpec(this, _httpRequest$5, void 0), _classPrivateFieldSet2(_client$4, this, client), _classPrivateFieldSet2(_httpRequest$5, this, httpRequest);
|
|
1853
2205
|
}
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
*
|
|
1857
|
-
* The name is resolved within the stack given by `stackId` on the request or
|
|
1858
|
-
* the client config. Passes the function's return value once it finishes.
|
|
1859
|
-
*
|
|
1860
|
-
* @param functionName - name of the function, as declared in the blueprint
|
|
1861
|
-
* @param request - payload and request options
|
|
1862
|
-
*/
|
|
1863
|
-
invoke(functionName, request) {
|
|
1864
|
-
return _invoke(_classPrivateFieldGet2(_client$4, this), _classPrivateFieldGet2(_httpRequest$5, this), functionName, request);
|
|
2206
|
+
invoke(functionName, request, options) {
|
|
2207
|
+
return _invoke(_classPrivateFieldGet2(_client$4, this), _classPrivateFieldGet2(_httpRequest$5, this), functionName, request, options);
|
|
1865
2208
|
}
|
|
1866
2209
|
}, _client2$4 = /* @__PURE__ */ new WeakMap(), _httpRequest2$5 = /* @__PURE__ */ new WeakMap(), FunctionsClient = class {
|
|
1867
2210
|
constructor(client, httpRequest) {
|
|
1868
2211
|
_classPrivateFieldInitSpec(this, _client2$4, void 0), _classPrivateFieldInitSpec(this, _httpRequest2$5, void 0), _classPrivateFieldSet2(_client2$4, this, client), _classPrivateFieldSet2(_httpRequest2$5, this, httpRequest);
|
|
1869
2212
|
}
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
*
|
|
1873
|
-
* The name is resolved within the stack given by `stackId` on the request or
|
|
1874
|
-
* the client config, which costs one extra request per call. Rejects if the
|
|
1875
|
-
* stack has no function by that name, or if the name resolves to anything
|
|
1876
|
-
* other than a `sanity.function.pubsub` function.
|
|
1877
|
-
*
|
|
1878
|
-
* The lookup is scoped to `projectId`, or to `organizationId` when one is set
|
|
1879
|
-
* for a stack deployed at organization scope.
|
|
1880
|
-
*
|
|
1881
|
-
* The request stays open until the function finishes, and resolves with its
|
|
1882
|
-
* return value, or `undefined` if it returns nothing. Long-running functions
|
|
1883
|
-
* may need an explicit `timeout`.
|
|
1884
|
-
*
|
|
1885
|
-
* @param functionName - name of the function, as declared in the blueprint
|
|
1886
|
-
* @param request - payload and request options
|
|
1887
|
-
*/
|
|
1888
|
-
invoke(functionName, request) {
|
|
1889
|
-
return lastValueFrom(_invoke(_classPrivateFieldGet2(_client2$4, this), _classPrivateFieldGet2(_httpRequest2$5, this), functionName, request));
|
|
2213
|
+
invoke(functionName, request, options) {
|
|
2214
|
+
return lastValueFrom(_invoke(_classPrivateFieldGet2(_client2$4, this), _classPrivateFieldGet2(_httpRequest2$5, this), functionName, request, options));
|
|
1890
2215
|
}
|
|
1891
2216
|
}, _client$3 = /* @__PURE__ */ new WeakMap(), _httpRequest$4 = /* @__PURE__ */ new WeakMap(), ObservableMediaLibraryVideoClient = class {
|
|
1892
2217
|
constructor(client, httpRequest) {
|
|
@@ -2025,7 +2350,19 @@ var _client$2 = /* @__PURE__ */ new WeakMap(), _httpRequest$3 = /* @__PURE__ */
|
|
|
2025
2350
|
*
|
|
2026
2351
|
* ~24 years (or 7.54e+8 seconds) needed, in order to have a 1% probability of at least one collision if 10 ID's are generated every hour.
|
|
2027
2352
|
*/
|
|
2028
|
-
|
|
2353
|
+
function generateReleaseId() {
|
|
2354
|
+
let id = "";
|
|
2355
|
+
for (; id.length < 8;) {
|
|
2356
|
+
let bytes = crypto.getRandomValues(new Uint8Array(8 - id.length));
|
|
2357
|
+
for (let byte of bytes) {
|
|
2358
|
+
let index = byte & 63;
|
|
2359
|
+
index < 62 && (id += "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"[index]);
|
|
2360
|
+
}
|
|
2361
|
+
}
|
|
2362
|
+
return id;
|
|
2363
|
+
}
|
|
2364
|
+
/** @internal */
|
|
2365
|
+
const getDocumentVersionId = (publishedId, releaseId) => releaseId ? getVersionId(publishedId, releaseId) : getDraftId(publishedId);
|
|
2029
2366
|
/** @internal */
|
|
2030
2367
|
function deriveDocumentVersionId(op, { releaseId, publishedId, document }) {
|
|
2031
2368
|
if (publishedId && document._id) {
|
|
@@ -2520,14 +2857,14 @@ var _client$1 = /* @__PURE__ */ new WeakMap(), _httpRequest$2 = /* @__PURE__ */
|
|
|
2520
2857
|
}
|
|
2521
2858
|
}, _clientConfig = /* @__PURE__ */ new WeakMap(), _httpRequest = /* @__PURE__ */ new WeakMap(), ObservableSanityClient = class ObservableSanityClient {
|
|
2522
2859
|
constructor(httpRequest, config = defaultConfig) {
|
|
2523
|
-
_defineProperty(this, "assets", void 0), _defineProperty(this, "datasets", void 0), _defineProperty(this, "live", void 0), _defineProperty(this, "mediaLibrary", void 0), _defineProperty(this, "projects", void 0), _defineProperty(this, "users", void 0), _defineProperty(this, "agent", void 0), _defineProperty(this, "functions", void 0), _defineProperty(this, "releases", void 0), _classPrivateFieldInitSpec(this, _clientConfig, void 0), _classPrivateFieldInitSpec(this, _httpRequest, void 0), _defineProperty(
|
|
2860
|
+
_defineProperty(this, "assets", void 0), _defineProperty(this, "datasets", void 0), _defineProperty(this, "live", void 0), _defineProperty(this, "mediaLibrary", void 0), _defineProperty(this, "projects", void 0), _defineProperty(this, "users", void 0), _defineProperty(this, "agent", void 0), _defineProperty(this, "collaboration", void 0), _defineProperty(this, "functions", void 0), _defineProperty(this, "releases", void 0), _classPrivateFieldInitSpec(this, _clientConfig, void 0), _classPrivateFieldInitSpec(this, _httpRequest, void 0), _defineProperty(
|
|
2524
2861
|
this,
|
|
2525
2862
|
/**
|
|
2526
2863
|
* Instance properties
|
|
2527
2864
|
*/
|
|
2528
2865
|
"listen",
|
|
2529
|
-
_listen
|
|
2530
|
-
), this.config(config), _classPrivateFieldSet2(_httpRequest, this, httpRequest), this.assets = new ObservableAssetsClient(this, _classPrivateFieldGet2(_httpRequest, this)), this.datasets = new ObservableDatasetsClient(this, _classPrivateFieldGet2(_httpRequest, this)), this.live = new LiveClient(this), this.mediaLibrary = { video: new ObservableMediaLibraryVideoClient(this, _classPrivateFieldGet2(_httpRequest, this)) }, this.projects = new ObservableProjectsClient(this, _classPrivateFieldGet2(_httpRequest, this)), this.users = new ObservableUsersClient(this, _classPrivateFieldGet2(_httpRequest, this)), this.agent = { action: new ObservableAgentsActionClient(this, _classPrivateFieldGet2(_httpRequest, this)) }, this.functions = new ObservableFunctionsClient(this, _classPrivateFieldGet2(_httpRequest, this)), this.releases = new ObservableReleasesClient(this, _classPrivateFieldGet2(_httpRequest, this));
|
|
2866
|
+
_listen$1
|
|
2867
|
+
), this.config(config), _classPrivateFieldSet2(_httpRequest, this, httpRequest), this.assets = new ObservableAssetsClient(this, _classPrivateFieldGet2(_httpRequest, this)), this.datasets = new ObservableDatasetsClient(this, _classPrivateFieldGet2(_httpRequest, this)), this.live = new LiveClient(this), this.mediaLibrary = { video: new ObservableMediaLibraryVideoClient(this, _classPrivateFieldGet2(_httpRequest, this)) }, this.projects = new ObservableProjectsClient(this, _classPrivateFieldGet2(_httpRequest, this)), this.users = new ObservableUsersClient(this, _classPrivateFieldGet2(_httpRequest, this)), this.agent = { action: new ObservableAgentsActionClient(this, _classPrivateFieldGet2(_httpRequest, this)) }, this.collaboration = { comments: new ObservableCollaborationCommentsClient(this, _classPrivateFieldGet2(_httpRequest, this)) }, this.functions = new ObservableFunctionsClient(this, _classPrivateFieldGet2(_httpRequest, this)), this.releases = new ObservableReleasesClient(this, _classPrivateFieldGet2(_httpRequest, this));
|
|
2531
2868
|
}
|
|
2532
2869
|
/**
|
|
2533
2870
|
* Clone the client - returns a new instance
|
|
@@ -2744,7 +3081,7 @@ var _client$1 = /* @__PURE__ */ new WeakMap(), _httpRequest$2 = /* @__PURE__ */
|
|
|
2744
3081
|
}
|
|
2745
3082
|
}, _clientConfig2 = /* @__PURE__ */ new WeakMap(), _httpRequest2 = /* @__PURE__ */ new WeakMap(), SanityClient = class SanityClient {
|
|
2746
3083
|
constructor(httpRequest, config = defaultConfig) {
|
|
2747
|
-
_defineProperty(this, "assets", void 0), _defineProperty(this, "datasets", void 0), _defineProperty(this, "live", void 0), _defineProperty(this, "mediaLibrary", void 0), _defineProperty(this, "projects", void 0), _defineProperty(this, "users", void 0), _defineProperty(this, "agent", void 0), _defineProperty(this, "functions", void 0), _defineProperty(this, "releases", void 0), _defineProperty(
|
|
3084
|
+
_defineProperty(this, "assets", void 0), _defineProperty(this, "datasets", void 0), _defineProperty(this, "live", void 0), _defineProperty(this, "mediaLibrary", void 0), _defineProperty(this, "projects", void 0), _defineProperty(this, "users", void 0), _defineProperty(this, "agent", void 0), _defineProperty(this, "collaboration", void 0), _defineProperty(this, "functions", void 0), _defineProperty(this, "releases", void 0), _defineProperty(
|
|
2748
3085
|
this,
|
|
2749
3086
|
/**
|
|
2750
3087
|
* Observable version of the Sanity client, with the same configuration as the promise-based one
|
|
@@ -2757,8 +3094,8 @@ var _client$1 = /* @__PURE__ */ new WeakMap(), _httpRequest$2 = /* @__PURE__ */
|
|
|
2757
3094
|
* Instance properties
|
|
2758
3095
|
*/
|
|
2759
3096
|
"listen",
|
|
2760
|
-
_listen
|
|
2761
|
-
), this.config(config), _classPrivateFieldSet2(_httpRequest2, this, httpRequest), this.assets = new AssetsClient(this, _classPrivateFieldGet2(_httpRequest2, this)), this.datasets = new DatasetsClient(this, _classPrivateFieldGet2(_httpRequest2, this)), this.live = new LiveClient(this), this.mediaLibrary = { video: new MediaLibraryVideoClient(this, _classPrivateFieldGet2(_httpRequest2, this)) }, this.projects = new ProjectsClient(this, _classPrivateFieldGet2(_httpRequest2, this)), this.users = new UsersClient(this, _classPrivateFieldGet2(_httpRequest2, this)), this.agent = { action: new AgentActionsClient(this, _classPrivateFieldGet2(_httpRequest2, this)) }, this.functions = new FunctionsClient(this, _classPrivateFieldGet2(_httpRequest2, this)), this.releases = new ReleasesClient(this, _classPrivateFieldGet2(_httpRequest2, this)), this.observable = new ObservableSanityClient(httpRequest, config);
|
|
3097
|
+
_listen$1
|
|
3098
|
+
), this.config(config), _classPrivateFieldSet2(_httpRequest2, this, httpRequest), this.assets = new AssetsClient(this, _classPrivateFieldGet2(_httpRequest2, this)), this.datasets = new DatasetsClient(this, _classPrivateFieldGet2(_httpRequest2, this)), this.live = new LiveClient(this), this.mediaLibrary = { video: new MediaLibraryVideoClient(this, _classPrivateFieldGet2(_httpRequest2, this)) }, this.projects = new ProjectsClient(this, _classPrivateFieldGet2(_httpRequest2, this)), this.users = new UsersClient(this, _classPrivateFieldGet2(_httpRequest2, this)), this.agent = { action: new AgentActionsClient(this, _classPrivateFieldGet2(_httpRequest2, this)) }, this.collaboration = { comments: new CollaborationCommentsClient(this, _classPrivateFieldGet2(_httpRequest2, this)) }, this.functions = new FunctionsClient(this, _classPrivateFieldGet2(_httpRequest2, this)), this.releases = new ReleasesClient(this, _classPrivateFieldGet2(_httpRequest2, this)), this.observable = new ObservableSanityClient(httpRequest, config);
|
|
2762
3099
|
}
|
|
2763
3100
|
/**
|
|
2764
3101
|
* Clone the client - returns a new instance
|
|
@@ -2788,7 +3125,7 @@ var _client$1 = /* @__PURE__ */ new WeakMap(), _httpRequest$2 = /* @__PURE__ */
|
|
|
2788
3125
|
});
|
|
2789
3126
|
}
|
|
2790
3127
|
fetch(query, params, options) {
|
|
2791
|
-
return _fetch(this, _classPrivateFieldGet2(_httpRequest2, this), _classPrivateFieldGet2(_clientConfig2, this).stega, query, params, options);
|
|
3128
|
+
return _fetch$1(this, _classPrivateFieldGet2(_httpRequest2, this), _classPrivateFieldGet2(_clientConfig2, this).stega, query, params, options);
|
|
2792
3129
|
}
|
|
2793
3130
|
getDocument(id, options) {
|
|
2794
3131
|
if (options?.includeAllVersions === !0) return _getDocument(this, _classPrivateFieldGet2(_httpRequest2, this), id, {
|
|
@@ -2826,7 +3163,7 @@ var _client$1 = /* @__PURE__ */ new WeakMap(), _httpRequest$2 = /* @__PURE__ */
|
|
|
2826
3163
|
return _documentsExists(this, _classPrivateFieldGet2(_httpRequest2, this), ids, options);
|
|
2827
3164
|
}
|
|
2828
3165
|
create(document, options) {
|
|
2829
|
-
return _create(this, _classPrivateFieldGet2(_httpRequest2, this), document, "create", options);
|
|
3166
|
+
return _create$1(this, _classPrivateFieldGet2(_httpRequest2, this), document, "create", options);
|
|
2830
3167
|
}
|
|
2831
3168
|
createIfNotExists(document, options) {
|
|
2832
3169
|
return _createIfNotExists(this, _classPrivateFieldGet2(_httpRequest2, this), document, options);
|
|
@@ -2847,7 +3184,7 @@ var _client$1 = /* @__PURE__ */ new WeakMap(), _httpRequest$2 = /* @__PURE__ */
|
|
|
2847
3184
|
return _createVersion(this, _classPrivateFieldGet2(_httpRequest2, this), documentVersion, versionPublishedId, options);
|
|
2848
3185
|
}
|
|
2849
3186
|
delete(selection, options) {
|
|
2850
|
-
return _delete(this, _classPrivateFieldGet2(_httpRequest2, this), selection, options);
|
|
3187
|
+
return _delete$1(this, _classPrivateFieldGet2(_httpRequest2, this), selection, options);
|
|
2851
3188
|
}
|
|
2852
3189
|
/**
|
|
2853
3190
|
* @public
|