@sanity/client 5.0.0-esm.1 → 5.0.0-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.
- package/dist/index.browser.cjs +244 -170
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +244 -170
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +245 -171
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +128 -154
- package/dist/index.js +245 -171
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
- package/src/SanityClient.ts +11 -77
- package/src/auth/AuthClient.ts +13 -9
- package/src/data/dataMethods.ts +29 -4
- package/src/data/listen.ts +4 -3
- package/src/datasets/DatasetsClient.ts +73 -57
- package/src/projects/ProjectsClient.ts +37 -23
- package/src/users/UsersClient.ts +37 -28
- package/umd/sanityClient.js +244 -170
- package/umd/sanityClient.min.js +3 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/client",
|
|
3
|
-
"version": "5.0.0-esm.
|
|
3
|
+
"version": "5.0.0-esm.3",
|
|
4
4
|
"description": "Client for retrieving, creating and patching data from Sanity.io",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
},
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"author": "Sanity.io <hello@sanity.io>",
|
|
25
|
-
"type": "module",
|
|
26
25
|
"sideEffects": false,
|
|
26
|
+
"type": "module",
|
|
27
27
|
"exports": {
|
|
28
28
|
".": {
|
|
29
29
|
"types": "./dist/index.d.ts",
|
|
@@ -44,9 +44,9 @@
|
|
|
44
44
|
"./package.json": "./package.json"
|
|
45
45
|
},
|
|
46
46
|
"main": "./dist/index.cjs",
|
|
47
|
+
"unpkg": "umd/sanityClient.min.js",
|
|
47
48
|
"module": "./dist/index.js",
|
|
48
49
|
"source": "./src/index.ts",
|
|
49
|
-
"unpkg": "umd/sanityClient.min.js",
|
|
50
50
|
"browser": {
|
|
51
51
|
"./dist/index.cjs": "./dist/index.browser.cjs",
|
|
52
52
|
"./dist/index.js": "./dist/index.browser.js"
|
|
@@ -57,10 +57,6 @@
|
|
|
57
57
|
"src",
|
|
58
58
|
"umd"
|
|
59
59
|
],
|
|
60
|
-
"browserslist": [
|
|
61
|
-
"> 0.2% and supports es6-module and supports es6-module-dynamic-import and not dead and not IE 11",
|
|
62
|
-
"maintained node versions"
|
|
63
|
-
],
|
|
64
60
|
"scripts": {
|
|
65
61
|
"prebuild": "npm run clean",
|
|
66
62
|
"build": "pkg build --strict && pkg --strict && npm run rollup && npm run minify",
|
|
@@ -71,10 +67,14 @@
|
|
|
71
67
|
"prepublishOnly": "npm run build",
|
|
72
68
|
"rollup": "NODE_ENV=production rollup -c rollup.config.cjs",
|
|
73
69
|
"test": "vitest run",
|
|
70
|
+
"test:bun": "(cd runtimes/bun && bun wiptest)",
|
|
74
71
|
"test:deno": "deno test --allow-read --allow-net --allow-env --import-map=runtimes/deno/import_map.json runtimes/deno",
|
|
75
|
-
"test:edge-runtime": "npm test -- --environment edge-runtime"
|
|
76
|
-
"test:bun": "(cd runtimes/bun && bun wiptest)"
|
|
72
|
+
"test:edge-runtime": "npm test -- --environment edge-runtime"
|
|
77
73
|
},
|
|
74
|
+
"browserslist": [
|
|
75
|
+
"> 0.2% and supports es6-module and supports es6-module-dynamic-import and not dead and not IE 11",
|
|
76
|
+
"maintained node versions"
|
|
77
|
+
],
|
|
78
78
|
"prettier": {
|
|
79
79
|
"bracketSpacing": false,
|
|
80
80
|
"printWidth": 100,
|
|
@@ -83,6 +83,7 @@
|
|
|
83
83
|
},
|
|
84
84
|
"dependencies": {
|
|
85
85
|
"@sanity/eventsource": "^4.0.0",
|
|
86
|
+
"@types/node": "^18",
|
|
86
87
|
"get-it": "^8.0.1",
|
|
87
88
|
"make-error": "^1.3.6",
|
|
88
89
|
"rxjs": "^7"
|
|
@@ -96,7 +97,6 @@
|
|
|
96
97
|
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
97
98
|
"@sanity/pkg-utils": "^2.1.1",
|
|
98
99
|
"@sanity/semantic-release-preset": "^2.0.5",
|
|
99
|
-
"@types/node": "^18.11.18",
|
|
100
100
|
"@typescript-eslint/eslint-plugin": "^5.48.0",
|
|
101
101
|
"@typescript-eslint/parser": "^5.48.0",
|
|
102
102
|
"babel-plugin-add-module-exports": "^1.0.4",
|
package/src/SanityClient.ts
CHANGED
|
@@ -7,16 +7,8 @@ import * as dataMethods from './data/dataMethods'
|
|
|
7
7
|
import {_listen} from './data/listen'
|
|
8
8
|
import {ObservablePatch, Patch} from './data/patch'
|
|
9
9
|
import {ObservableTransaction, Transaction} from './data/transaction'
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
DatasetsClient,
|
|
13
|
-
ObservableDatasetsClient,
|
|
14
|
-
} from './datasets/DatasetsClient'
|
|
15
|
-
import {
|
|
16
|
-
BaseProjectsClient,
|
|
17
|
-
ObservableProjectsClient,
|
|
18
|
-
ProjectsClient,
|
|
19
|
-
} from './projects/ProjectsClient'
|
|
10
|
+
import {DatasetsClient, ObservableDatasetsClient} from './datasets/DatasetsClient'
|
|
11
|
+
import {ObservableProjectsClient, ProjectsClient} from './projects/ProjectsClient'
|
|
20
12
|
import type {
|
|
21
13
|
AllDocumentIdsMutationOptions,
|
|
22
14
|
AllDocumentsMutationOptions,
|
|
@@ -40,16 +32,12 @@ import type {
|
|
|
40
32
|
SingleMutationResult,
|
|
41
33
|
UnfilteredResponseQueryOptions,
|
|
42
34
|
} from './types'
|
|
43
|
-
import {
|
|
44
|
-
import * as validators from './validators'
|
|
35
|
+
import {ObservableUsersClient, UsersClient} from './users/UsersClient'
|
|
45
36
|
|
|
46
37
|
export type {
|
|
47
38
|
_listen,
|
|
48
39
|
AssetsClient,
|
|
49
40
|
AuthClient,
|
|
50
|
-
BaseDatasetsClient,
|
|
51
|
-
BaseProjectsClient,
|
|
52
|
-
BaseUsersClient,
|
|
53
41
|
DatasetsClient,
|
|
54
42
|
ObservableAssetsClient,
|
|
55
43
|
ObservableAuthClient,
|
|
@@ -80,9 +68,9 @@ export class ObservableSanityClient {
|
|
|
80
68
|
|
|
81
69
|
this.assets = new ObservableAssetsClient(this, this.#httpRequest)
|
|
82
70
|
this.auth = new ObservableAuthClient(this, this.#httpRequest)
|
|
83
|
-
this.datasets = new ObservableDatasetsClient(this)
|
|
84
|
-
this.projects = new ObservableProjectsClient(this)
|
|
85
|
-
this.users = new ObservableUsersClient(this)
|
|
71
|
+
this.datasets = new ObservableDatasetsClient(this, this.#httpRequest)
|
|
72
|
+
this.projects = new ObservableProjectsClient(this, this.#httpRequest)
|
|
73
|
+
this.users = new ObservableUsersClient(this, this.#httpRequest)
|
|
86
74
|
}
|
|
87
75
|
|
|
88
76
|
/**
|
|
@@ -622,33 +610,6 @@ export class ObservableSanityClient {
|
|
|
622
610
|
request<R = any>(options: RawRequestOptions): Observable<R> {
|
|
623
611
|
return dataMethods._request(this, this.#httpRequest, options)
|
|
624
612
|
}
|
|
625
|
-
|
|
626
|
-
/**
|
|
627
|
-
* DEPRECATED: Get a Sanity API URL for the URI provided
|
|
628
|
-
*
|
|
629
|
-
* @deprecated Should be an internal concern
|
|
630
|
-
* @param uri URI/path to build URL for
|
|
631
|
-
* @param canUseCdn Whether or not to allow using the API CDN for this route
|
|
632
|
-
*/
|
|
633
|
-
getUrl(uri: string, canUseCdn = false) {
|
|
634
|
-
const base = canUseCdn ? this.#clientConfig.cdnUrl : this.#clientConfig.url
|
|
635
|
-
return `${base}/${uri.replace(/^\//, '')}`
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
/**
|
|
639
|
-
* DEPRECATED: Get a Sanity API URL for the data operation and path provided
|
|
640
|
-
*
|
|
641
|
-
* @deprecated Should be an internal concern
|
|
642
|
-
* @param operation Data operation
|
|
643
|
-
* @param path Path to append
|
|
644
|
-
*/
|
|
645
|
-
getDataUrl(operation: string, path?: string): string {
|
|
646
|
-
const config = this.config()
|
|
647
|
-
const catalog = validators.hasDataset(config)
|
|
648
|
-
const baseUri = `/${operation}/${catalog}`
|
|
649
|
-
const uri = path ? `${baseUri}/${path}` : baseUri
|
|
650
|
-
return `/data${uri}`.replace(/\/($|\?)/, '$1')
|
|
651
|
-
}
|
|
652
613
|
}
|
|
653
614
|
|
|
654
615
|
export class SanityClient {
|
|
@@ -675,17 +636,17 @@ export class SanityClient {
|
|
|
675
636
|
listen = _listen
|
|
676
637
|
|
|
677
638
|
constructor(httpRequest: HttpRequest, config: ClientConfig) {
|
|
639
|
+
this.observable = new ObservableSanityClient(httpRequest, config)
|
|
640
|
+
|
|
678
641
|
this.config(config)
|
|
679
642
|
|
|
680
643
|
this.#httpRequest = httpRequest
|
|
681
644
|
|
|
682
645
|
this.assets = new AssetsClient(this, this.#httpRequest)
|
|
683
646
|
this.auth = new AuthClient(this, this.#httpRequest)
|
|
684
|
-
this.datasets = new DatasetsClient(this)
|
|
685
|
-
this.projects = new ProjectsClient(this)
|
|
686
|
-
this.users = new UsersClient(this)
|
|
687
|
-
|
|
688
|
-
this.observable = new ObservableSanityClient(httpRequest, this.config())
|
|
647
|
+
this.datasets = new DatasetsClient(this, this.#httpRequest)
|
|
648
|
+
this.projects = new ProjectsClient(this, this.#httpRequest)
|
|
649
|
+
this.users = new UsersClient(this, this.#httpRequest)
|
|
689
650
|
}
|
|
690
651
|
|
|
691
652
|
/**
|
|
@@ -1245,31 +1206,4 @@ export class SanityClient {
|
|
|
1245
1206
|
dataRequest(endpoint: string, body: unknown, options?: BaseMutationOptions): Promise<any> {
|
|
1246
1207
|
return lastValueFrom(dataMethods._dataRequest(this, this.#httpRequest, endpoint, body, options))
|
|
1247
1208
|
}
|
|
1248
|
-
|
|
1249
|
-
/**
|
|
1250
|
-
* DEPRECATED: Get a Sanity API URL for the URI provided
|
|
1251
|
-
*
|
|
1252
|
-
* @deprecated Should be an internal concern
|
|
1253
|
-
* @param uri URI/path to build URL for
|
|
1254
|
-
* @param canUseCdn Whether or not to allow using the API CDN for this route
|
|
1255
|
-
*/
|
|
1256
|
-
getUrl(uri: string, canUseCdn = false) {
|
|
1257
|
-
const base = canUseCdn ? this.#clientConfig.cdnUrl : this.#clientConfig.url
|
|
1258
|
-
return `${base}/${uri.replace(/^\//, '')}`
|
|
1259
|
-
}
|
|
1260
|
-
|
|
1261
|
-
/**
|
|
1262
|
-
* DEPRECATED: Get a Sanity API URL for the data operation and path provided
|
|
1263
|
-
*
|
|
1264
|
-
* @deprecated Should be an internal concern
|
|
1265
|
-
* @param operation Data operation
|
|
1266
|
-
* @param path Path to append
|
|
1267
|
-
*/
|
|
1268
|
-
getDataUrl(operation: string, path?: string): string {
|
|
1269
|
-
const config = this.config()
|
|
1270
|
-
const catalog = validators.hasDataset(config)
|
|
1271
|
-
const baseUri = `/${operation}/${catalog}`
|
|
1272
|
-
const uri = path ? `${baseUri}/${path}` : baseUri
|
|
1273
|
-
return `/data${uri}`.replace(/\/($|\?)/, '$1')
|
|
1274
|
-
}
|
|
1275
1209
|
}
|
package/src/auth/AuthClient.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {type Observable, lastValueFrom} from 'rxjs'
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import {_request} from '../data/dataMethods'
|
|
4
4
|
import type {ObservableSanityClient, SanityClient} from '../SanityClient'
|
|
5
5
|
import type {AuthProviderResponse, HttpRequest} from '../types'
|
|
6
6
|
|
|
@@ -15,15 +15,17 @@ export class ObservableAuthClient {
|
|
|
15
15
|
/**
|
|
16
16
|
* Fetch available login providers
|
|
17
17
|
*/
|
|
18
|
-
getLoginProviders
|
|
19
|
-
return
|
|
18
|
+
getLoginProviders(): Observable<AuthProviderResponse> {
|
|
19
|
+
return _request<AuthProviderResponse>(this.#client, this.#httpRequest, {
|
|
20
|
+
uri: '/auth/providers',
|
|
21
|
+
})
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
/**
|
|
23
25
|
* Revoke the configured session/token
|
|
24
26
|
*/
|
|
25
|
-
logout
|
|
26
|
-
return
|
|
27
|
+
logout(): Observable<void> {
|
|
28
|
+
return _request<void>(this.#client, this.#httpRequest, {
|
|
27
29
|
uri: '/auth/logout',
|
|
28
30
|
method: 'POST',
|
|
29
31
|
})
|
|
@@ -41,18 +43,20 @@ export class AuthClient {
|
|
|
41
43
|
/**
|
|
42
44
|
* Fetch available login providers
|
|
43
45
|
*/
|
|
44
|
-
getLoginProviders
|
|
46
|
+
getLoginProviders(): Promise<AuthProviderResponse> {
|
|
45
47
|
return lastValueFrom(
|
|
46
|
-
|
|
48
|
+
_request<AuthProviderResponse>(this.#client, this.#httpRequest, {
|
|
49
|
+
uri: '/auth/providers',
|
|
50
|
+
})
|
|
47
51
|
)
|
|
48
52
|
}
|
|
49
53
|
|
|
50
54
|
/**
|
|
51
55
|
* Revoke the configured session/token
|
|
52
56
|
*/
|
|
53
|
-
logout
|
|
57
|
+
logout(): Promise<void> {
|
|
54
58
|
return lastValueFrom(
|
|
55
|
-
|
|
59
|
+
_request<void>(this.#client, this.#httpRequest, {
|
|
56
60
|
uri: '/auth/logout',
|
|
57
61
|
method: 'POST',
|
|
58
62
|
})
|
package/src/data/dataMethods.ts
CHANGED
|
@@ -79,7 +79,7 @@ export function _getDocument<R extends Record<string, any>>(
|
|
|
79
79
|
id: string,
|
|
80
80
|
opts: {tag?: string} = {}
|
|
81
81
|
): Observable<SanityDocument<R> | undefined> {
|
|
82
|
-
const options = {uri: client
|
|
82
|
+
const options = {uri: _getDataUrl(client, 'doc', id), json: true, tag: opts.tag}
|
|
83
83
|
return _requestObservable<SanityDocument<R> | undefined>(client, httpRequest, options).pipe(
|
|
84
84
|
filter(isResponse),
|
|
85
85
|
map((event) => event.body.documents && event.body.documents[0])
|
|
@@ -93,7 +93,7 @@ export function _getDocuments<R extends Record<string, any>>(
|
|
|
93
93
|
ids: string[],
|
|
94
94
|
opts: {tag?: string} = {}
|
|
95
95
|
): Observable<(SanityDocument<R> | null)[]> {
|
|
96
|
-
const options = {uri: client
|
|
96
|
+
const options = {uri: _getDataUrl(client, 'doc', ids.join(',')), json: true, tag: opts.tag}
|
|
97
97
|
return _requestObservable<(SanityDocument<R> | null)[]>(client, httpRequest, options).pipe(
|
|
98
98
|
filter(isResponse),
|
|
99
99
|
map((event: any) => {
|
|
@@ -210,7 +210,7 @@ export function _dataRequest(
|
|
|
210
210
|
const returnFirst = options.returnFirst
|
|
211
211
|
const {timeout, token, tag, headers} = options
|
|
212
212
|
|
|
213
|
-
const uri = client
|
|
213
|
+
const uri = _getDataUrl(client, endpoint, stringQuery)
|
|
214
214
|
|
|
215
215
|
const reqOptions = {
|
|
216
216
|
method: useGet ? 'GET' : 'POST',
|
|
@@ -302,7 +302,7 @@ export function _requestObservable<R>(
|
|
|
302
302
|
const reqOptions = getRequestOptions(
|
|
303
303
|
config,
|
|
304
304
|
Object.assign({}, options, {
|
|
305
|
-
url: client
|
|
305
|
+
url: _getUrl(client, uri, useCdn),
|
|
306
306
|
})
|
|
307
307
|
) as RequestOptions
|
|
308
308
|
|
|
@@ -326,3 +326,28 @@ export function _request<R>(
|
|
|
326
326
|
|
|
327
327
|
return observable
|
|
328
328
|
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* @internal
|
|
332
|
+
*/
|
|
333
|
+
export function _getDataUrl(
|
|
334
|
+
client: SanityClient | ObservableSanityClient,
|
|
335
|
+
operation: string,
|
|
336
|
+
path?: string
|
|
337
|
+
): string {
|
|
338
|
+
const config = client.config()
|
|
339
|
+
const catalog = validators.hasDataset(config)
|
|
340
|
+
const baseUri = `/${operation}/${catalog}`
|
|
341
|
+
const uri = path ? `${baseUri}/${path}` : baseUri
|
|
342
|
+
return `/data${uri}`.replace(/\/($|\?)/, '$1')
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
function _getUrl(
|
|
346
|
+
client: SanityClient | ObservableSanityClient,
|
|
347
|
+
uri: string,
|
|
348
|
+
canUseCdn = false
|
|
349
|
+
): string {
|
|
350
|
+
const {url, cdnUrl} = client.config()
|
|
351
|
+
const base = canUseCdn ? cdnUrl : url
|
|
352
|
+
return `${base}/${uri.replace(/^\//, '')}`
|
|
353
|
+
}
|
package/src/data/listen.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import polyfilledEventSource from '@sanity/eventsource'
|
|
2
2
|
import {Observable} from 'rxjs'
|
|
3
3
|
|
|
4
|
-
import type {
|
|
4
|
+
import type {SanityClient} from '../SanityClient'
|
|
5
5
|
import type {ListenEvent, ListenOptions, MutationEvent, QueryParams} from '../types'
|
|
6
6
|
import defaults from '../util/defaults'
|
|
7
7
|
import pick from '../util/pick'
|
|
8
|
+
import {_getDataUrl} from './dataMethods'
|
|
8
9
|
import encodeQueryString from './encodeQueryString'
|
|
9
10
|
|
|
10
11
|
// Limit is 16K for a _request_, eg including headers. Have to account for an
|
|
@@ -54,7 +55,7 @@ export function _listen<R extends Record<string, any> = Record<string, any>>(
|
|
|
54
55
|
): Observable<ListenEvent<R>>
|
|
55
56
|
/** @internal */
|
|
56
57
|
export function _listen<R extends Record<string, any> = Record<string, any>>(
|
|
57
|
-
this: SanityClient
|
|
58
|
+
this: SanityClient,
|
|
58
59
|
query: string,
|
|
59
60
|
params?: QueryParams,
|
|
60
61
|
opts: ListenOptions = {}
|
|
@@ -65,7 +66,7 @@ export function _listen<R extends Record<string, any> = Record<string, any>>(
|
|
|
65
66
|
const listenOpts = pick(options, possibleOptions)
|
|
66
67
|
const qs = encodeQueryString({query, params, options: {tag, ...listenOpts}})
|
|
67
68
|
|
|
68
|
-
const uri = `${url}${this
|
|
69
|
+
const uri = `${url}${_getDataUrl(this, 'listen', qs)}`
|
|
69
70
|
if (uri.length > MAX_URL_LENGTH) {
|
|
70
71
|
return new Observable((observer) => observer.error(new Error('Query too large for listener')))
|
|
71
72
|
}
|
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
import {type Observable} from 'rxjs'
|
|
1
|
+
import {type Observable, lastValueFrom} from 'rxjs'
|
|
2
2
|
|
|
3
|
+
import {_request} from '../data/dataMethods'
|
|
3
4
|
import type {ObservableSanityClient, SanityClient} from '../SanityClient'
|
|
4
|
-
import type {DatasetAclMode, DatasetResponse, DatasetsResponse} from '../types'
|
|
5
|
+
import type {DatasetAclMode, DatasetResponse, DatasetsResponse, HttpRequest} from '../types'
|
|
5
6
|
import * as validate from '../validators'
|
|
6
7
|
|
|
7
|
-
export class
|
|
8
|
-
client:
|
|
8
|
+
export class ObservableDatasetsClient {
|
|
9
|
+
#client: ObservableSanityClient
|
|
10
|
+
#httpRequest: HttpRequest
|
|
11
|
+
constructor(client: ObservableSanityClient, httpRequest: HttpRequest) {
|
|
12
|
+
this.#client = client
|
|
13
|
+
this.#httpRequest = httpRequest
|
|
14
|
+
}
|
|
9
15
|
|
|
10
16
|
/**
|
|
11
17
|
* Create a new dataset with the given name
|
|
@@ -13,21 +19,8 @@ export class BaseDatasetsClient {
|
|
|
13
19
|
* @param name - Name of the dataset to create
|
|
14
20
|
* @param options - Options for the dataset
|
|
15
21
|
*/
|
|
16
|
-
create(
|
|
17
|
-
this
|
|
18
|
-
name: string,
|
|
19
|
-
options?: {aclMode?: DatasetAclMode}
|
|
20
|
-
): Promise<DatasetResponse>
|
|
21
|
-
create(
|
|
22
|
-
this: ObservableDatasetsClient,
|
|
23
|
-
name: string,
|
|
24
|
-
options?: {aclMode?: DatasetAclMode}
|
|
25
|
-
): Observable<DatasetResponse>
|
|
26
|
-
create(
|
|
27
|
-
name: string,
|
|
28
|
-
options?: {aclMode?: DatasetAclMode}
|
|
29
|
-
): Promise<DatasetResponse> | Observable<DatasetResponse> {
|
|
30
|
-
return this.#_modify('PUT', name, options)
|
|
22
|
+
create(name: string, options?: {aclMode?: DatasetAclMode}): Observable<DatasetResponse> {
|
|
23
|
+
return _modify<DatasetResponse>(this.#client, this.#httpRequest, 'PUT', name, options)
|
|
31
24
|
}
|
|
32
25
|
|
|
33
26
|
/**
|
|
@@ -36,21 +29,8 @@ export class BaseDatasetsClient {
|
|
|
36
29
|
* @param name - Name of the dataset to edit
|
|
37
30
|
* @param options - New options for the dataset
|
|
38
31
|
*/
|
|
39
|
-
edit(
|
|
40
|
-
this
|
|
41
|
-
name: string,
|
|
42
|
-
options?: {aclMode?: DatasetAclMode}
|
|
43
|
-
): Promise<DatasetResponse>
|
|
44
|
-
edit(
|
|
45
|
-
this: ObservableDatasetsClient,
|
|
46
|
-
name: string,
|
|
47
|
-
options?: {aclMode?: DatasetAclMode}
|
|
48
|
-
): Observable<DatasetResponse>
|
|
49
|
-
edit(
|
|
50
|
-
name: string,
|
|
51
|
-
options?: {aclMode?: DatasetAclMode}
|
|
52
|
-
): Promise<DatasetResponse> | Observable<DatasetResponse> {
|
|
53
|
-
return this.#_modify('PATCH', name, options)
|
|
32
|
+
edit(name: string, options?: {aclMode?: DatasetAclMode}): Observable<DatasetResponse> {
|
|
33
|
+
return _modify<DatasetResponse>(this.#client, this.#httpRequest, 'PATCH', name, options)
|
|
54
34
|
}
|
|
55
35
|
|
|
56
36
|
/**
|
|
@@ -58,40 +38,76 @@ export class BaseDatasetsClient {
|
|
|
58
38
|
*
|
|
59
39
|
* @param name - Name of the dataset to delete
|
|
60
40
|
*/
|
|
61
|
-
delete(
|
|
62
|
-
|
|
63
|
-
delete(name: string): Promise<{deleted: true}> | Observable<{deleted: true}> {
|
|
64
|
-
return this.#_modify('DELETE', name)
|
|
41
|
+
delete(name: string): Observable<{deleted: true}> {
|
|
42
|
+
return _modify<{deleted: true}>(this.#client, this.#httpRequest, 'DELETE', name)
|
|
65
43
|
}
|
|
66
44
|
|
|
67
45
|
/**
|
|
68
46
|
* Fetch a list of datasets for the configured project
|
|
69
47
|
*/
|
|
70
|
-
list(
|
|
71
|
-
|
|
72
|
-
list(): Promise<DatasetsResponse> | Observable<DatasetsResponse> {
|
|
73
|
-
return this.client.request({uri: '/datasets'})
|
|
48
|
+
list(): Observable<DatasetsResponse> {
|
|
49
|
+
return _request<DatasetsResponse>(this.#client, this.#httpRequest, {uri: '/datasets'})
|
|
74
50
|
}
|
|
51
|
+
}
|
|
75
52
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
53
|
+
export class DatasetsClient {
|
|
54
|
+
#client: SanityClient
|
|
55
|
+
#httpRequest: HttpRequest
|
|
56
|
+
constructor(client: SanityClient, httpRequest: HttpRequest) {
|
|
57
|
+
this.#client = client
|
|
58
|
+
this.#httpRequest = httpRequest
|
|
79
59
|
}
|
|
80
|
-
}
|
|
81
60
|
|
|
82
|
-
|
|
83
|
-
|
|
61
|
+
/**
|
|
62
|
+
* Create a new dataset with the given name
|
|
63
|
+
*
|
|
64
|
+
* @param name - Name of the dataset to create
|
|
65
|
+
* @param options - Options for the dataset
|
|
66
|
+
*/
|
|
67
|
+
create(name: string, options?: {aclMode?: DatasetAclMode}): Promise<DatasetResponse> {
|
|
68
|
+
return lastValueFrom(
|
|
69
|
+
_modify<DatasetResponse>(this.#client, this.#httpRequest, 'PUT', name, options)
|
|
70
|
+
)
|
|
71
|
+
}
|
|
84
72
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
73
|
+
/**
|
|
74
|
+
* Edit a dataset with the given name
|
|
75
|
+
*
|
|
76
|
+
* @param name - Name of the dataset to edit
|
|
77
|
+
* @param options - New options for the dataset
|
|
78
|
+
*/
|
|
79
|
+
edit(name: string, options?: {aclMode?: DatasetAclMode}): Promise<DatasetResponse> {
|
|
80
|
+
return lastValueFrom(
|
|
81
|
+
_modify<DatasetResponse>(this.#client, this.#httpRequest, 'PATCH', name, options)
|
|
82
|
+
)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Delete a dataset with the given name
|
|
87
|
+
*
|
|
88
|
+
* @param name - Name of the dataset to delete
|
|
89
|
+
*/
|
|
90
|
+
delete(name: string): Promise<{deleted: true}> {
|
|
91
|
+
return lastValueFrom(_modify<{deleted: true}>(this.#client, this.#httpRequest, 'DELETE', name))
|
|
88
92
|
}
|
|
89
|
-
}
|
|
90
93
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
94
|
+
/**
|
|
95
|
+
* Fetch a list of datasets for the configured project
|
|
96
|
+
*/
|
|
97
|
+
list(): Promise<DatasetsResponse> {
|
|
98
|
+
return lastValueFrom(
|
|
99
|
+
_request<DatasetsResponse>(this.#client, this.#httpRequest, {uri: '/datasets'})
|
|
100
|
+
)
|
|
96
101
|
}
|
|
97
102
|
}
|
|
103
|
+
|
|
104
|
+
function _modify<R = unknown>(
|
|
105
|
+
client: SanityClient | ObservableSanityClient,
|
|
106
|
+
httpRequest: HttpRequest,
|
|
107
|
+
method: 'DELETE' | 'PATCH' | 'PUT',
|
|
108
|
+
name: string,
|
|
109
|
+
options?: {aclMode?: DatasetAclMode}
|
|
110
|
+
) {
|
|
111
|
+
validate.dataset(name)
|
|
112
|
+
return _request<R>(client, httpRequest, {method, uri: `/datasets/${name}`, body: options})
|
|
113
|
+
}
|
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
import {type Observable} from 'rxjs'
|
|
1
|
+
import {type Observable, lastValueFrom} from 'rxjs'
|
|
2
2
|
|
|
3
|
+
import {_request} from '../data/dataMethods'
|
|
3
4
|
import type {ObservableSanityClient, SanityClient} from '../SanityClient'
|
|
4
|
-
import type {SanityProject} from '../types'
|
|
5
|
+
import type {HttpRequest, SanityProject} from '../types'
|
|
5
6
|
|
|
6
|
-
export class
|
|
7
|
-
client:
|
|
7
|
+
export class ObservableProjectsClient {
|
|
8
|
+
#client: ObservableSanityClient
|
|
9
|
+
#httpRequest: HttpRequest
|
|
10
|
+
constructor(client: ObservableSanityClient, httpRequest: HttpRequest) {
|
|
11
|
+
this.#client = client
|
|
12
|
+
this.#httpRequest = httpRequest
|
|
13
|
+
}
|
|
8
14
|
|
|
9
15
|
/**
|
|
10
16
|
* Fetch a list of projects the authenticated user has access to
|
|
11
17
|
*/
|
|
12
|
-
list(
|
|
13
|
-
|
|
14
|
-
list(): Promise<SanityProject[]> | Observable<SanityProject[]> {
|
|
15
|
-
return this.client.request({uri: '/projects'})
|
|
18
|
+
list(): Observable<SanityProject[]> {
|
|
19
|
+
return _request<SanityProject[]>(this.#client, this.#httpRequest, {uri: '/projects'})
|
|
16
20
|
}
|
|
17
21
|
|
|
18
22
|
/**
|
|
@@ -20,26 +24,36 @@ export class BaseProjectsClient {
|
|
|
20
24
|
*
|
|
21
25
|
* @param projectId - ID of the project to fetch
|
|
22
26
|
*/
|
|
23
|
-
getById(
|
|
24
|
-
|
|
25
|
-
getById(projectId: string): Promise<SanityProject> | Observable<SanityProject> {
|
|
26
|
-
return this.client.request({uri: `/projects/${projectId}`})
|
|
27
|
+
getById(projectId: string): Observable<SanityProject> {
|
|
28
|
+
return _request<SanityProject>(this.#client, this.#httpRequest, {uri: `/projects/${projectId}`})
|
|
27
29
|
}
|
|
28
30
|
}
|
|
29
31
|
|
|
30
|
-
export class
|
|
31
|
-
client:
|
|
32
|
+
export class ProjectsClient {
|
|
33
|
+
#client: SanityClient
|
|
34
|
+
#httpRequest: HttpRequest
|
|
35
|
+
constructor(client: SanityClient, httpRequest: HttpRequest) {
|
|
36
|
+
this.#client = client
|
|
37
|
+
this.#httpRequest = httpRequest
|
|
38
|
+
}
|
|
32
39
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Fetch a list of projects the authenticated user has access to
|
|
42
|
+
*/
|
|
43
|
+
list(): Promise<SanityProject[]> {
|
|
44
|
+
return lastValueFrom(
|
|
45
|
+
_request<SanityProject[]>(this.#client, this.#httpRequest, {uri: '/projects'})
|
|
46
|
+
)
|
|
36
47
|
}
|
|
37
|
-
}
|
|
38
48
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
49
|
+
/**
|
|
50
|
+
* Fetch a project by project ID
|
|
51
|
+
*
|
|
52
|
+
* @param projectId - ID of the project to fetch
|
|
53
|
+
*/
|
|
54
|
+
getById(projectId: string): Promise<SanityProject> {
|
|
55
|
+
return lastValueFrom(
|
|
56
|
+
_request<SanityProject>(this.#client, this.#httpRequest, {uri: `/projects/${projectId}`})
|
|
57
|
+
)
|
|
44
58
|
}
|
|
45
59
|
}
|