Minor Changes
-
add
client.functions.invoke()for calling deployed functions on demand (#1258) (4c2f718)Invoke a Sanity Pubsub Function by the
name. Onlysanity.function.pubsubfunctions can be
invoked on demand.Available in two forms,
client.functions.invoke()resolves with the function's return value,client.observable.functions.invoke()emits it and accepts anevent.datapayload,
a per-calltimeoutand anAbortSignal.Names are only unique within a stack, so resolving one requires a
stackId, either from the new
stackIdclient config option or from the request. That resolution costs one extra request per
call. A function that returns nothing resolves toundefined.Stacks deployed at organization scope are reached with the new
organizationIdclient config
option, or a per-callorganizationId. It takes precedence overprojectId, which becomes
optional in that case. -
add request handler for client integrations (#1286) (a9db52f)
-
add variant definition actions (#1278) (7c98361)
Adds
CreateVariantDefinitionAction,EditVariantDefinitionActionand
DeleteVariantDefinitionAction, along with aVariantDefinitionActionunion, covering the
sanity.action.variant.definition.*actions. They are included in theActionunion, so
client.action()accepts them.Note that
Actionwidening is a breaking change for code that exhaustively switches on
Action['actionType']with aneverfallthrough, which will need to handle the new cases.
Patch Changes
-
route the live-events CORS probe through the configured transport (#1282) (aaada67)
The
/check/corsprobe thatclient.live.events()uses to distinguish a CORS
rejection from other connection failures called the globalfetchdirectly, so
a customresolveFetchor an explicitproxywas not applied to it. It now
resolves the same fetch the EventSource connection uses. -
reword the
createVersion()warning aboutbaseId(#1282) (aaada67)createVersion({document})warned that "the recommended approach is to provide abaseIdandreleaseIdinstead", which reads as a correction even when the caller had no other option:baseIdcreates a version of a document that already exists, so creating a genuinely new document inside a release can only be done by passingdocument.The client cannot tell those two cases apart, so the warning is now phrased as a condition rather than a correction: "If you are creating a version of a document that already exists, prefer providing
baseIdandreleaseIdinstead." No behavior changed, and both forms remain supported. -
correct the return type of
delete()andmutate()when called with no options (#1282) (aaada67)client.delete(id)andclient.mutate(mutations)were typed to resolve to a
document (SanityDocument<R>) when called without an options argument, but
they actually resolve to a mutation result object
({transactionId, documentIds, results},MultipleMutationResult). The
document is genuinely mutated, but code that read._idoff the resolved
value was readingundefinedat runtime without any type error. The
underlying method (create()) does return the document by default, so this
was easy to assume also held fordelete()andmutate()- it does not.Both methods now correctly type as resolving to
MultipleMutationResultby
default, matching the (unchanged) runtime behavior, on both the
promise-based and observable clients.Released as a patch rather than a major even though a declared type changed. Code that read
._idoff the result was readingundefinedat runtime, so no working application can have depended on the old type: anything that type-checked against it was already broken when it ran. What changes is that the mistake is now visible at compile time instead of at runtime.If
tscstarts failing on one of these calls, that failure is pointing at a real bug. To fix it:- To get the document back, pass
{returnFirst: true, returnDocuments: true}
explicitly:await client.delete(id, {returnFirst: true, returnDocuments: true}). - To keep the mutation-result shape, read
documentIds(ordocumentIdwith
returnFirst: true) off the result instead of_id.
No runtime behavior changed - this only corrects the public types.
- To get the document back, pass
-
populate server-sent event IDs on Cloudflare Workers (#1282) (aaada67)
client.live.events()andclient.listen()readlastEventIdoff the
MessageEventthateventsourceconstructs. workerd does not carry that member
through theMessageEventconstructor's init dict, so on bare Cloudflare Workers
every event arrived with an emptyid. Raising theeventsourcefloor to
>= 5.1.0picks up the fix. -
return the asset from
assets.upload()against a Media Library (#1282) (aaada67)client.assets.upload()resolved toundefinedwhen the client was configured against a Media Library (resource: {type: 'media-library', id}), even though the upload succeeded server-side. Content Lake's upload endpoint responds with{document: {...}}, andupload()unwrapped that key unconditionally - but the Media Library upload endpoint responds with{asset: {...}}instead, so the unwrap producedundefined.upload()now unwraps.assetfor a Media Library response and.documentotherwise, on both the promise-based and observable clients. It resolves to the uploaded asset instead ofundefined.The Media Library asset shape is not the same as a Content Lake asset document: it is a
sanity.assetdocument that tracks one or more uploaded versions viacurrentVersion/versions, rather than a document withurl,size,mimeType, and so on. That shape is now exported asMediaLibraryAssetDocument.The declared return type is knowingly incomplete, and this is a patch on purpose. Which shape you get back depends on how the client is configured, not on the arguments to
upload(), so no overload can discriminate it. Expressing it would mean widening the return type into a union that every existing caller has to narrow - a breaking change for all users, to correct the typing of a much less common configuration. So the declared type still describes only the Content Lake shape. If you upload to a Media Library, narrow the result yourself (for example, check forcurrentVersion) or annotate it asSanityImageAssetDocument | MediaLibraryAssetDocument. Typing this accurately is deferred to the next major.