@sanity/client 3.3.2 → 3.3.3-esm.3

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.
@@ -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 = assign({}, this.clientConfig, {
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
- assign(SanityClient.prototype, dataMethods);
69
- assign(SanityClient.prototype, {
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 assign({}, this.clientConfig);
77
+ return (0, _objectAssign.default)({}, this.clientConfig);
76
78
  }
77
79
 
78
80
  if (this.observable) {
79
- var observableConfig = assign({}, newConfig, {
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, assign({}, options, {
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) {
@@ -1,12 +1,14 @@
1
1
  "use strict";
2
2
 
3
- var assign = require('object-assign');
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
- assign(UsersClient.prototype, {
11
+ (0, _objectAssign.default)(UsersClient.prototype, {
10
12
  getById: function getById(id) {
11
13
  return this.client.request({
12
14
  uri: "/users/".concat(id)
@@ -1,18 +1,15 @@
1
1
  "use strict";
2
2
 
3
- // 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.
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 _require2 = require('rxjs/internal/operators/filter'),
9
- filter = _require2.filter;
5
+ var _filter = require("rxjs/internal/operators/filter");
10
6
 
11
- var _require3 = require('rxjs/internal/operators/map'),
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
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- var generateHelpUrl = require('@sanity/generate-help-url').generateHelpUrl;
3
+ var generateHelpUrl = require('./generateHelpUrl');
4
4
 
5
5
  var once = require('./util/once');
6
6
 
package/package.json CHANGED
@@ -1,22 +1,41 @@
1
1
  {
2
2
  "name": "@sanity/client",
3
- "version": "3.3.2",
3
+ "version": "3.3.3-esm.3",
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
- "@sanity/generate-help-url": "^3.0.0",
31
- "get-it": "^6.0.1",
49
+ "get-it": "6.1.1-esm.4",
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.17.6",
38
- "@babel/core": "^7.17.7",
39
- "@babel/preset-env": "^7.11.5",
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
- "eslint": "^8.11.0",
61
+ "esbuild": "^0.15.5",
62
+ "eslint": "^8.21.0",
43
63
  "eslint-config-prettier": "^8.5.0",
44
- "eslint-config-sanity": "^5.1.0",
45
- "nock": "^13.2.4",
64
+ "eslint-config-sanity": "^6.0.0",
65
+ "nock": "^13.2.9",
46
66
  "nyc": "^15.1.0",
47
- "prettier": "^2.6.0",
67
+ "prettier": "^2.7.1",
48
68
  "rimraf": "^3.0.2",
49
69
  "sse-channel": "^4.0.0",
50
- "tape": "^5.5.2",
70
+ "tape": "^5.5.3",
51
71
  "terser": "^5.12.1",
52
- "uglifyify": "^5.0.1",
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
@@ -224,14 +224,7 @@ export interface MultipleMutationResult {
224
224
  results: {id: string; operation: MutationOperation}[]
225
225
  }
226
226
 
227
- export class Patch {
228
- constructor(documentId: string, operations?: PatchOperations, client?: SanityClient)
229
-
230
- /**
231
- * Clones the patch
232
- */
233
- clone(): Patch
234
-
227
+ export abstract class BasePatch {
235
228
  /**
236
229
  * DEPRECATED: Don't use.
237
230
  * The operation is added to the current patch, ready to be commited by `commit()`
@@ -339,6 +332,20 @@ export class Patch {
339
332
  */
340
333
  toJSON(): PatchMutationOperation
341
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
+
342
349
  /**
343
350
  * Commit the patch, returning a promise that resolves to the first patched document
344
351
  *
@@ -373,17 +380,53 @@ export class Patch {
373
380
  * @param options Options for the mutation operation
374
381
  */
375
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)
376
387
 
377
388
  /**
378
- * Clears the patch of all operations
389
+ * Clones the patch
379
390
  */
380
- reset(): this
381
- }
391
+ clone(): ObservablePatch
382
392
 
383
- export class Transaction {
384
- constructor(operations?: Mutation[], client?: SanityClient, transactionId?: string)
385
- clone(): Transaction
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
+ }
386
428
 
429
+ export abstract class BaseTransaction {
387
430
  /**
388
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.
389
432
  * The operation is added to the current transaction, ready to be commited by `commit()`
@@ -452,6 +495,20 @@ export class Transaction {
452
495
  */
453
496
  toJSON(): Mutation[]
454
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
+
455
512
  /**
456
513
  * Commit the transaction, returning a promise that resolves to the first mutated document
457
514
  *
@@ -486,11 +543,50 @@ export class Transaction {
486
543
  * @param options Options for the mutation operation
487
544
  */
488
545
  commit(options?: BaseMutationOptions): Promise<MultipleMutationResult>
546
+ }
547
+
548
+ export class ObservableTransaction {
549
+ constructor(operations?: Mutation[], client?: ObservableSanityClient, transactionId?: string)
489
550
 
490
551
  /**
491
- * Clears the transaction of all operations
552
+ * Clones the transaction
492
553
  */
493
- reset(): this
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>
494
590
  }
495
591
 
496
592
  export interface ClientConfig {
@@ -1385,14 +1481,14 @@ export class ObservableSanityClient {
1385
1481
  * @param documentId Document ID to patch
1386
1482
  * @param operations Optional object of patch operations to initialize the patch instance with
1387
1483
  */
1388
- patch(documentId: string | MutationSelection, operations?: PatchOperations): Patch
1484
+ patch(documentId: string | MutationSelection, operations?: PatchOperations): ObservablePatch
1389
1485
 
1390
1486
  /**
1391
1487
  * Create a new transaction of mutations
1392
1488
  *
1393
1489
  * @param operations Optional array of mutation operations to initialize the transaction instance with
1394
1490
  */
1395
- transaction<R = any>(operations?: Mutation<R>[]): Transaction
1491
+ transaction<R = any>(operations?: Mutation<R>[]): ObservableTransaction
1396
1492
 
1397
1493
  // "Internals", should generally not be used externally
1398
1494
  /**