@sanity/client 7.8.2-datasets.0 → 7.9.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/_chunks-cjs/config.cjs +0 -1
- package/dist/_chunks-cjs/config.cjs.map +1 -1
- package/dist/_chunks-es/config.js +0 -1
- package/dist/_chunks-es/config.js.map +1 -1
- package/dist/index.browser.cjs +15 -51
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +4 -4
- package/dist/index.browser.d.ts +4 -4
- package/dist/index.browser.js +15 -51
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +16 -51
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +16 -51
- package/dist/index.js.map +1 -1
- package/dist/stega.browser.d.cts +4 -4
- package/dist/stega.browser.d.ts +4 -4
- package/dist/stega.d.cts +4 -4
- package/dist/stega.d.ts +4 -4
- package/package.json +1 -1
- package/src/assets/AssetsClient.ts +0 -5
- package/src/data/dataMethods.ts +1 -34
- package/src/datasets/DatasetsClient.ts +16 -39
- package/src/types.ts +4 -4
- package/src/validators.ts +0 -1
- package/umd/sanityClient.js +15 -51
- package/umd/sanityClient.min.js +2 -2
package/dist/stega.browser.d.cts
CHANGED
|
@@ -774,10 +774,6 @@ declare type ClientConfigResource =
|
|
|
774
774
|
type: 'dashboard'
|
|
775
775
|
id: string
|
|
776
776
|
}
|
|
777
|
-
| {
|
|
778
|
-
type: 'project'
|
|
779
|
-
id: string
|
|
780
|
-
}
|
|
781
777
|
|
|
782
778
|
/** @public */
|
|
783
779
|
export declare class ClientError extends Error {
|
|
@@ -4288,6 +4284,9 @@ export declare type ReleaseAction =
|
|
|
4288
4284
|
| UnscheduleReleaseAction
|
|
4289
4285
|
| DeleteReleaseAction
|
|
4290
4286
|
|
|
4287
|
+
/** @public */
|
|
4288
|
+
export declare type ReleaseCardinality = 'many' | 'one' | undefined
|
|
4289
|
+
|
|
4291
4290
|
/** @internal */
|
|
4292
4291
|
export declare interface ReleaseDocument extends SanityDocument {
|
|
4293
4292
|
/**
|
|
@@ -4324,6 +4323,7 @@ export declare interface ReleaseDocument extends SanityDocument {
|
|
|
4324
4323
|
description?: string
|
|
4325
4324
|
intendedPublishAt?: string
|
|
4326
4325
|
releaseType: ReleaseType
|
|
4326
|
+
cardinality?: ReleaseCardinality
|
|
4327
4327
|
}
|
|
4328
4328
|
}
|
|
4329
4329
|
|
package/dist/stega.browser.d.ts
CHANGED
|
@@ -774,10 +774,6 @@ declare type ClientConfigResource =
|
|
|
774
774
|
type: 'dashboard'
|
|
775
775
|
id: string
|
|
776
776
|
}
|
|
777
|
-
| {
|
|
778
|
-
type: 'project'
|
|
779
|
-
id: string
|
|
780
|
-
}
|
|
781
777
|
|
|
782
778
|
/** @public */
|
|
783
779
|
export declare class ClientError extends Error {
|
|
@@ -4288,6 +4284,9 @@ export declare type ReleaseAction =
|
|
|
4288
4284
|
| UnscheduleReleaseAction
|
|
4289
4285
|
| DeleteReleaseAction
|
|
4290
4286
|
|
|
4287
|
+
/** @public */
|
|
4288
|
+
export declare type ReleaseCardinality = 'many' | 'one' | undefined
|
|
4289
|
+
|
|
4291
4290
|
/** @internal */
|
|
4292
4291
|
export declare interface ReleaseDocument extends SanityDocument {
|
|
4293
4292
|
/**
|
|
@@ -4324,6 +4323,7 @@ export declare interface ReleaseDocument extends SanityDocument {
|
|
|
4324
4323
|
description?: string
|
|
4325
4324
|
intendedPublishAt?: string
|
|
4326
4325
|
releaseType: ReleaseType
|
|
4326
|
+
cardinality?: ReleaseCardinality
|
|
4327
4327
|
}
|
|
4328
4328
|
}
|
|
4329
4329
|
|
package/dist/stega.d.cts
CHANGED
|
@@ -774,10 +774,6 @@ declare type ClientConfigResource =
|
|
|
774
774
|
type: 'dashboard'
|
|
775
775
|
id: string
|
|
776
776
|
}
|
|
777
|
-
| {
|
|
778
|
-
type: 'project'
|
|
779
|
-
id: string
|
|
780
|
-
}
|
|
781
777
|
|
|
782
778
|
/** @public */
|
|
783
779
|
export declare class ClientError extends Error {
|
|
@@ -4288,6 +4284,9 @@ export declare type ReleaseAction =
|
|
|
4288
4284
|
| UnscheduleReleaseAction
|
|
4289
4285
|
| DeleteReleaseAction
|
|
4290
4286
|
|
|
4287
|
+
/** @public */
|
|
4288
|
+
export declare type ReleaseCardinality = 'many' | 'one' | undefined
|
|
4289
|
+
|
|
4291
4290
|
/** @internal */
|
|
4292
4291
|
export declare interface ReleaseDocument extends SanityDocument {
|
|
4293
4292
|
/**
|
|
@@ -4324,6 +4323,7 @@ export declare interface ReleaseDocument extends SanityDocument {
|
|
|
4324
4323
|
description?: string
|
|
4325
4324
|
intendedPublishAt?: string
|
|
4326
4325
|
releaseType: ReleaseType
|
|
4326
|
+
cardinality?: ReleaseCardinality
|
|
4327
4327
|
}
|
|
4328
4328
|
}
|
|
4329
4329
|
|
package/dist/stega.d.ts
CHANGED
|
@@ -774,10 +774,6 @@ declare type ClientConfigResource =
|
|
|
774
774
|
type: 'dashboard'
|
|
775
775
|
id: string
|
|
776
776
|
}
|
|
777
|
-
| {
|
|
778
|
-
type: 'project'
|
|
779
|
-
id: string
|
|
780
|
-
}
|
|
781
777
|
|
|
782
778
|
/** @public */
|
|
783
779
|
export declare class ClientError extends Error {
|
|
@@ -4288,6 +4284,9 @@ export declare type ReleaseAction =
|
|
|
4288
4284
|
| UnscheduleReleaseAction
|
|
4289
4285
|
| DeleteReleaseAction
|
|
4290
4286
|
|
|
4287
|
+
/** @public */
|
|
4288
|
+
export declare type ReleaseCardinality = 'many' | 'one' | undefined
|
|
4289
|
+
|
|
4291
4290
|
/** @internal */
|
|
4292
4291
|
export declare interface ReleaseDocument extends SanityDocument {
|
|
4293
4292
|
/**
|
|
@@ -4324,6 +4323,7 @@ export declare interface ReleaseDocument extends SanityDocument {
|
|
|
4324
4323
|
description?: string
|
|
4325
4324
|
intendedPublishAt?: string
|
|
4326
4325
|
releaseType: ReleaseType
|
|
4326
|
+
cardinality?: ReleaseCardinality
|
|
4327
4327
|
}
|
|
4328
4328
|
}
|
|
4329
4329
|
|
package/package.json
CHANGED
|
@@ -184,11 +184,6 @@ function buildAssetUploadUrl(config: InitializedClientConfig, assetType: 'image'
|
|
|
184
184
|
if (config['~experimental_resource']) {
|
|
185
185
|
const {type, id} = config['~experimental_resource']
|
|
186
186
|
switch (type) {
|
|
187
|
-
case 'project': {
|
|
188
|
-
throw new Error(
|
|
189
|
-
'Assets are not supported for project resources, yet. Configure the client with `{projectId: <projectId>}` instead.',
|
|
190
|
-
)
|
|
191
|
-
}
|
|
192
187
|
case 'dataset': {
|
|
193
188
|
throw new Error(
|
|
194
189
|
'Assets are not supported for dataset resources, yet. Configure the client with `{projectId: <projectId>, dataset: <datasetId>}` instead.',
|
package/src/data/dataMethods.ts
CHANGED
|
@@ -664,40 +664,10 @@ export function _getDataUrl(client: Client, operation: string, path?: string): s
|
|
|
664
664
|
const config = client.config()
|
|
665
665
|
if (config['~experimental_resource']) {
|
|
666
666
|
validators.resourceConfig(config)
|
|
667
|
-
|
|
668
|
-
// Special handling for dataset-related operations
|
|
669
|
-
if (operation === '' && path?.startsWith('datasets')) {
|
|
670
|
-
const {type, id} = config['~experimental_resource']
|
|
671
|
-
|
|
672
|
-
if (type === 'dataset') {
|
|
673
|
-
// For dataset resource performing dataset management operations,
|
|
674
|
-
// we need to use the project base URL
|
|
675
|
-
const segments = id.split('.')
|
|
676
|
-
if (segments.length !== 2) {
|
|
677
|
-
throw new Error('Invalid dataset resource ID. Expected format "project.dataset".')
|
|
678
|
-
}
|
|
679
|
-
const projectId = segments[0]
|
|
680
|
-
const base = `/projects/${projectId}`
|
|
681
|
-
const uri = [path].filter(Boolean).join('/')
|
|
682
|
-
return `${base}/${uri}`.replace(/\/($|\?)/, '$1')
|
|
683
|
-
} else if (type === 'project') {
|
|
684
|
-
// For project resource, use project base directly
|
|
685
|
-
const base = `/projects/${id}`
|
|
686
|
-
const uri = [path].filter(Boolean).join('/')
|
|
687
|
-
return `${base}/${uri}`.replace(/\/($|\?)/, '$1')
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
|
|
691
|
-
// For all other resource operations, use the standard resource base
|
|
692
667
|
const resourceBase = resourceDataBase(config)
|
|
693
|
-
const uri =
|
|
668
|
+
const uri = path !== undefined ? `${operation}/${path}` : operation
|
|
694
669
|
return `${resourceBase}/${uri}`.replace(/\/($|\?)/, '$1')
|
|
695
670
|
}
|
|
696
|
-
|
|
697
|
-
if (operation === '') {
|
|
698
|
-
return `/${path || ''}`
|
|
699
|
-
}
|
|
700
|
-
|
|
701
671
|
const catalog = validators.hasDataset(config)
|
|
702
672
|
const baseUri = `/${operation}/${catalog}`
|
|
703
673
|
const uri = path !== undefined ? `${baseUri}/${path}` : baseUri
|
|
@@ -783,9 +753,6 @@ const resourceDataBase = (config: InitializedClientConfig): string => {
|
|
|
783
753
|
case 'dashboard': {
|
|
784
754
|
return `/dashboards/${id}`
|
|
785
755
|
}
|
|
786
|
-
case 'project': {
|
|
787
|
-
return `/projects/${id}`
|
|
788
|
-
}
|
|
789
756
|
default:
|
|
790
757
|
// @ts-expect-error - handle all supported resource types
|
|
791
758
|
throw new Error(`Unsupported resource type: ${type.toString()}`)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {lastValueFrom, type Observable} from 'rxjs'
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {_request} from '../data/dataMethods'
|
|
4
4
|
import type {ObservableSanityClient, SanityClient} from '../SanityClient'
|
|
5
5
|
import type {DatasetAclMode, DatasetResponse, DatasetsResponse, HttpRequest} from '../types'
|
|
6
6
|
import * as validate from '../validators'
|
|
@@ -47,17 +47,14 @@ export class ObservableDatasetsClient {
|
|
|
47
47
|
* Fetch a list of datasets for the configured project
|
|
48
48
|
*/
|
|
49
49
|
list(): Observable<DatasetsResponse> {
|
|
50
|
+
validate.resourceGuard('dataset', this.#client.config())
|
|
50
51
|
const config = this.#client.config()
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
if (
|
|
54
|
-
|
|
55
|
-
if (resource.type !== 'project') {
|
|
56
|
-
throw new Error('`dataset.list()` requires a resource type of "project".')
|
|
57
|
-
}
|
|
52
|
+
const projectId = config.projectId
|
|
53
|
+
let uri = '/datasets'
|
|
54
|
+
if (config.useProjectHostname === false) {
|
|
55
|
+
uri = `/projects/${projectId}/datasets`
|
|
58
56
|
}
|
|
59
57
|
|
|
60
|
-
const uri = _getDataUrl(this.#client, '', 'datasets')
|
|
61
58
|
return _request<DatasetsResponse>(this.#client, this.#httpRequest, {
|
|
62
59
|
uri,
|
|
63
60
|
tag: null,
|
|
@@ -81,6 +78,7 @@ export class DatasetsClient {
|
|
|
81
78
|
* @param options - Options for the dataset
|
|
82
79
|
*/
|
|
83
80
|
create(name: string, options?: {aclMode?: DatasetAclMode}): Promise<DatasetResponse> {
|
|
81
|
+
validate.resourceGuard('dataset', this.#client.config())
|
|
84
82
|
return lastValueFrom(
|
|
85
83
|
_modify<DatasetResponse>(this.#client, this.#httpRequest, 'PUT', name, options),
|
|
86
84
|
)
|
|
@@ -93,6 +91,7 @@ export class DatasetsClient {
|
|
|
93
91
|
* @param options - New options for the dataset
|
|
94
92
|
*/
|
|
95
93
|
edit(name: string, options?: {aclMode?: DatasetAclMode}): Promise<DatasetResponse> {
|
|
94
|
+
validate.resourceGuard('dataset', this.#client.config())
|
|
96
95
|
return lastValueFrom(
|
|
97
96
|
_modify<DatasetResponse>(this.#client, this.#httpRequest, 'PATCH', name, options),
|
|
98
97
|
)
|
|
@@ -104,6 +103,7 @@ export class DatasetsClient {
|
|
|
104
103
|
* @param name - Name of the dataset to delete
|
|
105
104
|
*/
|
|
106
105
|
delete(name: string): Promise<{deleted: true}> {
|
|
106
|
+
validate.resourceGuard('dataset', this.#client.config())
|
|
107
107
|
return lastValueFrom(_modify<{deleted: true}>(this.#client, this.#httpRequest, 'DELETE', name))
|
|
108
108
|
}
|
|
109
109
|
|
|
@@ -111,17 +111,14 @@ export class DatasetsClient {
|
|
|
111
111
|
* Fetch a list of datasets for the configured project
|
|
112
112
|
*/
|
|
113
113
|
list(): Promise<DatasetsResponse> {
|
|
114
|
+
validate.resourceGuard('dataset', this.#client.config())
|
|
114
115
|
const config = this.#client.config()
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
if (
|
|
118
|
-
|
|
119
|
-
if (resource.type !== 'project') {
|
|
120
|
-
throw new Error('`dataset.list()` requires a resource type of "project".')
|
|
121
|
-
}
|
|
116
|
+
const projectId = config.projectId
|
|
117
|
+
let uri = '/datasets'
|
|
118
|
+
if (config.useProjectHostname === false) {
|
|
119
|
+
uri = `/projects/${projectId}/datasets`
|
|
122
120
|
}
|
|
123
121
|
|
|
124
|
-
const uri = _getDataUrl(this.#client, '', 'datasets')
|
|
125
122
|
return lastValueFrom(
|
|
126
123
|
_request<DatasetsResponse>(this.#client, this.#httpRequest, {uri, tag: null}),
|
|
127
124
|
)
|
|
@@ -135,32 +132,12 @@ function _modify<R = unknown>(
|
|
|
135
132
|
name: string,
|
|
136
133
|
options?: {aclMode?: DatasetAclMode},
|
|
137
134
|
) {
|
|
135
|
+
validate.resourceGuard('dataset', client.config())
|
|
138
136
|
validate.dataset(name)
|
|
139
137
|
|
|
140
|
-
const config = client.config()
|
|
141
|
-
const resource = config['~experimental_resource']
|
|
142
|
-
|
|
143
|
-
// For individual dataset operations, only "dataset" resource type makes sense
|
|
144
|
-
if (resource) {
|
|
145
|
-
if (resource.type === 'dataset') {
|
|
146
|
-
// Validate the resource ID format and ensure the name matches
|
|
147
|
-
const segments = resource.id.split('.')
|
|
148
|
-
if (segments.length !== 2) {
|
|
149
|
-
throw new Error('Dataset resource ID must be in the format "project.dataset"')
|
|
150
|
-
}
|
|
151
|
-
const datasetName = segments[1]
|
|
152
|
-
if (name !== datasetName) {
|
|
153
|
-
throw new Error(`Dataset name "${name}" does not match resource dataset "${datasetName}"`)
|
|
154
|
-
}
|
|
155
|
-
} else {
|
|
156
|
-
throw new Error('Dataset create/edit/delete operations require a resource type of "dataset"')
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
const uri = _getDataUrl(client, '', `datasets/${name}`)
|
|
161
138
|
return _request<R>(client, httpRequest, {
|
|
162
139
|
method,
|
|
163
|
-
uri
|
|
140
|
+
uri: `/datasets/${name}`,
|
|
164
141
|
body: options,
|
|
165
142
|
tag: null,
|
|
166
143
|
})
|
package/src/types.ts
CHANGED
|
@@ -70,10 +70,6 @@ type ClientConfigResource =
|
|
|
70
70
|
type: 'dashboard'
|
|
71
71
|
id: string
|
|
72
72
|
}
|
|
73
|
-
| {
|
|
74
|
-
type: 'project'
|
|
75
|
-
id: string
|
|
76
|
-
}
|
|
77
73
|
|
|
78
74
|
/** @public */
|
|
79
75
|
export interface ClientConfig {
|
|
@@ -1480,6 +1476,9 @@ export type ReleaseState =
|
|
|
1480
1476
|
/** @internal */
|
|
1481
1477
|
export type ReleaseType = 'asap' | 'scheduled' | 'undecided'
|
|
1482
1478
|
|
|
1479
|
+
/** @public */
|
|
1480
|
+
export type ReleaseCardinality = 'many' | 'one' | undefined
|
|
1481
|
+
|
|
1483
1482
|
/** @internal */
|
|
1484
1483
|
export interface ReleaseDocument extends SanityDocument {
|
|
1485
1484
|
/**
|
|
@@ -1516,6 +1515,7 @@ export interface ReleaseDocument extends SanityDocument {
|
|
|
1516
1515
|
description?: string
|
|
1517
1516
|
intendedPublishAt?: string
|
|
1518
1517
|
releaseType: ReleaseType
|
|
1518
|
+
cardinality?: ReleaseCardinality
|
|
1519
1519
|
}
|
|
1520
1520
|
}
|
|
1521
1521
|
|
package/src/validators.ts
CHANGED
package/umd/sanityClient.js
CHANGED
|
@@ -2250,7 +2250,6 @@ ${codeFrame(query, { start, end }, description)}${withTag}`;
|
|
|
2250
2250
|
throw new Error('Dataset resource ID must be in the format "project.dataset"');
|
|
2251
2251
|
return;
|
|
2252
2252
|
}
|
|
2253
|
-
case "project":
|
|
2254
2253
|
case "dashboard":
|
|
2255
2254
|
case "media-library":
|
|
2256
2255
|
case "canvas":
|
|
@@ -3075,24 +3074,10 @@ ${selectionOpts}`);
|
|
|
3075
3074
|
function _getDataUrl(client, operation, path) {
|
|
3076
3075
|
const config = client.config();
|
|
3077
3076
|
if (config["~experimental_resource"]) {
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
if (type === "dataset") {
|
|
3081
|
-
const segments = id.split(".");
|
|
3082
|
-
if (segments.length !== 2)
|
|
3083
|
-
throw new Error('Invalid dataset resource ID. Expected format "project.dataset".');
|
|
3084
|
-
const base = `/projects/${segments[0]}`, uri3 = [path].filter(Boolean).join("/");
|
|
3085
|
-
return `${base}/${uri3}`.replace(/\/($|\?)/, "$1");
|
|
3086
|
-
} else if (type === "project") {
|
|
3087
|
-
const base = `/projects/${id}`, uri3 = [path].filter(Boolean).join("/");
|
|
3088
|
-
return `${base}/${uri3}`.replace(/\/($|\?)/, "$1");
|
|
3089
|
-
}
|
|
3090
|
-
}
|
|
3091
|
-
const resourceBase = resourceDataBase(config), uri2 = [operation, path].filter(Boolean).join("/");
|
|
3077
|
+
resourceConfig(config);
|
|
3078
|
+
const resourceBase = resourceDataBase(config), uri2 = path !== void 0 ? `${operation}/${path}` : operation;
|
|
3092
3079
|
return `${resourceBase}/${uri2}`.replace(/\/($|\?)/, "$1");
|
|
3093
3080
|
}
|
|
3094
|
-
if (operation === "")
|
|
3095
|
-
return `/${path || ""}`;
|
|
3096
3081
|
const catalog = hasDataset(config), baseUri = `/${operation}/${catalog}`;
|
|
3097
3082
|
return `/data${path !== void 0 ? `${baseUri}/${path}` : baseUri}`.replace(/\/($|\?)/, "$1");
|
|
3098
3083
|
}
|
|
@@ -3137,8 +3122,6 @@ ${selectionOpts}`);
|
|
|
3137
3122
|
return `/media-libraries/${id}`;
|
|
3138
3123
|
case "dashboard":
|
|
3139
3124
|
return `/dashboards/${id}`;
|
|
3140
|
-
case "project":
|
|
3141
|
-
return `/projects/${id}`;
|
|
3142
3125
|
default:
|
|
3143
3126
|
throw new Error(`Unsupported resource type: ${type.toString()}`);
|
|
3144
3127
|
}
|
|
@@ -3309,10 +3292,6 @@ ${selectionOpts}`);
|
|
|
3309
3292
|
if (config["~experimental_resource"]) {
|
|
3310
3293
|
const { type, id } = config["~experimental_resource"];
|
|
3311
3294
|
switch (type) {
|
|
3312
|
-
case "project":
|
|
3313
|
-
throw new Error(
|
|
3314
|
-
"Assets are not supported for project resources, yet. Configure the client with `{projectId: <projectId>}` instead."
|
|
3315
|
-
);
|
|
3316
3295
|
case "dataset":
|
|
3317
3296
|
throw new Error(
|
|
3318
3297
|
"Assets are not supported for dataset resources, yet. Configure the client with `{projectId: <projectId>, dataset: <datasetId>}` instead."
|
|
@@ -3530,11 +3509,10 @@ ${selectionOpts}`);
|
|
|
3530
3509
|
* Fetch a list of datasets for the configured project
|
|
3531
3510
|
*/
|
|
3532
3511
|
list() {
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
return _request(this.#client, this.#httpRequest, {
|
|
3512
|
+
resourceGuard("dataset", this.#client.config());
|
|
3513
|
+
const config = this.#client.config(), projectId2 = config.projectId;
|
|
3514
|
+
let uri = "/datasets";
|
|
3515
|
+
return config.useProjectHostname === false && (uri = `/projects/${projectId2}/datasets`), _request(this.#client, this.#httpRequest, {
|
|
3538
3516
|
uri,
|
|
3539
3517
|
tag: null
|
|
3540
3518
|
});
|
|
@@ -3553,7 +3531,7 @@ ${selectionOpts}`);
|
|
|
3553
3531
|
* @param options - Options for the dataset
|
|
3554
3532
|
*/
|
|
3555
3533
|
create(name, options) {
|
|
3556
|
-
return lastValueFrom(
|
|
3534
|
+
return resourceGuard("dataset", this.#client.config()), lastValueFrom(
|
|
3557
3535
|
_modify(this.#client, this.#httpRequest, "PUT", name, options)
|
|
3558
3536
|
);
|
|
3559
3537
|
}
|
|
@@ -3564,7 +3542,7 @@ ${selectionOpts}`);
|
|
|
3564
3542
|
* @param options - New options for the dataset
|
|
3565
3543
|
*/
|
|
3566
3544
|
edit(name, options) {
|
|
3567
|
-
return lastValueFrom(
|
|
3545
|
+
return resourceGuard("dataset", this.#client.config()), lastValueFrom(
|
|
3568
3546
|
_modify(this.#client, this.#httpRequest, "PATCH", name, options)
|
|
3569
3547
|
);
|
|
3570
3548
|
}
|
|
@@ -3574,38 +3552,24 @@ ${selectionOpts}`);
|
|
|
3574
3552
|
* @param name - Name of the dataset to delete
|
|
3575
3553
|
*/
|
|
3576
3554
|
delete(name) {
|
|
3577
|
-
return lastValueFrom(_modify(this.#client, this.#httpRequest, "DELETE", name));
|
|
3555
|
+
return resourceGuard("dataset", this.#client.config()), lastValueFrom(_modify(this.#client, this.#httpRequest, "DELETE", name));
|
|
3578
3556
|
}
|
|
3579
3557
|
/**
|
|
3580
3558
|
* Fetch a list of datasets for the configured project
|
|
3581
3559
|
*/
|
|
3582
3560
|
list() {
|
|
3583
|
-
|
|
3584
|
-
|
|
3585
|
-
|
|
3586
|
-
|
|
3587
|
-
return lastValueFrom(
|
|
3561
|
+
resourceGuard("dataset", this.#client.config());
|
|
3562
|
+
const config = this.#client.config(), projectId2 = config.projectId;
|
|
3563
|
+
let uri = "/datasets";
|
|
3564
|
+
return config.useProjectHostname === false && (uri = `/projects/${projectId2}/datasets`), lastValueFrom(
|
|
3588
3565
|
_request(this.#client, this.#httpRequest, { uri, tag: null })
|
|
3589
3566
|
);
|
|
3590
3567
|
}
|
|
3591
3568
|
}
|
|
3592
3569
|
function _modify(client, httpRequest, method, name, options) {
|
|
3593
|
-
dataset(name)
|
|
3594
|
-
const resource = client.config()["~experimental_resource"];
|
|
3595
|
-
if (resource)
|
|
3596
|
-
if (resource.type === "dataset") {
|
|
3597
|
-
const segments = resource.id.split(".");
|
|
3598
|
-
if (segments.length !== 2)
|
|
3599
|
-
throw new Error('Dataset resource ID must be in the format "project.dataset"');
|
|
3600
|
-
const datasetName = segments[1];
|
|
3601
|
-
if (name !== datasetName)
|
|
3602
|
-
throw new Error(`Dataset name "${name}" does not match resource dataset "${datasetName}"`);
|
|
3603
|
-
} else
|
|
3604
|
-
throw new Error('Dataset create/edit/delete operations require a resource type of "dataset"');
|
|
3605
|
-
const uri = _getDataUrl(client, "", `datasets/${name}`);
|
|
3606
|
-
return _request(client, httpRequest, {
|
|
3570
|
+
return resourceGuard("dataset", client.config()), dataset(name), _request(client, httpRequest, {
|
|
3607
3571
|
method,
|
|
3608
|
-
uri
|
|
3572
|
+
uri: `/datasets/${name}`,
|
|
3609
3573
|
body: options,
|
|
3610
3574
|
tag: null
|
|
3611
3575
|
});
|