@sanity/sdk 3.9.1 → 3.9.2-next.20261014121948

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.
Files changed (27) hide show
  1. package/dist/_exports/_internal.d.ts +2 -2
  2. package/dist/_exports/_internal.js +9 -17
  3. package/dist/_exports/_internal.js.map +1 -1
  4. package/dist/_exports/agent.js +1 -1
  5. package/dist/_exports/comlink.d.ts +1 -0
  6. package/dist/_exports/comlink.d.ts.map +1 -1
  7. package/dist/_exports/comlink.js +1 -1
  8. package/dist/_exports/dashboard.d.ts +2 -2
  9. package/dist/_exports/dashboard.js +2 -2
  10. package/dist/{applications-DowvM7CN.d.ts → applications-CkDu_W5X.d.ts} +3 -3
  11. package/dist/{applications-DowvM7CN.d.ts.map → applications-CkDu_W5X.d.ts.map} +1 -1
  12. package/dist/{authStore-KH1GNOOB.js → authStore-DwKgZOzo.js} +8 -26
  13. package/dist/{authStore-KH1GNOOB.js.map → authStore-DwKgZOzo.js.map} +1 -1
  14. package/dist/{bus-ClLO0kQU.d.ts → bus-bvKfVggT.d.ts} +2 -2
  15. package/dist/{bus-ClLO0kQU.d.ts.map → bus-bvKfVggT.d.ts.map} +1 -1
  16. package/dist/{clientStore-DW3iIcbg.js → clientStore-DnMH7LPG.js} +2 -2
  17. package/dist/{clientStore-DW3iIcbg.js.map → clientStore-DnMH7LPG.js.map} +1 -1
  18. package/dist/{getNodeState-CkxvEZD5.js → getNodeState-Bp9sxNE1.js} +2 -5
  19. package/dist/{getNodeState-CkxvEZD5.js.map → getNodeState-Bp9sxNE1.js.map} +1 -1
  20. package/dist/index.d.ts +1 -1
  21. package/dist/index.js +50 -74
  22. package/dist/index.js.map +1 -1
  23. package/dist/{topicStore-CU-oF3fc.js → topicStore-CNzfuPGY.js} +2 -2
  24. package/dist/{topicStore-CU-oF3fc.js.map → topicStore-CNzfuPGY.js.map} +1 -1
  25. package/dist/{version-7EzMhxQE.js → version-Bx_0tNcN.js} +10 -14
  26. package/dist/{version-7EzMhxQE.js.map → version-Bx_0tNcN.js.map} +1 -1
  27. package/package.json +4 -4
@@ -1,5 +1,5 @@
1
1
  import { a as createActionBinder, i as bindActionGlobally, s as defineStore, t as createStateSourceAction, u as setCleanupTimeout } from "./createStateSourceAction-Bn0po7Z3.js";
2
- import { F as isMessageBusInstalled, L as _defineProperty, M as connectMessageBus, o as getIsInDashboardState, t as authStore } from "./authStore-KH1GNOOB.js";
2
+ import { F as isMessageBusInstalled, L as _defineProperty, M as connectMessageBus, o as getIsInDashboardState, t as authStore } from "./authStore-DwKgZOzo.js";
3
3
  import { distinctUntilChanged, map, skip } from "rxjs";
4
4
  /**
5
5
  * Returns the message bus connection for this instance, connecting on first call.
@@ -130,4 +130,4 @@ function getDashboardOrganizationId(instance) {
130
130
  }
131
131
  export { getDashboardMessageBus as a, resolveTopic as i, getDashboardOrganizationId as n, isDashboardEnvironment as o, getTopicState as r, requireDashboardMessageBus as s, TopicError as t };
132
132
 
133
- //# sourceMappingURL=topicStore-CU-oF3fc.js.map
133
+ //# sourceMappingURL=topicStore-CNzfuPGY.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"topicStore-CU-oF3fc.js","names":["bindActionByInstance"],"sources":["../src/dashboard/messageBus/store.ts","../src/dashboard/messageBus/topicStore.ts"],"sourcesContent":["import {getIsInDashboardState} from '../../auth/authStore'\nimport {createActionBinder} from '../../store/createActionBinder'\nimport {type SanityInstance} from '../../store/createSanityInstance'\nimport {defineStore} from '../../store/defineStore'\nimport {connectMessageBus, isMessageBusInstalled, type MessageBusConnection} from './bus'\n\ninterface DashboardMessageBusState {\n connection?: MessageBusConnection\n}\n\nconst bindActionByInstance = createActionBinder<{name: string}, [moduleId?: string]>(\n (instance) => ({name: instance.instanceId}),\n)\n\nconst dashboardMessageBusStore = defineStore<DashboardMessageBusState>({\n name: 'dashboardMessageBus',\n getInitialState: () => ({}),\n // Runs when the instance is disposed, tearing down this window's connection.\n initialize:\n ({state}) =>\n () =>\n state.get().connection?.disconnect(),\n})\n\n/**\n * Returns the message bus connection for this instance, connecting on first call.\n *\n * @remarks\n * One connection is made per {@link SanityInstance}, carrying that window's\n * module identity. The first caller wins; later callers get the cached\n * connection. When no host bus is installed it returns `undefined` without\n * caching, so a later call retries once a host installs the bus.\n * @internal\n */\nexport const getDashboardMessageBus = bindActionByInstance(\n dashboardMessageBusStore,\n ({state}, moduleId?: string): MessageBusConnection | undefined => {\n const current = state.get().connection\n if (current) return current\n if (!isMessageBusInstalled()) return undefined\n const connection = connectMessageBus({moduleId})\n if (!connection) return undefined\n state.set('connect', {connection})\n return connection\n },\n)\n\n/**\n * Returns the instance's message bus connection, or throws when no dashboard host has\n * installed a bus. `action` names what the caller was about to do, e.g. `read topic \"x\"`.\n * @internal\n */\nexport function requireDashboardMessageBus(\n instance: SanityInstance,\n action: string,\n): MessageBusConnection {\n const messageBus = getDashboardMessageBus(instance)\n if (!messageBus) {\n throw new Error(`Cannot ${action} without an installed dashboard message bus`)\n }\n return messageBus\n}\n\n/**\n * Returns whether a dashboard hosts the instance, over Comlink or an installed message bus.\n *\n * @remarks\n * Answers \"does a host own this session\", not \"has this instance connected yet\". Callers\n * such as the login redirect run before {@link getDashboardMessageBus} has been called for\n * the instance, so this must not depend on the connection state.\n * @internal\n */\nexport function isDashboardEnvironment(instance: SanityInstance): boolean {\n return getIsInDashboardState(instance).getCurrent() || isMessageBusInstalled()\n}\n","import {distinctUntilChanged, map, skip} from 'rxjs'\n\nimport {authStore} from '../../auth/authStore'\nimport {bindActionGlobally, createActionBinder} from '../../store/createActionBinder'\nimport {type SanityInstance} from '../../store/createSanityInstance'\nimport {createStateSourceAction, type StateSource} from '../../store/createStateSourceAction'\nimport {defineStore} from '../../store/defineStore'\nimport {setCleanupTimeout} from '../../utils/setCleanupTimeout'\nimport {type MessageBus, type MessageBusStateSource} from './bus'\nimport {getDashboardMessageBus, requireDashboardMessageBus} from './store'\nimport {type StateTopic, type ValueOf} from './topics'\n\n/**\n * An error raised when a dashboard state topic reports failure.\n * @public\n * @category Message Bus\n */\nexport class TopicError extends Error {\n /** The topic that failed. */\n readonly topic: StateTopic\n\n /** Creates an error for a failed topic. */\n constructor(topic: StateTopic) {\n super(`Topic \"${topic}\" failed`)\n this.name = 'TopicError'\n this.topic = topic\n }\n}\n\n/**\n * The value of a state topic, with `TopicResult` wrappers unwrapped to their success value.\n * @public\n * @category Message Bus\n */\nexport type TopicData<K extends StateTopic> =\n ValueOf<K> extends infer Value\n ? Value extends {ok: true; value: infer Success}\n ? Success\n : Value extends {ok: false}\n ? never\n : Value\n : never\n\n// Mirrors the `TopicResult` shape declared in the topic manifest; no plain-value topic has an `ok` field.\nfunction isTopicResult(value: unknown): value is {ok: boolean; value?: unknown} {\n return (\n typeof value === 'object' && value !== null && 'ok' in value && typeof value.ok === 'boolean'\n )\n}\n\nfunction unwrapTopicResult(topic: StateTopic, value: unknown): unknown {\n if (!isTopicResult(value)) return value\n if (!value.ok) throw new TopicError(topic)\n return value.value\n}\n\ninterface TopicEntry {\n /** Why the first-value query failed. Dropped with the entry when its last subscriber leaves. */\n error?: unknown\n /** The in-flight first-value query, shared by every suspended render of the topic. */\n pending?: Promise<void>\n subscribers: number\n}\n\ninterface DashboardTopicsState {\n topics: {[topic: string]: TopicEntry}\n}\n\n// Matches the query store: a suspended component re-renders after its promise settles before\n// the temporary subscriber is released, so it still sees the recorded failure.\nconst TOPIC_STATE_CLEAR_DELAY = 1000\n\nconst bindActionByInstance = createActionBinder<{name: string}, [topic: StateTopic]>(\n (instance) => ({name: instance.instanceId}),\n)\n\n// The bus is the source of truth for topic values (it already keeps one replaying source per\n// topic). This store only tracks what the bus cannot: read failures and who is still reading.\nconst dashboardTopicsStore = defineStore<DashboardTopicsState>({\n name: 'dashboardTopics',\n getInitialState: () => ({topics: {}}),\n})\n\nconst getMessageBus = (instance: SanityInstance, topic: StateTopic): MessageBus =>\n requireDashboardMessageBus(instance, `read topic \"${topic}\"`)\n\nfunction getSource(instance: SanityInstance, topic: StateTopic): MessageBusStateSource<unknown> {\n return getMessageBus(instance, topic).subscribe(topic)\n}\n\n// An entry lives as long as it has subscribers. Dropping it with the last one is what gives a\n// later mount a fresh deadline instead of a stale failure.\nconst updateEntry =\n (topic: string, update: (entry: TopicEntry) => TopicEntry) =>\n (state: DashboardTopicsState): DashboardTopicsState => {\n const {[topic]: entry = {subscribers: 0}, ...rest} = state.topics\n const next = update(entry)\n return {topics: next.subscribers > 0 ? {...rest, [topic]: next} : rest}\n }\n\nconst addSubscriber = (topic: string) =>\n updateEntry(topic, (entry) => ({...entry, subscribers: entry.subscribers + 1}))\n\nconst removeSubscriber = (topic: string) =>\n updateEntry(topic, (entry) => ({...entry, subscribers: entry.subscribers - 1}))\n\n/**\n * A state source for a dashboard state topic, with `TopicResult` wrappers unwrapped.\n *\n * @remarks\n * Returns `undefined` until the topic publishes; use {@link resolveTopic} to wait for that\n * first value. While the topic is still unpublished, reading throws the failure that\n * {@link resolveTopic} recorded. A published value takes precedence over a recorded failure,\n * and a {@link TopicError} is thrown when the topic itself reports failure. A thrown failure\n * ends the subscription, so a reader recovers by subscribing again.\n * @internal\n */\nexport const getTopicState = bindActionByInstance(\n dashboardTopicsStore,\n createStateSourceAction({\n selector: ({state, instance}, topic: StateTopic) => {\n const current = getSource(instance, topic).getCurrent()\n // A recorded failure only describes the wait for a first value; a published value wins.\n const entry = state.topics[topic]\n if (current === undefined && entry?.error) throw entry.error\n return unwrapTopicResult(topic, current)\n },\n onSubscribe: ({state, instance}, topic: StateTopic) => {\n state.set('addSubscriber', addSubscriber(topic))\n // Each publish writes a fresh state object so the selector re-runs against the bus.\n const subscription = getSource(instance, topic).subscribe(() =>\n state.set(\n 'publish',\n updateEntry(topic, (entry) => ({...entry})),\n ),\n )\n return () => {\n subscription.unsubscribe()\n setCleanupTimeout(\n () => state.set('removeSubscriber', removeSubscriber(topic)),\n TOPIC_STATE_CLEAR_DELAY,\n )\n }\n },\n }),\n)\n\n/**\n * Resolves once a dashboard state topic has published, or records the failure for\n * {@link getTopicState} to throw. Repeated calls for a pending topic share one query.\n *\n * @remarks\n * Holds a temporary subscriber while the query is in flight so a failure recorded after the\n * reading component has gone is dropped with it, rather than thrown at the next mount.\n * @internal\n */\nexport const resolveTopic = bindActionByInstance(\n dashboardTopicsStore,\n ({state, instance}, topic: StateTopic): Promise<void> => {\n const existing = state.get().topics[topic]?.pending\n if (existing) return existing\n\n const release = () =>\n setCleanupTimeout(\n () => state.set('removeSubscriber', removeSubscriber(topic)),\n TOPIC_STATE_CLEAR_DELAY,\n )\n const pending = getMessageBus(instance, topic)\n .query(topic)\n .then(\n () =>\n state.set(\n 'resolved',\n updateEntry(topic, ({pending: _pending, ...entry}) => entry),\n ),\n (error: unknown) =>\n state.set(\n 'failed',\n updateEntry(topic, ({pending: _pending, ...entry}) => ({...entry, error})),\n ),\n )\n pending.then(release, release)\n state.set(\n 'query',\n updateEntry(topic, (entry) => ({...entry, pending, subscribers: entry.subscribers + 1})),\n )\n return pending\n },\n)\n\nconst getComlinkOrganizationId = bindActionGlobally(\n authStore,\n createStateSourceAction(({state: {dashboardContext}}) => dashboardContext?.orgId),\n)\n\ntype CurrentOrganization = TopicData<'organizations.current'> | undefined\n\n/**\n * Returns the organization the dashboard has selected: the `organizations.current` topic on a\n * message bus, or the `_context` URL param in a Comlink dashboard.\n * @public\n */\nexport function getDashboardOrganizationId(\n instance: SanityInstance,\n): StateSource<string | undefined> {\n if (!getDashboardMessageBus(instance)) return getComlinkOrganizationId(instance)\n const organization = getTopicState(instance, 'organizations.current')\n const observable = organization.observable.pipe(\n map((value) => (value as CurrentOrganization)?.id),\n distinctUntilChanged(),\n )\n return {\n subscribe: (onStoreChanged) => {\n const subscription = observable.pipe(skip(1)).subscribe({\n next: () => onStoreChanged?.(),\n error: () => onStoreChanged?.(),\n })\n return () => subscription.unsubscribe()\n },\n getCurrent: () => (organization.getCurrent() as CurrentOrganization)?.id,\n observable,\n }\n}\n"],"mappings":";;;;;;;;;;;;;A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B,uBACC,EAAC,OAAO,YAAW,UAAqC;CACvD,IAAM,WAAW,MAAM,IAAI,CAAC,CAAC,OAAO,MAAM,EAAE;CAC5C,IAAI,UAAU,OAAO;CAErB,IAAM,gBACJ,wBACQ,MAAM,IAAI,oBAAoB,iBAAiB,KAAK,CAAC,GAC3D,uBACF,GACI,UAAU,cAAc,UAAU,KAAK,CAAC,CAC3C,MAAM,KAAK,CAAC,CACZ,WAEG,MAAM,IACJ,YACA,YAAY,QAAQ,EAAC,SAAS,UAAU,GAAG,YAAW,KAAK,CAC7D,IACD,UACC,MAAM,IACJ,UACA,YAAY,QAAQ,EAAC,SAAS,UAAU,GAAG,aAAY;EAAC,GAAG;EAAO;CAAK,EAAE,CAC3E,CACJ;CAMF,OALA,QAAQ,KAAK,SAAS,OAAO,GAC7B,MAAM,IACJ,SACA,YAAY,QAAQ,WAAW;EAAC,GAAG;EAAO;EAAS,aAAa,MAAM,cAAc;CAAC,EAAE,CACzF,GACO;AACT,CACF,GAEM,2BAA2B,mBAC/B,WACA,yBAAyB,EAAC,OAAO,EAAC,yBAAuB,kBAAkB,KAAK,CAClF;;;;;;AASA,SAAgB,2BACd,UACiC;CACjC,IAAI,CAAC,uBAAuB,QAAQ,GAAG,OAAO,yBAAyB,QAAQ;CAC/E,IAAM,eAAe,cAAc,UAAU,uBAAuB,GAC9D,aAAa,aAAa,WAAW,KACzC,KAAK,UAAW,OAA+B,EAAE,GACjD,qBAAqB,CACvB;CACA,OAAO;EACL,YAAY,mBAAmB;GAC7B,IAAM,eAAe,WAAW,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU;IACtD,YAAY,iBAAiB;IAC7B,aAAa,iBAAiB;GAChC,CAAC;GACD,aAAa,aAAa,YAAY;EACxC;EACA,kBAAmB,aAAa,WAAW,CAAC,EAA0B;EACtE;CACF;AACF"}
1
+ {"version":3,"file":"topicStore-CNzfuPGY.js","names":["bindActionByInstance"],"sources":["../src/dashboard/messageBus/store.ts","../src/dashboard/messageBus/topicStore.ts"],"sourcesContent":["import {getIsInDashboardState} from '../../auth/authStore'\nimport {createActionBinder} from '../../store/createActionBinder'\nimport {type SanityInstance} from '../../store/createSanityInstance'\nimport {defineStore} from '../../store/defineStore'\nimport {connectMessageBus, isMessageBusInstalled, type MessageBusConnection} from './bus'\n\ninterface DashboardMessageBusState {\n connection?: MessageBusConnection\n}\n\nconst bindActionByInstance = createActionBinder<{name: string}, [moduleId?: string]>(\n (instance) => ({name: instance.instanceId}),\n)\n\nconst dashboardMessageBusStore = defineStore<DashboardMessageBusState>({\n name: 'dashboardMessageBus',\n getInitialState: () => ({}),\n // Runs when the instance is disposed, tearing down this window's connection.\n initialize:\n ({state}) =>\n () =>\n state.get().connection?.disconnect(),\n})\n\n/**\n * Returns the message bus connection for this instance, connecting on first call.\n *\n * @remarks\n * One connection is made per {@link SanityInstance}, carrying that window's\n * module identity. The first caller wins; later callers get the cached\n * connection. When no host bus is installed it returns `undefined` without\n * caching, so a later call retries once a host installs the bus.\n * @internal\n */\nexport const getDashboardMessageBus = bindActionByInstance(\n dashboardMessageBusStore,\n ({state}, moduleId?: string): MessageBusConnection | undefined => {\n const current = state.get().connection\n if (current) return current\n if (!isMessageBusInstalled()) return undefined\n const connection = connectMessageBus({moduleId})\n if (!connection) return undefined\n state.set('connect', {connection})\n return connection\n },\n)\n\n/**\n * Returns the instance's message bus connection, or throws when no dashboard host has\n * installed a bus. `action` names what the caller was about to do, e.g. `read topic \"x\"`.\n * @internal\n */\nexport function requireDashboardMessageBus(\n instance: SanityInstance,\n action: string,\n): MessageBusConnection {\n const messageBus = getDashboardMessageBus(instance)\n if (!messageBus) {\n throw new Error(`Cannot ${action} without an installed dashboard message bus`)\n }\n return messageBus\n}\n\n/**\n * Returns whether a dashboard hosts the instance, over Comlink or an installed message bus.\n *\n * @remarks\n * Answers \"does a host own this session\", not \"has this instance connected yet\". Callers\n * such as the login redirect run before {@link getDashboardMessageBus} has been called for\n * the instance, so this must not depend on the connection state.\n * @internal\n */\nexport function isDashboardEnvironment(instance: SanityInstance): boolean {\n return getIsInDashboardState(instance).getCurrent() || isMessageBusInstalled()\n}\n","import {distinctUntilChanged, map, skip} from 'rxjs'\n\nimport {authStore} from '../../auth/authStore'\nimport {bindActionGlobally, createActionBinder} from '../../store/createActionBinder'\nimport {type SanityInstance} from '../../store/createSanityInstance'\nimport {createStateSourceAction, type StateSource} from '../../store/createStateSourceAction'\nimport {defineStore} from '../../store/defineStore'\nimport {setCleanupTimeout} from '../../utils/setCleanupTimeout'\nimport {type MessageBus, type MessageBusStateSource} from './bus'\nimport {getDashboardMessageBus, requireDashboardMessageBus} from './store'\nimport {type StateTopic, type ValueOf} from './topics'\n\n/**\n * An error raised when a dashboard state topic reports failure.\n * @public\n * @category Message Bus\n */\nexport class TopicError extends Error {\n /** The topic that failed. */\n readonly topic: StateTopic\n\n /** Creates an error for a failed topic. */\n constructor(topic: StateTopic) {\n super(`Topic \"${topic}\" failed`)\n this.name = 'TopicError'\n this.topic = topic\n }\n}\n\n/**\n * The value of a state topic, with `TopicResult` wrappers unwrapped to their success value.\n * @public\n * @category Message Bus\n */\nexport type TopicData<K extends StateTopic> =\n ValueOf<K> extends infer Value\n ? Value extends {ok: true; value: infer Success}\n ? Success\n : Value extends {ok: false}\n ? never\n : Value\n : never\n\n// Mirrors the `TopicResult` shape declared in the topic manifest; no plain-value topic has an `ok` field.\nfunction isTopicResult(value: unknown): value is {ok: boolean; value?: unknown} {\n return (\n typeof value === 'object' && value !== null && 'ok' in value && typeof value.ok === 'boolean'\n )\n}\n\nfunction unwrapTopicResult(topic: StateTopic, value: unknown): unknown {\n if (!isTopicResult(value)) return value\n if (!value.ok) throw new TopicError(topic)\n return value.value\n}\n\ninterface TopicEntry {\n /** Why the first-value query failed. Dropped with the entry when its last subscriber leaves. */\n error?: unknown\n /** The in-flight first-value query, shared by every suspended render of the topic. */\n pending?: Promise<void>\n subscribers: number\n}\n\ninterface DashboardTopicsState {\n topics: {[topic: string]: TopicEntry}\n}\n\n// Matches the query store: a suspended component re-renders after its promise settles before\n// the temporary subscriber is released, so it still sees the recorded failure.\nconst TOPIC_STATE_CLEAR_DELAY = 1000\n\nconst bindActionByInstance = createActionBinder<{name: string}, [topic: StateTopic]>(\n (instance) => ({name: instance.instanceId}),\n)\n\n// The bus is the source of truth for topic values (it already keeps one replaying source per\n// topic). This store only tracks what the bus cannot: read failures and who is still reading.\nconst dashboardTopicsStore = defineStore<DashboardTopicsState>({\n name: 'dashboardTopics',\n getInitialState: () => ({topics: {}}),\n})\n\nconst getMessageBus = (instance: SanityInstance, topic: StateTopic): MessageBus =>\n requireDashboardMessageBus(instance, `read topic \"${topic}\"`)\n\nfunction getSource(instance: SanityInstance, topic: StateTopic): MessageBusStateSource<unknown> {\n return getMessageBus(instance, topic).subscribe(topic)\n}\n\n// An entry lives as long as it has subscribers. Dropping it with the last one is what gives a\n// later mount a fresh deadline instead of a stale failure.\nconst updateEntry =\n (topic: string, update: (entry: TopicEntry) => TopicEntry) =>\n (state: DashboardTopicsState): DashboardTopicsState => {\n const {[topic]: entry = {subscribers: 0}, ...rest} = state.topics\n const next = update(entry)\n return {topics: next.subscribers > 0 ? {...rest, [topic]: next} : rest}\n }\n\nconst addSubscriber = (topic: string) =>\n updateEntry(topic, (entry) => ({...entry, subscribers: entry.subscribers + 1}))\n\nconst removeSubscriber = (topic: string) =>\n updateEntry(topic, (entry) => ({...entry, subscribers: entry.subscribers - 1}))\n\n/**\n * A state source for a dashboard state topic, with `TopicResult` wrappers unwrapped.\n *\n * @remarks\n * Returns `undefined` until the topic publishes; use {@link resolveTopic} to wait for that\n * first value. While the topic is still unpublished, reading throws the failure that\n * {@link resolveTopic} recorded. A published value takes precedence over a recorded failure,\n * and a {@link TopicError} is thrown when the topic itself reports failure. A thrown failure\n * ends the subscription, so a reader recovers by subscribing again.\n * @internal\n */\nexport const getTopicState = bindActionByInstance(\n dashboardTopicsStore,\n createStateSourceAction({\n selector: ({state, instance}, topic: StateTopic) => {\n const current = getSource(instance, topic).getCurrent()\n // A recorded failure only describes the wait for a first value; a published value wins.\n const entry = state.topics[topic]\n if (current === undefined && entry?.error) throw entry.error\n return unwrapTopicResult(topic, current)\n },\n onSubscribe: ({state, instance}, topic: StateTopic) => {\n state.set('addSubscriber', addSubscriber(topic))\n // Each publish writes a fresh state object so the selector re-runs against the bus.\n const subscription = getSource(instance, topic).subscribe(() =>\n state.set(\n 'publish',\n updateEntry(topic, (entry) => ({...entry})),\n ),\n )\n return () => {\n subscription.unsubscribe()\n setCleanupTimeout(\n () => state.set('removeSubscriber', removeSubscriber(topic)),\n TOPIC_STATE_CLEAR_DELAY,\n )\n }\n },\n }),\n)\n\n/**\n * Resolves once a dashboard state topic has published, or records the failure for\n * {@link getTopicState} to throw. Repeated calls for a pending topic share one query.\n *\n * @remarks\n * Holds a temporary subscriber while the query is in flight so a failure recorded after the\n * reading component has gone is dropped with it, rather than thrown at the next mount.\n * @internal\n */\nexport const resolveTopic = bindActionByInstance(\n dashboardTopicsStore,\n ({state, instance}, topic: StateTopic): Promise<void> => {\n const existing = state.get().topics[topic]?.pending\n if (existing) return existing\n\n const release = () =>\n setCleanupTimeout(\n () => state.set('removeSubscriber', removeSubscriber(topic)),\n TOPIC_STATE_CLEAR_DELAY,\n )\n const pending = getMessageBus(instance, topic)\n .query(topic)\n .then(\n () =>\n state.set(\n 'resolved',\n updateEntry(topic, ({pending: _pending, ...entry}) => entry),\n ),\n (error: unknown) =>\n state.set(\n 'failed',\n updateEntry(topic, ({pending: _pending, ...entry}) => ({...entry, error})),\n ),\n )\n pending.then(release, release)\n state.set(\n 'query',\n updateEntry(topic, (entry) => ({...entry, pending, subscribers: entry.subscribers + 1})),\n )\n return pending\n },\n)\n\nconst getComlinkOrganizationId = bindActionGlobally(\n authStore,\n createStateSourceAction(({state: {dashboardContext}}) => dashboardContext?.orgId),\n)\n\ntype CurrentOrganization = TopicData<'organizations.current'> | undefined\n\n/**\n * Returns the organization the dashboard has selected: the `organizations.current` topic on a\n * message bus, or the `_context` URL param in a Comlink dashboard.\n * @public\n */\nexport function getDashboardOrganizationId(\n instance: SanityInstance,\n): StateSource<string | undefined> {\n if (!getDashboardMessageBus(instance)) return getComlinkOrganizationId(instance)\n const organization = getTopicState(instance, 'organizations.current')\n const observable = organization.observable.pipe(\n map((value) => (value as CurrentOrganization)?.id),\n distinctUntilChanged(),\n )\n return {\n subscribe: (onStoreChanged) => {\n const subscription = observable.pipe(skip(1)).subscribe({\n next: () => onStoreChanged?.(),\n error: () => onStoreChanged?.(),\n })\n return () => subscription.unsubscribe()\n },\n getCurrent: () => (organization.getCurrent() as CurrentOrganization)?.id,\n observable,\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAkCA,MAAa,yBAxBgB,oBAC1B,cAAc,EAAC,MAAM,SAAS,WAAU,EAuBLA,CAAAA,CApBL,YAAsC;CACrE,MAAM;CACN,wBAAwB,CAAC;CAEzB,aACG,EAAC,kBAEA,MAAM,IAAI,CAAC,CAAC,YAAY,WAAW;AACzC,CAaE,IACC,EAAC,SAAQ,aAAwD;CAChE,IAAM,UAAU,MAAM,IAAI,CAAC,CAAC;CAC5B,IAAI,SAAS,OAAO;CACpB,IAAI,CAAC,sBAAsB,GAAG;CAC9B,IAAM,aAAa,kBAAkB,EAAC,SAAQ,CAAC;CAC/C,IAAK,YAEL,OADA,MAAM,IAAI,WAAW,EAAC,WAAU,CAAC,GAC1B;AACT,CACF;;;;;;AAOA,SAAgB,2BACd,UACA,QACsB;CACtB,IAAM,aAAa,uBAAuB,QAAQ;CAClD,IAAI,CAAC,YACH,MAAU,MAAM,UAAU,OAAO,4CAA4C;CAE/E,OAAO;AACT;;;;;;;;;;AAWA,SAAgB,uBAAuB,UAAmC;CACxE,OAAO,sBAAsB,QAAQ,CAAC,CAAC,WAAW,KAAK,sBAAsB;AAC/E;;;;;;ACzDA,IAAa,aAAb,cAAgC,MAAM;;CAKpC,YAAY,OAAmB;EAG7B,AAFA,MAAM,UAAU,MAAM,SAAS,GAJx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AAM,eAAe,cAAc,UAAU,uBAAuB,GAC9D,aAAa,aAAa,WAAW,KACzC,KAAK,UAAW,OAA+B,EAAE,GACjD,qBAAqB,CACvB;CACA,OAAO;EACL,YAAY,mBAAmB;GAC7B,IAAM,eAAe,WAAW,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU;IACtD,YAAY,iBAAiB;IAC7B,aAAa,iBAAiB;GAChC,CAAC;GACD,aAAa,aAAa,YAAY;EACxC;EACA,kBAAmB,aAAa,WAAW,CAAC,EAA0B;EACtE;CACF;AACF"}
@@ -1,8 +1,8 @@
1
1
  import { d as getEnv, f as isReleasePerspective, i as bindActionGlobally, l as setCleanupInterval, m as isDatasetResource, n as bindActionByResource, o as UPSTREAM_CLOSE_DELAY_MS, s as defineStore, t as createStateSourceAction, u as setCleanupTimeout } from "./createStateSourceAction-Bn0po7Z3.js";
2
- import { S as getClientErrorApiType, a as getCurrentUserState, b as getClientErrorApiBody, x as getClientErrorApiProjectId } from "./authStore-KH1GNOOB.js";
2
+ import { S as getClientErrorApiType, a as getCurrentUserState, b as getClientErrorApiBody, x as getClientErrorApiProjectId } from "./authStore-DwKgZOzo.js";
3
3
  import { r as omitProperty } from "./object-CxXlSVg7.js";
4
- import { n as getClient, r as getClientState } from "./clientStore-DW3iIcbg.js";
5
- import { t as getNodeState } from "./getNodeState-CkxvEZD5.js";
4
+ import { n as getClient, r as getClientState } from "./clientStore-DnMH7LPG.js";
5
+ import { t as getNodeState } from "./getNodeState-Bp9sxNE1.js";
6
6
  import { ClientError, ConnectionFailedError, CorsOriginError, DisconnectError } from "@sanity/client";
7
7
  import { BehaviorSubject, EMPTY, NEVER, Observable, Subscription, catchError, combineLatest, defer, distinctUntilChanged, filter, first, firstValueFrom, from, groupBy, map, mergeMap, of, pairwise, race, retry, share, startWith, switchMap, take, tap } from "rxjs";
8
8
  import "@sanity/types";
@@ -144,14 +144,10 @@ const definitions = /* @__PURE__ */ new Map(), inflight = /* @__PURE__ */ new Ma
144
144
  }), sub.add(def.fetch(instance)(...params).pipe(take(1)).subscribe({
145
145
  next: (data) => {
146
146
  let current = state.get().entries[key];
147
- if (current && current.version !== startVersion) {
148
- inflight.delete(key), current.isFetching && updateEntry(state, key, "fetchDiscard", (prev) => prev && {
149
- ...prev,
150
- isFetching: !1
151
- }), resolve(current.data), sub.unsubscribe();
152
- return;
153
- }
154
- updateEntry(state, key, "fetchSuccess", (prev) => ({
147
+ current && current.version !== startVersion ? (inflight.delete(key), current.isFetching && updateEntry(state, key, "fetchDiscard", (prev) => prev && {
148
+ ...prev,
149
+ isFetching: !1
150
+ }), resolve(current.data), sub.unsubscribe()) : (updateEntry(state, key, "fetchSuccess", (prev) => ({
155
151
  ...prev ?? baseEntry(def, key, instance, params),
156
152
  status: "success",
157
153
  data,
@@ -160,7 +156,7 @@ const definitions = /* @__PURE__ */ new Map(), inflight = /* @__PURE__ */ new Ma
160
156
  isFetching: !1,
161
157
  forcedStale: !1,
162
158
  tags: computeTags(def, data, params)
163
- })), resolve(data);
159
+ })), resolve(data));
164
160
  },
165
161
  error: (error) => {
166
162
  updateEntry(state, key, "fetchError", (prev) => prev && (prev.status === "success" ? {
@@ -1541,7 +1537,7 @@ const _resolveQuery = bindActionByResource(queryStore, ({ state, instance }, { s
1541
1537
  }, QUERY_STATE_CLEAR_DELAY);
1542
1538
  };
1543
1539
  return promise.then(releaseSubscriber, releaseSubscriber), promise;
1544
- }), CORE_SDK_VERSION = getEnv("PKG_VERSION") || "3.9.1-development";
1540
+ }), CORE_SDK_VERSION = getEnv("PKG_VERSION") || "3.9.2-next.20261014121948-development";
1545
1541
  export { randomUuid as $, toCommentsKeyParts as A, setPendingTransaction as B, commentsStore as C, parseCommentsOptionsKey as D, getCommentsState as E, receiveComment as F, provisionAddonDataset as G, toCommentFieldPath as H, removeCommentById as I, getProjectAccessErrorProjectId as J, COMMENTS_API_VERSION as K, restoreComments as L, applyCommentUpdate as M, clearPendingTransaction as N, resolveCommentThreads as O, getCommentsKey as P, randomId as Q, rollbackCommentUpdate as R, toFavoriteDocument as S, getCommentsOptionsKey as T, assertDatasetResource as U, normalizeComment as V, getAddonDatasetState as W, defineFetcher as X, getSignInMethodLabel as Y, defineMutation as Z, updateLastLoadMoreRequest as _, resolveQuery as a, favorites as b, getAllReleasesState as c, getUsersKey as d, initializeRequest as f, setUsersError as g, setUsersData as h, parseQueryKey as i, addComment as j, resolveComments as k, addSubscription as l, removeSubscription as m, getQueryKey as n, getPerspectiveState as o, parseUsersKey as p, getProjectAccessErrorDetails as q, getQueryState as r, getActiveReleasesState as s, CORE_SDK_VERSION as t, cancelRequest as u, PROJECT_API_VERSION as v, getCommentThreadsState as w, setFavorite as x, USERS_STATE_CLEAR_DELAY as y, setCommentCreateError as z };
1546
1542
 
1547
- //# sourceMappingURL=version-7EzMhxQE.js.map
1543
+ //# sourceMappingURL=version-Bx_0tNcN.js.map