next-sanity 13.0.0-cache-components.42 → 13.0.0-cache-components.44

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 (32) hide show
  1. package/dist/SanityLive.js +5 -3
  2. package/dist/SanityLive.js.map +1 -1
  3. package/dist/isCorsOriginError.js.map +1 -1
  4. package/dist/live/client-components/index.d.ts +7 -8
  5. package/dist/live/client-components/index.d.ts.map +1 -1
  6. package/dist/live/client-components/index.js +1 -1
  7. package/dist/live/client-components/index.js.map +1 -1
  8. package/dist/live/conditions/default/index.d.ts +226 -4
  9. package/dist/live/conditions/default/index.d.ts.map +1 -1
  10. package/dist/live/conditions/default/index.js +0 -4
  11. package/dist/live/conditions/default/index.js.map +1 -1
  12. package/dist/live/conditions/next-js/index.d.ts +232 -2
  13. package/dist/live/conditions/next-js/index.d.ts.map +1 -1
  14. package/dist/live/conditions/next-js/index.js +2 -1
  15. package/dist/live/conditions/next-js/index.js.map +1 -1
  16. package/dist/live/conditions/react-server/index.d.ts +232 -2
  17. package/dist/live/conditions/react-server/index.d.ts.map +1 -1
  18. package/dist/live/conditions/react-server/index.js +2 -1
  19. package/dist/live/conditions/react-server/index.js.map +1 -1
  20. package/dist/live/server-actions/{index.default.d.ts → index.d.ts} +1 -1
  21. package/dist/live/server-actions/index.d.ts.map +1 -0
  22. package/dist/live/server-actions/{index.next-js.js → index.js} +1 -1
  23. package/dist/live/server-actions/index.js.map +1 -0
  24. package/dist/types.d.ts +155 -77
  25. package/dist/types.d.ts.map +1 -1
  26. package/package.json +4 -10
  27. package/dist/live/server-actions/index.default.d.ts.map +0 -1
  28. package/dist/live/server-actions/index.default.js +0 -27
  29. package/dist/live/server-actions/index.default.js.map +0 -1
  30. package/dist/live/server-actions/index.next-js.d.ts +0 -11
  31. package/dist/live/server-actions/index.next-js.d.ts.map +0 -1
  32. package/dist/live/server-actions/index.next-js.js.map +0 -1
@@ -10,7 +10,7 @@ const RefreshOnMount = dynamic(() => import("./RefreshOnMount.js"));
10
10
  const RefreshOnInterval = dynamic(() => import("./RefreshOnInterval.js"));
11
11
  const RefreshOnReconnect = dynamic(() => import("./RefreshOnReconnect.js"));
12
12
  function SanityLive(props) {
13
- const { config, includeDrafts = false, action, onError, onWelcome = handleWelcome, onReconnect, onRestart, onGoAway = handleGoaway, refreshOnMount = false, refreshOnFocus = false, refreshOnReconnect = true, requestTag } = props;
13
+ const { config, includeDrafts = false, requestTag, waitFor, action, onError, onWelcome = handleWelcome, onReconnect, onRestart, onGoAway = handleGoaway, refreshOnMount = false, refreshOnFocus = false, refreshOnReconnect = true } = props;
14
14
  const { projectId, dataset, apiHost, apiVersion, useProjectHostname, token, requestTagPrefix } = config;
15
15
  const actionContext = { includeDrafts };
16
16
  const client = useMemo(() => createClient({
@@ -71,7 +71,8 @@ function SanityLive(props) {
71
71
  useEffect(() => {
72
72
  const subscription = client.live.events({
73
73
  includeDrafts,
74
- tag: requestTag
74
+ tag: requestTag,
75
+ waitFor
75
76
  }).subscribe({
76
77
  next: handleLiveEvent,
77
78
  error: handleError
@@ -80,7 +81,8 @@ function SanityLive(props) {
80
81
  }, [
81
82
  client.live,
82
83
  requestTag,
83
- includeDrafts
84
+ includeDrafts,
85
+ waitFor
84
86
  ]);
85
87
  return /* @__PURE__ */ jsxs(Fragment, { children: [
86
88
  refreshOnMount && /* @__PURE__ */ jsx(RefreshOnMount, {}),
@@ -1 +1 @@
1
- {"version":3,"file":"SanityLive.js","names":[],"sources":["../src/live/client-components/SanityLive.tsx"],"sourcesContent":["import {createClient, type InitializedClientConfig, type LiveEvent} from '@sanity/client'\nimport dynamic from 'next/dynamic'\nimport {useRouter} from 'next/navigation'\nimport {startTransition, useEffect, useEffectEvent, useMemo, useState} from 'react'\n\nimport {cacheTagPrefixes} from '#live/constants'\nimport {isCorsOriginError} from '#live/isCorsOriginError'\nimport type {\n SanityLiveAction,\n SanityLiveActionContext,\n SanityLiveOnError,\n SanityLiveOnGoaway,\n SanityLiveOnReconnect,\n SanityLiveOnRestart,\n SanityLiveOnWelcome,\n} from '#live/types'\n\nconst RefreshOnFocus = dynamic(() => import('./RefreshOnFocus'))\nconst RefreshOnMount = dynamic(() => import('./RefreshOnMount'))\nconst RefreshOnInterval = dynamic(() => import('./RefreshOnInterval'))\nconst RefreshOnReconnect = dynamic(() => import('./RefreshOnReconnect'))\n\ninterface SanityClientConfig extends Pick<\n InitializedClientConfig,\n | 'projectId'\n | 'dataset'\n | 'apiHost'\n | 'apiVersion'\n | 'useProjectHostname'\n | 'token'\n | 'requestTagPrefix'\n> {}\n\nexport interface SanityLiveProps {\n config: SanityClientConfig\n includeDrafts?: boolean\n requestTag: string\n\n action: SanityLiveAction\n onError: SanityLiveOnError | false | undefined\n onWelcome: SanityLiveOnWelcome | false | undefined\n onReconnect: SanityLiveOnReconnect | false | undefined\n onRestart: SanityLiveOnRestart | false | undefined\n onGoAway: SanityLiveOnGoaway | false | undefined\n\n refreshOnMount?: boolean\n refreshOnFocus?: boolean\n refreshOnReconnect?: boolean\n}\n\nfunction SanityLive(props: SanityLiveProps): React.JSX.Element | null {\n const {\n config,\n includeDrafts = false,\n action,\n onError,\n onWelcome = handleWelcome,\n onReconnect,\n onRestart,\n onGoAway = handleGoaway,\n refreshOnMount = false,\n refreshOnFocus = false,\n refreshOnReconnect = true,\n requestTag,\n } = props\n const {projectId, dataset, apiHost, apiVersion, useProjectHostname, token, requestTagPrefix} =\n config\n const actionContext = {includeDrafts} satisfies SanityLiveActionContext\n\n const client = useMemo(\n () =>\n createClient({\n projectId,\n dataset,\n apiHost,\n apiVersion,\n useProjectHostname,\n ignoreBrowserTokenWarning: true,\n token,\n useCdn: false,\n requestTagPrefix,\n }),\n [apiHost, apiVersion, dataset, projectId, requestTagPrefix, token, useProjectHostname],\n )\n\n const [refreshOnInterval, setRefreshOnInterval] = useState<number | false>(false)\n\n const [error, setError] = useState<unknown>(null)\n if (error) {\n // Throw during render to bubble up to the nearest <ErrorBoundary>, if `onError` is provided we won't rethrow\n throw error\n }\n const handleError = useEffectEvent((error: unknown) => {\n if (onError) {\n void onError(error, actionContext)\n } else {\n setError(\n isCorsOriginError(error)\n ? new Error(\n `Sanity Live is unable to connect to the Sanity API as the current origin - ${window.origin} - is not in the list of allowed CORS origins for this Sanity Project.${error.addOriginUrl ? ` Add it here: ${error.addOriginUrl}` : ''}`,\n {cause: error},\n )\n : error,\n )\n }\n })\n\n const router = useRouter()\n const handleLiveEvent = useEffectEvent((event: LiveEvent) => {\n switch (event.type) {\n case 'welcome': {\n // Disable long polling when welcome event is received, this is a no-op if long polling is already disabled\n startTransition(() => setRefreshOnInterval(false))\n\n if (onWelcome) {\n startTransition(() => onWelcome(event, actionContext))\n }\n break\n }\n case 'message': {\n startTransition(() =>\n action(\n event.tags.map(\n (tag) =>\n `${includeDrafts ? cacheTagPrefixes.drafts : cacheTagPrefixes.published}${tag}`,\n ),\n ).then((result) => {\n if (result === 'refresh') {\n startTransition(() => router.refresh())\n }\n }),\n )\n break\n }\n case 'restart': {\n // Disable long polling when restart event is received, this is a no-op if long polling is already disabled\n startTransition(() => setRefreshOnInterval(false))\n\n if (onRestart) {\n startTransition(() => onRestart(event, actionContext))\n }\n break\n }\n case 'reconnect': {\n // Disable long polling when reconnect event is received, this is a no-op if long polling is already disabled\n startTransition(() => setRefreshOnInterval(false))\n\n if (onReconnect) {\n startTransition(() => onReconnect(event, actionContext))\n }\n break\n }\n case 'goaway': {\n if (onGoAway) {\n startTransition(() =>\n onGoAway(event, actionContext, (interval) =>\n startTransition(() => setRefreshOnInterval(interval)),\n ),\n )\n } else if (!onGoAway) {\n handleError(\n new Error(\n `Sanity Live connection closed, automatic revalidation is disabled, the server gave this reason: ${event.reason}`,\n {cause: event},\n ),\n )\n }\n break\n }\n default:\n handleError(new Error(`Unknown live event type`, {cause: event}))\n break\n }\n })\n useEffect(() => {\n const subscription = client.live\n .events({includeDrafts, tag: requestTag})\n .subscribe({next: handleLiveEvent, error: handleError})\n return () => subscription.unsubscribe()\n }, [client.live, requestTag, includeDrafts])\n\n return (\n <>\n {refreshOnMount && <RefreshOnMount />}\n {refreshOnInterval && Number.isFinite(refreshOnInterval) && refreshOnInterval > 0 && (\n <RefreshOnInterval interval={refreshOnInterval} />\n )}\n {refreshOnFocus && <RefreshOnFocus />}\n {refreshOnReconnect && <RefreshOnReconnect />}\n </>\n )\n}\n\nSanityLive.displayName = 'SanityLiveClientComponent'\n\nexport default SanityLive\n\nconst handleWelcome: SanityLiveOnWelcome = (_, {includeDrafts}) => {\n // oxlint-disable-next-line no-console\n console.info(\n `<SanityLive${includeDrafts ? ' includeDrafts' : ''}> is connected and listening for live events to ${includeDrafts ? 'all content including drafts and version documents in content releases' : 'published content'}`,\n )\n}\n\nconst handleGoaway: SanityLiveOnGoaway = (event, {includeDrafts}, setLongPollingInterval) => {\n const interval = 30_000\n console.warn(\n `<SanityLive${includeDrafts ? ' includeDrafts' : ''}> connection is closed after receiving a 'goaway' event, the server gave this reason:`,\n event.reason,\n `Content will now be refreshed every ${interval / 1_000} seconds`,\n )\n setLongPollingInterval(interval)\n}\n"],"mappings":"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"}
1
+ {"version":3,"file":"SanityLive.js","names":[],"sources":["../src/live/client-components/SanityLive.tsx"],"sourcesContent":["import {createClient, type LiveEvent} from '@sanity/client'\nimport dynamic from 'next/dynamic'\nimport {useRouter} from 'next/navigation'\nimport {useEffect, useMemo, useState, useEffectEvent, startTransition} from 'react'\n\nimport {cacheTagPrefixes} from '#live/constants'\nimport {isCorsOriginError} from '#live/isCorsOriginError'\nimport type {\n SanityClientConfig,\n SanityLiveAction,\n SanityLiveActionContext,\n SanityLiveOnError,\n SanityLiveOnGoaway,\n SanityLiveOnReconnect,\n SanityLiveOnRestart,\n SanityLiveOnWelcome,\n} from '#live/types'\n\nconst RefreshOnFocus = dynamic(() => import('./RefreshOnFocus'))\nconst RefreshOnMount = dynamic(() => import('./RefreshOnMount'))\nconst RefreshOnInterval = dynamic(() => import('./RefreshOnInterval'))\nconst RefreshOnReconnect = dynamic(() => import('./RefreshOnReconnect'))\n\nexport interface SanityLiveProps {\n config: SanityClientConfig\n includeDrafts: boolean | undefined\n requestTag: string\n waitFor: 'function' | undefined\n\n action: SanityLiveAction\n onError: SanityLiveOnError | false | undefined\n onWelcome: SanityLiveOnWelcome | false | undefined\n onReconnect: SanityLiveOnReconnect | false | undefined\n onRestart: SanityLiveOnRestart | false | undefined\n onGoAway: SanityLiveOnGoaway | false | undefined\n\n refreshOnMount: boolean | undefined\n refreshOnFocus: boolean | undefined\n refreshOnReconnect: boolean | undefined\n}\n\nfunction SanityLive(props: SanityLiveProps): React.JSX.Element | null {\n const {\n config,\n includeDrafts = false,\n requestTag,\n waitFor,\n\n action,\n onError,\n onWelcome = handleWelcome,\n onReconnect,\n onRestart,\n onGoAway = handleGoaway,\n\n refreshOnMount = false,\n refreshOnFocus = false,\n refreshOnReconnect = true,\n } = props\n const {projectId, dataset, apiHost, apiVersion, useProjectHostname, token, requestTagPrefix} =\n config\n const actionContext = {includeDrafts} satisfies SanityLiveActionContext\n\n const client = useMemo(\n () =>\n createClient({\n projectId,\n dataset,\n apiHost,\n apiVersion,\n useProjectHostname,\n ignoreBrowserTokenWarning: true,\n token,\n useCdn: false,\n requestTagPrefix,\n }),\n [apiHost, apiVersion, dataset, projectId, requestTagPrefix, token, useProjectHostname],\n )\n\n const [refreshOnInterval, setRefreshOnInterval] = useState<number | false>(false)\n\n const [error, setError] = useState<unknown>(null)\n if (error) {\n // Throw during render to bubble up to the nearest <ErrorBoundary>, if `onError` is provided we won't rethrow\n throw error\n }\n const handleError = useEffectEvent((error: unknown) => {\n if (onError) {\n void onError(error, actionContext)\n } else {\n setError(\n isCorsOriginError(error)\n ? new Error(\n `Sanity Live is unable to connect to the Sanity API as the current origin - ${window.origin} - is not in the list of allowed CORS origins for this Sanity Project.${error.addOriginUrl ? ` Add it here: ${error.addOriginUrl}` : ''}`,\n {cause: error},\n )\n : error,\n )\n }\n })\n\n const router = useRouter()\n const handleLiveEvent = useEffectEvent((event: LiveEvent) => {\n switch (event.type) {\n case 'welcome': {\n // Disable long polling when welcome event is received, this is a no-op if long polling is already disabled\n startTransition(() => setRefreshOnInterval(false))\n\n if (onWelcome) {\n startTransition(() => onWelcome(event, actionContext))\n }\n break\n }\n case 'message': {\n startTransition(() =>\n action(\n event.tags.map(\n (tag) =>\n `${includeDrafts ? cacheTagPrefixes.drafts : cacheTagPrefixes.published}${tag}`,\n ),\n ).then((result) => {\n if (result === 'refresh') {\n startTransition(() => router.refresh())\n }\n }),\n )\n break\n }\n case 'restart': {\n // Disable long polling when restart event is received, this is a no-op if long polling is already disabled\n startTransition(() => setRefreshOnInterval(false))\n\n if (onRestart) {\n startTransition(() => onRestart(event, actionContext))\n }\n break\n }\n case 'reconnect': {\n // Disable long polling when reconnect event is received, this is a no-op if long polling is already disabled\n startTransition(() => setRefreshOnInterval(false))\n\n if (onReconnect) {\n startTransition(() => onReconnect(event, actionContext))\n }\n break\n }\n case 'goaway': {\n if (onGoAway) {\n startTransition(() =>\n onGoAway(event, actionContext, (interval) =>\n startTransition(() => setRefreshOnInterval(interval)),\n ),\n )\n } else if (!onGoAway) {\n handleError(\n new Error(\n `Sanity Live connection closed, automatic revalidation is disabled, the server gave this reason: ${event.reason}`,\n {cause: event},\n ),\n )\n }\n break\n }\n default:\n handleError(new Error(`Unknown live event type`, {cause: event}))\n break\n }\n })\n useEffect(() => {\n const subscription = client.live\n .events({includeDrafts, tag: requestTag, waitFor})\n .subscribe({next: handleLiveEvent, error: handleError})\n return () => subscription.unsubscribe()\n }, [client.live, requestTag, includeDrafts, waitFor])\n\n return (\n <>\n {refreshOnMount && <RefreshOnMount />}\n {refreshOnInterval && Number.isFinite(refreshOnInterval) && refreshOnInterval > 0 && (\n <RefreshOnInterval interval={refreshOnInterval} />\n )}\n {refreshOnFocus && <RefreshOnFocus />}\n {refreshOnReconnect && <RefreshOnReconnect />}\n </>\n )\n}\n\nSanityLive.displayName = 'SanityLiveClientComponent'\n\nexport default SanityLive\n\nconst handleWelcome: SanityLiveOnWelcome = (_, {includeDrafts}) => {\n // oxlint-disable-next-line no-console\n console.info(\n `<SanityLive${includeDrafts ? ' includeDrafts' : ''}> is connected and listening for live events to ${includeDrafts ? 'all content including drafts and version documents in content releases' : 'published content'}`,\n )\n}\n\nconst handleGoaway: SanityLiveOnGoaway = (event, {includeDrafts}, setLongPollingInterval) => {\n const interval = 30_000\n console.warn(\n `<SanityLive${includeDrafts ? ' includeDrafts' : ''}> connection is closed after receiving a 'goaway' event, the server gave this reason:`,\n event.reason,\n `Content will now be refreshed every ${interval / 1_000} seconds`,\n )\n setLongPollingInterval(interval)\n}\n"],"mappings":"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"}
@@ -1 +1 @@
1
- {"version":3,"file":"isCorsOriginError.js","names":[],"sources":["../src/live/shared/isCorsOriginError.ts"],"sourcesContent":["import type {CorsOriginError} from '@sanity/client'\n\n/** @public */\nexport function isCorsOriginError(error: unknown): error is CorsOriginError {\n return error instanceof Error && error.name === 'CorsOriginError'\n}\n\nexport type {CorsOriginError}\n"],"mappings":";AAGA,SAAgB,kBAAkB,OAA0C;AAC1E,QAAO,iBAAiB,SAAS,MAAM,SAAS"}
1
+ {"version":3,"file":"isCorsOriginError.js","names":[],"sources":["../src/live/shared/isCorsOriginError.ts"],"sourcesContent":["import type {CorsOriginError} from '@sanity/client'\n\n/** @public */\nexport function isCorsOriginError(error: unknown): error is CorsOriginError {\n return error instanceof Error && error.name === 'CorsOriginError'\n}\n"],"mappings":";AAGA,SAAgB,kBAAkB,OAA0C;AAC1E,QAAO,iBAAiB,SAAS,MAAM,SAAS"}
@@ -1,22 +1,21 @@
1
- import { a as SanityLiveAction, c as SanityLiveOnReconnect, l as SanityLiveOnRestart, o as SanityLiveOnError, s as SanityLiveOnGoaway, u as SanityLiveOnWelcome } from "../../types.js";
2
- import { InitializedClientConfig } from "@sanity/client";
3
- interface SanityClientConfig extends Pick<InitializedClientConfig, "projectId" | "dataset" | "apiHost" | "apiVersion" | "useProjectHostname" | "token" | "requestTagPrefix"> {}
1
+ import { a as SanityClientConfig, c as SanityLiveOnError, d as SanityLiveOnRestart, f as SanityLiveOnWelcome, l as SanityLiveOnGoaway, o as SanityLiveAction, u as SanityLiveOnReconnect } from "../../types.js";
4
2
  interface SanityLiveProps {
5
3
  config: SanityClientConfig;
6
- includeDrafts?: boolean;
4
+ includeDrafts: boolean | undefined;
7
5
  requestTag: string;
6
+ waitFor: "function" | undefined;
8
7
  action: SanityLiveAction;
9
8
  onError: SanityLiveOnError | false | undefined;
10
9
  onWelcome: SanityLiveOnWelcome | false | undefined;
11
10
  onReconnect: SanityLiveOnReconnect | false | undefined;
12
11
  onRestart: SanityLiveOnRestart | false | undefined;
13
12
  onGoAway: SanityLiveOnGoaway | false | undefined;
14
- refreshOnMount?: boolean;
15
- refreshOnFocus?: boolean;
16
- refreshOnReconnect?: boolean;
13
+ refreshOnMount: boolean | undefined;
14
+ refreshOnFocus: boolean | undefined;
15
+ refreshOnReconnect: boolean | undefined;
17
16
  }
18
17
  /**
19
- * @alpha CAUTION: this is an internal component and does not follow semver. Using it directly is at your own risk.
18
+ * @internal CAUTION: this is an internal component and does not follow semver. Using it directly is at your own risk.
20
19
  */
21
20
  declare const SanityLive: React.ComponentType<SanityLiveProps>;
22
21
  export { SanityLive };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/live/client-components/SanityLive.tsx","../../../src/live/client-components/index.ts"],"mappings":";;UAsBU,kBAAA,SAA2B,IAAA,CACnC,uBAAA;AAAA,UAUe,eAAA;EACf,MAAA,EAAQ,kBAAA;EACR,aAAA;EACA,UAAA;EAEA,MAAA,EAAQ,gBAAA;EACR,OAAA,EAAS,iBAAA;EACT,SAAA,EAAW,mBAAA;EACX,WAAA,EAAa,qBAAA;EACb,SAAA,EAAW,mBAAA;EACX,QAAA,EAAU,kBAAA;EAEV,cAAA;EACA,cAAA;EACA,kBAAA;AAAA;;;AAhCK;cCPM,UAAA,EAAY,KAAA,CAAM,aAAA,CAAc,eAAA"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/live/client-components/SanityLive.tsx","../../../src/live/client-components/index.ts"],"mappings":";UAuBiB,eAAA;EACf,MAAA,EAAQ,kBAAA;EACR,aAAA;EACA,UAAA;EACA,OAAA;EAEA,MAAA,EAAQ,gBAAA;EACR,OAAA,EAAS,iBAAA;EACT,SAAA,EAAW,mBAAA;EACX,WAAA,EAAa,qBAAA;EACb,SAAA,EAAW,mBAAA;EACX,QAAA,EAAU,kBAAA;EAEV,cAAA;EACA,cAAA;EACA,kBAAA;AAAA;;AAfF;;cCfa,UAAA,EAAY,KAAA,CAAM,aAAA,CAAc,eAAA"}
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import dynamic from "next/dynamic";
3
3
  /**
4
- * @alpha CAUTION: this is an internal component and does not follow semver. Using it directly is at your own risk.
4
+ * @internal CAUTION: this is an internal component and does not follow semver. Using it directly is at your own risk.
5
5
  */
6
6
  const SanityLive = dynamic(() => import("../../SanityLive.js"), { ssr: false });
7
7
  export { SanityLive };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../src/live/client-components/index.ts"],"sourcesContent":["'use client'\n\nimport dynamic from 'next/dynamic'\n\nimport type {SanityLiveProps} from './SanityLive'\n/**\n * @alpha CAUTION: this is an internal component and does not follow semver. Using it directly is at your own risk.\n */\nexport const SanityLive: React.ComponentType<SanityLiveProps> = dynamic(\n () => import('./SanityLive'),\n {ssr: false},\n)\n"],"mappings":";;;;;AAQA,MAAa,aAAmD,cACxD,OAAO,wBACb,EAAC,KAAK,OAAM,CACb"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../src/live/client-components/index.ts"],"sourcesContent":["'use client'\n\nimport dynamic from 'next/dynamic'\n\nimport type {SanityLiveProps} from './SanityLive'\n/**\n * @internal CAUTION: this is an internal component and does not follow semver. Using it directly is at your own risk.\n */\nexport const SanityLive: React.ComponentType<SanityLiveProps> = dynamic(\n () => import('./SanityLive'),\n {ssr: false},\n)\n"],"mappings":";;;;;AAQA,MAAa,aAAmD,cACxD,OAAO,wBACb,EAAC,KAAK,OAAM,CACb"}
@@ -1,8 +1,153 @@
1
1
  import { t as isCorsOriginError } from "../../../isCorsOriginError.js";
2
- import { d as StrictDefinedFetchType, f as StrictDefinedLiveProps, i as LivePerspective, n as DefinedFetchType, r as DefinedLiveProps, t as DefineLiveOptions } from "../../../types.js";
2
+ import { c as SanityLiveOnError, d as SanityLiveOnRestart, f as SanityLiveOnWelcome, i as LivePerspective, l as SanityLiveOnGoaway, m as StrictDefinedLiveProps, n as DefinedFetchType, o as SanityLiveAction, p as StrictDefinedFetchType, r as DefinedLiveProps, s as SanityLiveActionContext, t as DefineLiveOptions, u as SanityLiveOnReconnect } from "../../../types.js";
3
3
  import { n as resolvePerspectiveFromCookies$1, t as parseTags } from "../../../parseTags.js";
4
4
  /**
5
- * One
5
+ * Set up Sanity Live for Cache Components. `defineLive` returns `sanityFetch`
6
+ * and `<SanityLive />`, which connect your Sanity client to the Live Content API
7
+ * so cached pages can update in response to fine-grained content changes.
8
+ *
9
+ * With `strict: true`, `perspective` and `stega` become required
10
+ * `sanityFetch` options, and `includeDrafts` becomes required on
11
+ * `<SanityLive />`. Resolve dynamic values from `draftMode()` and `cookies()`
12
+ * outside `'use cache'` boundaries, then pass them into cached components.
13
+ *
14
+ * @see [Live Content API](https://www.sanity.io/docs/content-lake/live-content-api)
15
+ * @see [Sanity Live](https://www.sanity.io/live)
16
+ *
17
+ * @example
18
+ * ```tsx
19
+ * // sanity/live.ts
20
+ * import {cookies, draftMode} from 'next/headers'
21
+ * import {createClient} from 'next-sanity'
22
+ * import {
23
+ * defineLive,
24
+ * resolvePerspectiveFromCookies,
25
+ * type LivePerspective,
26
+ * } from 'next-sanity/live'
27
+ *
28
+ * const client = createClient({
29
+ * projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID,
30
+ * dataset: process.env.NEXT_PUBLIC_SANITY_DATASET,
31
+ * useCdn: true,
32
+ * perspective: 'published',
33
+ * })
34
+ * const token = process.env.SANITY_API_READ_TOKEN
35
+ *
36
+ * export const {sanityFetch, SanityLive} = defineLive({
37
+ * client,
38
+ * browserToken: token,
39
+ * serverToken: token,
40
+ * strict: true,
41
+ * })
42
+ *
43
+ * export interface DynamicFetchOptions {
44
+ * perspective: LivePerspective
45
+ * stega: boolean
46
+ * }
47
+ *
48
+ * // Resolve dynamic values outside 'use cache' boundaries.
49
+ * export async function getDynamicFetchOptions(): Promise<DynamicFetchOptions> {
50
+ * const {isEnabled: isDraftMode} = await draftMode()
51
+ * if (!isDraftMode) {
52
+ * return {perspective: 'published', stega: false}
53
+ * }
54
+ *
55
+ * const jar = await cookies()
56
+ * const perspective = await resolvePerspectiveFromCookies({cookies: jar})
57
+ * return {perspective: perspective ?? 'drafts', stega: true}
58
+ * }
59
+ * ```
60
+ *
61
+ * @example
62
+ * ```tsx
63
+ * // app/layout.tsx
64
+ * import {draftMode} from 'next/headers'
65
+ *
66
+ * import {SanityLive} from '@/sanity/live'
67
+ *
68
+ * export default async function RootLayout({children}: {children: React.ReactNode}) {
69
+ * const {isEnabled: isDraftMode} = await draftMode()
70
+ *
71
+ * return (
72
+ * <html lang="en">
73
+ * <body>
74
+ * {children}
75
+ * <SanityLive includeDrafts={isDraftMode} />
76
+ * </body>
77
+ * </html>
78
+ * )
79
+ * }
80
+ * ```
81
+ *
82
+ * @example
83
+ * ```tsx
84
+ * // app/[slug]/page.tsx
85
+ * import {draftMode} from 'next/headers'
86
+ * import {Suspense} from 'react'
87
+ * import {defineQuery} from 'next-sanity'
88
+ *
89
+ * import {
90
+ * getDynamicFetchOptions,
91
+ * sanityFetch,
92
+ * type DynamicFetchOptions,
93
+ * } from '@/sanity/live'
94
+ *
95
+ * const POSTS_SLUGS_QUERY = defineQuery(`
96
+ * *[_type == "post" && slug.current]{"slug": slug.current}
97
+ * `)
98
+ * const POST_QUERY = defineQuery(`
99
+ * *[_type == "post" && slug.current == $slug][0]
100
+ * `)
101
+ *
102
+ * export async function generateStaticParams() {
103
+ * const {data} = await sanityFetch({
104
+ * query: POSTS_SLUGS_QUERY,
105
+ * perspective: 'published',
106
+ * stega: false,
107
+ * })
108
+ *
109
+ * return data
110
+ * }
111
+ *
112
+ * export default async function Page(props: PageProps<'/[slug]'>) {
113
+ * const {isEnabled: isDraftMode} = await draftMode()
114
+ * if (isDraftMode) {
115
+ * return (
116
+ * <Suspense fallback={<div>Loading...</div>}>
117
+ * <DynamicPage params={props.params} />
118
+ * </Suspense>
119
+ * )
120
+ * }
121
+ *
122
+ * const {slug} = await props.params
123
+ * return <CachedPage slug={slug} perspective="published" stega={false} />
124
+ * }
125
+ *
126
+ * async function DynamicPage(props: Pick<PageProps<'/[slug]'>, 'params'>) {
127
+ * const {slug} = await props.params
128
+ * const {perspective, stega} = await getDynamicFetchOptions()
129
+ *
130
+ * return <CachedPage slug={slug} perspective={perspective} stega={stega} />
131
+ * }
132
+ *
133
+ * async function CachedPage({
134
+ * slug,
135
+ * perspective,
136
+ * stega,
137
+ * }: {slug: string} & DynamicFetchOptions) {
138
+ * 'use cache'
139
+ *
140
+ * const {data} = await sanityFetch({
141
+ * query: POST_QUERY,
142
+ * params: {slug},
143
+ * perspective,
144
+ * stega,
145
+ * })
146
+ *
147
+ * return <pre>{JSON.stringify(data, null, 2)}</pre>
148
+ * }
149
+ * ```
150
+ *
6
151
  * @public
7
152
  */
8
153
  declare function defineLive(config: DefineLiveOptions & {
@@ -12,7 +157,84 @@ declare function defineLive(config: DefineLiveOptions & {
12
157
  SanityLive: React.ComponentType<StrictDefinedLiveProps>;
13
158
  };
14
159
  /**
15
- * Two
160
+ * Set up Sanity Live. `defineLive` returns `sanityFetch` and `<SanityLive />`,
161
+ * which connect your Sanity client to the Live Content API so pages can serve
162
+ * cached content and update in response to fine-grained content changes.
163
+ *
164
+ * @see [Live Content API](https://www.sanity.io/docs/content-lake/live-content-api)
165
+ * @see [Sanity Live](https://www.sanity.io/live)
166
+ *
167
+ * @example
168
+ * ```tsx
169
+ * import {createClient} from 'next-sanity'
170
+ * import {defineLive} from 'next-sanity/live'
171
+ *
172
+ * const client = createClient({
173
+ * projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID,
174
+ * dataset: process.env.NEXT_PUBLIC_SANITY_DATASET,
175
+ * useCdn: true,
176
+ * perspective: 'published',
177
+ * })
178
+ * const token = process.env.SANITY_API_READ_TOKEN
179
+ *
180
+ * export const {sanityFetch, SanityLive} = defineLive({
181
+ * client,
182
+ * browserToken: token,
183
+ * serverToken: token,
184
+ * })
185
+ * ```
186
+ *
187
+ * @example
188
+ * ```tsx
189
+ * // app/layout.tsx
190
+ * import {SanityLive} from '@/sanity/live'
191
+ *
192
+ * export default function RootLayout({children}: {children: React.ReactNode}) {
193
+ * return (
194
+ * <html lang="en">
195
+ * <body>
196
+ * {children}
197
+ * <SanityLive />
198
+ * </body>
199
+ * </html>
200
+ * )
201
+ * }
202
+ * ```
203
+ *
204
+ * @example
205
+ * ```tsx
206
+ * // app/[slug]/page.tsx
207
+ * import {defineQuery} from 'next-sanity'
208
+ * import {sanityFetch} from '@/sanity/live'
209
+ *
210
+ * const POSTS_SLUGS_QUERY = defineQuery(`
211
+ * *[_type == "post" && slug.current]{"slug": slug.current}
212
+ * `)
213
+ * const POST_QUERY = defineQuery(`
214
+ * *[_type == "post" && slug.current == $slug][0]
215
+ * `)
216
+ *
217
+ * export async function generateStaticParams() {
218
+ * const {data} = await sanityFetch({
219
+ * query: POSTS_SLUGS_QUERY,
220
+ * perspective: 'published',
221
+ * stega: false,
222
+ * })
223
+ *
224
+ * return data
225
+ * }
226
+ *
227
+ * export default async function Page(props: PageProps<'/[slug]'>) {
228
+ * const {slug} = await props.params
229
+ * const {data} = await sanityFetch({
230
+ * query: POST_QUERY,
231
+ * params: {slug},
232
+ * })
233
+ *
234
+ * return <pre>{JSON.stringify(data, null, 2)}</pre>
235
+ * }
236
+ * ```
237
+ *
16
238
  * @public
17
239
  */
18
240
  declare function defineLive(config: DefineLiveOptions & {
@@ -50,5 +272,5 @@ declare function defineLive(config: DefineLiveOptions & {
50
272
  * @public
51
273
  */
52
274
  declare const resolvePerspectiveFromCookies: typeof resolvePerspectiveFromCookies$1;
53
- export { type LivePerspective, defineLive, isCorsOriginError, parseTags, resolvePerspectiveFromCookies };
275
+ export { type DefineLiveOptions, type DefinedFetchType, type DefinedLiveProps, type LivePerspective, type SanityLiveAction, type SanityLiveActionContext, type SanityLiveOnError, type SanityLiveOnGoaway, type SanityLiveOnReconnect, type SanityLiveOnRestart, type SanityLiveOnWelcome, type StrictDefinedFetchType, type StrictDefinedLiveProps, defineLive, isCorsOriginError, parseTags, resolvePerspectiveFromCookies };
54
276
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/live/conditions/default/index.ts"],"mappings":";;;AAsBA;;;;AAAA,iBAAgB,UAAA,CAAW,MAAA,EAAQ,iBAAA;EAAqB,MAAA;AAAA;EACtD,WAAA,EAAa,sBAAA;EACb,UAAA,EAAY,KAAA,CAAM,aAAA,CAAc,sBAAA;AAAA;;;;;iBAMlB,UAAA,CAAW,MAAA,EAAQ,iBAAA;EAAqB,MAAA;AAAA;EACtD,WAAA,EAAa,gBAAA;EACb,UAAA,EAAY,KAAA,CAAM,aAAA,CAAc,gBAAA;AAAA;AAFlC;;;;;;;;;;;;;;;;;;;;AAwCA;;;;;;;;AAxCA,cAwCa,6BAAA,SAAsC,+BAAA"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/live/conditions/default/index.ts"],"mappings":";;;AAuKA;;;;;;;;;;;;;;;;;;;;AAqFA;;;;;;;;;;;;;;;;;;;;AAoCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAzHA,iBAAgB,UAAA,CAAW,MAAA,EAAQ,iBAAA;EAAqB,MAAA;AAAA;EACtD,WAAA,EAAa,sBAAA;EACb,UAAA,EAAY,KAAA,CAAM,aAAA,CAAc,sBAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAmFlB,UAAA,CAAW,MAAA,EAAQ,iBAAA;EAAqB,MAAA;AAAA;EACtD,WAAA,EAAa,gBAAA;EACb,UAAA,EAAY,KAAA,CAAM,aAAA,CAAc,gBAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAkCrB,6BAAA,SAAsC,+BAAA"}
@@ -1,9 +1,5 @@
1
1
  import { t as isCorsOriginError } from "../../../isCorsOriginError.js";
2
2
  import { t as parseTags } from "../../../parseTags.js";
3
- /**
4
- * Three
5
- * @public
6
- */
7
3
  function defineLive(_config) {
8
4
  throw new Error(`defineLive can't be imported by a client component`);
9
5
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../../src/live/conditions/default/index.ts"],"sourcesContent":["// This is the fallback export condition for `import 'next-sanity/live'`,\n// it should have the same type definitions as the other conditions so that userland don't have to worry about setting the right\n// `customCondition` in their `tsconfig.json` in order to get accurate typings.\n// The implementation here though should all throw errors, as importing this file means userland made a mistake and somehow a client component is\n// trying to pull in something it shouldn't.\n\nimport type {resolvePerspectiveFromCookies as _resolvePerspectiveFromCookies} from '#live/resolvePerspectiveFromCookies'\nimport type {\n DefinedFetchType,\n DefinedLiveProps,\n DefineLiveOptions,\n StrictDefinedFetchType,\n StrictDefinedLiveProps,\n} from '#live/types'\n\nexport {isCorsOriginError} from '#live/isCorsOriginError'\nexport {parseTags} from '#live/parseTags'\n\n/**\n * One\n * @public\n */\nexport function defineLive(config: DefineLiveOptions & {strict: true}): {\n sanityFetch: StrictDefinedFetchType\n SanityLive: React.ComponentType<StrictDefinedLiveProps>\n}\n/**\n * Two\n * @public\n */\nexport function defineLive(config: DefineLiveOptions & {strict?: false}): {\n sanityFetch: DefinedFetchType\n SanityLive: React.ComponentType<DefinedLiveProps>\n}\n/**\n * Three\n * @public\n */\nexport function defineLive(_config: DefineLiveOptions): never {\n throw new Error(`defineLive can't be imported by a client component`)\n}\n\n/**\n * This helper is intended for use with Next.js Cache Components (`cacheComponents: true`),\n * where `cookies()` and `draftMode()` cannot be called inside `'use cache'` boundaries.\n * Resolve the perspective once outside the cache boundary and pass it in as a prop / cache key.\n *\n * @example\n * ```tsx\n * import {cookies, draftMode} from 'next/headers'\n * import {resolvePerspectiveFromCookies, type LivePerspective} from 'next-sanity/live'\n * import {sanityFetch} from '#sanity/live'\n *\n * function Page() {\n * const {isEnabled: isDraftMode} = await draftMode()\n * let perspective: LivePerspective = 'published'\n * if(isDraftMode) {\n * perspective = await resolvePerspectiveFromCookies({cookies: await cookies()})\n * }\n * const {data} = await cachedFetch({query, perspective, stega: isDraftMode})\n * }\n * function cachedFetch({query, params, perspective, stega}: {query: string, perspective: LivePerspective, stega: boolean}) {}) {\n * 'use cache'\n * const {data} = await sanityFetch({query, params, perspective, stega})\n * return {data}\n * }\n * ```\n *\n * @public\n */\nexport const resolvePerspectiveFromCookies: typeof _resolvePerspectiveFromCookies = () => {\n throw new Error(`resolvePerspectiveFromCookies can't be imported by a client component`)\n}\n\nexport type {LivePerspective} from '#live/types'\n"],"mappings":";;;;;;AAsCA,SAAgB,WAAW,SAAmC;AAC5D,OAAM,IAAI,MAAM,qDAAqD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BvE,MAAa,sCAA6E;AACxF,OAAM,IAAI,MAAM,wEAAwE"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../../src/live/conditions/default/index.ts"],"sourcesContent":["// This is the fallback export condition for `import 'next-sanity/live'`,\n// it should have the same type definitions as the other conditions so that userland don't have to worry about setting the right\n// `customCondition` in their `tsconfig.json` in order to get accurate typings.\n// The implementation here though should all throw errors, as importing this file means userland made a mistake and somehow a client component is\n// trying to pull in something it shouldn't.\n\nimport type {resolvePerspectiveFromCookies as _resolvePerspectiveFromCookies} from '#live/resolvePerspectiveFromCookies'\nimport type {\n DefinedFetchType,\n DefinedLiveProps,\n DefineLiveOptions,\n StrictDefinedFetchType,\n StrictDefinedLiveProps,\n} from '#live/types'\n\nexport {isCorsOriginError} from '#live/isCorsOriginError'\nexport {parseTags} from '#live/parseTags'\n\n/**\n * Set up Sanity Live for Cache Components. `defineLive` returns `sanityFetch`\n * and `<SanityLive />`, which connect your Sanity client to the Live Content API\n * so cached pages can update in response to fine-grained content changes.\n *\n * With `strict: true`, `perspective` and `stega` become required\n * `sanityFetch` options, and `includeDrafts` becomes required on\n * `<SanityLive />`. Resolve dynamic values from `draftMode()` and `cookies()`\n * outside `'use cache'` boundaries, then pass them into cached components.\n *\n * @see [Live Content API](https://www.sanity.io/docs/content-lake/live-content-api)\n * @see [Sanity Live](https://www.sanity.io/live)\n *\n * @example\n * ```tsx\n * // sanity/live.ts\n * import {cookies, draftMode} from 'next/headers'\n * import {createClient} from 'next-sanity'\n * import {\n * defineLive,\n * resolvePerspectiveFromCookies,\n * type LivePerspective,\n * } from 'next-sanity/live'\n *\n * const client = createClient({\n * projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID,\n * dataset: process.env.NEXT_PUBLIC_SANITY_DATASET,\n * useCdn: true,\n * perspective: 'published',\n * })\n * const token = process.env.SANITY_API_READ_TOKEN\n *\n * export const {sanityFetch, SanityLive} = defineLive({\n * client,\n * browserToken: token,\n * serverToken: token,\n * strict: true,\n * })\n *\n * export interface DynamicFetchOptions {\n * perspective: LivePerspective\n * stega: boolean\n * }\n *\n * // Resolve dynamic values outside 'use cache' boundaries.\n * export async function getDynamicFetchOptions(): Promise<DynamicFetchOptions> {\n * const {isEnabled: isDraftMode} = await draftMode()\n * if (!isDraftMode) {\n * return {perspective: 'published', stega: false}\n * }\n *\n * const jar = await cookies()\n * const perspective = await resolvePerspectiveFromCookies({cookies: jar})\n * return {perspective: perspective ?? 'drafts', stega: true}\n * }\n * ```\n *\n * @example\n * ```tsx\n * // app/layout.tsx\n * import {draftMode} from 'next/headers'\n *\n * import {SanityLive} from '@/sanity/live'\n *\n * export default async function RootLayout({children}: {children: React.ReactNode}) {\n * const {isEnabled: isDraftMode} = await draftMode()\n *\n * return (\n * <html lang=\"en\">\n * <body>\n * {children}\n * <SanityLive includeDrafts={isDraftMode} />\n * </body>\n * </html>\n * )\n * }\n * ```\n *\n * @example\n * ```tsx\n * // app/[slug]/page.tsx\n * import {draftMode} from 'next/headers'\n * import {Suspense} from 'react'\n * import {defineQuery} from 'next-sanity'\n *\n * import {\n * getDynamicFetchOptions,\n * sanityFetch,\n * type DynamicFetchOptions,\n * } from '@/sanity/live'\n *\n * const POSTS_SLUGS_QUERY = defineQuery(`\n * *[_type == \"post\" && slug.current]{\"slug\": slug.current}\n * `)\n * const POST_QUERY = defineQuery(`\n * *[_type == \"post\" && slug.current == $slug][0]\n * `)\n *\n * export async function generateStaticParams() {\n * const {data} = await sanityFetch({\n * query: POSTS_SLUGS_QUERY,\n * perspective: 'published',\n * stega: false,\n * })\n *\n * return data\n * }\n *\n * export default async function Page(props: PageProps<'/[slug]'>) {\n * const {isEnabled: isDraftMode} = await draftMode()\n * if (isDraftMode) {\n * return (\n * <Suspense fallback={<div>Loading...</div>}>\n * <DynamicPage params={props.params} />\n * </Suspense>\n * )\n * }\n *\n * const {slug} = await props.params\n * return <CachedPage slug={slug} perspective=\"published\" stega={false} />\n * }\n *\n * async function DynamicPage(props: Pick<PageProps<'/[slug]'>, 'params'>) {\n * const {slug} = await props.params\n * const {perspective, stega} = await getDynamicFetchOptions()\n *\n * return <CachedPage slug={slug} perspective={perspective} stega={stega} />\n * }\n *\n * async function CachedPage({\n * slug,\n * perspective,\n * stega,\n * }: {slug: string} & DynamicFetchOptions) {\n * 'use cache'\n *\n * const {data} = await sanityFetch({\n * query: POST_QUERY,\n * params: {slug},\n * perspective,\n * stega,\n * })\n *\n * return <pre>{JSON.stringify(data, null, 2)}</pre>\n * }\n * ```\n *\n * @public\n */\nexport function defineLive(config: DefineLiveOptions & {strict: true}): {\n sanityFetch: StrictDefinedFetchType\n SanityLive: React.ComponentType<StrictDefinedLiveProps>\n}\n/**\n * Set up Sanity Live. `defineLive` returns `sanityFetch` and `<SanityLive />`,\n * which connect your Sanity client to the Live Content API so pages can serve\n * cached content and update in response to fine-grained content changes.\n *\n * @see [Live Content API](https://www.sanity.io/docs/content-lake/live-content-api)\n * @see [Sanity Live](https://www.sanity.io/live)\n *\n * @example\n * ```tsx\n * import {createClient} from 'next-sanity'\n * import {defineLive} from 'next-sanity/live'\n *\n * const client = createClient({\n * projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID,\n * dataset: process.env.NEXT_PUBLIC_SANITY_DATASET,\n * useCdn: true,\n * perspective: 'published',\n * })\n * const token = process.env.SANITY_API_READ_TOKEN\n *\n * export const {sanityFetch, SanityLive} = defineLive({\n * client,\n * browserToken: token,\n * serverToken: token,\n * })\n * ```\n *\n * @example\n * ```tsx\n * // app/layout.tsx\n * import {SanityLive} from '@/sanity/live'\n *\n * export default function RootLayout({children}: {children: React.ReactNode}) {\n * return (\n * <html lang=\"en\">\n * <body>\n * {children}\n * <SanityLive />\n * </body>\n * </html>\n * )\n * }\n * ```\n *\n * @example\n * ```tsx\n * // app/[slug]/page.tsx\n * import {defineQuery} from 'next-sanity'\n * import {sanityFetch} from '@/sanity/live'\n *\n * const POSTS_SLUGS_QUERY = defineQuery(`\n * *[_type == \"post\" && slug.current]{\"slug\": slug.current}\n * `)\n * const POST_QUERY = defineQuery(`\n * *[_type == \"post\" && slug.current == $slug][0]\n * `)\n *\n * export async function generateStaticParams() {\n * const {data} = await sanityFetch({\n * query: POSTS_SLUGS_QUERY,\n * perspective: 'published',\n * stega: false,\n * })\n *\n * return data\n * }\n *\n * export default async function Page(props: PageProps<'/[slug]'>) {\n * const {slug} = await props.params\n * const {data} = await sanityFetch({\n * query: POST_QUERY,\n * params: {slug},\n * })\n *\n * return <pre>{JSON.stringify(data, null, 2)}</pre>\n * }\n * ```\n *\n * @public\n */\nexport function defineLive(config: DefineLiveOptions & {strict?: false}): {\n sanityFetch: DefinedFetchType\n SanityLive: React.ComponentType<DefinedLiveProps>\n}\nexport function defineLive(_config: DefineLiveOptions): never {\n throw new Error(`defineLive can't be imported by a client component`)\n}\n\n/**\n * This helper is intended for use with Next.js Cache Components (`cacheComponents: true`),\n * where `cookies()` and `draftMode()` cannot be called inside `'use cache'` boundaries.\n * Resolve the perspective once outside the cache boundary and pass it in as a prop / cache key.\n *\n * @example\n * ```tsx\n * import {cookies, draftMode} from 'next/headers'\n * import {resolvePerspectiveFromCookies, type LivePerspective} from 'next-sanity/live'\n * import {sanityFetch} from '#sanity/live'\n *\n * function Page() {\n * const {isEnabled: isDraftMode} = await draftMode()\n * let perspective: LivePerspective = 'published'\n * if(isDraftMode) {\n * perspective = await resolvePerspectiveFromCookies({cookies: await cookies()})\n * }\n * const {data} = await cachedFetch({query, perspective, stega: isDraftMode})\n * }\n * function cachedFetch({query, params, perspective, stega}: {query: string, perspective: LivePerspective, stega: boolean}) {}) {\n * 'use cache'\n * const {data} = await sanityFetch({query, params, perspective, stega})\n * return {data}\n * }\n * ```\n *\n * @public\n */\nexport const resolvePerspectiveFromCookies: typeof _resolvePerspectiveFromCookies = () => {\n throw new Error(`resolvePerspectiveFromCookies can't be imported by a client component`)\n}\n\nexport type {\n DefinedFetchType,\n DefinedLiveProps,\n DefineLiveOptions,\n LivePerspective,\n SanityLiveAction,\n SanityLiveActionContext,\n SanityLiveOnError,\n SanityLiveOnGoaway,\n SanityLiveOnReconnect,\n SanityLiveOnRestart,\n SanityLiveOnWelcome,\n StrictDefinedFetchType,\n StrictDefinedLiveProps,\n} from '#live/types'\n"],"mappings":";;AAgQA,SAAgB,WAAW,SAAmC;AAC5D,OAAM,IAAI,MAAM,qDAAqD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BvE,MAAa,sCAA6E;AACxF,OAAM,IAAI,MAAM,wEAAwE"}