@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.
@@ -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 BaseUsersClient {
7
- client: SanityClient | ObservableSanityClient
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
- getById<T extends 'me' | string>(
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
- | Promise<T extends 'me' ? CurrentSanityUser : SanityUser>
26
- | Observable<T extends 'me' ? CurrentSanityUser : SanityUser> {
27
- return this.client.request({uri: `/users/${id}`})
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 ObservableUsersClient extends BaseUsersClient {
32
- client: ObservableSanityClient
33
-
34
- constructor(client: ObservableSanityClient) {
35
- super()
36
- this.client = client
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
- export class UsersClient extends BaseUsersClient {
41
- client: SanityClient
42
- constructor(client: SanityClient) {
43
- super()
44
- this.client = client
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
  }