@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/src/users/UsersClient.ts
CHANGED
|
@@ -1,46 +1,55 @@
|
|
|
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 {CurrentSanityUser, SanityUser} from '../types'
|
|
5
|
+
import type {CurrentSanityUser, HttpRequest, SanityUser} from '../types'
|
|
5
6
|
|
|
6
|
-
export class
|
|
7
|
-
client:
|
|
7
|
+
export class ObservableUsersClient {
|
|
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 user by user ID
|
|
11
17
|
*
|
|
12
18
|
* @param id - User ID of the user to fetch. If `me` is provided, a minimal response including the users role is returned.
|
|
13
19
|
*/
|
|
14
|
-
|
|
15
|
-
this: UsersClient,
|
|
16
|
-
id: T
|
|
17
|
-
): Promise<T extends 'me' ? CurrentSanityUser : SanityUser>
|
|
18
|
-
getById<T extends 'me' | string>(
|
|
19
|
-
this: ObservableUsersClient,
|
|
20
|
-
id: T
|
|
21
|
-
): Observable<T extends 'me' ? CurrentSanityUser : SanityUser>
|
|
20
|
+
|
|
22
21
|
getById<T extends 'me' | string>(
|
|
23
22
|
id: T
|
|
24
|
-
):
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
): Observable<T extends 'me' ? CurrentSanityUser : SanityUser> {
|
|
24
|
+
return _request<T extends 'me' ? CurrentSanityUser : SanityUser>(
|
|
25
|
+
this.#client,
|
|
26
|
+
this.#httpRequest,
|
|
27
|
+
{uri: `/users/${id}`}
|
|
28
|
+
)
|
|
28
29
|
}
|
|
29
30
|
}
|
|
30
31
|
|
|
31
|
-
export class
|
|
32
|
-
client:
|
|
33
|
-
|
|
34
|
-
constructor(client:
|
|
35
|
-
|
|
36
|
-
this
|
|
32
|
+
export class UsersClient {
|
|
33
|
+
#client: SanityClient
|
|
34
|
+
#httpRequest: HttpRequest
|
|
35
|
+
constructor(client: SanityClient, httpRequest: HttpRequest) {
|
|
36
|
+
this.#client = client
|
|
37
|
+
this.#httpRequest = httpRequest
|
|
37
38
|
}
|
|
38
|
-
}
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Fetch a user by user ID
|
|
42
|
+
*
|
|
43
|
+
* @param id - User ID of the user to fetch. If `me` is provided, a minimal response including the users role is returned.
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
getById<T extends 'me' | string>(
|
|
47
|
+
id: T
|
|
48
|
+
): Promise<T extends 'me' ? CurrentSanityUser : SanityUser> {
|
|
49
|
+
return lastValueFrom(
|
|
50
|
+
_request<T extends 'me' ? CurrentSanityUser : SanityUser>(this.#client, this.#httpRequest, {
|
|
51
|
+
uri: `/users/${id}`,
|
|
52
|
+
})
|
|
53
|
+
)
|
|
45
54
|
}
|
|
46
55
|
}
|