@sanity/client 6.28.3-resources.0 → 6.28.3-resources.1
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 +10 -11
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +10 -11
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +11 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +11 -12
- package/dist/index.js.map +1 -1
- package/package.json +6 -25
- package/src/data/dataMethods.ts +23 -25
- package/umd/sanityClient.js +10 -11
- package/umd/sanityClient.min.js +2 -2
package/package.json
CHANGED
|
@@ -1,17 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/client",
|
|
3
|
-
"version": "6.28.3-resources.
|
|
3
|
+
"version": "6.28.3-resources.1",
|
|
4
4
|
"description": "Client for retrieving, creating and patching data from Sanity.io",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"sanity",
|
|
7
|
-
"cms",
|
|
8
|
-
"headless",
|
|
9
|
-
"realtime",
|
|
10
|
-
"content",
|
|
11
|
-
"client",
|
|
12
|
-
"fetch",
|
|
13
|
-
"api"
|
|
14
|
-
],
|
|
5
|
+
"keywords": ["sanity", "cms", "headless", "realtime", "content", "client", "fetch", "api"],
|
|
15
6
|
"homepage": "https://www.sanity.io/",
|
|
16
7
|
"bugs": {
|
|
17
8
|
"url": "https://github.com/sanity-io/client/issues"
|
|
@@ -75,19 +66,11 @@
|
|
|
75
66
|
"types": "./dist/index.d.ts",
|
|
76
67
|
"typesVersions": {
|
|
77
68
|
"*": {
|
|
78
|
-
"csm": [
|
|
79
|
-
|
|
80
|
-
],
|
|
81
|
-
"stega": [
|
|
82
|
-
"./dist/stega.d.ts"
|
|
83
|
-
]
|
|
69
|
+
"csm": ["./dist/csm.d.ts"],
|
|
70
|
+
"stega": ["./dist/stega.d.ts"]
|
|
84
71
|
}
|
|
85
72
|
},
|
|
86
|
-
"files": [
|
|
87
|
-
"dist",
|
|
88
|
-
"src",
|
|
89
|
-
"umd"
|
|
90
|
-
],
|
|
73
|
+
"files": ["dist", "src", "umd"],
|
|
91
74
|
"scripts": {
|
|
92
75
|
"benchmark": "npm test -- bench",
|
|
93
76
|
"prebuild": "npm run clean",
|
|
@@ -110,9 +93,7 @@
|
|
|
110
93
|
"browserslist": "extends @sanity/browserslist-config",
|
|
111
94
|
"prettier": {
|
|
112
95
|
"bracketSpacing": false,
|
|
113
|
-
"plugins": [
|
|
114
|
-
"prettier-plugin-packagejson"
|
|
115
|
-
],
|
|
96
|
+
"plugins": ["prettier-plugin-packagejson"],
|
|
116
97
|
"printWidth": 100,
|
|
117
98
|
"semi": false,
|
|
118
99
|
"singleQuote": true
|
package/src/data/dataMethods.ts
CHANGED
|
@@ -367,36 +367,34 @@ export function _create<R extends Record<string, Any>>(
|
|
|
367
367
|
const opts = Object.assign({returnFirst: true, returnDocuments: true}, options)
|
|
368
368
|
return _dataRequest(client, httpRequest, 'mutate', {mutations: [mutation]}, opts)
|
|
369
369
|
}
|
|
370
|
-
const
|
|
371
|
-
|
|
372
|
-
(config['~experimental_resource']
|
|
370
|
+
const resourceDatasetRegex = /^\/projects\/([^/]+)\/datasets\/([^/]+)\/([^/^?]+)\/?/
|
|
371
|
+
const isResourceDataEndpoint = (config: ClientConfig, uri: string, endpoint: string) => {
|
|
372
|
+
if (!config['~experimental_resource']) {
|
|
373
|
+
return false
|
|
374
|
+
}
|
|
375
|
+
if (
|
|
373
376
|
uri.startsWith(
|
|
374
|
-
`/${config['~experimental_resource'].type}/${config['~experimental_resource'].id}
|
|
375
|
-
)
|
|
377
|
+
`/${config['~experimental_resource'].type}/${config['~experimental_resource'].id}/${endpoint}`,
|
|
378
|
+
)
|
|
379
|
+
) {
|
|
380
|
+
return true
|
|
381
|
+
}
|
|
382
|
+
const match = uri.match(resourceDatasetRegex)
|
|
383
|
+
if (!match) {
|
|
384
|
+
return false
|
|
385
|
+
}
|
|
386
|
+
return match[3] === endpoint
|
|
387
|
+
}
|
|
388
|
+
const isQuery = (config: ClientConfig, uri: string) =>
|
|
389
|
+
uri.startsWith('/data/query/') || isResourceDataEndpoint(config, uri, 'query')
|
|
376
390
|
const isMutate = (config: ClientConfig, uri: string) =>
|
|
377
|
-
uri.startsWith('/data/mutate/') ||
|
|
378
|
-
(config['~experimental_resource'] &&
|
|
379
|
-
uri.startsWith(
|
|
380
|
-
`/${config['~experimental_resource'].type}/${config['~experimental_resource'].id}/mutate`,
|
|
381
|
-
))
|
|
391
|
+
uri.startsWith('/data/mutate/') || isResourceDataEndpoint(config, uri, 'mutate')
|
|
382
392
|
const isDoc = (config: ClientConfig, uri: string) =>
|
|
383
|
-
uri.startsWith('/data/doc/') ||
|
|
384
|
-
(config['~experimental_resource'] &&
|
|
385
|
-
uri.startsWith(
|
|
386
|
-
`/${config['~experimental_resource'].type}/${config['~experimental_resource'].id}/doc/`,
|
|
387
|
-
))
|
|
393
|
+
uri.startsWith('/data/doc/') || isResourceDataEndpoint(config, uri, 'doc')
|
|
388
394
|
const isListener = (config: ClientConfig, uri: string) =>
|
|
389
|
-
uri.startsWith('/data/listen/') ||
|
|
390
|
-
(config['~experimental_resource'] &&
|
|
391
|
-
uri.startsWith(
|
|
392
|
-
`/${config['~experimental_resource'].type}/${config['~experimental_resource'].id}/listen`,
|
|
393
|
-
))
|
|
395
|
+
uri.startsWith('/data/listen/') || isResourceDataEndpoint(config, uri, 'listen')
|
|
394
396
|
const isHistory = (config: ClientConfig, uri: string) =>
|
|
395
|
-
uri.startsWith('/data/history/') ||
|
|
396
|
-
(config['~experimental_resource'] &&
|
|
397
|
-
uri.startsWith(
|
|
398
|
-
`/${config['~experimental_resource'].type}/${config['~experimental_resource'].id}/history/`,
|
|
399
|
-
))
|
|
397
|
+
uri.startsWith('/data/history/') || isResourceDataEndpoint(config, uri, 'history')
|
|
400
398
|
const isData = (config: ClientConfig, uri: string) =>
|
|
401
399
|
uri.startsWith('/data/') ||
|
|
402
400
|
isQuery(config, uri) ||
|
package/umd/sanityClient.js
CHANGED
|
@@ -2779,17 +2779,16 @@ ${selectionOpts}`);
|
|
|
2779
2779
|
const mutation = { [op]: doc }, opts = Object.assign({ returnFirst: true, returnDocuments: true }, options);
|
|
2780
2780
|
return _dataRequest(client, httpRequest, "mutate", { mutations: [mutation] }, opts);
|
|
2781
2781
|
}
|
|
2782
|
-
const
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
), isData = (config, uri) => uri.startsWith("/data/") || isQuery(config, uri) || isMutate(config, uri) || isDoc(config, uri) || isListener(config, uri) || isHistory(config, uri);
|
|
2782
|
+
const resourceDatasetRegex = /^\/projects\/([^/]+)\/datasets\/([^/]+)\/([^/^?]+)\/?/, isResourceDataEndpoint = (config, uri, endpoint) => {
|
|
2783
|
+
if (!config["~experimental_resource"])
|
|
2784
|
+
return false;
|
|
2785
|
+
if (uri.startsWith(
|
|
2786
|
+
`/${config["~experimental_resource"].type}/${config["~experimental_resource"].id}/${endpoint}`
|
|
2787
|
+
))
|
|
2788
|
+
return true;
|
|
2789
|
+
const match = uri.match(resourceDatasetRegex);
|
|
2790
|
+
return match ? match[3] === endpoint : false;
|
|
2791
|
+
}, isQuery = (config, uri) => uri.startsWith("/data/query/") || isResourceDataEndpoint(config, uri, "query"), isMutate = (config, uri) => uri.startsWith("/data/mutate/") || isResourceDataEndpoint(config, uri, "mutate"), isDoc = (config, uri) => uri.startsWith("/data/doc/") || isResourceDataEndpoint(config, uri, "doc"), isListener = (config, uri) => uri.startsWith("/data/listen/") || isResourceDataEndpoint(config, uri, "listen"), isHistory = (config, uri) => uri.startsWith("/data/history/") || isResourceDataEndpoint(config, uri, "history"), isData = (config, uri) => uri.startsWith("/data/") || isQuery(config, uri) || isMutate(config, uri) || isDoc(config, uri) || isListener(config, uri) || isHistory(config, uri);
|
|
2793
2792
|
function _requestObservable(client, httpRequest, options) {
|
|
2794
2793
|
const uri = options.url || options.uri, config = client.config(), canUseCdn = typeof options.canUseCdn > "u" ? ["GET", "HEAD"].indexOf(options.method || "GET") >= 0 && isData(config, uri) : options.canUseCdn;
|
|
2795
2794
|
let useCdn = (options.useCdn ?? config.useCdn) && canUseCdn;
|