@sanity/client 3.3.1 → 3.3.3-esm.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 +1 -1
- package/dist/sanityClient.browser.mjs +1169 -0
- package/dist/sanityClient.browser.mjs.map +7 -0
- package/lib/assets/assetsClient.js +6 -4
- package/lib/auth/authClient.js +4 -2
- package/lib/config.js +6 -4
- package/lib/data/dataMethods.js +5 -3
- package/lib/data/listen.js +8 -6
- package/lib/data/patch.js +11 -9
- package/lib/data/transaction.js +7 -5
- package/lib/datasets/datasetsClient.js +4 -2
- package/lib/generateHelpUrl.js +7 -0
- package/lib/http/errors.js +8 -6
- package/lib/http/nodeMiddleware.js +8 -6
- package/lib/http/request.js +12 -10
- package/lib/http/requestOptions.js +5 -3
- package/lib/projects/projectsClient.js +4 -2
- package/lib/sanityClient.js +10 -8
- package/lib/users/usersClient.js +4 -2
- package/lib/util/observable.js +8 -11
- package/lib/warnings.js +1 -1
- package/package.json +37 -16
- package/sanityClient.d.ts +117 -20
- package/umd/sanityClient.js +45 -45
- package/umd/sanityClient.min.js +1 -1
- package/test/client.test.js +0 -2561
- package/test/encodeQueryString.test.js +0 -36
- package/test/fixtures/horsehead-nebula.jpg +0 -0
- package/test/fixtures/pdf-sample.pdf +0 -0
- package/test/helpers/sseServer.js +0 -26
- package/test/listen.test.js +0 -205
- package/test/warnings.test.disabled.js +0 -80
package/lib/sanityClient.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _objectAssign = _interopRequireDefault(require("object-assign"));
|
|
4
|
+
|
|
5
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
|
+
|
|
3
7
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
4
8
|
|
|
5
9
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
6
10
|
|
|
7
11
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
8
12
|
|
|
9
|
-
var assign = require('object-assign');
|
|
10
|
-
|
|
11
13
|
var _require = require('./util/observable'),
|
|
12
14
|
Observable = _require.Observable,
|
|
13
15
|
map = _require.map,
|
|
@@ -58,25 +60,25 @@ function SanityClient() {
|
|
|
58
60
|
this.auth = new AuthClient(this);
|
|
59
61
|
|
|
60
62
|
if (this.clientConfig.isPromiseAPI) {
|
|
61
|
-
var observableConfig =
|
|
63
|
+
var observableConfig = (0, _objectAssign.default)({}, this.clientConfig, {
|
|
62
64
|
isPromiseAPI: false
|
|
63
65
|
});
|
|
64
66
|
this.observable = new SanityClient(observableConfig);
|
|
65
67
|
}
|
|
66
68
|
}
|
|
67
69
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
+
(0, _objectAssign.default)(SanityClient.prototype, dataMethods);
|
|
71
|
+
(0, _objectAssign.default)(SanityClient.prototype, {
|
|
70
72
|
clone: function clone() {
|
|
71
73
|
return new SanityClient(this.config());
|
|
72
74
|
},
|
|
73
75
|
config: function config(newConfig) {
|
|
74
76
|
if (typeof newConfig === 'undefined') {
|
|
75
|
-
return
|
|
77
|
+
return (0, _objectAssign.default)({}, this.clientConfig);
|
|
76
78
|
}
|
|
77
79
|
|
|
78
80
|
if (this.observable) {
|
|
79
|
-
var observableConfig =
|
|
81
|
+
var observableConfig = (0, _objectAssign.default)({}, newConfig, {
|
|
80
82
|
isPromiseAPI: false
|
|
81
83
|
});
|
|
82
84
|
this.observable.config(observableConfig);
|
|
@@ -112,7 +114,7 @@ assign(SanityClient.prototype, {
|
|
|
112
114
|
}, options.query);
|
|
113
115
|
}
|
|
114
116
|
|
|
115
|
-
var reqOptions = getRequestOptions(this.clientConfig,
|
|
117
|
+
var reqOptions = getRequestOptions(this.clientConfig, (0, _objectAssign.default)({}, options, {
|
|
116
118
|
url: this.getUrl(uri, useCdn)
|
|
117
119
|
}));
|
|
118
120
|
return new Observable(function (subscriber) {
|
package/lib/users/usersClient.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _objectAssign = _interopRequireDefault(require("object-assign"));
|
|
4
|
+
|
|
5
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
4
6
|
|
|
5
7
|
function UsersClient(client) {
|
|
6
8
|
this.client = client;
|
|
7
9
|
}
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
(0, _objectAssign.default)(UsersClient.prototype, {
|
|
10
12
|
getById: function getById(id) {
|
|
11
13
|
return this.client.request({
|
|
12
14
|
uri: "/users/".concat(id)
|
package/lib/util/observable.js
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
// The internal import paths here is a stop-gap measure and will become less of a problem when @sanity/client export tree-shakeable esm bundles
|
|
5
|
-
var _require = require('rxjs/internal/Observable'),
|
|
6
|
-
Observable = _require.Observable;
|
|
3
|
+
var _Observable = require("rxjs/internal/Observable");
|
|
7
4
|
|
|
8
|
-
var
|
|
9
|
-
filter = _require2.filter;
|
|
5
|
+
var _filter = require("rxjs/internal/operators/filter");
|
|
10
6
|
|
|
11
|
-
var
|
|
12
|
-
map = _require3.map;
|
|
7
|
+
var _map = require("rxjs/internal/operators/map");
|
|
13
8
|
|
|
9
|
+
// Since `@sanity/client` doesn't offer ESM exports (yet) const {filter} = require('rxjs/operators') will cause the the whole of rxjs to be included in the bundle.
|
|
10
|
+
// The internal import paths here is a stop-gap measure and will become less of a problem when @sanity/client export tree-shakeable esm bundles
|
|
14
11
|
module.exports = {
|
|
15
|
-
Observable: Observable,
|
|
16
|
-
filter: filter,
|
|
17
|
-
map: map
|
|
12
|
+
Observable: _Observable.Observable,
|
|
13
|
+
filter: _filter.filter,
|
|
14
|
+
map: _map.map
|
|
18
15
|
};
|
package/lib/warnings.js
CHANGED
package/package.json
CHANGED
|
@@ -1,22 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/client",
|
|
3
|
-
"version": "3.3.1",
|
|
3
|
+
"version": "3.3.3-esm.1",
|
|
4
4
|
"description": "Client for retrieving, creating and patching data from Sanity.io",
|
|
5
|
+
"type": "commonjs",
|
|
5
6
|
"main": "lib/sanityClient.js",
|
|
6
7
|
"umd": "umd/sanityClient.min.js",
|
|
7
8
|
"unpkg": "umd/sanityClient.min.js",
|
|
8
9
|
"types": "./sanityClient.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"source": "./src/sanityClient.js",
|
|
13
|
+
"types": "./sanityClient.d.ts",
|
|
14
|
+
"browser": "./dist/sanityClient.browser.mjs",
|
|
15
|
+
"deno": "./dist/sanityClient.browser.mjs",
|
|
16
|
+
"default": "./lib/sanityClient.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"lib",
|
|
22
|
+
"umd",
|
|
23
|
+
"sanityClient.d.ts"
|
|
24
|
+
],
|
|
9
25
|
"scripts": {
|
|
10
26
|
"browserify": "NODE_ENV=production BROWSERIFY_ENV=build DEBUG='' browserify -t envify -g uglifyify lib/sanityClient.js -o umd/sanityClient.js --standalone=SanityClient",
|
|
11
27
|
"compile": "babel -d lib src",
|
|
12
|
-
"build": "npm run compile && npm run browserify && npm run minify",
|
|
28
|
+
"build": "npm run compile && npm run browserify && npm run minify && npm run esbuild:browser",
|
|
29
|
+
"esbuild": "esbuild src/sanityClient.js --bundle --sourcemap --external:object-assign --external:rxjs --external:@sanity/eventsource --external:get-it --external:make-error",
|
|
30
|
+
"esbuild:browser": "npm run esbuild -- --format=esm --outfile=dist/sanityClient.browser.mjs --platform=browser",
|
|
13
31
|
"lint": "eslint .",
|
|
14
|
-
"clean": "rimraf lib coverage .nyc_output umd/*.js",
|
|
32
|
+
"clean": "rimraf dist lib coverage .nyc_output umd/*.js",
|
|
33
|
+
"typecheck": "tsc --lib es2015 --lib dom,es2015 --noEmit sanityClient.d.ts",
|
|
15
34
|
"coverage": "DEBUG=sanity NODE_ENV=test nyc --reporter=html --reporter=lcov --reporter=text npm test",
|
|
16
35
|
"minify": "terser -c -m -- umd/sanityClient.js > umd/sanityClient.min.js",
|
|
17
|
-
"prepublishOnly": "npm run build",
|
|
36
|
+
"prepublishOnly": "npm run clean && npm run build",
|
|
18
37
|
"test": "NODE_ENV=test tape test/*.test.js",
|
|
19
|
-
"posttest": "npm run lint"
|
|
38
|
+
"posttest": "npm run lint && npm run typecheck"
|
|
20
39
|
},
|
|
21
40
|
"browser": {
|
|
22
41
|
"./src/http/nodeMiddleware.js": "./src/http/browserMiddleware.js",
|
|
@@ -27,29 +46,31 @@
|
|
|
27
46
|
},
|
|
28
47
|
"dependencies": {
|
|
29
48
|
"@sanity/eventsource": "^4.0.0",
|
|
30
|
-
"
|
|
31
|
-
"get-it": "^6.0.1",
|
|
49
|
+
"get-it": "^6.1.1",
|
|
32
50
|
"make-error": "^1.3.0",
|
|
33
51
|
"object-assign": "^4.1.1",
|
|
34
52
|
"rxjs": "^6.0.0"
|
|
35
53
|
},
|
|
36
54
|
"devDependencies": {
|
|
37
|
-
"@babel/cli": "^7.
|
|
38
|
-
"@babel/core": "^7.
|
|
39
|
-
"@babel/preset-env": "^7.
|
|
55
|
+
"@babel/cli": "^7.18.10",
|
|
56
|
+
"@babel/core": "^7.18.10",
|
|
57
|
+
"@babel/preset-env": "^7.18.10",
|
|
58
|
+
"@types/node": "^16.11.49",
|
|
40
59
|
"browserify": "^17.0.0",
|
|
41
60
|
"envify": "^4.0.0",
|
|
42
|
-
"
|
|
61
|
+
"esbuild": "^0.15.5",
|
|
62
|
+
"eslint": "^8.21.0",
|
|
43
63
|
"eslint-config-prettier": "^8.5.0",
|
|
44
|
-
"eslint-config-sanity": "^
|
|
45
|
-
"nock": "^13.2.
|
|
64
|
+
"eslint-config-sanity": "^6.0.0",
|
|
65
|
+
"nock": "^13.2.9",
|
|
46
66
|
"nyc": "^15.1.0",
|
|
47
|
-
"prettier": "^2.
|
|
67
|
+
"prettier": "^2.7.1",
|
|
48
68
|
"rimraf": "^3.0.2",
|
|
49
69
|
"sse-channel": "^4.0.0",
|
|
50
|
-
"tape": "^5.5.
|
|
70
|
+
"tape": "^5.5.3",
|
|
51
71
|
"terser": "^5.12.1",
|
|
52
|
-
"
|
|
72
|
+
"typescript": "^4.7.4",
|
|
73
|
+
"uglifyify": "^5.0.0",
|
|
53
74
|
"xtend": "4.0.2"
|
|
54
75
|
},
|
|
55
76
|
"repository": {
|
package/sanityClient.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export type AssetMetadataType =
|
|
|
12
12
|
export type DatasetAclMode = 'public' | 'private' | 'custom'
|
|
13
13
|
export type ListenVisibility = 'sync' | 'async' | 'query'
|
|
14
14
|
export type ListenEventName = 'mutation' | 'welcome' | 'reconnect'
|
|
15
|
+
export type MutationOperation = 'create' | 'delete' | 'update' | 'none'
|
|
15
16
|
|
|
16
17
|
export interface ResponseEvent<T = unknown> {
|
|
17
18
|
type: 'response'
|
|
@@ -214,23 +215,16 @@ export type Mutation<R = any> =
|
|
|
214
215
|
export interface SingleMutationResult {
|
|
215
216
|
transactionId: string
|
|
216
217
|
documentId: string
|
|
217
|
-
results: {id: string}[]
|
|
218
|
+
results: {id: string; operation: MutationOperation}[]
|
|
218
219
|
}
|
|
219
220
|
|
|
220
221
|
export interface MultipleMutationResult {
|
|
221
222
|
transactionId: string
|
|
222
223
|
documentIds: string[]
|
|
223
|
-
results: {id: string}[]
|
|
224
|
+
results: {id: string; operation: MutationOperation}[]
|
|
224
225
|
}
|
|
225
226
|
|
|
226
|
-
export class
|
|
227
|
-
constructor(documentId: string, operations?: PatchOperations, client?: SanityClient)
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* Clones the patch
|
|
231
|
-
*/
|
|
232
|
-
clone(): Patch
|
|
233
|
-
|
|
227
|
+
export abstract class BasePatch {
|
|
234
228
|
/**
|
|
235
229
|
* DEPRECATED: Don't use.
|
|
236
230
|
* The operation is added to the current patch, ready to be commited by `commit()`
|
|
@@ -338,6 +332,20 @@ export class Patch {
|
|
|
338
332
|
*/
|
|
339
333
|
toJSON(): PatchMutationOperation
|
|
340
334
|
|
|
335
|
+
/**
|
|
336
|
+
* Clears the patch of all operations
|
|
337
|
+
*/
|
|
338
|
+
reset(): this
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
export class Patch extends BasePatch {
|
|
342
|
+
constructor(documentId: string, operations?: PatchOperations, client?: SanityClient)
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Clones the patch
|
|
346
|
+
*/
|
|
347
|
+
clone(): Patch
|
|
348
|
+
|
|
341
349
|
/**
|
|
342
350
|
* Commit the patch, returning a promise that resolves to the first patched document
|
|
343
351
|
*
|
|
@@ -372,17 +380,53 @@ export class Patch {
|
|
|
372
380
|
* @param options Options for the mutation operation
|
|
373
381
|
*/
|
|
374
382
|
commit<R = any>(options?: BaseMutationOptions): Promise<SanityDocument<R>>
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
export class ObservablePatch extends BasePatch {
|
|
386
|
+
constructor(documentId: string, operations?: PatchOperations, client?: ObservableSanityClient)
|
|
375
387
|
|
|
376
388
|
/**
|
|
377
|
-
*
|
|
389
|
+
* Clones the patch
|
|
378
390
|
*/
|
|
379
|
-
|
|
380
|
-
}
|
|
391
|
+
clone(): ObservablePatch
|
|
381
392
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
393
|
+
/**
|
|
394
|
+
* Commit the patch, returning an observable that produces the first patched document
|
|
395
|
+
*
|
|
396
|
+
* @param options Options for the mutation operation
|
|
397
|
+
*/
|
|
398
|
+
commit<R = any>(options: FirstDocumentMutationOptions): Observable<SanityDocument<R>>
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Commit the patch, returning an observable that produces an array of the mutated documents
|
|
402
|
+
*
|
|
403
|
+
* @param options Options for the mutation operation
|
|
404
|
+
*/
|
|
405
|
+
commit<R = any>(options: AllDocumentsMutationOptions): Observable<SanityDocument<R>[]>
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* Commit the patch, returning an observable that produces a mutation result object
|
|
409
|
+
*
|
|
410
|
+
* @param options Options for the mutation operation
|
|
411
|
+
*/
|
|
412
|
+
commit(options: FirstDocumentIdMutationOptions): Observable<SingleMutationResult>
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* Commit the patch, returning an observable that produces a mutation result object
|
|
416
|
+
*
|
|
417
|
+
* @param options Options for the mutation operation
|
|
418
|
+
*/
|
|
419
|
+
commit(options: AllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* Commit the patch, returning an observable that produces the first patched document
|
|
423
|
+
*
|
|
424
|
+
* @param options Options for the mutation operation
|
|
425
|
+
*/
|
|
426
|
+
commit<R = any>(options?: BaseMutationOptions): Observable<SanityDocument<R>>
|
|
427
|
+
}
|
|
385
428
|
|
|
429
|
+
export abstract class BaseTransaction {
|
|
386
430
|
/**
|
|
387
431
|
* Creates a new Sanity document. If `_id` is provided and already exists, the mutation will fail. If no `_id` is given, one will automatically be generated by the database.
|
|
388
432
|
* The operation is added to the current transaction, ready to be commited by `commit()`
|
|
@@ -451,6 +495,20 @@ export class Transaction {
|
|
|
451
495
|
*/
|
|
452
496
|
toJSON(): Mutation[]
|
|
453
497
|
|
|
498
|
+
/**
|
|
499
|
+
* Clears the transaction of all operations
|
|
500
|
+
*/
|
|
501
|
+
reset(): this
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
export class Transaction extends BaseTransaction {
|
|
505
|
+
constructor(operations?: Mutation[], client?: SanityClient, transactionId?: string)
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* Clones the transaction
|
|
509
|
+
*/
|
|
510
|
+
clone(): Transaction
|
|
511
|
+
|
|
454
512
|
/**
|
|
455
513
|
* Commit the transaction, returning a promise that resolves to the first mutated document
|
|
456
514
|
*
|
|
@@ -485,11 +543,50 @@ export class Transaction {
|
|
|
485
543
|
* @param options Options for the mutation operation
|
|
486
544
|
*/
|
|
487
545
|
commit(options?: BaseMutationOptions): Promise<MultipleMutationResult>
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
export class ObservableTransaction {
|
|
549
|
+
constructor(operations?: Mutation[], client?: ObservableSanityClient, transactionId?: string)
|
|
488
550
|
|
|
489
551
|
/**
|
|
490
|
-
*
|
|
552
|
+
* Clones the transaction
|
|
491
553
|
*/
|
|
492
|
-
|
|
554
|
+
clone(): ObservableTransaction
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* Commit the transaction, returning an observable that produces the first mutated document
|
|
558
|
+
*
|
|
559
|
+
* @param options Options for the mutation operation
|
|
560
|
+
*/
|
|
561
|
+
commit<R>(options: TransactionFirstDocumentMutationOptions): Observable<SanityDocument<R>>
|
|
562
|
+
|
|
563
|
+
/**
|
|
564
|
+
* Commit the transaction, returning an observable that produces an array of the mutated documents
|
|
565
|
+
*
|
|
566
|
+
* @param options Options for the mutation operation
|
|
567
|
+
*/
|
|
568
|
+
commit<R>(options: TransactionAllDocumentsMutationOptions): Observable<SanityDocument<R>[]>
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* Commit the transaction, returning an observable that produces a mutation result object
|
|
572
|
+
*
|
|
573
|
+
* @param options Options for the mutation operation
|
|
574
|
+
*/
|
|
575
|
+
commit(options: TransactionFirstDocumentIdMutationOptions): Observable<SingleMutationResult>
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* Commit the transaction, returning an observable that produces a mutation result object
|
|
579
|
+
*
|
|
580
|
+
* @param options Options for the mutation operation
|
|
581
|
+
*/
|
|
582
|
+
commit(options: TransactionAllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
|
|
583
|
+
|
|
584
|
+
/**
|
|
585
|
+
* Commit the transaction, returning an observable that produces a mutation result object
|
|
586
|
+
*
|
|
587
|
+
* @param options Options for the mutation operation
|
|
588
|
+
*/
|
|
589
|
+
commit(options?: BaseMutationOptions): Observable<MultipleMutationResult>
|
|
493
590
|
}
|
|
494
591
|
|
|
495
592
|
export interface ClientConfig {
|
|
@@ -1384,14 +1481,14 @@ export class ObservableSanityClient {
|
|
|
1384
1481
|
* @param documentId Document ID to patch
|
|
1385
1482
|
* @param operations Optional object of patch operations to initialize the patch instance with
|
|
1386
1483
|
*/
|
|
1387
|
-
patch(documentId: string | MutationSelection, operations?: PatchOperations):
|
|
1484
|
+
patch(documentId: string | MutationSelection, operations?: PatchOperations): ObservablePatch
|
|
1388
1485
|
|
|
1389
1486
|
/**
|
|
1390
1487
|
* Create a new transaction of mutations
|
|
1391
1488
|
*
|
|
1392
1489
|
* @param operations Optional array of mutation operations to initialize the transaction instance with
|
|
1393
1490
|
*/
|
|
1394
|
-
transaction<R = any>(operations?: Mutation<R>[]):
|
|
1491
|
+
transaction<R = any>(operations?: Mutation<R>[]): ObservableTransaction
|
|
1395
1492
|
|
|
1396
1493
|
// "Internals", should generally not be used externally
|
|
1397
1494
|
/**
|