@sanity/client 5.0.0-esm.13 → 5.0.0-esm.15
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 +60 -1
- package/dist/index.browser.cjs +75 -154
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +75 -154
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +76 -155
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +44 -50
- package/dist/index.js +76 -155
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/SanityClient.ts +21 -23
- package/src/assets/AssetsClient.ts +28 -4
- package/src/data/dataMethods.ts +2 -2
- package/src/data/encodeQueryString.ts +15 -14
- package/src/data/patch.ts +0 -12
- package/umd/sanityClient.js +100 -179
- package/umd/sanityClient.min.js +3 -3
- package/src/auth/AuthClient.ts +0 -67
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.15",
|
|
4
4
|
"description": "Client for retrieving, creating and patching data from Sanity.io",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -94,8 +94,8 @@
|
|
|
94
94
|
"rxjs": "^7"
|
|
95
95
|
},
|
|
96
96
|
"devDependencies": {
|
|
97
|
-
"@edge-runtime/types": "^2.0.
|
|
98
|
-
"@edge-runtime/vm": "^2.0.
|
|
97
|
+
"@edge-runtime/types": "^2.0.3",
|
|
98
|
+
"@edge-runtime/vm": "^2.0.3",
|
|
99
99
|
"@rollup/plugin-commonjs": "^24.0.0",
|
|
100
100
|
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
101
101
|
"@sanity/pkg-utils": "^2.2.1",
|
|
@@ -113,7 +113,7 @@
|
|
|
113
113
|
"nock": "^13.3.0",
|
|
114
114
|
"prettier": "^2.8.3",
|
|
115
115
|
"prettier-plugin-packagejson": "^2.4.0",
|
|
116
|
-
"rimraf": "^4.1.
|
|
116
|
+
"rimraf": "^4.1.1",
|
|
117
117
|
"rollup": "^3.10.0",
|
|
118
118
|
"sse-channel": "^4.0.0",
|
|
119
119
|
"terser": "^5.16.1",
|
|
@@ -122,6 +122,6 @@
|
|
|
122
122
|
"vitest-github-actions-reporter": "^0.9.0"
|
|
123
123
|
},
|
|
124
124
|
"engines": {
|
|
125
|
-
"node": ">=14"
|
|
125
|
+
"node": ">=14.18"
|
|
126
126
|
}
|
|
127
127
|
}
|
package/src/SanityClient.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {lastValueFrom, Observable} from 'rxjs'
|
|
2
2
|
|
|
3
3
|
import {AssetsClient, ObservableAssetsClient} from './assets/AssetsClient'
|
|
4
|
-
import {AuthClient, ObservableAuthClient} from './auth/AuthClient'
|
|
5
4
|
import {defaultConfig, initConfig} from './config'
|
|
6
5
|
import * as dataMethods from './data/dataMethods'
|
|
7
6
|
import {_listen} from './data/listen'
|
|
@@ -39,10 +38,8 @@ import {ObservableUsersClient, UsersClient} from './users/UsersClient'
|
|
|
39
38
|
export type {
|
|
40
39
|
_listen,
|
|
41
40
|
AssetsClient,
|
|
42
|
-
AuthClient,
|
|
43
41
|
DatasetsClient,
|
|
44
42
|
ObservableAssetsClient,
|
|
45
|
-
ObservableAuthClient,
|
|
46
43
|
ObservableDatasetsClient,
|
|
47
44
|
ObservableProjectsClient,
|
|
48
45
|
ObservableUsersClient,
|
|
@@ -53,7 +50,6 @@ export type {
|
|
|
53
50
|
/** @public */
|
|
54
51
|
export class ObservableSanityClient {
|
|
55
52
|
assets: ObservableAssetsClient
|
|
56
|
-
auth: ObservableAuthClient
|
|
57
53
|
datasets: ObservableDatasetsClient
|
|
58
54
|
projects: ObservableProjectsClient
|
|
59
55
|
users: ObservableUsersClient
|
|
@@ -64,13 +60,17 @@ export class ObservableSanityClient {
|
|
|
64
60
|
#clientConfig: InitializedClientConfig
|
|
65
61
|
#httpRequest: HttpRequest
|
|
66
62
|
|
|
63
|
+
/**
|
|
64
|
+
* Instance properties
|
|
65
|
+
*/
|
|
66
|
+
listen = _listen
|
|
67
|
+
|
|
67
68
|
constructor(httpRequest: HttpRequest, config: ClientConfig = defaultConfig) {
|
|
68
69
|
this.config(config)
|
|
69
70
|
|
|
70
71
|
this.#httpRequest = httpRequest
|
|
71
72
|
|
|
72
73
|
this.assets = new ObservableAssetsClient(this, this.#httpRequest)
|
|
73
|
-
this.auth = new ObservableAuthClient(this, this.#httpRequest)
|
|
74
74
|
this.datasets = new ObservableDatasetsClient(this, this.#httpRequest)
|
|
75
75
|
this.projects = new ObservableProjectsClient(this, this.#httpRequest)
|
|
76
76
|
this.users = new ObservableUsersClient(this, this.#httpRequest)
|
|
@@ -127,7 +127,7 @@ export class ObservableSanityClient {
|
|
|
127
127
|
* @param query - GROQ-query to perform
|
|
128
128
|
* @param params - Query parameters
|
|
129
129
|
*/
|
|
130
|
-
fetch<R = FIXME>(query: string, params:
|
|
130
|
+
fetch<R = FIXME, Q = QueryParams>(query: string, params: Q): Observable<R>
|
|
131
131
|
/**
|
|
132
132
|
* Perform a GROQ-query against the configured dataset.
|
|
133
133
|
*
|
|
@@ -135,9 +135,9 @@ export class ObservableSanityClient {
|
|
|
135
135
|
* @param params - Query parameters
|
|
136
136
|
* @param options - Request options
|
|
137
137
|
*/
|
|
138
|
-
fetch<R = FIXME>(
|
|
138
|
+
fetch<R = FIXME, Q = QueryParams>(
|
|
139
139
|
query: string,
|
|
140
|
-
params:
|
|
140
|
+
params: Q | undefined,
|
|
141
141
|
options: FilteredResponseQueryOptions
|
|
142
142
|
): Observable<R>
|
|
143
143
|
/**
|
|
@@ -147,17 +147,17 @@ export class ObservableSanityClient {
|
|
|
147
147
|
* @param params - Query parameters
|
|
148
148
|
* @param options - Request options
|
|
149
149
|
*/
|
|
150
|
-
fetch<R = FIXME>(
|
|
150
|
+
fetch<R = FIXME, Q = QueryParams>(
|
|
151
151
|
query: string,
|
|
152
|
-
params:
|
|
152
|
+
params: Q | undefined,
|
|
153
153
|
options: UnfilteredResponseQueryOptions
|
|
154
154
|
): Observable<RawQueryResponse<R>>
|
|
155
|
-
fetch<R
|
|
155
|
+
fetch<R, Q extends QueryParams>(
|
|
156
156
|
query: string,
|
|
157
|
-
params?:
|
|
157
|
+
params?: Q,
|
|
158
158
|
options: FilteredResponseQueryOptions | UnfilteredResponseQueryOptions = {}
|
|
159
159
|
): Observable<RawQueryResponse<R> | R> {
|
|
160
|
-
return dataMethods._fetch<R>(this, this.#httpRequest, query, params, options)
|
|
160
|
+
return dataMethods._fetch<R, Q>(this, this.#httpRequest, query, params, options)
|
|
161
161
|
}
|
|
162
162
|
|
|
163
163
|
/**
|
|
@@ -618,7 +618,6 @@ export class ObservableSanityClient {
|
|
|
618
618
|
/** @public */
|
|
619
619
|
export class SanityClient {
|
|
620
620
|
assets: AssetsClient
|
|
621
|
-
auth: AuthClient
|
|
622
621
|
datasets: DatasetsClient
|
|
623
622
|
projects: ProjectsClient
|
|
624
623
|
users: UsersClient
|
|
@@ -645,7 +644,6 @@ export class SanityClient {
|
|
|
645
644
|
this.#httpRequest = httpRequest
|
|
646
645
|
|
|
647
646
|
this.assets = new AssetsClient(this, this.#httpRequest)
|
|
648
|
-
this.auth = new AuthClient(this, this.#httpRequest)
|
|
649
647
|
this.datasets = new DatasetsClient(this, this.#httpRequest)
|
|
650
648
|
this.projects = new ProjectsClient(this, this.#httpRequest)
|
|
651
649
|
this.users = new UsersClient(this, this.#httpRequest)
|
|
@@ -708,7 +706,7 @@ export class SanityClient {
|
|
|
708
706
|
* @param query - GROQ-query to perform
|
|
709
707
|
* @param params - Optional query parameters
|
|
710
708
|
*/
|
|
711
|
-
fetch<R = FIXME>(query: string, params:
|
|
709
|
+
fetch<R = FIXME, Q = QueryParams>(query: string, params: Q): Promise<R>
|
|
712
710
|
/**
|
|
713
711
|
* Perform a GROQ-query against the configured dataset.
|
|
714
712
|
*
|
|
@@ -716,9 +714,9 @@ export class SanityClient {
|
|
|
716
714
|
* @param params - Optional query parameters
|
|
717
715
|
* @param options - Request options
|
|
718
716
|
*/
|
|
719
|
-
fetch<R = FIXME>(
|
|
717
|
+
fetch<R = FIXME, Q = QueryParams>(
|
|
720
718
|
query: string,
|
|
721
|
-
params:
|
|
719
|
+
params: Q | undefined,
|
|
722
720
|
options: FilteredResponseQueryOptions
|
|
723
721
|
): Promise<R>
|
|
724
722
|
/**
|
|
@@ -728,17 +726,17 @@ export class SanityClient {
|
|
|
728
726
|
* @param params - Optional query parameters
|
|
729
727
|
* @param options - Request options
|
|
730
728
|
*/
|
|
731
|
-
fetch<R = FIXME>(
|
|
729
|
+
fetch<R = FIXME, Q = QueryParams>(
|
|
732
730
|
query: string,
|
|
733
|
-
params:
|
|
731
|
+
params: Q | undefined,
|
|
734
732
|
options: UnfilteredResponseQueryOptions
|
|
735
733
|
): Promise<RawQueryResponse<R>>
|
|
736
|
-
fetch<R
|
|
734
|
+
fetch<R, Q extends QueryParams>(
|
|
737
735
|
query: string,
|
|
738
|
-
params?:
|
|
736
|
+
params?: Q,
|
|
739
737
|
options: FilteredResponseQueryOptions | UnfilteredResponseQueryOptions = {}
|
|
740
738
|
): Promise<RawQueryResponse<R> | R> {
|
|
741
|
-
return lastValueFrom(dataMethods._fetch<R>(this, this.#httpRequest, query, params, options))
|
|
739
|
+
return lastValueFrom(dataMethods._fetch<R, Q>(this, this.#httpRequest, query, params, options))
|
|
742
740
|
}
|
|
743
741
|
|
|
744
742
|
/**
|
|
@@ -26,7 +26,7 @@ export class ObservableAssetsClient {
|
|
|
26
26
|
/**
|
|
27
27
|
* Uploads a file asset to the configured dataset
|
|
28
28
|
*
|
|
29
|
-
* @param assetType - Asset type (file
|
|
29
|
+
* @param assetType - Asset type (file)
|
|
30
30
|
* @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
|
|
31
31
|
* @param options - Options to use for the upload
|
|
32
32
|
*/
|
|
@@ -39,7 +39,7 @@ export class ObservableAssetsClient {
|
|
|
39
39
|
/**
|
|
40
40
|
* Uploads an image asset to the configured dataset
|
|
41
41
|
*
|
|
42
|
-
* @param assetType - Asset type (
|
|
42
|
+
* @param assetType - Asset type (image)
|
|
43
43
|
* @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
|
|
44
44
|
* @param options - Options to use for the upload
|
|
45
45
|
*/
|
|
@@ -48,6 +48,18 @@ export class ObservableAssetsClient {
|
|
|
48
48
|
body: File | Blob | Buffer | NodeJS.ReadableStream,
|
|
49
49
|
options?: UploadClientConfig
|
|
50
50
|
): Observable<HttpRequestEvent<{document: SanityImageAssetDocument}>>
|
|
51
|
+
/**
|
|
52
|
+
* Uploads a file or an image asset to the configured dataset
|
|
53
|
+
*
|
|
54
|
+
* @param assetType - Asset type (file/image)
|
|
55
|
+
* @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
|
|
56
|
+
* @param options - Options to use for the upload
|
|
57
|
+
*/
|
|
58
|
+
upload(
|
|
59
|
+
assetType: 'file' | 'image',
|
|
60
|
+
body: File | Blob | Buffer | NodeJS.ReadableStream,
|
|
61
|
+
options?: UploadClientConfig
|
|
62
|
+
): Observable<HttpRequestEvent<{document: SanityAssetDocument | SanityImageAssetDocument}>>
|
|
51
63
|
upload(
|
|
52
64
|
assetType: 'file' | 'image',
|
|
53
65
|
body: File | Blob | Buffer | NodeJS.ReadableStream,
|
|
@@ -69,7 +81,7 @@ export class AssetsClient {
|
|
|
69
81
|
/**
|
|
70
82
|
* Uploads a file asset to the configured dataset
|
|
71
83
|
*
|
|
72
|
-
* @param assetType - Asset type (file
|
|
84
|
+
* @param assetType - Asset type (file)
|
|
73
85
|
* @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
|
|
74
86
|
* @param options - Options to use for the upload
|
|
75
87
|
*/
|
|
@@ -81,7 +93,7 @@ export class AssetsClient {
|
|
|
81
93
|
/**
|
|
82
94
|
* Uploads an image asset to the configured dataset
|
|
83
95
|
*
|
|
84
|
-
* @param assetType - Asset type (
|
|
96
|
+
* @param assetType - Asset type (image)
|
|
85
97
|
* @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
|
|
86
98
|
* @param options - Options to use for the upload
|
|
87
99
|
*/
|
|
@@ -90,6 +102,18 @@ export class AssetsClient {
|
|
|
90
102
|
body: File | Blob | Buffer | NodeJS.ReadableStream,
|
|
91
103
|
options?: UploadClientConfig
|
|
92
104
|
): Promise<SanityImageAssetDocument>
|
|
105
|
+
/**
|
|
106
|
+
* Uploads a file or an image asset to the configured dataset
|
|
107
|
+
*
|
|
108
|
+
* @param assetType - Asset type (file/image)
|
|
109
|
+
* @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
|
|
110
|
+
* @param options - Options to use for the upload
|
|
111
|
+
*/
|
|
112
|
+
upload(
|
|
113
|
+
assetType: 'file' | 'image',
|
|
114
|
+
body: File | Blob | Buffer | NodeJS.ReadableStream,
|
|
115
|
+
options?: UploadClientConfig
|
|
116
|
+
): Promise<SanityAssetDocument | SanityImageAssetDocument>
|
|
93
117
|
upload(
|
|
94
118
|
assetType: 'file' | 'image',
|
|
95
119
|
body: File | Blob | Buffer | NodeJS.ReadableStream,
|
package/src/data/dataMethods.ts
CHANGED
|
@@ -60,11 +60,11 @@ const indexBy = (docs: FIXME[], attr: FIXME) =>
|
|
|
60
60
|
const getQuerySizeLimit = 11264
|
|
61
61
|
|
|
62
62
|
/** @internal */
|
|
63
|
-
export function _fetch<R>(
|
|
63
|
+
export function _fetch<R, Q extends QueryParams>(
|
|
64
64
|
client: ObservableSanityClient | SanityClient,
|
|
65
65
|
httpRequest: HttpRequest,
|
|
66
66
|
query: string,
|
|
67
|
-
params?:
|
|
67
|
+
params?: Q,
|
|
68
68
|
options: FilteredResponseQueryOptions | UnfilteredResponseQueryOptions = {}
|
|
69
69
|
): Observable<RawQueryResponse<R> | R> {
|
|
70
70
|
const mapResponse =
|
|
@@ -1,28 +1,29 @@
|
|
|
1
1
|
import type {FIXME, QueryParams} from '../types'
|
|
2
2
|
|
|
3
|
-
const enc = encodeURIComponent
|
|
4
|
-
|
|
5
3
|
export default ({
|
|
6
4
|
query,
|
|
7
|
-
params = {}
|
|
8
|
-
options = {}
|
|
5
|
+
params = {},
|
|
6
|
+
options = {},
|
|
9
7
|
}: {
|
|
10
8
|
query: string
|
|
11
9
|
params?: QueryParams
|
|
12
10
|
options?: FIXME
|
|
13
11
|
}) => {
|
|
12
|
+
const searchParams = new URLSearchParams()
|
|
14
13
|
// We generally want tag at the start of the query string
|
|
15
14
|
const {tag, ...opts} = options
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
if (tag) searchParams.set('tag', tag)
|
|
16
|
+
searchParams.set('query', query)
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
// Iterate params, the keys are prefixed with `$` and their values JSON stringified
|
|
19
|
+
for (const [key, value] of Object.entries(params)) {
|
|
20
|
+
searchParams.set(`$${key}`, JSON.stringify(value))
|
|
21
|
+
}
|
|
22
|
+
// Options are passed as-is
|
|
23
|
+
for (const [key, value] of Object.entries(opts)) {
|
|
24
|
+
// Skip falsy values
|
|
25
|
+
if (value) searchParams.set(key, `${value}`)
|
|
26
|
+
}
|
|
23
27
|
|
|
24
|
-
return
|
|
25
|
-
// Only include the option if it is truthy
|
|
26
|
-
return options[option] ? `${qs}&${enc(option)}=${enc(options[option])}` : qs
|
|
27
|
-
}, qString)
|
|
28
|
+
return `?${searchParams}`
|
|
28
29
|
}
|
package/src/data/patch.ts
CHANGED
|
@@ -28,18 +28,6 @@ export class BasePatch {
|
|
|
28
28
|
this.operations = operations
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
/**
|
|
32
|
-
* DEPRECATED: Don't use.
|
|
33
|
-
* The operation is added to the current patch, ready to be commited by `commit()`
|
|
34
|
-
*
|
|
35
|
-
* @deprecated - Don't use.
|
|
36
|
-
* @param attrs - Attributes to replace
|
|
37
|
-
*/
|
|
38
|
-
replace(attrs: AttributeSet): this {
|
|
39
|
-
validateObject('replace', attrs)
|
|
40
|
-
return this._set('set', {$: attrs})
|
|
41
|
-
}
|
|
42
|
-
|
|
43
31
|
/**
|
|
44
32
|
* Sets the given attributes to the document. Does NOT merge objects.
|
|
45
33
|
* The operation is added to the current patch, ready to be commited by `commit()`
|