next-sanity 13.0.0-cache-components.41 → 13.0.0-cache-components.43

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 (37) hide show
  1. package/dist/live/client-components/index.d.ts +1 -1
  2. package/dist/live/conditions/default/index.d.ts +251 -4
  3. package/dist/live/conditions/default/index.d.ts.map +1 -1
  4. package/dist/live/conditions/default/index.js +30 -6
  5. package/dist/live/conditions/default/index.js.map +1 -1
  6. package/dist/live/conditions/next-js/index.d.ts +229 -2
  7. package/dist/live/conditions/next-js/index.d.ts.map +1 -1
  8. package/dist/live/conditions/next-js/index.js +2 -2
  9. package/dist/live/conditions/next-js/index.js.map +1 -1
  10. package/dist/live/conditions/react-server/index.d.ts +229 -2
  11. package/dist/live/conditions/react-server/index.d.ts.map +1 -1
  12. package/dist/live/conditions/react-server/index.js +3 -8
  13. package/dist/live/conditions/react-server/index.js.map +1 -1
  14. package/dist/live/server-actions/index.d.ts +11 -0
  15. package/dist/live/server-actions/index.d.ts.map +1 -0
  16. package/dist/live/server-actions/index.js +27 -0
  17. package/dist/live/server-actions/index.js.map +1 -0
  18. package/dist/parseTags.d.ts +17 -8
  19. package/dist/parseTags.d.ts.map +1 -1
  20. package/dist/resolvePerspectiveFromCookies.js +17 -8
  21. package/dist/resolvePerspectiveFromCookies.js.map +1 -1
  22. package/dist/types.d.ts +114 -45
  23. package/dist/types.d.ts.map +1 -1
  24. package/dist/visual-editing/index.js +2 -2
  25. package/dist/visual-editing/index.js.map +1 -1
  26. package/dist/visual-editing/server-actions/index.d.ts +2 -2
  27. package/dist/visual-editing/server-actions/index.js +3 -3
  28. package/dist/visual-editing/server-actions/index.js.map +1 -1
  29. package/package.json +2 -5
  30. package/dist/live/server-actions/index.default.d.ts +0 -10
  31. package/dist/live/server-actions/index.default.d.ts.map +0 -1
  32. package/dist/live/server-actions/index.default.js +0 -27
  33. package/dist/live/server-actions/index.default.js.map +0 -1
  34. package/dist/live/server-actions/index.next-js.d.ts +0 -10
  35. package/dist/live/server-actions/index.next-js.d.ts.map +0 -1
  36. package/dist/live/server-actions/index.next-js.js +0 -26
  37. package/dist/live/server-actions/index.next-js.js.map +0 -1
package/dist/types.d.ts CHANGED
@@ -5,29 +5,47 @@ import { ClientPerspective, ClientReturn, ContentSourceMap, LiveEvent, QueryPara
5
5
  */
6
6
  type LivePerspective = Exclude<ClientPerspective, "raw">;
7
7
  /**
8
- * TODO: docs
8
+ * Fetches data through the configured Sanity client and returns the result
9
+ * together with the source map and cache tags that Sanity Live uses for
10
+ * targeted revalidation.
11
+ *
12
+ * Returned by `defineLive({strict: false})` and `defineLive({strict: undefined})`.
9
13
  */
10
14
  type DefinedFetchType = <const QueryString extends string>(options: {
15
+ /**
16
+ * GROQ query to execute.
17
+ */
11
18
  query: QueryString;
19
+ /**
20
+ * Parameters used by the GROQ query.
21
+ */
12
22
  params?: QueryParams | Promise<QueryParams>;
13
23
  /**
14
- * @defaultValue 'published'
24
+ * Content perspective used for the fetch.
25
+ *
26
+ * @defaultValue The configured client perspective, usually `'published'`.
15
27
  */
16
28
  perspective?: LivePerspective;
17
29
  /**
18
- * Enables stega encoding of the data, this is typically only used in draft mode in conjunction with `perspective: 'drafts'` and with `@sanity/visual-editing` setup.
30
+ * Enables stega encoding of the data. This is typically only used in draft
31
+ * mode with `perspective: 'drafts'` and `@sanity/visual-editing`.
32
+ *
19
33
  * @defaultValue `false`
20
34
  */
21
35
  stega?: boolean;
22
36
  /**
23
- * Custom cache tags that can be used with next's `updateTag` functions for custom `read-your-write` server actions,
24
- * for example a like button that uses client.mutate to update a document and then immediately shows the result.
37
+ * Additional cache tags to associate with this fetch.
38
+ *
39
+ * `sanityFetch` automatically adds Sanity Live sync tags for the query. Use
40
+ * this for custom tags that should also be invalidated by your own server
41
+ * actions, for example after a mutation that needs read-your-own-write UI.
25
42
  */
26
43
  tags?: string[];
27
44
  /**
28
- * This request tag is used to identify the request when viewing request logs from your Sanity Content Lake.
45
+ * Request tag used to identify the request in Sanity Content Lake logs.
46
+ *
29
47
  * @see https://www.sanity.io/docs/reference-api-request-tags
30
- * @defaultValue 'next-loader.fetch'
48
+ * @defaultValue `'next-loader.fetch'` or `'next-loader.fetch.cache-components'`
31
49
  */
32
50
  requestTag?: string;
33
51
  }) => Promise<{
@@ -36,125 +54,176 @@ type DefinedFetchType = <const QueryString extends string>(options: {
36
54
  tags: string[];
37
55
  }>;
38
56
  /**
39
- * TODO: docs
57
+ * Context passed to Sanity Live event handlers.
40
58
  */
41
59
  interface SanityLiveActionContext {
60
+ /**
61
+ * Whether the current `<SanityLive />` connection includes draft and content
62
+ * release version events.
63
+ */
42
64
  includeDrafts: boolean;
43
65
  }
44
66
  /**
45
- * TODO: docs
46
- * Has a default implementation tailed the nextjs env and config
67
+ * Server action invoked when Sanity Live receives a content-change message.
68
+ *
69
+ * The argument is the list of cache tags derived from the Live Content API
70
+ * event. The default action revalidates those tags. Return `'refresh'` from a
71
+ * custom action to also call `router.refresh()` in the browser.
47
72
  */
48
73
  type SanityLiveAction = (unsafeTags: unknown) => Promise<void | "refresh">;
49
74
  /**
50
- * TODO: docs
51
- * If not defined it'll throw the error during render instead, which will crash the react app
52
- * unless there's an <ErrorBoundary> surrounding the <SanityLive> component
75
+ * Handles connection, parsing, and event-processing errors.
76
+ *
77
+ * If no handler is provided, the error is thrown during render so it can be
78
+ * caught by the nearest React error boundary.
53
79
  */
54
80
  type SanityLiveOnError = (event: unknown, context: SanityLiveActionContext) => void | Promise<void>;
55
81
  /**
56
- * TODO: docs
57
- * Optional, logs console.info by default
82
+ * Handles the Live Content API `welcome` event.
83
+ *
84
+ * This event fires when the EventSource connection is established. Some export
85
+ * conditions log a connection message by default; pass `false` to
86
+ * `<SanityLive onWelcome={false} />` to disable that behavior.
58
87
  */
59
88
  type SanityLiveOnWelcome = (event: Extract<LiveEvent, {
60
89
  type: "welcome";
61
90
  }>, context: SanityLiveActionContext) => void | Promise<void>;
62
91
  /**
63
- * TODO: docs
92
+ * Handles the Live Content API `reconnect` event.
93
+ *
94
+ * The default behavior refreshes the route so Server Components can render with
95
+ * fresh data after reconnecting.
64
96
  */
65
97
  type SanityLiveOnReconnect = (event: Extract<LiveEvent, {
66
98
  type: "reconnect";
67
99
  }>, context: SanityLiveActionContext) => void | Promise<void>;
68
100
  /**
69
- * TODO: docs
101
+ * Handles the Live Content API `restart` event.
102
+ *
103
+ * The default behavior refreshes the route so Server Components can render with
104
+ * fresh data after the Live Content API restarts.
70
105
  */
71
106
  type SanityLiveOnRestart = (event: Extract<LiveEvent, {
72
107
  type: "restart";
73
108
  }>, context: SanityLiveActionContext) => void | Promise<void>;
74
109
  /**
75
- * TODO: docs
76
- * This event is fired when the API has hit the limit of concurrent connections, and the API will not deliver live events, in this case long polling intervals is a possible fallback strategy.
77
- * By default a message will be logged to the console, that creates a refresh interval of 30 seconds.
78
- * If you set your own event handler make sure you call `setPollingInterval` if you want to activate long-polling, otherwise content goes stale.
110
+ * Handles the Live Content API `goaway` event.
111
+ *
112
+ * This event means the API closed the live connection and will not deliver live
113
+ * events. This can happen when connection limits are reached. A polling refresh
114
+ * interval is the usual fallback; call `setPollingInterval()` from a custom
115
+ * handler to keep content fresh.
79
116
  */
80
117
  type SanityLiveOnGoaway = (event: Extract<LiveEvent, {
81
118
  type: "goaway";
82
119
  }>, context: SanityLiveActionContext, setPollingInterval: (interval: number) => void) => void | Promise<void>;
83
120
  interface DefinedLiveProps {
84
121
  /**
85
- * TODO: docs, settings this to `true` enables live events for draft content and requires `browserToken` to be set.
122
+ * Include draft and content release version events in the live connection.
123
+ *
124
+ * Set this to `true` when draft mode is enabled. A `browserToken` must be
125
+ * configured in `defineLive()` for draft events to be included.
126
+ *
127
+ * @defaultValue `false`
86
128
  */
87
129
  includeDrafts?: boolean;
88
130
  /**
89
- * TODO: docs
131
+ * Server action called for each content-change message from the Live Content
132
+ * API.
133
+ *
134
+ * The default action revalidates the cache tags produced by `sanityFetch`.
90
135
  */
91
136
  action?: SanityLiveAction;
92
137
  /**
93
- * TODO: docs
138
+ * Custom error handler. Pass `false` to disable custom handling and throw
139
+ * errors to the nearest React error boundary.
94
140
  */
95
141
  onError?: SanityLiveOnError | false;
96
142
  /**
97
- * TODO: docs
143
+ * Custom handler for the `welcome` event. Pass `false` to disable the default
144
+ * connection log.
98
145
  */
99
146
  onWelcome?: SanityLiveOnWelcome | false;
100
147
  /**
101
- * TODO: docs
148
+ * Custom handler for the `reconnect` event. Pass `false` to disable the
149
+ * default refresh behavior.
102
150
  */
103
151
  onReconnect?: SanityLiveOnReconnect | false;
104
152
  /**
105
- * TODO: docs
153
+ * Custom handler for the `restart` event. Pass `false` to disable the default
154
+ * refresh behavior.
106
155
  */
107
156
  onRestart?: SanityLiveOnRestart | false;
108
157
  /**
109
- *
158
+ * Custom handler for the `goaway` event. Pass `false` to disable the default
159
+ * long-polling fallback.
110
160
  */
111
161
  onGoAway?: SanityLiveOnGoaway | false;
112
162
  /**
113
- * Automatic refresh of RSC when the component <SanityLive /> is mounted.
163
+ * Refresh Server Components once when `<SanityLive />` mounts.
164
+ *
165
+ * This can close the gap between the initial server render and the browser
166
+ * establishing the live EventSource connection.
167
+ *
114
168
  * @defaultValue `false`
115
169
  */
116
170
  refreshOnMount?: boolean;
117
171
  /**
118
- * Automatically refresh when window gets focused
172
+ * Refresh Server Components when the page becomes visible or the window
173
+ * regains focus.
174
+ *
119
175
  * @defaultValue `false`
120
176
  */
121
177
  refreshOnFocus?: boolean;
122
178
  /**
123
- * Automatically refresh when the browser regains a network connection (via navigator.onLine)
124
- * @defaultValue `false`
179
+ * Refresh Server Components when the browser regains a network connection.
125
180
  */
126
181
  refreshOnReconnect?: boolean;
127
182
  /**
128
- * This request tag is used to identify the request when viewing request logs from your Sanity Content Lake.
183
+ * Request tag used to identify the live EventSource request in Sanity Content
184
+ * Lake logs.
185
+ *
129
186
  * @see https://www.sanity.io/docs/reference-api-request-tags
130
- * @defaultValue 'next-loader.live'|'next-loader.live.cache-components'
187
+ * @defaultValue `'next-loader.live'` or `'next-loader.live.cache-components'`
131
188
  */
132
189
  requestTag?: string;
133
190
  }
134
191
  interface DefineLiveOptions {
135
192
  /**
136
- * Required for `fetch()` and `<Live>` to work
193
+ * Sanity client used by `sanityFetch()` and `<SanityLive />`.
137
194
  */
138
195
  client: SanityClient;
139
196
  /**
140
- * Optional. If provided then the token needs to have permissions to query documents with `drafts.` prefixes in order for `perspective: 'drafts'` to work.
141
- * This token is never shared with the browser, unless you reuse it in `browserToken`..
197
+ * Token used by the server to query drafts and content release versions.
198
+ *
199
+ * This token is never shared with the browser unless you also pass it as
200
+ * `browserToken`.
142
201
  */
143
202
  serverToken?: string | false;
144
203
  /**
145
- * Optional. This token is shared with the browser when `<Live>` is given a `perspective` prop other than `"published"`, and should only have access to query published documents.
146
- * It is used to setup a `Live Draft Content` EventSource connection, and enables live previewing drafts stand-alone, outside of Presentation Tool.
204
+ * Token shared with the browser when `<SanityLive includeDrafts />` opens a
205
+ * draft-capable live connection.
206
+ *
207
+ * Use a browser-safe token with the minimum read permissions needed for live
208
+ * previewing drafts outside Presentation Tool.
147
209
  */
148
210
  browserToken?: string | false;
149
211
  /**
150
- * Optional. Include stega encoding when draft mode is enabled.
151
- * @deprecated This option is deprecated, as it does not have an effect when `cacheComponents: true`
152
- * @defaultValue `true`
212
+ * Include stega encoding automatically when draft mode is enabled.
213
+ *
214
+ * @deprecated This option does not affect the `next-js` export condition used
215
+ * with `cacheComponents: true`. Pass `stega` to `sanityFetch()` instead.
216
+ * @defaultValue `true`
153
217
  */
154
218
  stega?: boolean;
155
219
  /**
156
- * When `true`, requires explicit `includeDrafts` on `<SanityLive>` and explicit `perspective`/`stega` on `sanityFetch`.
157
- * Use this to prepare for migrating to `cacheComponents: true` while still using `cacheComponents: false`.
220
+ * Require explicit live-content options at every call site.
221
+ *
222
+ * When `true`, `includeDrafts` is required on `<SanityLive />` and
223
+ * `perspective`/`stega` are required on `sanityFetch()`. This matches the
224
+ * explicit data flow needed inside Cache Components, where `draftMode()` and
225
+ * `cookies()` must be resolved outside `'use cache'` boundaries.
226
+ *
158
227
  * @defaultValue `false`
159
228
  */
160
229
  strict?: boolean;
@@ -182,5 +251,5 @@ type StrictDefinedFetchType = <const QueryString extends string>(options: {
182
251
  sourceMap: ContentSourceMap | null;
183
252
  tags: string[];
184
253
  }>;
185
- export { SanityLiveAction as a, SanityLiveOnReconnect as c, StrictDefinedFetchType as d, StrictDefinedLiveProps as f, LivePerspective as i, SanityLiveOnRestart as l, DefinedFetchType as n, SanityLiveOnError as o, DefinedLiveProps as r, SanityLiveOnGoaway as s, DefineLiveOptions as t, SanityLiveOnWelcome as u };
254
+ export { SanityLiveAction as a, SanityLiveOnGoaway as c, SanityLiveOnWelcome as d, StrictDefinedFetchType as f, LivePerspective as i, SanityLiveOnReconnect as l, DefinedFetchType as n, SanityLiveActionContext as o, StrictDefinedLiveProps as p, DefinedLiveProps as r, SanityLiveOnError as s, DefineLiveOptions as t, SanityLiveOnRestart as u };
186
255
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","names":[],"sources":["../src/live/shared/types.ts"],"mappings":";;AAcA;;;KAAY,eAAA,GAAkB,OAAA,CAAQ,iBAAA;;AAKtC;;KAAY,gBAAA,sCAAsD,OAAA;EAChE,KAAA,EAAO,WAAA;EACP,MAAA,GAAS,WAAA,GAAc,OAAA,CAAQ,WAAA;;;;EAI/B,WAAA,GAAc,eAAA;;;;;EAKd,KAAA;;;;;EAKA,IAAA;;;;;;EAMA,UAAA;AAAA,MACI,OAAA;EACJ,IAAA,EAAM,YAAA,CAAa,WAAA;EACnB,SAAA,EAAW,gBAAA;EACX,IAAA;AAAA;;;;UAMe,uBAAA;EACf,aAAA;AAAA;AADF;;;;AAAA,KAQY,gBAAA,IAAoB,UAAA,cAAwB,OAAA;AAAxD;;;;;AAAA,KAMY,iBAAA,IACV,KAAA,WACA,OAAA,EAAS,uBAAA,YACC,OAAA;;;;;KAKA,mBAA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EAKZ,WAAA,GAAc,qBAAA;;;;;EAKd,SAAA,GAAY,mBAAA;;;;;EAKZ,QAAA,GAAW,kBAAA;;;AAiCb;;;;;;EAvBE,cAAA;;;;;;AAoEF;EA7DE,cAAA;;;;EAIA,kBAAA;;;;AAiEF;;;;EAxDE,UAAA;AAAA;AAAA,UAGe,iBAAA;;;;EAIf,MAAA,EAAQ,YAAA;;;;;;;EAOR,WAAA;;;;;;;;EAQA,YAAA;;;;;;;;EAQA,KAAA;;;;;;;;;;;EAWA,MAAA;AAAA;;;;;UAOe,sBAAA,SAA+B,IAAA,CAAK,gBAAA;EACnD,aAAA;AAAA;;;;;KAOU,sBAAA,sCAA4D,OAAA;EACtE,KAAA,EAAO,WAAA;EACP,MAAA,GAAS,WAAA,GAAc,OAAA,CAAQ,WAAA;EAC/B,WAAA,EAAa,eAAA;EACb,KAAA;EACA,IAAA;EACA,UAAA;AAAA,MACI,OAAA;EACJ,IAAA,EAAM,YAAA,CAAa,WAAA;EACnB,SAAA,EAAW,gBAAA;EACX,IAAA;AAAA"}
@@ -1,6 +1,6 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import { VisualEditing as VisualEditing$1 } from "next-sanity/visual-editing/client-component";
3
- import { actionPerspectiveChange } from "next-sanity/visual-editing/server-actions";
3
+ import { perspectiveChangeAction } from "next-sanity/visual-editing/server-actions";
4
4
  /**
5
5
  * @public
6
6
  */
@@ -20,7 +20,7 @@ function VisualEditing(props) {
20
20
  console.error("Failed detecting trailingSlash", err);
21
21
  }
22
22
  return /* @__PURE__ */ jsx(VisualEditing$1, {
23
- onPerspectiveChange: actionPerspectiveChange,
23
+ onPerspectiveChange: perspectiveChangeAction,
24
24
  ...props,
25
25
  basePath: props.basePath ?? autoBasePath,
26
26
  trailingSlash: props.trailingSlash ?? autoTrailingSlash
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["VisualEditingComponent"],"sources":["../../src/visual-editing/VisualEditing.tsx"],"sourcesContent":["import type {VisualEditingProps} from 'next-sanity/visual-editing/client-component'\nimport {VisualEditing as VisualEditingComponent} from 'next-sanity/visual-editing/client-component'\nimport {actionPerspectiveChange} from 'next-sanity/visual-editing/server-actions'\n\n/**\n * @public\n */\nexport function VisualEditing(props: VisualEditingProps): React.ReactElement {\n let autoBasePath: string | undefined\n if (typeof props.basePath !== 'string') {\n try {\n autoBasePath = process.env['__NEXT_ROUTER_BASEPATH']\n if (autoBasePath) {\n // oxlint-disable-next-line no-console\n console.log(\n `Detected next basePath as ${JSON.stringify(autoBasePath)} by reading \"process.env.__NEXT_ROUTER_BASEPATH\". If this is incorrect then you can set it manually with the basePath prop on the <VisualEditing /> component.`,\n )\n }\n } catch (err) {\n console.error('Failed detecting basePath', err)\n }\n }\n let autoTrailingSlash: boolean | undefined\n if (typeof props.trailingSlash !== 'boolean') {\n try {\n autoTrailingSlash = Boolean(process.env['__NEXT_TRAILING_SLASH'])\n if (autoTrailingSlash) {\n // oxlint-disable-next-line no-console\n console.log(\n `Detected next trailingSlash as ${JSON.stringify(autoTrailingSlash)} by reading \"process.env.__NEXT_TRAILING_SLASH\". If this is incorrect then you can set it manually with the trailingSlash prop on the <VisualEditing /> component.`,\n )\n }\n } catch (err) {\n console.error('Failed detecting trailingSlash', err)\n }\n }\n return (\n <VisualEditingComponent\n onPerspectiveChange={actionPerspectiveChange}\n {...props}\n basePath={props.basePath ?? autoBasePath}\n trailingSlash={props.trailingSlash ?? autoTrailingSlash}\n />\n )\n}\n\nexport type {VisualEditingProps} from 'next-sanity/visual-editing/client-component'\n"],"mappings":";;;;;;AAOA,SAAgB,cAAc,OAA+C;CAC3E,IAAI;AACJ,KAAI,OAAO,MAAM,aAAa,SAC5B,KAAI;AACF,iBAAe,QAAQ,IAAI;AAC3B,MAAI,aAEF,SAAQ,IACN,6BAA6B,KAAK,UAAU,aAAa,CAAC,gKAC3D;UAEI,KAAK;AACZ,UAAQ,MAAM,6BAA6B,IAAI;;CAGnD,IAAI;AACJ,KAAI,OAAO,MAAM,kBAAkB,UACjC,KAAI;AACF,sBAAoB,QAAQ,QAAQ,IAAI,yBAAyB;AACjE,MAAI,kBAEF,SAAQ,IACN,kCAAkC,KAAK,UAAU,kBAAkB,CAAC,oKACrE;UAEI,KAAK;AACZ,UAAQ,MAAM,kCAAkC,IAAI;;AAGxD,QACE,oBAACA,iBAAD;EACE,qBAAqB;EACrB,GAAI;EACJ,UAAU,MAAM,YAAY;EAC5B,eAAe,MAAM,iBAAiB;EACtC,CAAA"}
1
+ {"version":3,"file":"index.js","names":["VisualEditingComponent"],"sources":["../../src/visual-editing/VisualEditing.tsx"],"sourcesContent":["import type {VisualEditingProps} from 'next-sanity/visual-editing/client-component'\nimport {VisualEditing as VisualEditingComponent} from 'next-sanity/visual-editing/client-component'\nimport {perspectiveChangeAction} from 'next-sanity/visual-editing/server-actions'\n\n/**\n * @public\n */\nexport function VisualEditing(props: VisualEditingProps): React.ReactElement {\n let autoBasePath: string | undefined\n if (typeof props.basePath !== 'string') {\n try {\n autoBasePath = process.env['__NEXT_ROUTER_BASEPATH']\n if (autoBasePath) {\n // oxlint-disable-next-line no-console\n console.log(\n `Detected next basePath as ${JSON.stringify(autoBasePath)} by reading \"process.env.__NEXT_ROUTER_BASEPATH\". If this is incorrect then you can set it manually with the basePath prop on the <VisualEditing /> component.`,\n )\n }\n } catch (err) {\n console.error('Failed detecting basePath', err)\n }\n }\n let autoTrailingSlash: boolean | undefined\n if (typeof props.trailingSlash !== 'boolean') {\n try {\n autoTrailingSlash = Boolean(process.env['__NEXT_TRAILING_SLASH'])\n if (autoTrailingSlash) {\n // oxlint-disable-next-line no-console\n console.log(\n `Detected next trailingSlash as ${JSON.stringify(autoTrailingSlash)} by reading \"process.env.__NEXT_TRAILING_SLASH\". If this is incorrect then you can set it manually with the trailingSlash prop on the <VisualEditing /> component.`,\n )\n }\n } catch (err) {\n console.error('Failed detecting trailingSlash', err)\n }\n }\n return (\n <VisualEditingComponent\n onPerspectiveChange={perspectiveChangeAction}\n {...props}\n basePath={props.basePath ?? autoBasePath}\n trailingSlash={props.trailingSlash ?? autoTrailingSlash}\n />\n )\n}\n\nexport type {VisualEditingProps} from 'next-sanity/visual-editing/client-component'\n"],"mappings":";;;;;;AAOA,SAAgB,cAAc,OAA+C;CAC3E,IAAI;AACJ,KAAI,OAAO,MAAM,aAAa,SAC5B,KAAI;AACF,iBAAe,QAAQ,IAAI;AAC3B,MAAI,aAEF,SAAQ,IACN,6BAA6B,KAAK,UAAU,aAAa,CAAC,gKAC3D;UAEI,KAAK;AACZ,UAAQ,MAAM,6BAA6B,IAAI;;CAGnD,IAAI;AACJ,KAAI,OAAO,MAAM,kBAAkB,UACjC,KAAI;AACF,sBAAoB,QAAQ,QAAQ,IAAI,yBAAyB;AACjE,MAAI,kBAEF,SAAQ,IACN,kCAAkC,KAAK,UAAU,kBAAkB,CAAC,oKACrE;UAEI,KAAK;AACZ,UAAQ,MAAM,kCAAkC,IAAI;;AAGxD,QACE,oBAACA,iBAAD;EACE,qBAAqB;EACrB,GAAI;EACJ,UAAU,MAAM,YAAY;EAC5B,eAAe,MAAM,iBAAiB;EACtC,CAAA"}
@@ -2,6 +2,6 @@ import { ClientPerspective } from "@sanity/client";
2
2
  /**
3
3
  * @internal CAUTION: this is an internal action and does not follow semver. Using it directly is at your own risk.
4
4
  */
5
- declare function actionPerspectiveChange(perspective: ClientPerspective): Promise<void>;
6
- export { actionPerspectiveChange };
5
+ declare function perspectiveChangeAction(perspective: ClientPerspective): Promise<void>;
6
+ export { perspectiveChangeAction };
7
7
  //# sourceMappingURL=index.d.ts.map
@@ -6,13 +6,13 @@ import { refresh } from "next/cache";
6
6
  /**
7
7
  * @internal CAUTION: this is an internal action and does not follow semver. Using it directly is at your own risk.
8
8
  */
9
- async function actionPerspectiveChange(perspective) {
9
+ async function perspectiveChangeAction(perspective) {
10
10
  const sanitizedPerspective = sanitizePerspective(perspective, "drafts");
11
11
  if (!sanitizedPerspective || Array.isArray(sanitizedPerspective) && sanitizedPerspective.length === 0) throw new Error(`Invalid perspective`, { cause: perspective });
12
12
  const nextPerspective = Array.isArray(sanitizedPerspective) ? sanitizedPerspective.join(",") : sanitizedPerspective;
13
13
  const jar = await cookies();
14
14
  if (nextPerspective === jar.get(perspectiveCookieName)?.value && process.env.NODE_ENV !== "production") {
15
- console.debug("actionPerspectiveChange", "Perspective is the same, skipping", nextPerspective);
15
+ console.debug("perspectiveChangeAction", "Perspective is the same, skipping", nextPerspective);
16
16
  return;
17
17
  }
18
18
  jar.set(perspectiveCookieName, nextPerspective, {
@@ -23,6 +23,6 @@ async function actionPerspectiveChange(perspective) {
23
23
  });
24
24
  refresh();
25
25
  }
26
- export { actionPerspectiveChange };
26
+ export { perspectiveChangeAction };
27
27
 
28
28
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../src/visual-editing/server-actions/index.ts"],"sourcesContent":["'use server'\n\nimport type {ClientPerspective} from '@sanity/client'\nimport {perspectiveCookieName} from '@sanity/preview-url-secret/constants'\nimport {refresh} from 'next/cache'\nimport {cookies} from 'next/headers'\n\nimport {sanitizePerspective} from '#live/sanitizePerspective'\n\n/**\n * @internal CAUTION: this is an internal action and does not follow semver. Using it directly is at your own risk.\n */\nexport async function actionPerspectiveChange(perspective: ClientPerspective): Promise<void> {\n const sanitizedPerspective = sanitizePerspective(perspective, 'drafts')\n if (\n !sanitizedPerspective ||\n (Array.isArray(sanitizedPerspective) && sanitizedPerspective.length === 0)\n ) {\n throw new Error(`Invalid perspective`, {cause: perspective})\n }\n\n const nextPerspective = Array.isArray(sanitizedPerspective)\n ? sanitizedPerspective.join(',')\n : sanitizedPerspective\n const jar = await cookies()\n if (\n nextPerspective === jar.get(perspectiveCookieName)?.value &&\n process.env.NODE_ENV !== 'production'\n ) {\n // oxlint-disable-next-line no-console\n console.debug('actionPerspectiveChange', 'Perspective is the same, skipping', nextPerspective)\n return\n }\n jar.set(perspectiveCookieName, nextPerspective, {\n httpOnly: true,\n path: '/',\n secure: true,\n sameSite: 'none',\n })\n\n refresh()\n}\n"],"mappings":";;;;;;;;AAYA,eAAsB,wBAAwB,aAA+C;CAC3F,MAAM,uBAAuB,oBAAoB,aAAa,SAAS;AACvE,KACE,CAAC,wBACA,MAAM,QAAQ,qBAAqB,IAAI,qBAAqB,WAAW,EAExE,OAAM,IAAI,MAAM,uBAAuB,EAAC,OAAO,aAAY,CAAC;CAG9D,MAAM,kBAAkB,MAAM,QAAQ,qBAAqB,GACvD,qBAAqB,KAAK,IAAI,GAC9B;CACJ,MAAM,MAAM,MAAM,SAAS;AAC3B,KACE,oBAAoB,IAAI,IAAI,sBAAsB,EAAE,SACpD,QAAQ,IAAI,aAAa,cACzB;AAEA,UAAQ,MAAM,2BAA2B,qCAAqC,gBAAgB;AAC9F;;AAEF,KAAI,IAAI,uBAAuB,iBAAiB;EAC9C,UAAU;EACV,MAAM;EACN,QAAQ;EACR,UAAU;EACX,CAAC;AAEF,UAAS"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../src/visual-editing/server-actions/index.ts"],"sourcesContent":["'use server'\n\nimport type {ClientPerspective} from '@sanity/client'\nimport {perspectiveCookieName} from '@sanity/preview-url-secret/constants'\nimport {refresh} from 'next/cache'\nimport {cookies} from 'next/headers'\n\nimport {sanitizePerspective} from '#live/sanitizePerspective'\n\n/**\n * @internal CAUTION: this is an internal action and does not follow semver. Using it directly is at your own risk.\n */\nexport async function perspectiveChangeAction(perspective: ClientPerspective): Promise<void> {\n const sanitizedPerspective = sanitizePerspective(perspective, 'drafts')\n if (\n !sanitizedPerspective ||\n (Array.isArray(sanitizedPerspective) && sanitizedPerspective.length === 0)\n ) {\n throw new Error(`Invalid perspective`, {cause: perspective})\n }\n\n const nextPerspective = Array.isArray(sanitizedPerspective)\n ? sanitizedPerspective.join(',')\n : sanitizedPerspective\n const jar = await cookies()\n if (\n nextPerspective === jar.get(perspectiveCookieName)?.value &&\n process.env.NODE_ENV !== 'production'\n ) {\n // oxlint-disable-next-line no-console\n console.debug('perspectiveChangeAction', 'Perspective is the same, skipping', nextPerspective)\n return\n }\n jar.set(perspectiveCookieName, nextPerspective, {\n httpOnly: true,\n path: '/',\n secure: true,\n sameSite: 'none',\n })\n\n refresh()\n}\n"],"mappings":";;;;;;;;AAYA,eAAsB,wBAAwB,aAA+C;CAC3F,MAAM,uBAAuB,oBAAoB,aAAa,SAAS;AACvE,KACE,CAAC,wBACA,MAAM,QAAQ,qBAAqB,IAAI,qBAAqB,WAAW,EAExE,OAAM,IAAI,MAAM,uBAAuB,EAAC,OAAO,aAAY,CAAC;CAG9D,MAAM,kBAAkB,MAAM,QAAQ,qBAAqB,GACvD,qBAAqB,KAAK,IAAI,GAC9B;CACJ,MAAM,MAAM,MAAM,SAAS;AAC3B,KACE,oBAAoB,IAAI,IAAI,sBAAsB,EAAE,SACpD,QAAQ,IAAI,aAAa,cACzB;AAEA,UAAQ,MAAM,2BAA2B,qCAAqC,gBAAgB;AAC9F;;AAEF,KAAI,IAAI,uBAAuB,iBAAiB;EAC9C,UAAU;EACV,MAAM;EACN,QAAQ;EACR,UAAU;EACX,CAAC;AAEF,UAAS"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-sanity",
3
- "version": "13.0.0-cache-components.41",
3
+ "version": "13.0.0-cache-components.43",
4
4
  "description": "Sanity.io toolkit for Next.js",
5
5
  "keywords": [
6
6
  "live",
@@ -48,10 +48,7 @@
48
48
  },
49
49
  "./live/cache-life": "./dist/live/cache-life.js",
50
50
  "./live/client-components": "./dist/live/client-components/index.js",
51
- "./live/server-actions": {
52
- "next-js": "./dist/live/server-actions/index.next-js.js",
53
- "default": "./dist/live/server-actions/index.default.js"
54
- },
51
+ "./live/server-actions": "./dist/live/server-actions/index.js",
55
52
  "./studio": "./dist/studio/index.js",
56
53
  "./studio/client-component": "./dist/studio/client-component/index.js",
57
54
  "./visual-editing": "./dist/visual-editing/index.js",
@@ -1,10 +0,0 @@
1
- /**
2
- * Used by `<SanityLive action={actionRevalidateTags} />`
3
- */
4
- declare function actionUpdateTags(unsafeTags: unknown): Promise<void>;
5
- /**
6
- * Used by `<SanityLive onReconnect={actionRefresh} onRestart={actionRefresh} />`
7
- */
8
- declare function actionRefresh(): Promise<void>;
9
- export { actionRefresh, actionUpdateTags };
10
- //# sourceMappingURL=index.default.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.default.d.ts","names":[],"sources":["../../../src/live/server-actions/index.default.ts"],"mappings":"AAUA;;;AAAA,iBAAsB,gBAAA,CAAiB,UAAA,YAAsB,OAAA;;AAuB7D;;iBAAsB,aAAA,CAAA,GAAiB,OAAA"}
@@ -1,27 +0,0 @@
1
- "use server";
2
- import { t as parseTags } from "../../parseTags.js";
3
- import { draftMode } from "next/headers";
4
- import { refresh, revalidateTag, updateTag } from "next/cache";
5
- /**
6
- * Used by `<SanityLive action={actionRevalidateTags} />`
7
- */
8
- async function actionUpdateTags(unsafeTags) {
9
- const { tags, prefixType } = parseTags(unsafeTags);
10
- if ((await draftMode()).isEnabled) {
11
- console.warn(`<SanityLive ${prefixType === "drafts" ? "includeDrafts " : ""}/> action called in draft mode, cache is bypassed in draft mode so the refresh() function is called instead of updateTag()`, { tags });
12
- refresh();
13
- return;
14
- }
15
- for (const tag of tags) updateTag(tag);
16
- revalidateTag("sanity:fetch-sync-tags", "max");
17
- console.log(`<SanityLive ${prefixType === "drafts" ? "includeDrafts " : ""}/> updated tags: ${tags.join(", ")} and revalidated tag: "sanity:fetch-sync-tags" with cache profile "max"`);
18
- }
19
- /**
20
- * Used by `<SanityLive onReconnect={actionRefresh} onRestart={actionRefresh} />`
21
- */
22
- async function actionRefresh() {
23
- refresh();
24
- }
25
- export { actionRefresh, actionUpdateTags };
26
-
27
- //# sourceMappingURL=index.default.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.default.js","names":[],"sources":["../../../src/live/server-actions/index.default.ts"],"sourcesContent":["'use server'\n\nimport {refresh, revalidateTag, updateTag} from 'next/cache'\nimport {draftMode} from 'next/headers'\n\nimport {parseTags} from '#live/parseTags'\n\n/**\n * Used by `<SanityLive action={actionRevalidateTags} />`\n */\nexport async function actionUpdateTags(unsafeTags: unknown): Promise<void> {\n const {tags, prefixType} = parseTags(unsafeTags)\n if ((await draftMode()).isEnabled) {\n console.warn(\n `<SanityLive ${prefixType === 'drafts' ? 'includeDrafts ' : ''}/> action called in draft mode, cache is bypassed in draft mode so the refresh() function is called instead of updateTag()`,\n {tags},\n )\n refresh()\n return undefined\n }\n for (const tag of tags) {\n updateTag(tag)\n }\n revalidateTag('sanity:fetch-sync-tags', 'max')\n // oxlint-disable-next-line no-console\n console.log(\n `<SanityLive ${prefixType === 'drafts' ? 'includeDrafts ' : ''}/> updated tags: ${tags.join(', ')} and revalidated tag: \"sanity:fetch-sync-tags\" with cache profile \"max\"`,\n )\n}\n\n/**\n * Used by `<SanityLive onReconnect={actionRefresh} onRestart={actionRefresh} />`\n */\nexport async function actionRefresh(): Promise<void> {\n refresh()\n}\n"],"mappings":";;;;;;;AAUA,eAAsB,iBAAiB,YAAoC;CACzE,MAAM,EAAC,MAAM,eAAc,UAAU,WAAW;AAChD,MAAK,MAAM,WAAW,EAAE,WAAW;AACjC,UAAQ,KACN,eAAe,eAAe,WAAW,mBAAmB,GAAG,6HAC/D,EAAC,MAAK,CACP;AACD,WAAS;AACT;;AAEF,MAAK,MAAM,OAAO,KAChB,WAAU,IAAI;AAEhB,eAAc,0BAA0B,MAAM;AAE9C,SAAQ,IACN,eAAe,eAAe,WAAW,mBAAmB,GAAG,mBAAmB,KAAK,KAAK,KAAK,CAAC,yEACnG;;;;;AAMH,eAAsB,gBAA+B;AACnD,UAAS"}
@@ -1,10 +0,0 @@
1
- /**
2
- * Used by `<SanityLive action={actionRevalidateTags} />`
3
- */
4
- declare function actionUpdateTags(unsafeTags: unknown): Promise<void>;
5
- /**
6
- * Used by `<SanityLive onReconnect={actionRefresh} onRestart={actionRefresh} />`
7
- */
8
- declare function actionRefresh(): Promise<void>;
9
- export { actionRefresh, actionUpdateTags };
10
- //# sourceMappingURL=index.next-js.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.next-js.d.ts","names":[],"sources":["../../../src/live/server-actions/index.next-js.ts"],"mappings":"AAUA;;;AAAA,iBAAsB,gBAAA,CAAiB,UAAA,YAAsB,OAAA;;AAsB7D;;iBAAsB,aAAA,CAAA,GAAiB,OAAA"}
@@ -1,26 +0,0 @@
1
- "use server";
2
- import { t as parseTags } from "../../parseTags.js";
3
- import { draftMode } from "next/headers";
4
- import { refresh, updateTag } from "next/cache";
5
- /**
6
- * Used by `<SanityLive action={actionRevalidateTags} />`
7
- */
8
- async function actionUpdateTags(unsafeTags) {
9
- const { tags, prefixType } = parseTags(unsafeTags);
10
- if ((await draftMode()).isEnabled) {
11
- console.warn(`<SanityLive ${prefixType === "drafts" ? "includeDrafts " : ""}/> action called in draft mode, cache is bypassed in draft mode so the refresh() function is called instead of updateTag()`, { tags });
12
- refresh();
13
- return;
14
- }
15
- for (const tag of tags) updateTag(tag);
16
- console.log(`<SanityLive ${prefixType === "drafts" ? "includeDrafts " : ""}/> updated tags: ${tags.join(", ")}`);
17
- }
18
- /**
19
- * Used by `<SanityLive onReconnect={actionRefresh} onRestart={actionRefresh} />`
20
- */
21
- async function actionRefresh() {
22
- refresh();
23
- }
24
- export { actionRefresh, actionUpdateTags };
25
-
26
- //# sourceMappingURL=index.next-js.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.next-js.js","names":[],"sources":["../../../src/live/server-actions/index.next-js.ts"],"sourcesContent":["'use server'\n\nimport {refresh, updateTag} from 'next/cache'\nimport {draftMode} from 'next/headers'\n\nimport {parseTags} from '#live/parseTags'\n\n/**\n * Used by `<SanityLive action={actionRevalidateTags} />`\n */\nexport async function actionUpdateTags(unsafeTags: unknown): Promise<void> {\n const {tags, prefixType} = parseTags(unsafeTags)\n if ((await draftMode()).isEnabled) {\n console.warn(\n `<SanityLive ${prefixType === 'drafts' ? 'includeDrafts ' : ''}/> action called in draft mode, cache is bypassed in draft mode so the refresh() function is called instead of updateTag()`,\n {tags},\n )\n refresh()\n return undefined\n }\n for (const tag of tags) {\n updateTag(tag)\n }\n // oxlint-disable-next-line no-console\n console.log(\n `<SanityLive ${prefixType === 'drafts' ? 'includeDrafts ' : ''}/> updated tags: ${tags.join(', ')}`,\n )\n}\n\n/**\n * Used by `<SanityLive onReconnect={actionRefresh} onRestart={actionRefresh} />`\n */\nexport async function actionRefresh(): Promise<void> {\n refresh()\n}\n"],"mappings":";;;;;;;AAUA,eAAsB,iBAAiB,YAAoC;CACzE,MAAM,EAAC,MAAM,eAAc,UAAU,WAAW;AAChD,MAAK,MAAM,WAAW,EAAE,WAAW;AACjC,UAAQ,KACN,eAAe,eAAe,WAAW,mBAAmB,GAAG,6HAC/D,EAAC,MAAK,CACP;AACD,WAAS;AACT;;AAEF,MAAK,MAAM,OAAO,KAChB,WAAU,IAAI;AAGhB,SAAQ,IACN,eAAe,eAAe,WAAW,mBAAmB,GAAG,mBAAmB,KAAK,KAAK,KAAK,GAClG;;;;;AAMH,eAAsB,gBAA+B;AACnD,UAAS"}