@sanity/client 6.29.0-generate.2 → 6.29.0-generate.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.
@@ -2,19 +2,9 @@ import {lastValueFrom, type Observable} from 'rxjs'
2
2
 
3
3
  import type {ObservableSanityClient, SanityClient} from '../../SanityClient'
4
4
  import type {Any, HttpRequest, IdentifiedSanityDocumentStub, TranslateDocument} from '../../types'
5
- import {
6
- _generate,
7
- type GenerateAsyncInstruction,
8
- type GenerateInstruction,
9
- type GenerateSyncInstruction,
10
- } from './generate'
11
- import {
12
- _transform,
13
- type TransformDocument,
14
- type TransformDocumentAsync,
15
- type TransformDocumentSync,
16
- } from './transform'
17
- import {_translate, type TranslateDocumentAsync, type TranslateDocumentSync} from './translate'
5
+ import {_generate, type GenerateInstruction} from './generate'
6
+ import {_transform, type TransformDocument} from './transform'
7
+ import {_translate} from './translate'
18
8
 
19
9
  /** @public */
20
10
  export class ObservableAgentsActionClient {
@@ -25,59 +15,44 @@ export class ObservableAgentsActionClient {
25
15
  this.#httpRequest = httpRequest
26
16
  }
27
17
 
28
- generate(request: GenerateAsyncInstruction): Observable<{_id: string}>
29
-
30
- generate<DocumentShape extends Record<string, Any>>(
31
- request: GenerateSyncInstruction<DocumentShape>,
32
- ): Observable<IdentifiedSanityDocumentStub & DocumentShape>
33
-
34
18
  /**
35
19
  * Run an instruction to generate content in a target document.
36
20
  * @param request instruction request
37
21
  */
38
- generate<
39
- DocumentShape extends Record<string, Any>,
40
- Req extends GenerateInstruction<DocumentShape>,
41
- >(
42
- request: Req,
22
+ generate<DocumentShape extends Record<string, Any>>(
23
+ request: GenerateInstruction<DocumentShape>,
43
24
  ): Observable<
44
- Req['async'] extends true ? {_id: string} : IdentifiedSanityDocumentStub & DocumentShape
25
+ (typeof request)['async'] extends true
26
+ ? {_id: string}
27
+ : IdentifiedSanityDocumentStub & DocumentShape
45
28
  > {
46
29
  return _generate(this.#client, this.#httpRequest, request)
47
30
  }
48
31
 
49
- transform(request: TransformDocumentAsync): Observable<{_id: string}>
50
-
51
- transform<DocumentShape extends Record<string, Any>>(
52
- request: TransformDocumentSync,
53
- ): Observable<IdentifiedSanityDocumentStub & DocumentShape>
54
-
55
32
  /**
56
33
  * Transform a target document based on a source.
57
34
  * @param request translation request
58
35
  */
59
- transform<DocumentShape extends Record<string, Any>, Req extends TransformDocument>(
60
- request: Req,
36
+ transform<DocumentShape extends Record<string, Any>>(
37
+ request: TransformDocument<DocumentShape>,
61
38
  ): Observable<
62
- Req['async'] extends true ? {_id: string} : IdentifiedSanityDocumentStub & DocumentShape
39
+ (typeof request)['async'] extends true
40
+ ? {_id: string}
41
+ : IdentifiedSanityDocumentStub & DocumentShape
63
42
  > {
64
43
  return _transform(this.#client, this.#httpRequest, request)
65
44
  }
66
45
 
67
- translate(request: TranslateDocumentAsync): Observable<{_id: string}>
68
-
69
- translate<DocumentShape extends Record<string, Any>>(
70
- request: TranslateDocumentSync,
71
- ): Observable<IdentifiedSanityDocumentStub & DocumentShape>
72
-
73
46
  /**
74
47
  * Translate a target document based on a source.
75
48
  * @param request translation request
76
49
  */
77
- translate<DocumentShape extends Record<string, Any>, Req extends TranslateDocument>(
78
- request: Req,
50
+ translate<DocumentShape extends Record<string, Any>>(
51
+ request: TranslateDocument<DocumentShape>,
79
52
  ): Observable<
80
- Req['async'] extends true ? {_id: string} : IdentifiedSanityDocumentStub & DocumentShape
53
+ (typeof request)['async'] extends true
54
+ ? {_id: string}
55
+ : IdentifiedSanityDocumentStub & DocumentShape
81
56
  > {
82
57
  return _translate(this.#client, this.#httpRequest, request)
83
58
  }
@@ -92,59 +67,44 @@ export class AgentActionsClient {
92
67
  this.#httpRequest = httpRequest
93
68
  }
94
69
 
95
- generate(request: GenerateAsyncInstruction): Promise<{_id: string}>
96
-
97
- generate<DocumentShape extends Record<string, Any>>(
98
- request: GenerateSyncInstruction<DocumentShape>,
99
- ): Promise<IdentifiedSanityDocumentStub & DocumentShape>
100
-
101
70
  /**
102
71
  * Run an instruction to generate content in a target document.
103
72
  * @param request instruction request
104
73
  */
105
- generate<
106
- DocumentShape extends Record<string, Any>,
107
- Req extends GenerateInstruction<DocumentShape>,
108
- >(
109
- request: Req,
74
+ generate<DocumentShape extends Record<string, Any>>(
75
+ request: GenerateInstruction<DocumentShape>,
110
76
  ): Promise<
111
- Req['async'] extends true ? {_id: string} : IdentifiedSanityDocumentStub & DocumentShape
77
+ (typeof request)['async'] extends true
78
+ ? {_id: string}
79
+ : IdentifiedSanityDocumentStub & DocumentShape
112
80
  > {
113
81
  return lastValueFrom(_generate(this.#client, this.#httpRequest, request))
114
82
  }
115
83
 
116
- transform(request: TransformDocumentAsync): Promise<{_id: string}>
117
-
118
- transform<DocumentShape extends Record<string, Any>>(
119
- request: TransformDocumentSync,
120
- ): Promise<IdentifiedSanityDocumentStub & DocumentShape>
121
-
122
84
  /**
123
85
  * Transform a target document based on a source.
124
86
  * @param request translation request
125
87
  */
126
- transform<DocumentShape extends Record<string, Any>, Req extends TransformDocument>(
127
- request: Req,
88
+ transform<DocumentShape extends Record<string, Any>>(
89
+ request: TransformDocument<DocumentShape>,
128
90
  ): Promise<
129
- Req['async'] extends true ? {_id: string} : IdentifiedSanityDocumentStub & DocumentShape
91
+ (typeof request)['async'] extends true
92
+ ? {_id: string}
93
+ : IdentifiedSanityDocumentStub & DocumentShape
130
94
  > {
131
95
  return lastValueFrom(_transform(this.#client, this.#httpRequest, request))
132
96
  }
133
97
 
134
- translate(request: TranslateDocumentAsync): Promise<{_id: string}>
135
-
136
- translate<DocumentShape extends Record<string, Any>>(
137
- request: TranslateDocumentSync,
138
- ): Promise<IdentifiedSanityDocumentStub & DocumentShape>
139
-
140
98
  /**
141
99
  * Translate a target document based on a source.
142
100
  * @param request translation request
143
101
  */
144
- translate<DocumentShape extends Record<string, Any>, Req extends TranslateDocument>(
145
- request: Req,
102
+ translate<DocumentShape extends Record<string, Any>>(
103
+ request: TranslateDocument<DocumentShape>,
146
104
  ): Promise<
147
- Req['async'] extends true ? {_id: string} : IdentifiedSanityDocumentStub & DocumentShape
105
+ (typeof request)['async'] extends true
106
+ ? {_id: string}
107
+ : IdentifiedSanityDocumentStub & DocumentShape
148
108
  > {
149
109
  return lastValueFrom(_translate(this.#client, this.#httpRequest, request))
150
110
  }
@@ -156,15 +156,14 @@ export type GenerateInstruction<T extends Record<string, Any> = Record<string, A
156
156
  | GenerateSyncInstruction<T>
157
157
  | GenerateAsyncInstruction<T>
158
158
 
159
- export function _generate<
160
- DocumentShape extends Record<string, Any>,
161
- Req extends GenerateInstruction<DocumentShape>,
162
- >(
159
+ export function _generate<DocumentShape extends Record<string, Any>>(
163
160
  client: SanityClient | ObservableSanityClient,
164
161
  httpRequest: HttpRequest,
165
- request: Req,
162
+ request: GenerateInstruction<DocumentShape>,
166
163
  ): Observable<
167
- Req['async'] extends true ? {_id: string} : IdentifiedSanityDocumentStub & DocumentShape
164
+ (typeof request)['async'] extends true
165
+ ? {_id: string}
166
+ : IdentifiedSanityDocumentStub & DocumentShape
168
167
  > {
169
168
  const dataset = hasDataset(client.config())
170
169
  return _request(client, httpRequest, {
@@ -80,23 +80,27 @@ export interface TransformTarget extends AgentActionTarget {
80
80
  }
81
81
 
82
82
  /** @beta */
83
- export type TransformDocumentSync = TransformRequestBase & AgentActionSync
83
+ // need the generics to hold optional call-site response generics
84
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
85
+ export type TransformDocumentSync<T extends Record<string, Any> = Record<string, Any>> =
86
+ TransformRequestBase & AgentActionSync
84
87
 
85
88
  /** @beta */
86
89
  export type TransformDocumentAsync = TransformRequestBase & AgentActionAsync
87
90
 
88
91
  /** @beta */
89
- export type TransformDocument = TransformDocumentSync | TransformDocumentAsync
92
+ export type TransformDocument<T extends Record<string, Any> = Record<string, Any>> =
93
+ | TransformDocumentSync<T>
94
+ | TransformDocumentAsync
90
95
 
91
- export function _transform<
92
- DocumentShape extends Record<string, Any>,
93
- Req extends TransformDocument,
94
- >(
96
+ export function _transform<DocumentShape extends Record<string, Any>>(
95
97
  client: SanityClient | ObservableSanityClient,
96
98
  httpRequest: HttpRequest,
97
- request: Req,
99
+ request: TransformDocument<DocumentShape>,
98
100
  ): Observable<
99
- Req['async'] extends true ? {_id: string} : IdentifiedSanityDocumentStub & DocumentShape
101
+ (typeof request)['async'] extends true
102
+ ? {_id: string}
103
+ : IdentifiedSanityDocumentStub & DocumentShape
100
104
  > {
101
105
  const dataset = hasDataset(client.config())
102
106
  return _request(client, httpRequest, {
@@ -93,23 +93,27 @@ export interface TranslateTarget extends AgentActionTarget {
93
93
  }
94
94
 
95
95
  /** @beta */
96
- export type TranslateDocumentSync = TranslateRequestBase & AgentActionSync
96
+ // need the generics to hold optional call-site response generics
97
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
98
+ export type TranslateDocumentSync<T extends Record<string, Any> = Record<string, Any>> =
99
+ TranslateRequestBase & AgentActionSync
97
100
 
98
101
  /** @beta */
99
102
  export type TranslateDocumentAsync = TranslateRequestBase & AgentActionAsync
100
103
 
101
104
  /** @beta */
102
- export type TranslateDocument = TranslateDocumentSync | TranslateDocumentAsync
105
+ export type TranslateDocument<T extends Record<string, Any> = Record<string, Any>> =
106
+ | TranslateDocumentSync<T>
107
+ | TranslateDocumentAsync
103
108
 
104
- export function _translate<
105
- DocumentShape extends Record<string, Any>,
106
- Req extends TranslateDocument,
107
- >(
109
+ export function _translate<DocumentShape extends Record<string, Any>>(
108
110
  client: SanityClient | ObservableSanityClient,
109
111
  httpRequest: HttpRequest,
110
- request: Req,
112
+ request: TranslateDocument<DocumentShape>,
111
113
  ): Observable<
112
- Req['async'] extends true ? {_id: string} : IdentifiedSanityDocumentStub & DocumentShape
114
+ (typeof request)['async'] extends true
115
+ ? {_id: string}
116
+ : IdentifiedSanityDocumentStub & DocumentShape
113
117
  > {
114
118
  const dataset = hasDataset(client.config())
115
119
  return _request(client, httpRequest, {