@sanity/client 7.0.1-canary.1 → 7.1.0
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 +102 -4
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +1366 -1538
- package/dist/index.browser.d.ts +1366 -1538
- package/dist/index.browser.js +102 -4
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +103 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1366 -1538
- package/dist/index.d.ts +1366 -1538
- package/dist/index.js +103 -5
- package/dist/index.js.map +1 -1
- package/dist/stega.browser.d.cts +1373 -1545
- package/dist/stega.browser.d.ts +1373 -1545
- package/dist/stega.d.cts +1373 -1545
- package/dist/stega.d.ts +1373 -1545
- package/package.json +2 -1
- package/src/SanityClient.ts +30 -1078
- package/src/agent/actions/AgentActionsClient.ts +111 -0
- package/src/agent/actions/commonTypes.ts +336 -0
- package/src/agent/actions/generate.ts +274 -0
- package/src/agent/actions/transform.ts +215 -0
- package/src/agent/actions/translate.ts +165 -0
- package/src/assets/AssetsClient.ts +2 -98
- package/src/data/dataMethods.ts +1 -1
- package/src/data/transaction.ts +1 -1
- package/src/projects/ProjectsClient.ts +2 -2
- package/src/types.ts +30 -1
- package/umd/sanityClient.js +102 -4
- package/umd/sanityClient.min.js +2 -2
|
@@ -16,104 +16,8 @@ import type {
|
|
|
16
16
|
} from '../types'
|
|
17
17
|
import * as validators from '../validators'
|
|
18
18
|
|
|
19
|
-
/**
|
|
20
|
-
* The interface implemented by the `ObservableAssetsClient` class.
|
|
21
|
-
* When writing code that wants to take an instance of `ObservableAssetsClient` as input it's better to use this type,
|
|
22
|
-
* as the `ObservableAssetsClient` class has private properties and thus TypeScript will consider the type incompatible
|
|
23
|
-
* in cases where you might have multiple `@sanity/client` instances in your node_modules.
|
|
24
|
-
* @public
|
|
25
|
-
*/
|
|
26
|
-
export interface ObservableAssetsClientType {
|
|
27
|
-
/**
|
|
28
|
-
* Uploads a file asset to the configured dataset
|
|
29
|
-
*
|
|
30
|
-
* @param assetType - Asset type (file)
|
|
31
|
-
* @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
|
|
32
|
-
* @param options - Options to use for the upload
|
|
33
|
-
*/
|
|
34
|
-
upload(
|
|
35
|
-
assetType: 'file',
|
|
36
|
-
body: UploadBody,
|
|
37
|
-
options?: UploadClientConfig,
|
|
38
|
-
): Observable<HttpRequestEvent<{document: SanityAssetDocument}>>
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Uploads an image asset to the configured dataset
|
|
42
|
-
*
|
|
43
|
-
* @param assetType - Asset type (image)
|
|
44
|
-
* @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
|
|
45
|
-
* @param options - Options to use for the upload
|
|
46
|
-
*/
|
|
47
|
-
upload(
|
|
48
|
-
assetType: 'image',
|
|
49
|
-
body: UploadBody,
|
|
50
|
-
options?: UploadClientConfig,
|
|
51
|
-
): Observable<HttpRequestEvent<{document: SanityImageAssetDocument}>>
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Uploads a file or an image asset to the configured dataset
|
|
55
|
-
*
|
|
56
|
-
* @param assetType - Asset type (file/image)
|
|
57
|
-
* @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
|
|
58
|
-
* @param options - Options to use for the upload
|
|
59
|
-
*/
|
|
60
|
-
upload(
|
|
61
|
-
assetType: 'file' | 'image',
|
|
62
|
-
body: UploadBody,
|
|
63
|
-
options?: UploadClientConfig,
|
|
64
|
-
): Observable<HttpRequestEvent<{document: SanityAssetDocument | SanityImageAssetDocument}>>
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* The interface implemented by the `AssetsClient` class.
|
|
69
|
-
* When writing code that wants to take an instance of `AssetsClient` as input it's better to use this type,
|
|
70
|
-
* as the `AssetsClient` class has private properties and thus TypeScript will consider the type incompatible
|
|
71
|
-
* in cases where you might have multiple `@sanity/client` instances in your node_modules.
|
|
72
|
-
* @public
|
|
73
|
-
*/
|
|
74
|
-
export interface AssetsClientType {
|
|
75
|
-
/**
|
|
76
|
-
* Uploads a file asset to the configured dataset
|
|
77
|
-
*
|
|
78
|
-
* @param assetType - Asset type (file)
|
|
79
|
-
* @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
|
|
80
|
-
* @param options - Options to use for the upload
|
|
81
|
-
*/
|
|
82
|
-
upload(
|
|
83
|
-
assetType: 'file',
|
|
84
|
-
body: UploadBody,
|
|
85
|
-
options?: UploadClientConfig,
|
|
86
|
-
): Promise<SanityAssetDocument>
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Uploads an image asset to the configured dataset
|
|
90
|
-
*
|
|
91
|
-
* @param assetType - Asset type (image)
|
|
92
|
-
* @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
|
|
93
|
-
* @param options - Options to use for the upload
|
|
94
|
-
*/
|
|
95
|
-
upload(
|
|
96
|
-
assetType: 'image',
|
|
97
|
-
body: UploadBody,
|
|
98
|
-
options?: UploadClientConfig,
|
|
99
|
-
): Promise<SanityImageAssetDocument>
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Uploads a file or an image asset to the configured dataset
|
|
103
|
-
*
|
|
104
|
-
* @param assetType - Asset type (file/image)
|
|
105
|
-
* @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
|
|
106
|
-
* @param options - Options to use for the upload
|
|
107
|
-
*/
|
|
108
|
-
upload(
|
|
109
|
-
assetType: 'file' | 'image',
|
|
110
|
-
body: UploadBody,
|
|
111
|
-
options?: UploadClientConfig,
|
|
112
|
-
): Promise<SanityAssetDocument | SanityImageAssetDocument>
|
|
113
|
-
}
|
|
114
|
-
|
|
115
19
|
/** @internal */
|
|
116
|
-
export class ObservableAssetsClient
|
|
20
|
+
export class ObservableAssetsClient {
|
|
117
21
|
#client: ObservableSanityClient
|
|
118
22
|
#httpRequest: HttpRequest
|
|
119
23
|
constructor(client: ObservableSanityClient, httpRequest: HttpRequest) {
|
|
@@ -168,7 +72,7 @@ export class ObservableAssetsClient implements ObservableAssetsClientType {
|
|
|
168
72
|
}
|
|
169
73
|
|
|
170
74
|
/** @internal */
|
|
171
|
-
export class AssetsClient
|
|
75
|
+
export class AssetsClient {
|
|
172
76
|
#client: SanityClient
|
|
173
77
|
#httpRequest: HttpRequest
|
|
174
78
|
constructor(client: SanityClient, httpRequest: HttpRequest) {
|
package/src/data/dataMethods.ts
CHANGED
|
@@ -549,7 +549,7 @@ const isDomExceptionSupported = Boolean(globalThis.DOMException)
|
|
|
549
549
|
|
|
550
550
|
/**
|
|
551
551
|
* @internal
|
|
552
|
-
* @param signal
|
|
552
|
+
* @param signal - The abort signal to use.
|
|
553
553
|
* Original source copied from https://github.com/sindresorhus/ky/blob/740732c78aad97e9aec199e9871bdbf0ae29b805/source/errors/DOMException.ts
|
|
554
554
|
* TODO: When targeting Node.js 18, use `signal.throwIfAborted()` (https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/throwIfAborted)
|
|
555
555
|
*/
|
package/src/data/transaction.ts
CHANGED
|
@@ -253,7 +253,7 @@ export class Transaction extends BaseTransaction {
|
|
|
253
253
|
return this._add({patch: patch.serialize()})
|
|
254
254
|
}
|
|
255
255
|
|
|
256
|
-
|
|
256
|
+
/*
|
|
257
257
|
* transaction.patch(
|
|
258
258
|
* {query: "*[_type == 'person' && points >= $threshold]", params: { threshold: 100 }},
|
|
259
259
|
* {dec: { points: 100 }, inc: { bonuses: 1 }}
|
|
@@ -18,7 +18,7 @@ export class ObservableProjectsClient {
|
|
|
18
18
|
* Fetch a list of projects the authenticated user has access to.
|
|
19
19
|
*
|
|
20
20
|
* @param options - Options for the list request
|
|
21
|
-
*
|
|
21
|
+
* - `includeMembers` - Whether to include members in the response (default: true)
|
|
22
22
|
*/
|
|
23
23
|
list(options?: {includeMembers?: true}): Observable<SanityProject[]>
|
|
24
24
|
list(options?: {includeMembers?: false}): Observable<Omit<SanityProject, 'members'>[]>
|
|
@@ -54,7 +54,7 @@ export class ProjectsClient {
|
|
|
54
54
|
* Fetch a list of projects the authenticated user has access to.
|
|
55
55
|
*
|
|
56
56
|
* @param options - Options for the list request
|
|
57
|
-
*
|
|
57
|
+
* - `includeMembers` - Whether to include members in the response (default: true)
|
|
58
58
|
*/
|
|
59
59
|
list(options?: {includeMembers?: true}): Promise<SanityProject[]>
|
|
60
60
|
list(options?: {includeMembers?: false}): Promise<Omit<SanityProject, 'members'>[]>
|
package/src/types.ts
CHANGED
|
@@ -963,7 +963,7 @@ export interface ListenOptions {
|
|
|
963
963
|
*/
|
|
964
964
|
includePreviousRevision?: boolean
|
|
965
965
|
|
|
966
|
-
|
|
966
|
+
/*
|
|
967
967
|
* Whether to include events for drafts and versions. As of API Version >= v2025-02-19, only events
|
|
968
968
|
* for published documents will be included by default (see {@link https://www.sanity.io/changelog/676aaa9d-2da6-44fb-abe5-580f28047c10|Changelog})
|
|
969
969
|
* If you need events from drafts and versions, set this to `true`.
|
|
@@ -1372,6 +1372,35 @@ export type ClientReturn<
|
|
|
1372
1372
|
Fallback = Any,
|
|
1373
1373
|
> = GroqString extends keyof SanityQueries ? SanityQueries[GroqString] : Fallback
|
|
1374
1374
|
|
|
1375
|
+
export type {
|
|
1376
|
+
AgentActionParam,
|
|
1377
|
+
AgentActionParams,
|
|
1378
|
+
AgentActionPath,
|
|
1379
|
+
AgentActionPathSegment,
|
|
1380
|
+
AgentActionTarget,
|
|
1381
|
+
ConstantAgentActionParam,
|
|
1382
|
+
DocumentAgentActionParam,
|
|
1383
|
+
FieldAgentActionParam,
|
|
1384
|
+
GroqAgentActionParam,
|
|
1385
|
+
} from './agent/actions/commonTypes'
|
|
1386
|
+
export type {
|
|
1387
|
+
GenerateInstruction,
|
|
1388
|
+
GenerateOperation,
|
|
1389
|
+
GenerateTarget,
|
|
1390
|
+
GenerateTargetDocument,
|
|
1391
|
+
GenerateTargetInclude,
|
|
1392
|
+
} from './agent/actions/generate'
|
|
1393
|
+
export type {
|
|
1394
|
+
TransformDocument,
|
|
1395
|
+
TransformTarget,
|
|
1396
|
+
TransformTargetDocument,
|
|
1397
|
+
TransformTargetInclude,
|
|
1398
|
+
} from './agent/actions/transform'
|
|
1399
|
+
export type {
|
|
1400
|
+
TranslateDocument,
|
|
1401
|
+
TranslateTarget,
|
|
1402
|
+
TranslateTargetInclude,
|
|
1403
|
+
} from './agent/actions/translate'
|
|
1375
1404
|
export type {
|
|
1376
1405
|
ContentSourceMapParsedPath,
|
|
1377
1406
|
ContentSourceMapParsedPathKeyedSegment,
|
package/umd/sanityClient.js
CHANGED
|
@@ -2871,6 +2871,86 @@ ${selectionOpts}`);
|
|
|
2871
2871
|
throw new Error(`Unsupported resource type: ${type.toString()}`);
|
|
2872
2872
|
}
|
|
2873
2873
|
};
|
|
2874
|
+
function _generate(client, httpRequest, request) {
|
|
2875
|
+
const dataset2 = hasDataset(client.config());
|
|
2876
|
+
return _request(client, httpRequest, {
|
|
2877
|
+
method: "POST",
|
|
2878
|
+
uri: `/agent/action/generate/${dataset2}`,
|
|
2879
|
+
body: request
|
|
2880
|
+
});
|
|
2881
|
+
}
|
|
2882
|
+
function _transform(client, httpRequest, request) {
|
|
2883
|
+
const dataset2 = hasDataset(client.config());
|
|
2884
|
+
return _request(client, httpRequest, {
|
|
2885
|
+
method: "POST",
|
|
2886
|
+
uri: `/agent/action/transform/${dataset2}`,
|
|
2887
|
+
body: request
|
|
2888
|
+
});
|
|
2889
|
+
}
|
|
2890
|
+
function _translate(client, httpRequest, request) {
|
|
2891
|
+
const dataset2 = hasDataset(client.config());
|
|
2892
|
+
return _request(client, httpRequest, {
|
|
2893
|
+
method: "POST",
|
|
2894
|
+
uri: `/agent/action/translate/${dataset2}`,
|
|
2895
|
+
body: request
|
|
2896
|
+
});
|
|
2897
|
+
}
|
|
2898
|
+
class ObservableAgentsActionClient {
|
|
2899
|
+
#client;
|
|
2900
|
+
#httpRequest;
|
|
2901
|
+
constructor(client, httpRequest) {
|
|
2902
|
+
this.#client = client, this.#httpRequest = httpRequest;
|
|
2903
|
+
}
|
|
2904
|
+
/**
|
|
2905
|
+
* Run an instruction to generate content in a target document.
|
|
2906
|
+
* @param request - instruction request
|
|
2907
|
+
*/
|
|
2908
|
+
generate(request) {
|
|
2909
|
+
return _generate(this.#client, this.#httpRequest, request);
|
|
2910
|
+
}
|
|
2911
|
+
/**
|
|
2912
|
+
* Transform a target document based on a source.
|
|
2913
|
+
* @param request - translation request
|
|
2914
|
+
*/
|
|
2915
|
+
transform(request) {
|
|
2916
|
+
return _transform(this.#client, this.#httpRequest, request);
|
|
2917
|
+
}
|
|
2918
|
+
/**
|
|
2919
|
+
* Translate a target document based on a source.
|
|
2920
|
+
* @param request - translation request
|
|
2921
|
+
*/
|
|
2922
|
+
translate(request) {
|
|
2923
|
+
return _translate(this.#client, this.#httpRequest, request);
|
|
2924
|
+
}
|
|
2925
|
+
}
|
|
2926
|
+
class AgentActionsClient {
|
|
2927
|
+
#client;
|
|
2928
|
+
#httpRequest;
|
|
2929
|
+
constructor(client, httpRequest) {
|
|
2930
|
+
this.#client = client, this.#httpRequest = httpRequest;
|
|
2931
|
+
}
|
|
2932
|
+
/**
|
|
2933
|
+
* Run an instruction to generate content in a target document.
|
|
2934
|
+
* @param request - instruction request
|
|
2935
|
+
*/
|
|
2936
|
+
generate(request) {
|
|
2937
|
+
return lastValueFrom(_generate(this.#client, this.#httpRequest, request));
|
|
2938
|
+
}
|
|
2939
|
+
/**
|
|
2940
|
+
* Transform a target document based on a source.
|
|
2941
|
+
* @param request - translation request
|
|
2942
|
+
*/
|
|
2943
|
+
transform(request) {
|
|
2944
|
+
return lastValueFrom(_transform(this.#client, this.#httpRequest, request));
|
|
2945
|
+
}
|
|
2946
|
+
/**
|
|
2947
|
+
* Translate a target document based on a source.
|
|
2948
|
+
* @param request - translation request
|
|
2949
|
+
*/
|
|
2950
|
+
translate(request) {
|
|
2951
|
+
return lastValueFrom(_translate(this.#client, this.#httpRequest, request));
|
|
2952
|
+
}
|
|
2953
|
+
}
|
|
2874
2954
|
class ObservableAssetsClient {
|
|
2875
2955
|
#client;
|
|
2876
2956
|
#httpRequest;
|
|
@@ -3291,11 +3371,20 @@ ${selectionOpts}`);
|
|
|
3291
3371
|
live;
|
|
3292
3372
|
projects;
|
|
3293
3373
|
users;
|
|
3374
|
+
agent;
|
|
3375
|
+
/**
|
|
3376
|
+
* Private properties
|
|
3377
|
+
*/
|
|
3294
3378
|
#clientConfig;
|
|
3295
3379
|
#httpRequest;
|
|
3380
|
+
/**
|
|
3381
|
+
* Instance properties
|
|
3382
|
+
*/
|
|
3296
3383
|
listen = _listen;
|
|
3297
3384
|
constructor(httpRequest, config = defaultConfig) {
|
|
3298
|
-
this.config(config), this.#httpRequest = httpRequest, this.assets = new ObservableAssetsClient(this, this.#httpRequest), this.datasets = new ObservableDatasetsClient(this, this.#httpRequest), this.live = new LiveClient(this), this.projects = new ObservableProjectsClient(this, this.#httpRequest), this.users = new ObservableUsersClient(this, this.#httpRequest)
|
|
3385
|
+
this.config(config), this.#httpRequest = httpRequest, this.assets = new ObservableAssetsClient(this, this.#httpRequest), this.datasets = new ObservableDatasetsClient(this, this.#httpRequest), this.live = new LiveClient(this), this.projects = new ObservableProjectsClient(this, this.#httpRequest), this.users = new ObservableUsersClient(this, this.#httpRequest), this.agent = {
|
|
3386
|
+
action: new ObservableAgentsActionClient(this, this.#httpRequest)
|
|
3387
|
+
};
|
|
3299
3388
|
}
|
|
3300
3389
|
/**
|
|
3301
3390
|
* Clone the client - returns a new instance
|
|
@@ -3434,15 +3523,24 @@ ${selectionOpts}`);
|
|
|
3434
3523
|
live;
|
|
3435
3524
|
projects;
|
|
3436
3525
|
users;
|
|
3526
|
+
agent;
|
|
3437
3527
|
/**
|
|
3438
3528
|
* Observable version of the Sanity client, with the same configuration as the promise-based one
|
|
3439
3529
|
*/
|
|
3440
3530
|
observable;
|
|
3531
|
+
/**
|
|
3532
|
+
* Private properties
|
|
3533
|
+
*/
|
|
3441
3534
|
#clientConfig;
|
|
3442
3535
|
#httpRequest;
|
|
3536
|
+
/**
|
|
3537
|
+
* Instance properties
|
|
3538
|
+
*/
|
|
3443
3539
|
listen = _listen;
|
|
3444
3540
|
constructor(httpRequest, config = defaultConfig) {
|
|
3445
|
-
this.config(config), this.#httpRequest = httpRequest, this.assets = new AssetsClient(this, this.#httpRequest), this.datasets = new DatasetsClient(this, this.#httpRequest), this.live = new LiveClient(this), this.projects = new ProjectsClient(this, this.#httpRequest), this.users = new UsersClient(this, this.#httpRequest), this.
|
|
3541
|
+
this.config(config), this.#httpRequest = httpRequest, this.assets = new AssetsClient(this, this.#httpRequest), this.datasets = new DatasetsClient(this, this.#httpRequest), this.live = new LiveClient(this), this.projects = new ProjectsClient(this, this.#httpRequest), this.users = new UsersClient(this, this.#httpRequest), this.agent = {
|
|
3542
|
+
action: new AgentActionsClient(this, this.#httpRequest)
|
|
3543
|
+
}, this.observable = new ObservableSanityClient(httpRequest, config);
|
|
3446
3544
|
}
|
|
3447
3545
|
/**
|
|
3448
3546
|
* Clone the client - returns a new instance
|
|
@@ -3536,8 +3634,8 @@ ${selectionOpts}`);
|
|
|
3536
3634
|
* @param operations - Optional object of patch operations to initialize the patch instance with
|
|
3537
3635
|
* @returns Patch instance - call `.commit()` to perform the operations defined
|
|
3538
3636
|
*/
|
|
3539
|
-
patch(
|
|
3540
|
-
return new Patch(
|
|
3637
|
+
patch(documentId, operations) {
|
|
3638
|
+
return new Patch(documentId, operations, this);
|
|
3541
3639
|
}
|
|
3542
3640
|
/**
|
|
3543
3641
|
* Create a new transaction of mutations
|