@sanity/client
Advanced tools
Comparing version 6.25.0-alpha.0 to 6.25.0
@@ -258,4 +258,3 @@ const rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g, reKeySegment = /_key\s*==\s*['"](.*)['"]/, reIndexTuple = /^\d*:\d*$/; | ||
); | ||
if (!baseUrl) | ||
return; | ||
if (!baseUrl) return; | ||
const { _id, _type, _projectId, _dataset } = sourceDoc; | ||
@@ -262,0 +261,0 @@ return { |
@@ -6,4 +6,3 @@ var s = { 0: 8203, 1: 8204, 2: 8205, 3: 8290, 4: 8291, 5: 8288, 6: 65279, 7: 8289, 8: 119155, 9: 119156, a: 119157, b: 119158, c: 119159, d: 119160, e: 119161, f: 119162 }, c = { 0: 8203, 1: 8204, 2: 8205, 3: 65279 }, u = new Array(4).fill(String.fromCodePoint(c[0])).join(""); | ||
let n = r.charCodeAt(0); | ||
if (n > 255) | ||
throw new Error(`Only ASCII edit info can be encoded. Error attempting to encode ${e} on character ${r} (${n})`); | ||
if (n > 255) throw new Error(`Only ASCII edit info can be encoded. Error attempting to encode ${e} on character ${r} (${n})`); | ||
return Array.from(n.toString(4).padStart(4, "0")).map((o) => String.fromCodePoint(c[o])).join(""); | ||
@@ -10,0 +9,0 @@ }).join("")}`; |
@@ -293,4 +293,3 @@ import { C } from "./stegaClean.js"; | ||
); | ||
if (!baseUrl) | ||
return value; | ||
if (!baseUrl) return value; | ||
const { _id: id, _type: type, _projectId: projectId, _dataset: dataset } = sourceDocument; | ||
@@ -297,0 +296,0 @@ return C( |
@@ -1,20 +0,7 @@ | ||
import {Any} from '@sanity/client' | ||
import {ClientPerspective} from '@sanity/client' | ||
import {ContentSourceMap} from '@sanity/client' | ||
import {ContentSourceMapDocument} from '@sanity/client' | ||
import {ContentSourceMapDocumentBase} from '@sanity/client' | ||
import {ContentSourceMapDocuments} from '@sanity/client' | ||
import {ContentSourceMapDocumentValueSource} from '@sanity/client' | ||
import {ContentSourceMapLiteralSource} from '@sanity/client' | ||
import {ContentSourceMapMapping} from '@sanity/client' | ||
import {ContentSourceMapMappings} from '@sanity/client' | ||
import {ContentSourceMapPaths} from '@sanity/client' | ||
import {ContentSourceMapRemoteDocument} from '@sanity/client' | ||
import {ContentSourceMapSource} from '@sanity/client' | ||
import {ContentSourceMapUnknownSource} from '@sanity/client' | ||
import {ContentSourceMapValueMapping} from '@sanity/client' | ||
import {SanityDocument} from '@sanity/client' | ||
/** | ||
* Used to tag types that is set to `any` as a temporary measure, but should be replaced with proper typings in the future | ||
* @internal | ||
*/ | ||
export declare type Any = any | ||
export {Any} | ||
/** | ||
@@ -48,19 +35,58 @@ * Optimistically applies source documents to a result, using the content source map to trace fields. | ||
export {ClientPerspective} | ||
/** @public */ | ||
export declare type ClientPerspective = | ||
| 'previewDrafts' | ||
| 'published' | ||
| 'drafts' | ||
| 'raw' | ||
| ('published' | 'drafts' | ReleaseId)[] | ||
export {ContentSourceMap} | ||
/** @public */ | ||
export declare interface ContentSourceMap { | ||
mappings: ContentSourceMapMappings | ||
documents: ContentSourceMapDocuments | ||
paths: ContentSourceMapPaths | ||
} | ||
export {ContentSourceMapDocument} | ||
/** @public */ | ||
export declare interface ContentSourceMapDocument extends ContentSourceMapDocumentBase { | ||
_projectId?: undefined | ||
_dataset?: undefined | ||
} | ||
export {ContentSourceMapDocumentBase} | ||
/** @public */ | ||
export declare interface ContentSourceMapDocumentBase { | ||
_id: string | ||
_type: string | ||
} | ||
export {ContentSourceMapDocuments} | ||
/** @public */ | ||
export declare type ContentSourceMapDocuments = ( | ||
| ContentSourceMapDocument | ||
| ContentSourceMapRemoteDocument | ||
)[] | ||
export {ContentSourceMapDocumentValueSource} | ||
/** | ||
* DocumentValueSource is a path to a value within a document | ||
* @public | ||
*/ | ||
export declare interface ContentSourceMapDocumentValueSource { | ||
type: 'documentValue' | ||
document: number | ||
path: number | ||
} | ||
export {ContentSourceMapLiteralSource} | ||
/** | ||
* When a value is not from a source, its a literal | ||
* @public | ||
*/ | ||
export declare interface ContentSourceMapLiteralSource { | ||
type: 'literal' | ||
} | ||
export {ContentSourceMapMapping} | ||
/** @public */ | ||
export declare type ContentSourceMapMapping = ContentSourceMapValueMapping | ||
export {ContentSourceMapMappings} | ||
/** @public */ | ||
export declare type ContentSourceMapMappings = Record<string, ContentSourceMapMapping> | ||
@@ -86,11 +112,34 @@ /** @alpha */ | ||
export {ContentSourceMapPaths} | ||
/** @public */ | ||
export declare type ContentSourceMapPaths = string[] | ||
export {ContentSourceMapRemoteDocument} | ||
/** @public */ | ||
export declare interface ContentSourceMapRemoteDocument extends ContentSourceMapDocumentBase { | ||
_projectId: string | ||
_dataset: string | ||
} | ||
export {ContentSourceMapSource} | ||
/** @public */ | ||
export declare type ContentSourceMapSource = | ||
| ContentSourceMapDocumentValueSource | ||
| ContentSourceMapLiteralSource | ||
| ContentSourceMapUnknownSource | ||
export {ContentSourceMapUnknownSource} | ||
/** | ||
* When a field source is unknown | ||
* @public | ||
*/ | ||
export declare interface ContentSourceMapUnknownSource { | ||
type: 'unknown' | ||
} | ||
export {ContentSourceMapValueMapping} | ||
/** | ||
* ValueMapping is a mapping when for value that is from a single source value | ||
* It may refer to a field within a document or a literal value | ||
* @public | ||
*/ | ||
export declare interface ContentSourceMapValueMapping { | ||
type: 'value' | ||
source: ContentSourceMapSource | ||
} | ||
@@ -174,2 +223,5 @@ /** @internal */ | ||
/** @public */ | ||
declare type ReleaseId = `r${string}` | ||
/** | ||
@@ -225,3 +277,16 @@ * @internal | ||
export {SanityDocument} | ||
/** @internal */ | ||
export declare type SanityDocument<T extends Record<string, Any> = Record<string, Any>> = { | ||
[P in keyof T]: T[P] | ||
} & { | ||
_id: string | ||
_rev: string | ||
_type: string | ||
_createdAt: string | ||
_updatedAt: string | ||
/** | ||
* Present when `perspective` is set to `previewDrafts` | ||
*/ | ||
_originalId?: string | ||
} | ||
@@ -228,0 +293,0 @@ /** @alpha */ |
@@ -5,4 +5,3 @@ import { walkMap, resolveMapping, parseJsonPath, toString, DRAFTS_PREFIX, getPublishedId, get, jsonPath, studioPathToJsonPath, resolveEditInfo, createEditUrl } from "./_chunks-es/resolveEditInfo.js"; | ||
function applySourceDocuments(result, resultSourceMap, getCachedDocument, updateFn = defaultUpdateFunction, perspective = "raw") { | ||
if (!resultSourceMap) | ||
return result; | ||
if (!resultSourceMap) return result; | ||
if (perspective !== "published" && perspective !== "raw" && perspective !== "previewDrafts") | ||
@@ -9,0 +8,0 @@ throw new Error(`Unknown perspective "${perspective}"`); |
{ | ||
"name": "@sanity/client", | ||
"version": "6.25.0-alpha.0", | ||
"version": "6.25.0", | ||
"description": "Client for retrieving, creating and patching data from Sanity.io", | ||
@@ -122,3 +122,3 @@ "keywords": [ | ||
"@sanity/eventsource": "^5.0.2", | ||
"get-it": "^8.6.5", | ||
"get-it": "^8.6.6", | ||
"rxjs": "^7.0.0" | ||
@@ -132,7 +132,7 @@ }, | ||
"@sanity/client-latest": "npm:@sanity/client@latest", | ||
"@sanity/pkg-utils": "^6.12.2", | ||
"@sanity/pkg-utils": "^7.0.1", | ||
"@types/json-diff": "^1.0.3", | ||
"@types/node": "^22.9.0", | ||
"@typescript-eslint/eslint-plugin": "^8.18.1", | ||
"@typescript-eslint/parser": "^8.18.1", | ||
"@typescript-eslint/eslint-plugin": "^8.19.1", | ||
"@typescript-eslint/parser": "^8.19.1", | ||
"@vercel/stega": "0.1.2", | ||
@@ -149,3 +149,3 @@ "@vitest/coverage-v8": "2.1.8", | ||
"msw": "^2.7.0", | ||
"next": "^15.1.1", | ||
"next": "^15.1.4", | ||
"nock": "^13.5.6", | ||
@@ -155,6 +155,6 @@ "prettier": "^3.4.2", | ||
"rimraf": "^5.0.7", | ||
"rollup": "^4.28.1", | ||
"rollup": "^4.30.1", | ||
"sse-channel": "^4.0.0", | ||
"terser": "^5.37.0", | ||
"typescript": "5.7.2", | ||
"typescript": "5.7.3", | ||
"vitest": "2.1.8", | ||
@@ -161,0 +161,0 @@ "vitest-github-actions-reporter": "0.11.1" |
@@ -10,2 +10,3 @@ import type {Observable} from 'rxjs' | ||
Mutation, | ||
MutationSelection, | ||
PatchOperations, | ||
@@ -218,2 +219,9 @@ SanityDocument, | ||
/** | ||
* Performs a patch on the given selection. Can either be a builder function or an object of patch operations. | ||
* | ||
* @param selection - An object with `query` and optional `params`, defining which document(s) to patch | ||
* @param patchOps - Operations to perform, or a builder function | ||
*/ | ||
patch(patch: MutationSelection, patchOps?: PatchBuilder | PatchOperations): this | ||
/** | ||
* Adds the given patch instance to the transaction. | ||
@@ -225,5 +233,11 @@ * The operation is added to the current transaction, ready to be commited by `commit()` | ||
patch(patch: Patch): this | ||
patch(patchOrDocumentId: Patch | string, patchOps?: PatchBuilder | PatchOperations): this { | ||
patch( | ||
patchOrDocumentId: Patch | MutationSelection | string, | ||
patchOps?: PatchBuilder | PatchOperations, | ||
): this { | ||
const isBuilder = typeof patchOps === 'function' | ||
const isPatch = typeof patchOrDocumentId !== 'string' && patchOrDocumentId instanceof Patch | ||
const isMutationSelection = | ||
typeof patchOrDocumentId === 'object' && | ||
('query' in patchOrDocumentId || 'id' in patchOrDocumentId) | ||
@@ -245,2 +259,13 @@ // transaction.patch(client.patch('documentId').inc({visits: 1})) | ||
/** | ||
* transaction.patch( | ||
* {query: "*[_type == 'person' && points >= $threshold]", params: { threshold: 100 }}, | ||
* {dec: { points: 100 }, inc: { bonuses: 1 }} | ||
* ) | ||
*/ | ||
if (isMutationSelection) { | ||
const patch = new Patch(patchOrDocumentId, patchOps || {}, this.#client) | ||
return this._add({patch: patch.serialize()}) | ||
} | ||
return this._add({patch: {id: patchOrDocumentId, ...patchOps}}) | ||
@@ -247,0 +272,0 @@ } |
@@ -41,6 +41,7 @@ import type {Middlewares} from 'get-it' | ||
const createClient = (config: ClientConfigType) => | ||
new ClassConstructor( | ||
const createClient = (config: ClientConfigType) => { | ||
const clientRequester = defineHttpRequest(envMiddleware) | ||
return new ClassConstructor( | ||
(options, requester) => | ||
(requester || defaultRequester)({ | ||
(requester || clientRequester)({ | ||
maxRedirects: 0, | ||
@@ -53,4 +54,5 @@ maxRetries: config.maxRetries, | ||
) | ||
} | ||
return {requester: defaultRequester, createClient} | ||
} |
@@ -20,9 +20,16 @@ import {getIt, type Middlewares, type Requester} from 'get-it' | ||
const printWarnings = { | ||
onResponse: (res: Any) => { | ||
const warn = res.headers['x-sanity-warning'] | ||
const warnings = Array.isArray(warn) ? warn : [warn] | ||
warnings.filter(Boolean).forEach((msg) => console.warn(msg)) // eslint-disable-line no-console | ||
return res | ||
}, | ||
function printWarnings() { | ||
const seen: Record<string, boolean> = {} | ||
return { | ||
onResponse: (res: Any) => { | ||
const warn = res.headers['x-sanity-warning'] | ||
const warnings = Array.isArray(warn) ? warn : [warn] | ||
for (const msg of warnings) { | ||
if (!msg || seen[msg]) continue | ||
seen[msg] = true | ||
console.warn(msg) // eslint-disable-line no-console | ||
} | ||
return res | ||
}, | ||
} | ||
} | ||
@@ -35,3 +42,3 @@ | ||
...envMiddleware, | ||
printWarnings, | ||
printWarnings(), | ||
jsonRequest(), | ||
@@ -38,0 +45,0 @@ jsonResponse(), |
@@ -884,2 +884,3 @@ // deno-lint-ignore-file no-empty-interface | ||
| WelcomeEvent | ||
| OpenEvent | ||
@@ -886,0 +887,0 @@ /** @public */ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
2747848
33126
0
Updatedget-it@^8.6.6