@sanity/client 7.8.1 → 7.8.2-datasets.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/README.md +17 -16
- package/dist/_chunks-cjs/config.cjs +1 -0
- package/dist/_chunks-cjs/config.cjs.map +1 -1
- package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs +29 -2
- package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs.map +1 -1
- package/dist/_chunks-es/config.js +1 -0
- package/dist/_chunks-es/config.js.map +1 -1
- package/dist/_chunks-es/stegaEncodeSourceMap.js +29 -2
- package/dist/_chunks-es/stegaEncodeSourceMap.js.map +1 -1
- package/dist/index.browser.cjs +54 -14
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +25 -10
- package/dist/index.browser.d.ts +25 -10
- package/dist/index.browser.js +54 -14
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +54 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -10
- package/dist/index.d.ts +10 -10
- package/dist/index.js +54 -15
- package/dist/index.js.map +1 -1
- package/dist/stega.browser.d.cts +9 -10
- package/dist/stega.browser.d.ts +9 -10
- package/dist/stega.d.cts +9 -10
- package/dist/stega.d.ts +9 -10
- package/package.json +1 -1
- package/src/agent/actions/commonTypes.ts +3 -0
- package/src/agent/actions/prompt.ts +4 -10
- package/src/assets/AssetsClient.ts +5 -0
- package/src/data/dataMethods.ts +34 -1
- package/src/datasets/DatasetsClient.ts +48 -9
- package/src/projects/ProjectsClient.ts +0 -5
- package/src/stega/filterDefault.ts +30 -2
- package/src/types.ts +4 -0
- package/src/validators.ts +1 -0
- package/umd/sanityClient.js +83 -16
- package/umd/sanityClient.min.js +2 -2
package/dist/index.browser.d.cts
CHANGED
|
@@ -780,6 +780,10 @@ declare type ClientConfigResource =
|
|
|
780
780
|
type: 'dashboard'
|
|
781
781
|
id: string
|
|
782
782
|
}
|
|
783
|
+
| {
|
|
784
|
+
type: 'project'
|
|
785
|
+
id: string
|
|
786
|
+
}
|
|
783
787
|
|
|
784
788
|
/** @public */
|
|
785
789
|
export declare class ClientError extends Error {
|
|
@@ -798,6 +802,14 @@ export declare type ClientPerspective =
|
|
|
798
802
|
| 'raw'
|
|
799
803
|
| StackablePerspective[]
|
|
800
804
|
|
|
805
|
+
/** @public */
|
|
806
|
+
declare type ClientPerspective_2 =
|
|
807
|
+
| DeprecatedPreviewDrafts_2
|
|
808
|
+
| 'published'
|
|
809
|
+
| 'drafts'
|
|
810
|
+
| 'raw'
|
|
811
|
+
| StackablePerspective_2[]
|
|
812
|
+
|
|
801
813
|
/** @public */
|
|
802
814
|
export declare type ClientReturn<
|
|
803
815
|
GroqString extends string,
|
|
@@ -1147,6 +1159,11 @@ export default deprecatedCreateClient
|
|
|
1147
1159
|
*/
|
|
1148
1160
|
declare type DeprecatedPreviewDrafts = 'previewDrafts'
|
|
1149
1161
|
|
|
1162
|
+
/**
|
|
1163
|
+
* @deprecated use 'drafts' instead
|
|
1164
|
+
*/
|
|
1165
|
+
declare type DeprecatedPreviewDrafts_2 = 'previewDrafts'
|
|
1166
|
+
|
|
1150
1167
|
/**
|
|
1151
1168
|
* Delete the draft version of a document.
|
|
1152
1169
|
* It is an error if it does not exist. If the purge flag is set, the document history is also deleted.
|
|
@@ -1745,6 +1762,7 @@ export declare interface GroqAgentActionParam {
|
|
|
1745
1762
|
type: 'groq'
|
|
1746
1763
|
query: string
|
|
1747
1764
|
params?: Record<string, string>
|
|
1765
|
+
perspective?: ClientPerspective_2
|
|
1748
1766
|
}
|
|
1749
1767
|
|
|
1750
1768
|
/**
|
|
@@ -3822,10 +3840,8 @@ export declare class ProjectsClient {
|
|
|
3822
3840
|
declare interface PromptJsonResponse<T extends Record<string, Any> = Record<string, Any>> {
|
|
3823
3841
|
/**
|
|
3824
3842
|
*
|
|
3825
|
-
* When
|
|
3826
|
-
*
|
|
3827
|
-
*
|
|
3828
|
-
* Note: In addition to setting this to true, `instruction` MUST include the word 'JSON', or 'json' for this to work.
|
|
3843
|
+
* When format is 'json', the response will be json according to the instruction.
|
|
3844
|
+
* Note: In addition to setting this to 'json', `instruction` MUST include the word 'JSON', or 'json' for this to work.
|
|
3829
3845
|
*/
|
|
3830
3846
|
format: 'json'
|
|
3831
3847
|
}
|
|
@@ -3932,13 +3948,9 @@ declare interface PromptRequestBase {
|
|
|
3932
3948
|
|
|
3933
3949
|
declare interface PromptTextResponse {
|
|
3934
3950
|
/**
|
|
3935
|
-
*
|
|
3936
|
-
* When true, the response body will be json according to the instruction.
|
|
3937
|
-
* When false, the response is the raw text response to the instruction.
|
|
3938
|
-
*
|
|
3939
|
-
* Note: In addition to setting this to true, `instruction` MUST include the word 'JSON', or 'json' for this to work.
|
|
3951
|
+
* When format is 'string', the response will be a raw text response to the instruction.
|
|
3940
3952
|
*/
|
|
3941
|
-
format?: '
|
|
3953
|
+
format?: 'string'
|
|
3942
3954
|
}
|
|
3943
3955
|
|
|
3944
3956
|
/**
|
|
@@ -5490,6 +5502,9 @@ export declare interface SingleMutationResult {
|
|
|
5490
5502
|
/** @public */
|
|
5491
5503
|
export declare type StackablePerspective = ('published' | 'drafts' | string) & {}
|
|
5492
5504
|
|
|
5505
|
+
/** @public */
|
|
5506
|
+
declare type StackablePerspective_2 = ('published' | 'drafts' | string) & {}
|
|
5507
|
+
|
|
5493
5508
|
/** @public */
|
|
5494
5509
|
export declare interface StegaConfig {
|
|
5495
5510
|
/**
|
package/dist/index.browser.d.ts
CHANGED
|
@@ -780,6 +780,10 @@ declare type ClientConfigResource =
|
|
|
780
780
|
type: 'dashboard'
|
|
781
781
|
id: string
|
|
782
782
|
}
|
|
783
|
+
| {
|
|
784
|
+
type: 'project'
|
|
785
|
+
id: string
|
|
786
|
+
}
|
|
783
787
|
|
|
784
788
|
/** @public */
|
|
785
789
|
export declare class ClientError extends Error {
|
|
@@ -798,6 +802,14 @@ export declare type ClientPerspective =
|
|
|
798
802
|
| 'raw'
|
|
799
803
|
| StackablePerspective[]
|
|
800
804
|
|
|
805
|
+
/** @public */
|
|
806
|
+
declare type ClientPerspective_2 =
|
|
807
|
+
| DeprecatedPreviewDrafts_2
|
|
808
|
+
| 'published'
|
|
809
|
+
| 'drafts'
|
|
810
|
+
| 'raw'
|
|
811
|
+
| StackablePerspective_2[]
|
|
812
|
+
|
|
801
813
|
/** @public */
|
|
802
814
|
export declare type ClientReturn<
|
|
803
815
|
GroqString extends string,
|
|
@@ -1147,6 +1159,11 @@ export default deprecatedCreateClient
|
|
|
1147
1159
|
*/
|
|
1148
1160
|
declare type DeprecatedPreviewDrafts = 'previewDrafts'
|
|
1149
1161
|
|
|
1162
|
+
/**
|
|
1163
|
+
* @deprecated use 'drafts' instead
|
|
1164
|
+
*/
|
|
1165
|
+
declare type DeprecatedPreviewDrafts_2 = 'previewDrafts'
|
|
1166
|
+
|
|
1150
1167
|
/**
|
|
1151
1168
|
* Delete the draft version of a document.
|
|
1152
1169
|
* It is an error if it does not exist. If the purge flag is set, the document history is also deleted.
|
|
@@ -1745,6 +1762,7 @@ export declare interface GroqAgentActionParam {
|
|
|
1745
1762
|
type: 'groq'
|
|
1746
1763
|
query: string
|
|
1747
1764
|
params?: Record<string, string>
|
|
1765
|
+
perspective?: ClientPerspective_2
|
|
1748
1766
|
}
|
|
1749
1767
|
|
|
1750
1768
|
/**
|
|
@@ -3822,10 +3840,8 @@ export declare class ProjectsClient {
|
|
|
3822
3840
|
declare interface PromptJsonResponse<T extends Record<string, Any> = Record<string, Any>> {
|
|
3823
3841
|
/**
|
|
3824
3842
|
*
|
|
3825
|
-
* When
|
|
3826
|
-
*
|
|
3827
|
-
*
|
|
3828
|
-
* Note: In addition to setting this to true, `instruction` MUST include the word 'JSON', or 'json' for this to work.
|
|
3843
|
+
* When format is 'json', the response will be json according to the instruction.
|
|
3844
|
+
* Note: In addition to setting this to 'json', `instruction` MUST include the word 'JSON', or 'json' for this to work.
|
|
3829
3845
|
*/
|
|
3830
3846
|
format: 'json'
|
|
3831
3847
|
}
|
|
@@ -3932,13 +3948,9 @@ declare interface PromptRequestBase {
|
|
|
3932
3948
|
|
|
3933
3949
|
declare interface PromptTextResponse {
|
|
3934
3950
|
/**
|
|
3935
|
-
*
|
|
3936
|
-
* When true, the response body will be json according to the instruction.
|
|
3937
|
-
* When false, the response is the raw text response to the instruction.
|
|
3938
|
-
*
|
|
3939
|
-
* Note: In addition to setting this to true, `instruction` MUST include the word 'JSON', or 'json' for this to work.
|
|
3951
|
+
* When format is 'string', the response will be a raw text response to the instruction.
|
|
3940
3952
|
*/
|
|
3941
|
-
format?: '
|
|
3953
|
+
format?: 'string'
|
|
3942
3954
|
}
|
|
3943
3955
|
|
|
3944
3956
|
/**
|
|
@@ -5490,6 +5502,9 @@ export declare interface SingleMutationResult {
|
|
|
5490
5502
|
/** @public */
|
|
5491
5503
|
export declare type StackablePerspective = ('published' | 'drafts' | string) & {}
|
|
5492
5504
|
|
|
5505
|
+
/** @public */
|
|
5506
|
+
declare type StackablePerspective_2 = ('published' | 'drafts' | string) & {}
|
|
5507
|
+
|
|
5493
5508
|
/** @public */
|
|
5494
5509
|
export declare interface StegaConfig {
|
|
5495
5510
|
/**
|
package/dist/index.browser.js
CHANGED
|
@@ -276,6 +276,7 @@ const VALID_ASSET_TYPES = ["image", "file"], VALID_INSERT_LOCATIONS = ["before",
|
|
|
276
276
|
throw new Error('Dataset resource ID must be in the format "project.dataset"');
|
|
277
277
|
return;
|
|
278
278
|
}
|
|
279
|
+
case "project":
|
|
279
280
|
case "dashboard":
|
|
280
281
|
case "media-library":
|
|
281
282
|
case "canvas":
|
|
@@ -1100,10 +1101,24 @@ function _request(client, httpRequest, options) {
|
|
|
1100
1101
|
function _getDataUrl(client, operation, path) {
|
|
1101
1102
|
const config = client.config();
|
|
1102
1103
|
if (config["~experimental_resource"]) {
|
|
1103
|
-
resourceConfig(config)
|
|
1104
|
-
|
|
1104
|
+
if (resourceConfig(config), operation === "" && path?.startsWith("datasets")) {
|
|
1105
|
+
const { type, id } = config["~experimental_resource"];
|
|
1106
|
+
if (type === "dataset") {
|
|
1107
|
+
const segments = id.split(".");
|
|
1108
|
+
if (segments.length !== 2)
|
|
1109
|
+
throw new Error('Invalid dataset resource ID. Expected format "project.dataset".');
|
|
1110
|
+
const base = `/projects/${segments[0]}`, uri3 = [path].filter(Boolean).join("/");
|
|
1111
|
+
return `${base}/${uri3}`.replace(/\/($|\?)/, "$1");
|
|
1112
|
+
} else if (type === "project") {
|
|
1113
|
+
const base = `/projects/${id}`, uri3 = [path].filter(Boolean).join("/");
|
|
1114
|
+
return `${base}/${uri3}`.replace(/\/($|\?)/, "$1");
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
const resourceBase = resourceDataBase(config), uri2 = [operation, path].filter(Boolean).join("/");
|
|
1105
1118
|
return `${resourceBase}/${uri2}`.replace(/\/($|\?)/, "$1");
|
|
1106
1119
|
}
|
|
1120
|
+
if (operation === "")
|
|
1121
|
+
return `/${path || ""}`;
|
|
1107
1122
|
const catalog = hasDataset(config), baseUri = `/${operation}/${catalog}`;
|
|
1108
1123
|
return `/data${path !== void 0 ? `${baseUri}/${path}` : baseUri}`.replace(/\/($|\?)/, "$1");
|
|
1109
1124
|
}
|
|
@@ -1148,6 +1163,8 @@ const resourceDataBase = (config) => {
|
|
|
1148
1163
|
return `/media-libraries/${id}`;
|
|
1149
1164
|
case "dashboard":
|
|
1150
1165
|
return `/dashboards/${id}`;
|
|
1166
|
+
case "project":
|
|
1167
|
+
return `/projects/${id}`;
|
|
1151
1168
|
default:
|
|
1152
1169
|
throw new Error(`Unsupported resource type: ${type.toString()}`);
|
|
1153
1170
|
}
|
|
@@ -1318,6 +1335,10 @@ function buildAssetUploadUrl(config, assetType) {
|
|
|
1318
1335
|
if (config["~experimental_resource"]) {
|
|
1319
1336
|
const { type, id } = config["~experimental_resource"];
|
|
1320
1337
|
switch (type) {
|
|
1338
|
+
case "project":
|
|
1339
|
+
throw new Error(
|
|
1340
|
+
"Assets are not supported for project resources, yet. Configure the client with `{projectId: <projectId>}` instead."
|
|
1341
|
+
);
|
|
1321
1342
|
case "dataset":
|
|
1322
1343
|
throw new Error(
|
|
1323
1344
|
"Assets are not supported for dataset resources, yet. Configure the client with `{projectId: <projectId>, dataset: <datasetId>}` instead."
|
|
@@ -1535,8 +1556,12 @@ class ObservableDatasetsClient {
|
|
|
1535
1556
|
* Fetch a list of datasets for the configured project
|
|
1536
1557
|
*/
|
|
1537
1558
|
list() {
|
|
1559
|
+
const resource = this.#client.config()["~experimental_resource"];
|
|
1560
|
+
if (resource && resource.type !== "project")
|
|
1561
|
+
throw new Error('`dataset.list()` requires a resource type of "project".');
|
|
1562
|
+
const uri = _getDataUrl(this.#client, "", "datasets");
|
|
1538
1563
|
return _request(this.#client, this.#httpRequest, {
|
|
1539
|
-
uri
|
|
1564
|
+
uri,
|
|
1540
1565
|
tag: null
|
|
1541
1566
|
});
|
|
1542
1567
|
}
|
|
@@ -1554,7 +1579,7 @@ class DatasetsClient {
|
|
|
1554
1579
|
* @param options - Options for the dataset
|
|
1555
1580
|
*/
|
|
1556
1581
|
create(name, options) {
|
|
1557
|
-
return
|
|
1582
|
+
return lastValueFrom(
|
|
1558
1583
|
_modify(this.#client, this.#httpRequest, "PUT", name, options)
|
|
1559
1584
|
);
|
|
1560
1585
|
}
|
|
@@ -1565,7 +1590,7 @@ class DatasetsClient {
|
|
|
1565
1590
|
* @param options - New options for the dataset
|
|
1566
1591
|
*/
|
|
1567
1592
|
edit(name, options) {
|
|
1568
|
-
return
|
|
1593
|
+
return lastValueFrom(
|
|
1569
1594
|
_modify(this.#client, this.#httpRequest, "PATCH", name, options)
|
|
1570
1595
|
);
|
|
1571
1596
|
}
|
|
@@ -1575,21 +1600,38 @@ class DatasetsClient {
|
|
|
1575
1600
|
* @param name - Name of the dataset to delete
|
|
1576
1601
|
*/
|
|
1577
1602
|
delete(name) {
|
|
1578
|
-
return
|
|
1603
|
+
return lastValueFrom(_modify(this.#client, this.#httpRequest, "DELETE", name));
|
|
1579
1604
|
}
|
|
1580
1605
|
/**
|
|
1581
1606
|
* Fetch a list of datasets for the configured project
|
|
1582
1607
|
*/
|
|
1583
1608
|
list() {
|
|
1584
|
-
|
|
1585
|
-
|
|
1609
|
+
const resource = this.#client.config()["~experimental_resource"];
|
|
1610
|
+
if (resource && resource.type !== "project")
|
|
1611
|
+
throw new Error('`dataset.list()` requires a resource type of "project".');
|
|
1612
|
+
const uri = _getDataUrl(this.#client, "", "datasets");
|
|
1613
|
+
return lastValueFrom(
|
|
1614
|
+
_request(this.#client, this.#httpRequest, { uri, tag: null })
|
|
1586
1615
|
);
|
|
1587
1616
|
}
|
|
1588
1617
|
}
|
|
1589
1618
|
function _modify(client, httpRequest, method, name, options) {
|
|
1590
|
-
|
|
1619
|
+
dataset(name);
|
|
1620
|
+
const resource = client.config()["~experimental_resource"];
|
|
1621
|
+
if (resource)
|
|
1622
|
+
if (resource.type === "dataset") {
|
|
1623
|
+
const segments = resource.id.split(".");
|
|
1624
|
+
if (segments.length !== 2)
|
|
1625
|
+
throw new Error('Dataset resource ID must be in the format "project.dataset"');
|
|
1626
|
+
const datasetName = segments[1];
|
|
1627
|
+
if (name !== datasetName)
|
|
1628
|
+
throw new Error(`Dataset name "${name}" does not match resource dataset "${datasetName}"`);
|
|
1629
|
+
} else
|
|
1630
|
+
throw new Error('Dataset create/edit/delete operations require a resource type of "dataset"');
|
|
1631
|
+
const uri = _getDataUrl(client, "", `datasets/${name}`);
|
|
1632
|
+
return _request(client, httpRequest, {
|
|
1591
1633
|
method,
|
|
1592
|
-
uri
|
|
1634
|
+
uri,
|
|
1593
1635
|
body: options,
|
|
1594
1636
|
tag: null
|
|
1595
1637
|
});
|
|
@@ -1601,7 +1643,6 @@ class ObservableProjectsClient {
|
|
|
1601
1643
|
this.#client = client, this.#httpRequest = httpRequest;
|
|
1602
1644
|
}
|
|
1603
1645
|
list(options) {
|
|
1604
|
-
resourceGuard("projects", this.#client.config());
|
|
1605
1646
|
const uri = options?.includeMembers === !1 ? "/projects?includeMembers=false" : "/projects";
|
|
1606
1647
|
return _request(this.#client, this.#httpRequest, { uri });
|
|
1607
1648
|
}
|
|
@@ -1611,7 +1652,7 @@ class ObservableProjectsClient {
|
|
|
1611
1652
|
* @param projectId - ID of the project to fetch
|
|
1612
1653
|
*/
|
|
1613
1654
|
getById(projectId2) {
|
|
1614
|
-
return
|
|
1655
|
+
return _request(this.#client, this.#httpRequest, { uri: `/projects/${projectId2}` });
|
|
1615
1656
|
}
|
|
1616
1657
|
}
|
|
1617
1658
|
class ProjectsClient {
|
|
@@ -1621,7 +1662,6 @@ class ProjectsClient {
|
|
|
1621
1662
|
this.#client = client, this.#httpRequest = httpRequest;
|
|
1622
1663
|
}
|
|
1623
1664
|
list(options) {
|
|
1624
|
-
resourceGuard("projects", this.#client.config());
|
|
1625
1665
|
const uri = options?.includeMembers === !1 ? "/projects?includeMembers=false" : "/projects";
|
|
1626
1666
|
return lastValueFrom(_request(this.#client, this.#httpRequest, { uri }));
|
|
1627
1667
|
}
|
|
@@ -1631,7 +1671,7 @@ class ProjectsClient {
|
|
|
1631
1671
|
* @param projectId - ID of the project to fetch
|
|
1632
1672
|
*/
|
|
1633
1673
|
getById(projectId2) {
|
|
1634
|
-
return
|
|
1674
|
+
return lastValueFrom(
|
|
1635
1675
|
_request(this.#client, this.#httpRequest, { uri: `/projects/${projectId2}` })
|
|
1636
1676
|
);
|
|
1637
1677
|
}
|