@sanity/sdk-react 0.0.0-alpha.2 → 0.0.0-alpha.21

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 (116) hide show
  1. package/README.md +38 -67
  2. package/dist/index.d.ts +4811 -2
  3. package/dist/index.js +1069 -2
  4. package/dist/index.js.map +1 -1
  5. package/package.json +27 -58
  6. package/src/_exports/index.ts +66 -10
  7. package/src/components/Login/LoginLinks.test.tsx +4 -14
  8. package/src/components/Login/LoginLinks.tsx +16 -31
  9. package/src/components/SDKProvider.test.tsx +79 -0
  10. package/src/components/SDKProvider.tsx +42 -0
  11. package/src/components/SanityApp.test.tsx +156 -0
  12. package/src/components/SanityApp.tsx +90 -0
  13. package/src/components/auth/AuthBoundary.test.tsx +6 -19
  14. package/src/components/auth/AuthBoundary.tsx +20 -4
  15. package/src/components/auth/Login.test.tsx +2 -16
  16. package/src/components/auth/Login.tsx +11 -30
  17. package/src/components/auth/LoginCallback.test.tsx +5 -20
  18. package/src/components/auth/LoginCallback.tsx +9 -14
  19. package/src/components/auth/LoginError.test.tsx +2 -17
  20. package/src/components/auth/LoginError.tsx +11 -16
  21. package/src/components/auth/LoginFooter.test.tsx +2 -16
  22. package/src/components/auth/LoginFooter.tsx +8 -24
  23. package/src/components/auth/LoginLayout.test.tsx +2 -16
  24. package/src/components/auth/LoginLayout.tsx +8 -38
  25. package/src/components/auth/authTestHelpers.tsx +11 -0
  26. package/src/components/utils.ts +22 -0
  27. package/src/context/SanityInstanceContext.ts +4 -0
  28. package/src/{components/context → context}/SanityProvider.test.tsx +2 -2
  29. package/src/context/SanityProvider.tsx +50 -0
  30. package/src/hooks/_synchronous-groq-js.mjs +4 -0
  31. package/src/hooks/auth/useAuthState.tsx +4 -5
  32. package/src/hooks/auth/useAuthToken.tsx +1 -1
  33. package/src/hooks/auth/useCurrentUser.tsx +28 -4
  34. package/src/hooks/auth/useDashboardOrganizationId.test.tsx +42 -0
  35. package/src/hooks/auth/useDashboardOrganizationId.tsx +29 -0
  36. package/src/hooks/auth/useHandleAuthCallback.test.tsx +16 -0
  37. package/src/hooks/auth/{useHandleCallback.tsx → useHandleAuthCallback.tsx} +7 -6
  38. package/src/hooks/auth/useLogOut.test.tsx +2 -2
  39. package/src/hooks/auth/useLogOut.tsx +1 -1
  40. package/src/hooks/auth/useLoginUrls.tsx +1 -0
  41. package/src/hooks/client/useClient.ts +9 -30
  42. package/src/hooks/comlink/useFrameConnection.test.tsx +167 -0
  43. package/src/hooks/comlink/useFrameConnection.ts +107 -0
  44. package/src/hooks/comlink/useManageFavorite.test.ts +111 -0
  45. package/src/hooks/comlink/useManageFavorite.ts +130 -0
  46. package/src/hooks/comlink/useRecordDocumentHistoryEvent.test.ts +81 -0
  47. package/src/hooks/comlink/useRecordDocumentHistoryEvent.ts +106 -0
  48. package/src/hooks/comlink/useWindowConnection.test.ts +135 -0
  49. package/src/hooks/comlink/useWindowConnection.ts +122 -0
  50. package/src/hooks/context/useSanityInstance.test.tsx +2 -2
  51. package/src/hooks/context/useSanityInstance.ts +24 -8
  52. package/src/hooks/dashboard/useNavigateToStudioDocument.test.ts +178 -0
  53. package/src/hooks/dashboard/useNavigateToStudioDocument.ts +123 -0
  54. package/src/hooks/dashboard/useStudioWorkspacesByResourceId.test.tsx +278 -0
  55. package/src/hooks/dashboard/useStudioWorkspacesByResourceId.ts +92 -0
  56. package/src/hooks/datasets/useDatasets.ts +40 -0
  57. package/src/hooks/document/useApplyDocumentActions.test.ts +25 -0
  58. package/src/hooks/document/useApplyDocumentActions.ts +75 -0
  59. package/src/hooks/document/useDocument.test.ts +81 -0
  60. package/src/hooks/document/useDocument.ts +107 -0
  61. package/src/hooks/document/useDocumentEvent.test.ts +63 -0
  62. package/src/hooks/document/useDocumentEvent.ts +54 -0
  63. package/src/hooks/document/useDocumentPermissions.ts +84 -0
  64. package/src/hooks/document/useDocumentSyncStatus.test.ts +16 -0
  65. package/src/hooks/document/useDocumentSyncStatus.ts +33 -0
  66. package/src/hooks/document/useEditDocument.test.ts +179 -0
  67. package/src/hooks/document/useEditDocument.ts +195 -0
  68. package/src/hooks/documents/useDocuments.test.tsx +152 -0
  69. package/src/hooks/documents/useDocuments.ts +174 -0
  70. package/src/hooks/helpers/createCallbackHook.tsx +3 -2
  71. package/src/hooks/helpers/createStateSourceHook.test.tsx +66 -0
  72. package/src/hooks/helpers/createStateSourceHook.tsx +29 -10
  73. package/src/hooks/paginatedDocuments/usePaginatedDocuments.test.tsx +259 -0
  74. package/src/hooks/paginatedDocuments/usePaginatedDocuments.ts +290 -0
  75. package/src/hooks/preview/usePreview.test.tsx +19 -10
  76. package/src/hooks/preview/usePreview.tsx +67 -13
  77. package/src/hooks/projection/useProjection.test.tsx +218 -0
  78. package/src/hooks/projection/useProjection.ts +147 -0
  79. package/src/hooks/projects/useProject.ts +48 -0
  80. package/src/hooks/projects/useProjects.ts +45 -0
  81. package/src/hooks/query/useQuery.test.tsx +188 -0
  82. package/src/hooks/query/useQuery.ts +103 -0
  83. package/src/hooks/users/useUsers.test.ts +163 -0
  84. package/src/hooks/users/useUsers.ts +107 -0
  85. package/src/utils/getEnv.ts +21 -0
  86. package/src/version.ts +8 -0
  87. package/src/vite-env.d.ts +10 -0
  88. package/dist/_chunks-es/useLogOut.js +0 -44
  89. package/dist/_chunks-es/useLogOut.js.map +0 -1
  90. package/dist/assets/bundle-CcAyERuZ.css +0 -11
  91. package/dist/components.d.ts +0 -257
  92. package/dist/components.js +0 -316
  93. package/dist/components.js.map +0 -1
  94. package/dist/hooks.d.ts +0 -187
  95. package/dist/hooks.js +0 -81
  96. package/dist/hooks.js.map +0 -1
  97. package/src/_exports/components.ts +0 -13
  98. package/src/_exports/hooks.ts +0 -9
  99. package/src/components/DocumentGridLayout/DocumentGridLayout.stories.tsx +0 -113
  100. package/src/components/DocumentGridLayout/DocumentGridLayout.test.tsx +0 -42
  101. package/src/components/DocumentGridLayout/DocumentGridLayout.tsx +0 -21
  102. package/src/components/DocumentListLayout/DocumentListLayout.stories.tsx +0 -105
  103. package/src/components/DocumentListLayout/DocumentListLayout.test.tsx +0 -42
  104. package/src/components/DocumentListLayout/DocumentListLayout.tsx +0 -12
  105. package/src/components/DocumentPreviewLayout/DocumentPreviewLayout.md +0 -49
  106. package/src/components/DocumentPreviewLayout/DocumentPreviewLayout.stories.tsx +0 -39
  107. package/src/components/DocumentPreviewLayout/DocumentPreviewLayout.test.tsx +0 -30
  108. package/src/components/DocumentPreviewLayout/DocumentPreviewLayout.tsx +0 -171
  109. package/src/components/context/SanityProvider.tsx +0 -42
  110. package/src/css/css.config.js +0 -220
  111. package/src/css/paramour.css +0 -2347
  112. package/src/css/styles.css +0 -11
  113. package/src/hooks/auth/useHandleCallback.test.tsx +0 -16
  114. package/src/hooks/client/useClient.test.tsx +0 -130
  115. package/src/hooks/documentCollection/useDocuments.test.ts +0 -130
  116. package/src/hooks/documentCollection/useDocuments.ts +0 -87
@@ -1,26 +1,11 @@
1
- import {createSanityInstance} from '@sanity/sdk'
2
- import {ThemeProvider} from '@sanity/ui'
3
- import {buildTheme} from '@sanity/ui/theme'
4
- import {render, screen, waitFor} from '@testing-library/react'
5
- import React from 'react'
1
+ import {screen, waitFor} from '@testing-library/react'
6
2
  import {afterAll, beforeAll, beforeEach, describe, expect, it, vi} from 'vitest'
7
3
 
8
- import {SanityProvider} from '../context/SanityProvider'
4
+ import {renderWithWrappers} from './authTestHelpers'
9
5
 
10
- const theme = buildTheme({})
11
- const sanityInstance = createSanityInstance({projectId: 'test-project-id', dataset: 'production'})
12
-
13
- const renderWithWrappers = (ui: React.ReactElement) => {
14
- return render(
15
- <ThemeProvider theme={theme}>
16
- <SanityProvider sanityInstance={sanityInstance}>{ui}</SanityProvider>
17
- </ThemeProvider>,
18
- )
19
- }
20
-
21
- // Mock `useHandleCallback`
22
- vi.mock('../../hooks/auth/useHandleCallback', () => ({
23
- useHandleCallback: vi.fn(() => async (url: string) => {
6
+ // Mock `useHandleAuthCallback`
7
+ vi.mock('../../hooks/auth/useHandleAuthCallback', () => ({
8
+ useHandleAuthCallback: vi.fn(() => async (url: string) => {
24
9
  const parsedUrl = new URL(url)
25
10
  const sid = new URLSearchParams(parsedUrl.hash.slice(1)).get('sid')
26
11
  if (sid === 'valid') {
@@ -1,14 +1,9 @@
1
- import {Flex, Spinner, Text} from '@sanity/ui'
2
1
  import {useEffect} from 'react'
3
- import styled from 'styled-components'
4
2
 
5
- import {useHandleCallback} from '../../hooks/auth/useHandleCallback'
3
+ import {useHandleAuthCallback} from '../../hooks/auth/useHandleAuthCallback'
6
4
  import {LoginLayout, type LoginLayoutProps} from './LoginLayout'
7
5
 
8
- const StyledFlex = styled(Flex)`
9
- margin: auto;
10
- `
11
-
6
+ /**
12
7
  /**
13
8
  * Component shown during auth callback processing that handles login completion.
14
9
  * Automatically processes the auth callback when mounted and updates the URL
@@ -17,25 +12,25 @@ const StyledFlex = styled(Flex)`
17
12
  * @alpha
18
13
  */
19
14
  export function LoginCallback({header, footer}: LoginLayoutProps): React.ReactNode {
20
- const handleCallback = useHandleCallback()
15
+ const handleAuthCallback = useHandleAuthCallback()
21
16
 
22
17
  useEffect(() => {
23
18
  const url = new URL(location.href)
24
- handleCallback(url.toString()).then((replacementLocation) => {
19
+ handleAuthCallback(url.toString()).then((replacementLocation) => {
25
20
  if (replacementLocation) {
26
21
  // history API with `replaceState` is used to prevent a reload but still
27
22
  // remove the short-lived token from the URL
28
23
  history.replaceState(null, '', replacementLocation)
29
24
  }
30
25
  })
31
- }, [handleCallback])
26
+ }, [handleAuthCallback])
32
27
 
33
28
  return (
34
29
  <LoginLayout header={header} footer={footer}>
35
- <StyledFlex direction="column" justify="center" align="center" gap={4}>
36
- <Text size={1}>Logging you in…</Text>
37
- <Spinner size={4} />
38
- </StyledFlex>
30
+ <div className="sc-login-callback">
31
+ <h1 className="sc-login-callback__title">Logging you in…</h1>
32
+ <div className="sc-login-callback__loading">Loading…</div>
33
+ </div>
39
34
  </LoginLayout>
40
35
  )
41
36
  }
@@ -1,29 +1,14 @@
1
- import {createSanityInstance} from '@sanity/sdk'
2
- import {ThemeProvider} from '@sanity/ui'
3
- import {buildTheme} from '@sanity/ui/theme'
4
- import {fireEvent, render, screen, waitFor} from '@testing-library/react'
5
- import React from 'react'
1
+ import {fireEvent, screen, waitFor} from '@testing-library/react'
6
2
  import {describe, expect, it, vi} from 'vitest'
7
3
 
8
- import {SanityProvider} from '../context/SanityProvider'
9
4
  import {AuthError} from './AuthError'
5
+ import {renderWithWrappers} from './authTestHelpers'
10
6
  import {LoginError} from './LoginError'
11
7
 
12
8
  vi.mock('../../hooks/auth/useLogOut', () => ({
13
9
  useLogOut: vi.fn(() => async () => {}),
14
10
  }))
15
11
 
16
- const theme = buildTheme({})
17
- const sanityInstance = createSanityInstance({projectId: 'test-project-id', dataset: 'production'})
18
-
19
- const renderWithWrappers = (ui: React.ReactElement) => {
20
- return render(
21
- <ThemeProvider theme={theme}>
22
- <SanityProvider sanityInstance={sanityInstance}>{ui}</SanityProvider>
23
- </ThemeProvider>,
24
- )
25
- }
26
-
27
12
  describe('LoginError', () => {
28
13
  it('shows authentication error and retry button', async () => {
29
14
  const mockReset = vi.fn()
@@ -1,7 +1,5 @@
1
- import {Button, Flex, Text} from '@sanity/ui'
2
1
  import {useCallback} from 'react'
3
2
  import {type FallbackProps} from 'react-error-boundary'
4
- import styled from 'styled-components'
5
3
 
6
4
  import {useLogOut} from '../../hooks/auth/useLogOut'
7
5
  import {AuthError} from './AuthError'
@@ -12,10 +10,6 @@ import {LoginLayout, type LoginLayoutProps} from './LoginLayout'
12
10
  */
13
11
  export type LoginErrorProps = FallbackProps & LoginLayoutProps
14
12
 
15
- const StyledFlex = styled(Flex)`
16
- margin: auto;
17
- `
18
-
19
13
  /**
20
14
  * Displays authentication error details and provides retry functionality.
21
15
  * Only handles {@link AuthError} instances - rethrows other error types.
@@ -38,17 +32,18 @@ export function LoginError({
38
32
 
39
33
  return (
40
34
  <LoginLayout header={header} footer={footer}>
41
- <StyledFlex direction="column" gap={4}>
42
- <Flex direction="column" gap={3}>
43
- <Text as="h2" align="center" weight="bold" size={3}>
44
- Authentication Error
45
- </Text>
46
- <Text size={1} align="center">
35
+ <div className="sc-login-error">
36
+ <div className="sc-login-error__content">
37
+ <h2 className="sc-login-error__title">Authentication Error</h2>
38
+ <p className="sc-login-error__description">
47
39
  Please try again or contact support if the problem persists.
48
- </Text>
49
- </Flex>
50
- <Button text="Retry" tone="primary" onClick={handleRetry} />
51
- </StyledFlex>
40
+ </p>
41
+ </div>
42
+
43
+ <button className="sc-login-error__button" onClick={handleRetry}>
44
+ Retry
45
+ </button>
46
+ </div>
52
47
  </LoginLayout>
53
48
  )
54
49
  }
@@ -1,23 +1,9 @@
1
- import {createSanityInstance} from '@sanity/sdk'
2
- import {ThemeProvider} from '@sanity/ui'
3
- import {buildTheme} from '@sanity/ui/theme'
4
- import {render, screen} from '@testing-library/react'
5
- import React from 'react'
1
+ import {screen} from '@testing-library/react'
6
2
  import {describe, expect, it} from 'vitest'
7
3
 
8
- import {SanityProvider} from '../context/SanityProvider'
4
+ import {renderWithWrappers} from './authTestHelpers'
9
5
  import {LoginFooter} from './LoginFooter'
10
6
 
11
- const theme = buildTheme({})
12
- const sanityInstance = createSanityInstance({projectId: 'test-project-id', dataset: 'production'})
13
- const renderWithWrappers = (ui: React.ReactElement) => {
14
- return render(
15
- <ThemeProvider theme={theme}>
16
- <SanityProvider sanityInstance={sanityInstance}>{ui}</SanityProvider>
17
- </ThemeProvider>,
18
- )
19
- }
20
-
21
7
  describe('LoginFooter', () => {
22
8
  it('renders footer links', () => {
23
9
  renderWithWrappers(<LoginFooter />)
@@ -1,7 +1,5 @@
1
1
  import {SanityLogo} from '@sanity/logos'
2
- import {Flex, Text} from '@sanity/ui'
3
2
  import {Fragment} from 'react'
4
- import styled from 'styled-components'
5
3
 
6
4
  const LINKS = [
7
5
  {
@@ -26,12 +24,6 @@ const LINKS = [
26
24
  },
27
25
  ]
28
26
 
29
- const StyledText = styled(Text)`
30
- a {
31
- color: inherit;
32
- }
33
- `
34
-
35
27
  /**
36
28
  * Default footer component for login screens showing Sanity branding and legal
37
29
  * links.
@@ -40,28 +32,20 @@ const StyledText = styled(Text)`
40
32
  */
41
33
  export function LoginFooter(): React.ReactNode {
42
34
  return (
43
- <Flex direction="column" gap={4} justify="center" align="center" paddingTop={2}>
44
- <Text size={3}>
45
- <SanityLogo />
46
- </Text>
35
+ <div className="sc-login-footer">
36
+ <SanityLogo className="sc-login-footer__logo" />
47
37
 
48
- <Flex align="center" gap={2}>
49
- {LINKS.map((link, index) => (
38
+ <ul className="sc-login-footer__links">
39
+ {LINKS.map((link) => (
50
40
  <Fragment key={link.title}>
51
- <StyledText muted size={1}>
41
+ <li className="sc-login-footer__link">
52
42
  <a href={link.url} target="_blank" rel="noopener noreferrer">
53
43
  {link.title}
54
44
  </a>
55
- </StyledText>
56
-
57
- {index < LINKS.length - 1 && (
58
- <Text size={1} muted>
59
-
60
- </Text>
61
- )}
45
+ </li>
62
46
  </Fragment>
63
47
  ))}
64
- </Flex>
65
- </Flex>
48
+ </ul>
49
+ </div>
66
50
  )
67
51
  }
@@ -1,23 +1,9 @@
1
- import {createSanityInstance} from '@sanity/sdk'
2
- import {ThemeProvider} from '@sanity/ui'
3
- import {buildTheme} from '@sanity/ui/theme'
4
- import {render, screen} from '@testing-library/react'
5
- import React from 'react'
1
+ import {screen} from '@testing-library/react'
6
2
  import {describe, expect, it} from 'vitest'
7
3
 
8
- import {SanityProvider} from '../context/SanityProvider'
4
+ import {renderWithWrappers} from './authTestHelpers'
9
5
  import {LoginLayout} from './LoginLayout'
10
6
 
11
- const theme = buildTheme({})
12
- const sanityInstance = createSanityInstance({projectId: 'test-project-id', dataset: 'production'})
13
- const renderWithWrappers = (ui: React.ReactElement) => {
14
- return render(
15
- <ThemeProvider theme={theme}>
16
- <SanityProvider sanityInstance={sanityInstance}>{ui}</SanityProvider>
17
- </ThemeProvider>,
18
- )
19
- }
20
-
21
7
  describe('LoginLayout', () => {
22
8
  it('renders header, children, and footer', () => {
23
9
  renderWithWrappers(
@@ -1,6 +1,3 @@
1
- import {Card, Flex} from '@sanity/ui'
2
- import styled from 'styled-components'
3
-
4
1
  import {LoginFooter} from './LoginFooter'
5
2
 
6
3
  /**
@@ -17,23 +14,6 @@ export interface LoginLayoutProps {
17
14
  children?: React.ReactNode
18
15
  }
19
16
 
20
- const Root = styled.div`
21
- width: 100%;
22
- display: flex;
23
- `
24
-
25
- const Container = styled(Flex)`
26
- width: 320px;
27
- margin: auto;
28
- display: flex;
29
- `
30
-
31
- const StyledCard = styled(Card)``
32
-
33
- const ChildrenFlex = styled(Flex)`
34
- min-height: 154px;
35
- `
36
-
37
17
  /**
38
18
  * Layout component for login-related screens providing consistent styling and structure.
39
19
  * Renders content in a centered card with optional header and footer sections.
@@ -74,26 +54,16 @@ export function LoginLayout({
74
54
  header,
75
55
  }: LoginLayoutProps): React.ReactNode {
76
56
  return (
77
- <Root>
78
- <Container direction="column" gap={4}>
79
- <StyledCard border radius={2} paddingY={4}>
80
- <Flex direction="column" gap={4}>
81
- {header && (
82
- <Card borderBottom paddingX={4} paddingBottom={3}>
83
- {header}
84
- </Card>
85
- )}
57
+ <div className="sc-login-layout">
58
+ <div className="sc-login-layout__container">
59
+ <div className="sc-login-layout__card">
60
+ {header && <div className="sc-login-layout__card-header">{header}</div>}
86
61
 
87
- {children && (
88
- <ChildrenFlex paddingX={4} direction="column">
89
- {children}
90
- </ChildrenFlex>
91
- )}
92
- </Flex>
93
- </StyledCard>
62
+ {children && <div className="sc-login-layout__card-body">{children}</div>}
63
+ </div>
94
64
 
95
65
  {footer}
96
- </Container>
97
- </Root>
66
+ </div>
67
+ </div>
98
68
  )
99
69
  }
@@ -0,0 +1,11 @@
1
+ import {createSanityInstance} from '@sanity/sdk'
2
+ import {render, type RenderResult} from '@testing-library/react'
3
+ import React from 'react'
4
+
5
+ import {SanityProvider} from '../../context/SanityProvider'
6
+
7
+ const sanityInstance = createSanityInstance({projectId: 'test-project-id', dataset: 'production'})
8
+
9
+ export const renderWithWrappers = (ui: React.ReactElement): RenderResult => {
10
+ return render(<SanityProvider sanityInstances={[sanityInstance]}>{ui}</SanityProvider>)
11
+ }
@@ -0,0 +1,22 @@
1
+ export function isInIframe(): boolean {
2
+ return typeof window !== 'undefined' && window.self !== window.top
3
+ }
4
+
5
+ /**
6
+ * @internal
7
+ *
8
+ * Checks if the current URL is a local URL.
9
+ *
10
+ * @param window - The window object
11
+ * @returns True if the current URL is a local URL, false otherwise
12
+ */
13
+ export function isLocalUrl(window: Window): boolean {
14
+ const url = typeof window !== 'undefined' ? window.location.href : ''
15
+
16
+ return (
17
+ url.startsWith('http://localhost') ||
18
+ url.startsWith('https://localhost') ||
19
+ url.startsWith('http://127.0.0.1') ||
20
+ url.startsWith('https://127.0.0.1')
21
+ )
22
+ }
@@ -0,0 +1,4 @@
1
+ import {type SanityInstance} from '@sanity/sdk'
2
+ import {createContext} from 'react'
3
+
4
+ export const SanityInstanceContext = createContext<SanityInstance[] | null>(null)
@@ -2,7 +2,7 @@ import {createSanityInstance} from '@sanity/sdk'
2
2
  import {render} from '@testing-library/react'
3
3
  import {describe, expect, it} from 'vitest'
4
4
 
5
- import {useSanityInstance} from '../../hooks/context/useSanityInstance'
5
+ import {useSanityInstance} from '../hooks/context/useSanityInstance'
6
6
  import {SanityProvider} from './SanityProvider'
7
7
 
8
8
  describe('SanityProvider', () => {
@@ -15,7 +15,7 @@ describe('SanityProvider', () => {
15
15
  }
16
16
 
17
17
  const {getByTestId} = render(
18
- <SanityProvider sanityInstance={sanityInstance}>
18
+ <SanityProvider sanityInstances={[sanityInstance]}>
19
19
  <TestComponent />
20
20
  </SanityProvider>,
21
21
  )
@@ -0,0 +1,50 @@
1
+ import {type SanityInstance} from '@sanity/sdk'
2
+ import {type ReactElement} from 'react'
3
+
4
+ import {SanityInstanceContext} from './SanityInstanceContext'
5
+
6
+ /**
7
+ * @internal
8
+ */
9
+ export interface SanityProviderProps {
10
+ children: React.ReactNode
11
+ sanityInstances: SanityInstance[]
12
+ }
13
+
14
+ /**
15
+ * @internal
16
+ *
17
+ * Top-level context provider that provides access to the Sanity configuration instance.
18
+ * This must wrap any components making use of the Sanity SDK React hooks.
19
+ *
20
+ * @remarks In most cases, SanityApp should be used rather than SanityProvider directly; SanityApp bundles both SanityProvider and an authentication layer.
21
+ * @param props - Sanity project and dataset configuration
22
+ * @returns Rendered component
23
+ * @example
24
+ * ```tsx
25
+ * import {createSanityInstance} from '@sanity/sdk'
26
+ * import {SanityProvider} from '@sanity/sdk-react'
27
+ *
28
+ * import MyAppRoot from './Root'
29
+ *
30
+ * const sanityInstance = createSanityInstance({
31
+ * projectId: 'your-project-id',
32
+ * dataset: 'production',
33
+ * })
34
+ *
35
+ * export default function MyApp() {
36
+ * return (
37
+ * <SanityProvider sanityInstance={sanityInstance}>
38
+ * <MyAppRoot />
39
+ * </SanityProvider>
40
+ * )
41
+ * }
42
+ * ```
43
+ */
44
+ export const SanityProvider = ({children, sanityInstances}: SanityProviderProps): ReactElement => {
45
+ return (
46
+ <SanityInstanceContext.Provider value={sanityInstances}>
47
+ {children}
48
+ </SanityInstanceContext.Provider>
49
+ )
50
+ }
@@ -0,0 +1,4 @@
1
+ // NOTE: this is a stop-gap measure until sychronous groq is out
2
+ // eslint-disable
3
+ // prettier-ignore
4
+ class e{pattern;patternRe;constructor(e){this.pattern=e,this.patternRe=function(e){const t=[];for(const r of e.split("."))"*"===r?t.push("[^.]+"):"**"===r?t.push(".*"):t.push(r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"));return new RegExp(`^${t.join(".")}$`)}(e)}matches(e){return this.patternRe.test(e)}toJSON(){return this.pattern}}class t{type="stream";generator;ticker;isDone;data;constructor(e){this.generator=e,this.ticker=null,this.isDone=!1,this.data=[]}isArray(){return!0}async get(){const e=[];for await(const t of this)e.push(await t.get());return e}async first(e=()=>!0){for await(const t of this)if(e(t))return t}async reduce(e,t){let r=t;for await(const t of this)r=await e(r,t);return r}async*[Symbol.asyncIterator](){let e=0;for(;;){for(;e<this.data.length;e++)yield this.data[e];if(this.isDone)return;await this._nextTick()}}_nextTick(){if(this.ticker)return this.ticker;let e;const t=()=>{this.ticker=new Promise((t=>{e=t}))},r=()=>{e(),t()};return t(),(async()=>{for await(const e of this.generator())this.data.push(e),r();this.isDone=!0,r()})(),this.ticker}}const r=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|([-+]\d{2}:\d{2}))$/;function n(e,t){let r=e.toString();for(;r.length<t;)r=`0${r}`;return r}class o{data;type;constructor(e,t){this.data=e,this.type=t}isArray(){return"array"===this.type}get(){return this.data}first(e=()=>!0){if(!this.isArray())throw new Error("`first` can only be called on array `StaticValue`s");const t=this.get();for(const r of t){const t=f(r,"sync");if(e(t))return t}}reduce(e,t){if(!this.isArray())throw new Error("`reduce` can only be called on array `StaticValue`s");const r=this.get();let n=t;for(const t of r){n=e(n,f(t,"sync"))}return n}[Symbol.asyncIterator](){if(Array.isArray(this.data))return function*(e){for(const t of e)yield f(t,"async")}(this.data);throw new Error(`Cannot iterate over: ${this.type}`)}}const i=new o(null,"null"),s=new o(!0,"boolean"),a=new o(!1,"boolean");class c{date;constructor(e){this.date=e}static parseToValue(e){const t=function(e){return r.test(e)?new Date(e):null}(e);return t?new o(new c(t),"datetime"):i}equals(e){return this.date.getTime()==e.date.getTime()}add(e){const t=new Date(this.date.getTime());return t.setTime(t.getTime()+1e3*e),new c(t)}difference(e){return(this.date.getTime()-e.date.getTime())/1e3}compareTo(e){return this.date.getTime()-e.date.getTime()}toString(){return function(e){const t=n(e.getUTCFullYear(),4),r=n(e.getUTCMonth()+1,2),o=n(e.getUTCDate(),2),i=n(e.getUTCHours(),2),s=n(e.getUTCMinutes(),2),a=n(e.getUTCSeconds(),2);let c="";const u=e.getMilliseconds();return 0!=u&&(c=`.${n(u,3)}`),`${t}-${r}-${o}T${i}:${s}:${a}${c}Z`}(this.date)}toJSON(){return this.toString()}}function u(e){return Number.isFinite(e)?new o(e,"number"):i}function p(e){return new o(e,"string")}function l(e){return new o(e,"datetime")}function f(e,r){return(n=e)&&"function"==typeof n.next&&"sync"!==r?new t((async function*(){for await(const t of e)yield f(t,"async")})):null==e?i:new o(e,y(e));var n}function y(t){return null===t||typeof t>"u"?"null":Array.isArray(t)?"array":t instanceof e?"path":t instanceof c?"datetime":typeof t}const d=e=>"object"==typeof e&&!!e&&"then"in e&&"function"==typeof e.then;function h(e){const t=e(),r=t.next();if(r.done)return r.value;function n(e){const r=t.next(e);if(r.done)return r.value;const o=r.value;return o&&d(o)?o.then(n):n(o)}const o=r.value;return o&&d(o)?o.then(n):n(o)}function m(e,t){return"string"===e.type&&"string"===t.type||"boolean"===e.type&&"boolean"===t.type||"null"===e.type&&"null"===t.type||"number"===e.type&&"number"===t.type?e.data===t.data:"datetime"===e.type&&"datetime"===t.type&&e.data.equals(t.data)}const b=/([^!@#$%^&*(),\\/?";:{}|[\]+<>\s-])+/g,g=/([^!@#$%^&(),\\/?";:{}|[\]+<>\s-])+/g,w=/(\b\.+|\.+\b)/g;function k(e){return e.replace(w,"").match(b)||[]}function v(e){return x(e).map((e=>t=>t.some((t=>e.test(t)))))}function x(e){return(e.replace(w,"").match(g)||[]).map((e=>new RegExp(`^${e.slice(0,1024).replace(/\*/g,".*")}$`,"i")))}const _={datetime:1,number:2,string:3,boolean:4};function A(e,t){const r=y(e);if(r!==y(t))return null;switch(r){case"number":case"boolean":return e-t;case"string":return e<t?-1:e>t?1:0;case"datetime":return e.compareTo(t);default:return null}}function E(e,t){const r=y(e),n=y(t),o=_[r]||100,i=_[n]||100;if(o!==i)return o-i;let s=A(e,t);return null===s&&(s=0),s}const j={"==":function(e,t){return m(e,t)?s:a},"!=":function(e,t){return m(e,t)?a:s},">":function(e,t){if("stream"===e.type||"stream"===t.type)return i;const r=A(e.data,t.data);return null===r?i:r>0?s:a},">=":function(e,t){if("stream"===e.type||"stream"===t.type)return i;const r=A(e.data,t.data);return null===r?i:r>=0?s:a},"<":function(e,t){if("stream"===e.type||"stream"===t.type)return i;const r=A(e.data,t.data);return null===r?i:r<0?s:a},"<=":function(e,t){if("stream"===e.type||"stream"===t.type)return i;const r=A(e.data,t.data);return null===r?i:r<=0?s:a},in:function(e,t){return h((function*(){return"path"===t.type?"string"!==e.type?i:t.data.matches(e.data)?s:a:t.isArray()?(yield t.first((t=>m(e,t))))?s:a:i}))},match:function(e,t){return h((function*(){const r=yield e.get(),n=yield t.get();let o,i=[];if(Array.isArray(r)?i=r.filter((e=>"string"==typeof e)):"string"==typeof r&&(i=[r]),Array.isArray(n)?o=n.filter((e=>"string"==typeof e)):"string"==typeof n&&(o=[n]),!o?.length)return a;return function(e,t){return 0!==e.length&&0!==t.length&&t.every((t=>t(e)))}(i.flatMap(k),o.flatMap(v))?s:a}))},"+":function(e,r,n){return"datetime"===e.type&&"number"===r.type?l(e.data.add(r.data)):"number"===e.type&&"number"===r.type?u(e.data+r.data):"string"===e.type&&"string"===r.type?p(e.data+r.data):"object"===e.type&&"object"===r.type?f({...e.data,...r.data},n):"array"===e.type&&"array"===r.type?f(e.data.concat(r.data),n):e.isArray()&&r.isArray()?"sync"===n?h((function*(){const t=[...yield e.get(),...yield r.get()];return new o(t,"array")})):new t((async function*(){for await(const t of e)yield t;for await(const e of r)yield e})):i},"-":function(e,t){return"datetime"===e.type&&"number"===t.type?l(e.data.add(-t.data)):"datetime"===e.type&&"datetime"===t.type?u(e.data.difference(t.data)):"number"===e.type&&"number"===t.type?u(e.data-t.data):i},"*":S(((e,t)=>e*t)),"/":S(((e,t)=>e/t)),"%":S(((e,t)=>e%t)),"**":S(((e,t)=>Math.pow(e,t)))};function S(e){return function(t,r){if("number"===t.type&&"number"===r.type){return u(e(t.data,r.data))}return i}}let O=class e{params;source;value;parent;context;isHidden=!1;constructor(e,t,r,n,o){this.params=e,this.source=t,this.value=r,this.context=n,this.parent=o}createNested(t){return this.isHidden?new e(this.params,this.source,t,this.context,this.parent):new e(this.params,this.source,t,this.context,this)}createHidden(e){const t=this.createNested(e);return t.isHidden=!0,t}};function I(e,t,r){return(0,$[e.type])(e,t,r)}const $={This:(e,t)=>t.value,Selector(){throw new Error("Selectors can not be evaluated")},Everything:(e,t)=>t.source,Parameter:({name:e},t,r)=>f(t.params[e],r),Context({key:e},t){if("before"===e||"after"===e)return t.context[e]||i;throw new Error(`unknown context key: ${e}`)},Parent({n:e},t){let r=t;for(let t=0;t<e;t++){if(!r.parent)return i;r=r.parent}return r.value},OpCall:({op:e,left:t,right:r},n,o)=>h((function*(){const i=j[e];if(!i)throw new Error(`Unknown operator: ${e}`);const s=yield I(t,n,o),a=yield I(r,n,o);return yield i(s,a,o)})),Select:({alternatives:e,fallback:t},r,n)=>h((function*(){for(const t of e){const e=yield I(t.condition,r,n);if("boolean"===e.type&&!0===e.data)return yield I(t.value,r,n)}return t?yield I(t,r,n):i})),InRange:({base:e,left:t,right:r,isInclusive:n},o,c)=>h((function*(){const u=yield I(e,o,c),p=yield I(t,o,c),l=yield I(r,o,c),f=A(yield u.get(),yield p.get());if(null===f)return i;const y=A(yield u.get(),yield l.get());return null===y?i:n?f>=0&&y<=0?s:a:f>=0&&y<0?s:a})),Filter:({base:e,expr:r},n,s)=>h((function*(){const a=yield I(e,n,s);if(!a.isArray())return i;if("sync"===s){const e=yield a.get(),t=[];for(const o of e){const e=f(o,s),i=n.createNested(e),a=yield I(r,i,s);"boolean"===a.type&&!0===a.data&&t.push(o)}return new o(t,"array")}return new t((async function*(){for await(const e of a){const t=n.createNested(e),o=await I(r,t,s);"boolean"===o.type&&!0===o.data&&(yield e)}}))})),Projection:({base:e,expr:t},r,n)=>h((function*(){const o=yield I(e,r,n);if("object"!==o.type)return i;const s=r.createNested(o);return yield I(t,s,n)})),FuncCall:({func:e,args:t},r,n)=>e(t,r,n),PipeFuncCall:({func:e,base:t,args:r},n,o)=>h((function*(){const i=yield I(t,n,o);return yield e(i,r,n,o)})),AccessAttribute:({base:e,name:t},r,n)=>h((function*(){let o=r.value;return e&&(o=yield I(e,r,n)),"object"===o.type&&o.data.hasOwnProperty(t)?f(o.data[t],n):i})),AccessElement:({base:e,index:t},r,n)=>h((function*(){const o=yield I(e,r,n);if(!o.isArray())return i;const s=yield o.get();return f(s[t<0?t+s.length:t],n)})),Slice:({base:e,left:t,right:r,isInclusive:n},o,s)=>h((function*(){const a=yield I(e,o,s);if(!a.isArray())return i;const c=yield a.get();let u=t,p=r;return u<0&&(u=c.length+u),p<0&&(p=c.length+p),n&&p++,u<0&&(u=0),p<0&&(p=0),f(c.slice(u,p),s)})),Deref:({base:e},t,r)=>h((function*(){const n=yield I(e,t,r);if(!t.source.isArray()||"object"!==n.type)return i;const o=n.data._ref;if("string"!=typeof o)return i;if(t.context.dereference){return f(yield t.context.dereference({_ref:o}),r)}return(yield t.source.first((e=>"object"===e.type&&o==e.data._id)))||i})),Value:({value:e},t,r)=>f(e,r),Group:({base:e},t,r)=>I(e,t,r),Object:({attributes:e},t,r)=>h((function*(){const n={};for(const o of e){const e=o.type;switch(o.type){case"ObjectAttributeValue":{const e=yield I(o.value,t,r);n[o.name]=yield e.get();break}case"ObjectConditionalSplat":{const e=yield I(o.condition,t,r);if("boolean"!==e.type||!1===e.data)continue;const i=yield I(o.value,t,r);"object"===i.type&&Object.assign(n,i.data);break}case"ObjectSplat":{const e=yield I(o.value,t,r);"object"===e.type&&Object.assign(n,e.data);break}default:throw new Error(`Unknown node type: ${e}`)}}return f(n,r)})),Array:({elements:e},r,n)=>h((function*(){if("sync"===n){const t=[];for(const o of e){const e=yield I(o.value,r,n);if(o.isSplat){if(e.isArray()){const r=yield e.get();t.push(...r)}}else t.push(yield e.get())}return new o(t,"array")}return new t((async function*(){for(const t of e){const e=await I(t.value,r,n);if(t.isSplat){if(e.isArray())for await(const t of e)yield t}else yield e}}))})),Tuple(){throw new Error("tuples can not be evaluated")},Or:({left:e,right:t},r,n)=>h((function*(){const o=yield I(e,r,n),c=yield I(t,r,n);return"boolean"===o.type&&!0===o.data||"boolean"===c.type&&!0===c.data?s:"boolean"!==o.type||"boolean"!==c.type?i:a})),And:({left:e,right:t},r,n)=>h((function*(){const o=yield I(e,r,n),c=yield I(t,r,n);return"boolean"===o.type&&!1===o.data||"boolean"===c.type&&!1===c.data?a:"boolean"!==o.type||"boolean"!==c.type?i:s})),Not:({base:e},t,r)=>h((function*(){const n=yield I(e,t,r);return"boolean"!==n.type?i:n.data?a:s})),Neg:({base:e},t,r)=>h((function*(){const n=yield I(e,t,r);return"number"!==n.type?i:u(-n.data)})),Pos:({base:e},t,r)=>h((function*(){const n=yield I(e,t,r);return"number"!==n.type?i:u(n.data)})),Asc:()=>i,Desc:()=>i,ArrayCoerce:({base:e},t,r)=>h((function*(){const n=yield I(e,t,r);return n.isArray()?n:i})),Map:({base:e,expr:r},n,s)=>h((function*(){const a=yield I(e,n,s);if(!a.isArray())return i;if("sync"===s){const e=yield a.get(),t=[];for(const o of e){const e=f(o,"sync"),i=n.createHidden(e),a=yield I(r,i,s);t.push(yield a.get())}return new o(t,"array")}return new t((async function*(){for await(const e of a){const t=n.createHidden(e);yield await I(r,t,s)}}))})),FlatMap:({base:e,expr:r},n,s)=>h((function*(){const a=yield I(e,n,s);if(!a.isArray())return i;if("sync"===s){const e=yield a.get(),t=[];for(const o of e){const e=f(o,"sync"),i=n.createHidden(e),a=yield I(r,i,s);if(a.isArray()){const e=yield a.get();t.push(...e)}else{const e=yield a.get();t.push(e)}}return new o(t,"array")}return new t((async function*(){for await(const e of a){const t=n.createHidden(e),o=await I(r,t,s);if(o.isArray())for await(const e of o)yield e;else yield o}}))}))};function C(e,t={}){const r=f(t.root,"sync"),n=f(t.dataset,"sync"),o={...t.params},i=new O(o,n,r,function(e={},t){return{timestamp:e.timestamp||new Date,identity:void 0===e.identity?"me":e.identity,sanity:e.sanity,after:e.after?f(e.after,t):null,before:e.before?f(e.before,t):null,dereference:e.dereference}}(t,"sync"),null),s=I(e,i,"sync");if(d(s))throw new Error("Unexpected promise when evaluating. This expression may not support evaluateSync.");return s}function M(e){switch(e.type){case"Group":return M(e.base);case"Value":case"Parameter":return!0;case"Pos":case"Neg":return M(e.base);case"OpCall":switch(e.op){case"+":case"-":case"*":case"/":case"%":case"**":return M(e.left)&&M(e.right);default:return!1}default:return!1}}const T=new O({},i,i,{timestamp:new Date(0),identity:"me",before:null,after:null},null);function P(e){return M(e)?function(e){const t=I(e,T,"sync");if(d(t))throw new Error("BUG: constant evaluate should never return a promise");return t}(e):null}function N(e,t){return h((function*(){if("object"===e.type)return V(e.data);if(e.isArray()){const r=yield U(e,t);if(r.length>0)return r.join("\n\n")}return null}))}function U(e,t){return h((function*(){const r=[],n=yield e.get();for(const e of n){const n=f(e,t);if("object"===n.type){const e=V(n.data);null!==e&&r.push(e)}else if(n.isArray()){const e=yield U(n,t);r.push(...e)}}return r}))}function V(e){if("string"!=typeof e._type)return null;const t=e.children;if(!Array.isArray(t))return null;let r="";for(const e of t)e&&"object"==typeof e&&"string"==typeof e._type&&"span"===e._type&&"string"==typeof e.text&&(r+=e.text);return r}const D=1.2;function F(e,t,r){return h((function*(){if("OpCall"===e.type&&"match"===e.op){return function(e,t){return h((function*(){const r=yield e.get(),n=yield t.get();let o,i=[];if(Array.isArray(r)?i=r.filter((e=>"string"==typeof e)):"string"==typeof r&&(i=[r]),Array.isArray(n)?o=n.filter((e=>"string"==typeof e)):"string"==typeof n&&(o=[n]),!o?.length)return 0;const s=i.flatMap(k),a=o.flatMap(x);if(0===s.length||0===a.length)return 0;let c=0;for(const e of a){const t=s.reduce(((t,r)=>t+(e.test(r)?1:0)),0);c+=2.2*t/(t+D)}return c}))}(yield I(e.left,t,r),yield I(e.right,t,r))}if("FuncCall"===e.type&&"boost"===e.name){const n=yield F(e.args[0],t,r),o=yield I(e.args[1],t,r);return"number"===o.type&&n>0?n+o.data:0}switch(e.type){case"Or":return(yield F(e.left,t,r))+(yield F(e.right,t,r));case"And":{const n=yield F(e.left,t,r),o=yield F(e.right,t,r);return 0===n||0===o?0:n+o}default:{const n=yield I(e,t,r);return"boolean"===n.type&&!0===n.data?1:0}}}))}function R(e,t){switch(y(e)){case"array":for(const r of e)if(R(r,t))return!0;break;case"object":if(e._ref)return t.has(e._ref);for(const r of Object.values(e))if(R(r,t))return!0}return!1}const q={anywhere:function(){throw new Error("not implemented")}};q.anywhere.arity=1,q.coalesce=function(e,t,r){return h((function*(){for(const n of e){const e=yield I(n,t,r);if("null"!==e.type)return e}return i}))},q.count=function(e,t,r){return h((function*(){const n=yield I(e[0],t,r);if(!n.isArray())return i;return u(yield n.reduce((e=>e+1),0))}))},q.count.arity=1,q.dateTime=function(e,t,r){return h((function*(){const n=yield I(e[0],t,r);return"datetime"===n.type?n:"string"!==n.type?i:c.parseToValue(n.data)}))},q.dateTime.arity=1,q.defined=function(e,t,r){return h((function*(){return"null"===(yield I(e[0],t,r)).type?a:s}))},q.defined.arity=1,q.identity=function(e,t){return p(t.context.identity)},q.identity.arity=0,q.length=function(e,t,r){return h((function*(){const n=yield I(e[0],t,r);if("string"===n.type)return u(function(e){let t=0;for(let r=0;r<e.length;r++){const n=e.charCodeAt(r);n>=55296&&n<=56319||t++}return t}(n.data));if(n.isArray()){return u(yield n.reduce((e=>e+1),0))}return i}))},q.length.arity=1,q.path=function(t,r,n){return h((function*(){const s=yield I(t[0],r,n);return"string"!==s.type?i:(a=new e(s.data),new o(a,"path"));var a}))},q.path.arity=1,q.string=function(e,t,r){return h((function*(){const n=yield I(e[0],t,r);switch(n.type){case"number":case"string":case"boolean":case"datetime":return p(`${n.data}`);default:return i}}))},q.string.arity=1,q.references=function(e,t,r){return h((function*(){const n=new Set;for(const o of e){const e=yield I(o,t,r);if("string"===e.type)n.add(e.data);else if(e.isArray()){const t=yield e.get();for(const e of t)"string"==typeof e&&n.add(e)}}if(0===n.size)return a;return R(yield t.value.get(),n)?s:a}))},q.references.arity=e=>e>=1,q.round=function(e,t,r){return h((function*(){const n=yield I(e[0],t,r);if("number"!==n.type)return i;const o=n.data;let s=0;if(2===e.length){const n=yield I(e[1],t,r);if("number"!==n.type||n.data<0||!Number.isInteger(n.data))return i;s=n.data}return u(0===s?o<0?-Math.round(-o):Math.round(o):Number(o.toFixed(s)))}))},q.round.arity=e=>e>=1&&e<=2,q.now=function(e,t){return p(t.context.timestamp.toISOString())},q.now.arity=0,q.boost=function(){throw new Error("unexpected boost call")},q.boost.arity=2;const G={lower:function(e,t,r){return h((function*(){const n=yield I(e[0],t,r);return"string"!==n.type?i:p(n.data.toLowerCase())}))}};G.lower.arity=1,G.upper=function(e,t,r){return h((function*(){const n=yield I(e[0],t,r);return"string"!==n.type?i:p(n.data.toUpperCase())}))},G.upper.arity=1,G.split=function(e,t,r){return h((function*(){const n=yield I(e[0],t,r);if("string"!==n.type)return i;const o=yield I(e[1],t,r);return"string"!==o.type?i:0===n.data.length?f([],r):0===o.data.length?f(Array.from(n.data),r):f(n.data.split(o.data),r)}))},G.split.arity=2,q.lower=G.lower,q.upper=G.upper,G.startsWith=function(e,t,r){return h((function*(){const n=yield I(e[0],t,r);if("string"!==n.type)return i;const o=yield I(e[1],t,r);return"string"!==o.type?i:n.data.startsWith(o.data)?s:a}))},G.startsWith.arity=2;const H={join:function(e,t,r){return h((function*(){const n=yield I(e[0],t,r);if(!n.isArray())return i;const o=yield I(e[1],t,r);if("string"!==o.type)return i;let s="",a=!1;const c=yield n.get();for(const e of c){const t=f(e,r);switch(a&&(s+=o.data),t.type){case"number":case"string":case"boolean":case"datetime":s+=`${t.data}`;break;default:return i}a=!0}return f(s,r)}))}};H.join.arity=2,H.compact=function(e,r,n){return h((function*(){const o=yield I(e[0],r,n);return o.isArray()?new t((async function*(){for await(const e of o)"null"!==e.type&&(yield e)})):i}))},H.compact.arity=1,H.unique=function(e,r,n){return h((function*(){const s=yield I(e[0],r,n);if(!s.isArray())return i;if("sync"===n){const e=yield s.get(),t=new Set,r=[];for(const n of e){const e=f(n,"sync");switch(e.type){case"number":case"string":case"boolean":case"datetime":t.has(n)||(t.add(n),r.push(e));break;default:r.push(e)}}return new o(r,"array")}return new t((async function*(){const e=new Set;for await(const t of s)switch(t.type){case"number":case"string":case"boolean":case"datetime":e.has(t.data)||(e.add(t.data),yield t);break;default:yield t}}))}))},H.unique.arity=1,H.intersects=function(e,t,r){return h((function*(){const n=yield I(e[0],t,r);if(!n.isArray())return i;const o=yield I(e[1],t,r);return o.isArray()?(yield n.first((e=>!!o.first((t=>m(e,t))))))?s:a:i}))},H.intersects.arity=2;const B={text:function(e,t,r){return h((function*(){const n=yield I(e[0],t,r),o=yield N(n,r);return null===o?i:p(o)}))}};B.text.arity=1;const W={projectId:function(e,t){return t.context.sanity?p(t.context.sanity.projectId):i},dataset:function(e,t){return t.context.sanity?p(t.context.sanity.dataset):i},versionsOf:function(e,t,r){return h((function*(){if(!t.source.isArray())return i;const n=yield I(e[0],t,r);if("string"!==n.type)return i;const o=n.data;return f(yield t.source.reduce(((e,t)=>{if("object"===y(t)){const r=t.get();r&&"_id"in r&&2===r._id.split(".").length&&r._id.endsWith(`.${o}`)&&"_version"in r&&"object"==typeof r._version&&e.push(r._id)}return e}),[]),r)}))}};W.versionsOf.arity=1,W.partOfRelease=function(e,t,r){return h((function*(){if(!t.source.isArray())return i;const n=yield I(e[0],t,r);if("string"!==n.type)return i;const o=n.data;return f(yield t.source.reduce(((e,t)=>{if("object"===y(t)){const r=t.get();r&&"_id"in r&&2===r._id.split(".").length&&r._id.startsWith(`${o}.`)&&"_version"in r&&"object"==typeof r._version&&e.push(r._id)}return e}),[]),r)}))},W.partOfRelease.arity=1;const Z={order:function(e,t,r,n){return h((function*(){if(!e.isArray())return i;const o=[],s=[];let a=0;for(let e of t){let t="asc";"Desc"===e.type?(t="desc",e=e.base):"Asc"===e.type&&(e=e.base),o.push(e),s.push(t),a++}const c=[];let u=0;const p=yield e.get();for(const e of p){const t=f(e,n),i=r.createNested(t),s=[yield t.get(),u];for(let e=0;e<a;e++){const t=yield I(o[e],i,n);s.push(yield t.get())}c.push(s),u++}return c.sort(((e,t)=>{for(let r=0;r<a;r++){let n=E(e[r+2],t[r+2]);if("desc"===s[r]&&(n=-n),0!==n)return n}return e[1]-t[1]})),f(c.map((e=>e[0])),n)}))}};Z.order.arity=e=>e>=1,Z.score=function(e,t,r,n){return h((function*(){if(!e.isArray())return i;const o=[],s=[],a=yield e.get();for(const e of a){const i=f(e,n);if("object"!==i.type){o.push(yield i.get());continue}const a=r.createNested(i);let c="number"==typeof i.data._score?i.data._score:0;for(const e of t)c+=(yield F(e,a,n));const u=Object.assign({},i.data,{_score:c});s.push(u)}return s.sort(((e,t)=>t._score-e._score)),f(s,n)}))},Z.score.arity=e=>e>=1;const z={operation:function(e,t){const r=null!==t.context.before,n=null!==t.context.after;return r&&n?p("update"):n?p("create"):r?p("delete"):i},changedAny:()=>{throw new Error("not implemented")}};z.changedAny.arity=1,z.changedAny.mode="delta",z.changedOnly=()=>{throw new Error("not implemented")},z.changedOnly.arity=1,z.changedOnly.mode="delta";const J={changedAny:()=>{throw new Error("not implemented")}};J.changedAny.arity=3,J.changedOnly=()=>{throw new Error("not implemented")},J.changedOnly.arity=3;const Q={min:function(e,t,r){return h((function*(){const n=yield I(e[0],t,r);if(!n.isArray()||(yield n.first((e=>"null"!==e.type&&"number"!==e.type))))return i;const o=yield n.get();let s;for(const e of o)"number"==typeof e&&(void 0===s||e<s)&&(s=e);return f(s,r)}))}};Q.min.arity=1,Q.max=function(e,t,r){return h((function*(){const n=yield I(e[0],t,r);if(!n.isArray()||(yield n.first((e=>"null"!==e.type&&"number"!==e.type))))return i;const o=yield n.get();let s;for(const e of o)"number"==typeof e&&(void 0===s||e>s)&&(s=e);return f(s,r)}))},Q.max.arity=1,Q.sum=function(e,t,r){return h((function*(){const n=yield I(e[0],t,r);if(!n.isArray()||(yield n.first((e=>"null"!==e.type&&"number"!==e.type))))return i;return f(yield n.reduce(((e,t)=>"number"!==t.type?e:e+t.data),0),r)}))},Q.sum.arity=1,Q.avg=function(e,t,r){return h((function*(){const n=yield I(e[0],t,r);if(!n.isArray()||(yield n.first((e=>"null"!==e.type&&"number"!==e.type))))return i;const o=yield n.reduce(((e,t)=>"number"!==t.type?e:e+1),0),s=yield n.reduce(((e,t)=>"number"!==t.type?e:e+t.data),0);return 0===o?i:f(s/o,r)}))},Q.avg.arity=1;const L={now:function(e,t){return l(new c(t.context.timestamp))}};L.now.arity=0;const Y={global:q,string:G,array:H,pt:B,delta:z,diff:J,sanity:W,math:Q,dateTime:L};class K{string;marks;index;parseOptions;allowBoost=!1;constructor(e,t,r){this.string=e,this.marks=t,this.index=0,this.parseOptions=r}hasMark(e=0){return this.index+e<this.marks.length}getMark(e=0){return this.marks[this.index+e]}shift(){this.index+=1}process(e){const t=this.marks[this.index];this.shift();const r=e[t.name];if(!r)throw new Error(`Unknown handler: ${t.name}`);return r.call(e,this,t)}processString(){return this.shift(),this.processStringEnd()}processStringEnd(){const e=this.marks[this.index-1],t=this.marks[this.index];return this.shift(),this.string.slice(e.position,t.position)}slice(e){const t=this.marks[this.index].position;return this.string.slice(t,t+e)}}const X=/^([\t\n\v\f\r \u0085\u00A0]|(\/\/[^\n]*\n))+/,ee=/^\d+/,te=/^[a-zA-Z_][a-zA-Z_0-9]*/;function re(e,t,r){let n,o=t;switch(e[t]){case"+":{let r=re(e,se(e,t+1),10);if("error"===r.type)return r;n=[{name:"pos",position:o}].concat(r.marks),t=r.position;break}case"-":{let r=re(e,se(e,t+1),8);if("error"===r.type)return r;n=[{name:"neg",position:o}].concat(r.marks),t=r.position;break}case"(":{let r=re(e,se(e,t+1),0);if("error"===r.type)return r;switch(e[t=se(e,r.position)]){case",":for(n=[{name:"tuple",position:o}].concat(r.marks),t=se(e,t+1);;){if(r=re(e,t,0),"error"===r.type)return r;if(","!==e[t=se(e,r.position)])break;t=se(e,t+1)}if(")"!==e[t])return{type:"error",position:t};t++,n.push({name:"tuple_end",position:t});break;case")":t++,n=[{name:"group",position:o}].concat(r.marks);break;default:return{type:"error",position:t}}break}case"!":{let r=re(e,se(e,t+1),10);if("error"===r.type)return r;n=[{name:"not",position:o}].concat(r.marks),t=r.position;break}case"{":{let r=ie(e,t);if("error"===r.type)return r;n=r.marks,t=r.position;break}case"[":if(n=[{name:"array",position:t}],"]"!==e[t=se(e,t+1)])for(;;){"..."===e.slice(t,t+3)&&(n.push({name:"array_splat",position:t}),t=se(e,t+3));let r=re(e,t,0);if("error"===r.type)return r;if(n=n.concat(r.marks),","!==e[t=se(e,t=r.position)]||"]"===e[t=se(e,t+1)])break}if("]"!==e[t])return{type:"error",position:t};t++,n.push({name:"array_end",position:t});break;case"'":case'"':{let r=function(e,t){let r=e[t];t+=1;const n=[{name:"str",position:t}];e:for(;;t++){if(t>e.length)return{type:"error",position:t};switch(e[t]){case r:n.push({name:"str_end",position:t}),t++;break e;case"\\":n.push({name:"str_pause",position:t}),"u"===e[t+1]?"{"===e[t+2]?(n.push({name:"unicode_hex",position:t+3}),t=e.indexOf("}",t+3),n.push({name:"unicode_hex_end",position:t})):(n.push({name:"unicode_hex",position:t+2}),n.push({name:"unicode_hex_end",position:t+6}),t+=5):(n.push({name:"single_escape",position:t+1}),t+=1),n.push({name:"str_start",position:t+1})}}return{type:"success",marks:n,position:t}}(e,t);if("error"===r.type)return r;n=r.marks,t=r.position;break}case"^":for(t++,n=[];"."===e[t]&&"^"===e[t+1];)n.push({name:"dblparent",position:o}),t+=2;n.push({name:"parent",position:o});break;case"@":n=[{name:"this",position:o}],t++;break;case"*":n=[{name:"everything",position:o}],t++;break;case"$":{let r=ae(e,t+1,te);r&&(n=[{name:"param",position:o},{name:"ident",position:o+1},{name:"ident_end",position:t+=1+r}]);break}default:{let r=ae(e,t,ee);if(r){let i="integer";if("."===e[t+=r]){let r=ae(e,t+1,ee);r&&(i="float",t+=1+r)}if("e"===e[t]||"E"===e[t]){i="sci",("+"===e[++t]||"-"===e[t])&&t++;let r=ae(e,t,ee);if(!r)return{type:"error",position:t};t+=r}n=[{name:i,position:o},{name:i+"_end",position:t}];break}let i=ae(e,t,te);if(i){switch(e[t+=i]){case":":case"(":{let r=oe(e,o,t);if("error"===r.type)return r;n=r.marks,t=r.position;break}default:n=[{name:"this_attr",position:o},{name:"ident",position:o},{name:"ident_end",position:t}]}break}}}if(!n)return{type:"error",position:t};let i,s=12;e:for(;;){let a=se(e,t);if(a===e.length){t=a;break}if(i=ne(e,a),"success"!==i.type)switch(e[a]){case"=":switch(e[a+1]){case">":{if(r>1||s<=1)break e;let i=re(e,se(e,a+2),1);if("error"===i.type)return i;n=n.concat(i.marks),n.unshift({name:"pair",position:o}),t=i.position,s=1;break}case"=":{if(r>4||s<=4)break e;let i=re(e,se(e,a+2),5);if("error"===i.type)return i;n.unshift({name:"comp",position:o}),n.push({name:"op",position:a},{name:"op_end",position:a+2}),n=n.concat(i.marks),t=i.position,s=4;break}default:break e}break;case"+":{if(r>6||s<6)break e;let i=re(e,se(e,a+1),7);if("error"===i.type)return i;n=n.concat(i.marks),n.unshift({name:"add",position:o}),t=i.position,s=6;break}case"-":{if(r>6||s<6)break e;let i=re(e,se(e,a+1),7);if("error"===i.type)return i;n=n.concat(i.marks),n.unshift({name:"sub",position:o}),t=i.position,s=6;break}case"*":{if("*"===e[a+1]){if(r>8||s<=8)break e;let i=re(e,se(e,a+2),8);if("error"===i.type)return i;n=n.concat(i.marks),n.unshift({name:"pow",position:o}),t=i.position,s=8;break}if(r>7||s<7)break e;let i=re(e,se(e,a+1),8);if("error"===i.type)return i;n=n.concat(i.marks),n.unshift({name:"mul",position:o}),t=i.position,s=7;break}case"/":{if(r>7||s<7)break e;let i=re(e,se(e,a+1),8);if("error"===i.type)return i;n=n.concat(i.marks),n.unshift({name:"div",position:o}),t=i.position,s=7;break}case"%":{if(r>7||s<7)break e;let i=re(e,se(e,a+1),8);if("error"===i.type)return i;n=n.concat(i.marks),n.unshift({name:"mod",position:o}),t=i.position,s=7;break}case"<":case">":{if(r>4||s<=4)break e;let i=a+1;"="===e[i]&&i++;let c=re(e,se(e,i),5);if("error"===c.type)return c;n.unshift({name:"comp",position:o}),n.push({name:"op",position:a},{name:"op_end",position:i}),n=n.concat(c.marks),t=c.position,s=4;break}case"|":if("|"===e[a+1]){if(r>2||s<2)break e;let i=re(e,se(e,a+2),3);if("error"===i.type)return i;n=n.concat(i.marks),n.unshift({name:"or",position:o}),t=i.position,s=2}else{if(r>11||s<11)break e;let i=se(e,a+1),c=ae(e,i,te);if(!c)return{type:"error",position:i};if("("===e[t=i+c]||":"===e[t]){let r=oe(e,i,t);if("error"===r.type)return r;n=n.concat(r.marks),n.unshift({name:"pipecall",position:o}),t=r.position,s=11}}break;case"&":{if("&"!=e[a+1]||r>3||s<3)break e;let i=re(e,se(e,a+2),4);if("error"===i.type)return i;n=n.concat(i.marks),n.unshift({name:"and",position:o}),t=i.position,s=3;break}case"!":{if("="!==e[a+1]||r>4||s<=4)break e;let i=re(e,se(e,a+2),5);if("error"===i.type)return i;n.unshift({name:"comp",position:o}),n.push({name:"op",position:a},{name:"op_end",position:a+2}),n=n.concat(i.marks),t=i.position,s=4;break}case"d":if("desc"!==e.slice(a,a+4)||r>4||s<4)break e;n.unshift({name:"desc",position:o}),t=a+4,s=4;break;case"a":if("asc"!==e.slice(a,a+3)||r>4||s<4)break e;n.unshift({name:"asc",position:o}),t=a+3,s=4;break;default:switch(ce(e,a,te)){case"in":{if(r>4||s<=4)break e;let i=!1;"("===e[t=se(e,a+2)]&&(i=!0,t=se(e,t+1));let c=t,u=re(e,t,5);if("error"===u.type)return u;if("."===e[t=se(e,u.position)]&&"."===e[t+1]){let r="inc_range";"."===e[t+2]?(r="exc_range",t=se(e,t+3)):t=se(e,t+2);let i=re(e,t,5);if("error"===i.type)return i;n.unshift({name:"in_range",position:o}),n=n.concat({name:r,position:c},u.marks,i.marks),t=i.position}else n.unshift({name:"comp",position:o}),n.push({name:"op",position:a},{name:"op_end",position:a+2}),n=n.concat(u.marks);if(i){if(")"!==e[t=se(e,t)])return{type:"error",position:t};t++}s=4;break}case"match":{if(r>4||s<=4)break e;let i=re(e,se(e,a+5),5);if("error"===i.type)return i;n.unshift({name:"comp",position:o}),n.push({name:"op",position:a},{name:"op_end",position:a+5}),n=n.concat(i.marks),t=i.position,s=4;break}default:break e}}else{for(n.unshift({name:"traverse",position:o});"success"===i.type;)n=n.concat(i.marks),i=ne(e,se(e,t=i.position));n.push({name:"traversal_end",position:t})}}return{type:"success",marks:n,position:t,failPosition:"error"===i?.type&&i.position}}function ne(e,t){let r=t;switch(e[t]){case".":{let n=t=se(e,t+1),o=ae(e,t,te);return o?{type:"success",marks:[{name:"attr_access",position:r},{name:"ident",position:n},{name:"ident_end",position:t+=o}],position:t}:{type:"error",position:t}}case"-":if(">"!==e[t+1])return{type:"error",position:t};let n=[{name:"deref",position:r}],o=se(e,t+=2),i=ae(e,o,te);return i&&(t=o+i,n.push({name:"deref_attr",position:o},{name:"ident",position:o},{name:"ident_end",position:t})),{type:"success",marks:n,position:t};case"[":{if("]"===e[t=se(e,t+1)])return{type:"success",marks:[{name:"array_postfix",position:r}],position:t+1};let n=t,o=re(e,t,0);if("error"===o.type)return o;if("."===e[t=se(e,o.position)]&&"."===e[t+1]){let i="inc_range";"."===e[t+2]?(i="exc_range",t+=3):t+=2;let s=re(e,t=se(e,t),0);return"error"===s.type?s:"]"!==e[t=se(e,s.position)]?{type:"error",position:t}:{type:"success",marks:[{name:"slice",position:r},{name:i,position:n}].concat(o.marks,s.marks),position:t+1}}return"]"!==e[t]?{type:"error",position:t}:{type:"success",marks:[{name:"square_bracket",position:r}].concat(o.marks),position:t+1}}case"|":if("{"===e[t=se(e,t+1)]){let n=ie(e,t);return"error"===n.type||n.marks.unshift({name:"projection",position:r}),n}break;case"{":{let n=ie(e,t);return"error"===n.type||n.marks.unshift({name:"projection",position:r}),n}}return{type:"error",position:t}}function oe(e,t,r){let n=[];if(n.push({name:"func_call",position:t}),":"===e[r]&&":"===e[r+1]){n.push({name:"namespace",position:t}),n.push({name:"ident",position:t},{name:"ident_end",position:r});let o=ae(e,r=se(e,r+2),te);if(!o)return{type:"error",position:r};if(n.push({name:"ident",position:r},{name:"ident_end",position:r+o}),"("!==e[r=se(e,r+o)])return{type:"error",position:r};r=se(e,++r)}else n.push({name:"ident",position:t},{name:"ident_end",position:r}),r=se(e,r+1);let o=r;if(")"!==e[r])for(;;){let t=re(e,r,0);if("error"===t.type)return t;if(n=n.concat(t.marks),o=t.position,","!==e[r=se(e,t.position)]||")"===e[r=se(e,r+1)])break}return")"!==e[r]?{type:"error",position:r}:(n.push({name:"func_args_end",position:o}),{type:"success",marks:n,position:r+1})}function ie(e,t){let r=[{name:"object",position:t}];for(t=se(e,t+1);"}"!==e[t];){let n=t;if("..."===e.slice(t,t+3))if("}"!==e[t=se(e,t+3)]&&","!==e[t]){let o=re(e,t,0);if("error"===o.type)return o;r.push({name:"object_splat",position:n}),r=r.concat(o.marks),t=o.position}else r.push({name:"object_splat_this",position:n});else{let o=re(e,t,0);if("error"===o.type)return o;let i=se(e,o.position);if("str"===o.marks[0].name&&":"===e[i]){let s=re(e,se(e,i+1),0);if("error"===s.type)return s;r.push({name:"object_pair",position:n}),r=r.concat(o.marks,s.marks),t=s.position}else r=r.concat({name:"object_expr",position:t},o.marks),t=o.position}if(","!==e[t=se(e,t)])break;t=se(e,t+1)}return"}"!==e[t]?{type:"error",position:t}:(t++,r.push({name:"object_end",position:t}),{type:"success",marks:r,position:t})}function se(e,t){return t+ae(e,t,X)}function ae(e,t,r){let n=r.exec(e.slice(t));return n?n[0].length:0}function ce(e,t,r){let n=r.exec(e.slice(t));return n?n[0]:null}function ue(e,t){return r=>t(e(r))}function pe(e){return t=>({type:"Map",base:t,expr:e({type:"This"})})}function le(e,t){if(!t)return{type:"a-a",build:e};switch(t.type){case"a-a":return{type:"a-a",build:ue(e,t.build)};case"a-b":return{type:"a-b",build:ue(e,t.build)};case"b-b":return{type:"a-a",build:ue(e,pe(t.build))};case"b-a":return{type:"a-a",build:ue(e,(r=t.build,e=>({type:"FlatMap",base:e,expr:r({type:"This"})})))};default:throw new Error(`unknown type: ${t.type}`)}var r}function fe(e,t){if(!t)return{type:"b-b",build:e};switch(t.type){case"a-a":case"b-a":return{type:"b-a",build:ue(e,t.build)};case"a-b":case"b-b":return{type:"b-b",build:ue(e,t.build)};default:throw new Error(`unknown type: ${t.type}`)}}const ye={"'":"'",'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:"\n",r:"\r",t:"\t"};function de(e){const t=parseInt(e,16);return String.fromCharCode(t)}class he extends Error{name="GroqQueryError"}const me={group:e=>({type:"Group",base:e.process(me)}),everything:()=>({type:"Everything"}),this:()=>({type:"This"}),parent:()=>({type:"Parent",n:1}),dblparent:e=>({type:"Parent",n:e.process(me).n+1}),traverse(e){const t=e.process(me),r=[];for(;"traversal_end"!==e.getMark().name;)r.push(e.process(ge));e.shift();let n=null;for(let e=r.length-1;e>=0;e--)n=r[e](n);if(("Everything"===t.type||"Array"===t.type||"PipeFuncCall"===t.type)&&(n=le((e=>e),n)),null===n)throw new Error("BUG: unexpected empty traversal");return n.build(t)},this_attr(e){const t=e.processString();return"null"===t?{type:"Value",value:null}:"true"===t?{type:"Value",value:!0}:"false"===t?{type:"Value",value:!1}:{type:"AccessAttribute",name:t}},neg:e=>({type:"Neg",base:e.process(me)}),pos:e=>({type:"Pos",base:e.process(me)}),add:e=>({type:"OpCall",op:"+",left:e.process(me),right:e.process(me)}),sub:e=>({type:"OpCall",op:"-",left:e.process(me),right:e.process(me)}),mul:e=>({type:"OpCall",op:"*",left:e.process(me),right:e.process(me)}),div:e=>({type:"OpCall",op:"/",left:e.process(me),right:e.process(me)}),mod:e=>({type:"OpCall",op:"%",left:e.process(me),right:e.process(me)}),pow:e=>({type:"OpCall",op:"**",left:e.process(me),right:e.process(me)}),comp(e){const t=e.process(me);return{type:"OpCall",op:e.processString(),left:t,right:e.process(me)}},in_range(e){const t=e.process(me),r="inc_range"===e.getMark().name;e.shift();return{type:"InRange",base:t,left:e.process(me),right:e.process(me),isInclusive:r}},str(e){let t="";e:for(;e.hasMark();){const r=e.getMark();switch(r.name){case"str_end":t+=e.processStringEnd();break e;case"str_pause":t+=e.processStringEnd();break;case"str_start":e.shift();break;case"single_escape":{const r=e.slice(1);e.shift(),t+=ye[r];break}case"unicode_hex":e.shift(),t+=de(e.processStringEnd());break;default:throw new Error(`unexpected mark: ${r.name}`)}}return{type:"Value",value:t}},integer(e){const t=e.processStringEnd();return{type:"Value",value:Number(t)}},float(e){const t=e.processStringEnd();return{type:"Value",value:Number(t)}},sci(e){const t=e.processStringEnd();return{type:"Value",value:Number(t)}},object(e){const t=[];for(;"object_end"!==e.getMark().name;)t.push(e.process(be));return e.shift(),{type:"Object",attributes:t}},array(e){const t=[];for(;"array_end"!==e.getMark().name;){let r=!1;"array_splat"===e.getMark().name&&(r=!0,e.shift());const n=e.process(me);t.push({type:"ArrayElement",value:n,isSplat:r})}return e.shift(),{type:"Array",elements:t}},tuple(e){const t=[];for(;"tuple_end"!==e.getMark().name;)t.push(e.process(me));return e.shift(),{type:"Tuple",members:t}},func_call(e){let t="global";"namespace"===e.getMark().name&&(e.shift(),t=e.processString());const r=e.processString();if("global"===t&&"select"===r){const t={type:"Select",alternatives:[]};for(;"func_args_end"!==e.getMark().name;)if("pair"===e.getMark().name){if(t.fallback)throw new he("unexpected argument to select()");e.shift();const r=e.process(me),n=e.process(me);t.alternatives.push({type:"SelectAlternative",condition:r,value:n})}else{if(t.fallback)throw new he("unexpected argument to select()");const r=e.process(me);t.fallback=r}return e.shift(),t}const n=[];for(;"func_args_end"!==e.getMark().name;)xe(t,r,n.length)?(e.process(we),n.push({type:"Selector"})):n.push(e.process(me));if(e.shift(),"global"===t&&("before"===r||"after"===r)&&"delta"===e.parseOptions.mode)return{type:"Context",key:r};if("global"===t&&"boost"===r&&!e.allowBoost)throw new he("unexpected boost");const o=Y[t];if(!o)throw new he(`Undefined namespace: ${t}`);const i=o[r];if(!i)throw new he(`Undefined function: ${r}`);if(void 0!==i.arity&&ve(r,i.arity,n.length),void 0!==i.mode&&i.mode!==e.parseOptions.mode)throw new he(`Undefined function: ${r}`);return{type:"FuncCall",func:i,namespace:t,name:r,args:n}},pipecall(e){const t=e.process(me);e.shift();let r="global";if("namespace"===e.getMark().name&&(e.shift(),r=e.processString()),"global"!==r)throw new he(`Undefined namespace: ${r}`);const n=e.processString(),o=[],i=e.allowBoost;for("score"===n&&(e.allowBoost=!0);;){const t=e.getMark().name;if("func_args_end"===t)break;if("order"===n){if("asc"===t){e.shift(),o.push({type:"Asc",base:e.process(me)});continue}if("desc"===t){e.shift(),o.push({type:"Desc",base:e.process(me)});continue}}o.push(e.process(me))}e.shift(),e.allowBoost=i;const s=Z[n];if(!s)throw new he(`Undefined pipe function: ${n}`);return s.arity&&ve(n,s.arity,o.length),{type:"PipeFuncCall",func:s,base:t,name:n,args:o}},pair(){throw new he("unexpected =>")},and:e=>({type:"And",left:e.process(me),right:e.process(me)}),or:e=>({type:"Or",left:e.process(me),right:e.process(me)}),not:e=>({type:"Not",base:e.process(me)}),asc(){throw new he("unexpected asc")},desc(){throw new he("unexpected desc")},param(e){const t=e.processString();return e.parseOptions.params&&e.parseOptions.params.hasOwnProperty(t)?{type:"Value",value:e.parseOptions.params[t]}:{type:"Parameter",name:t}}},be={object_expr(e){if("pair"===e.getMark().name){e.shift();return{type:"ObjectConditionalSplat",condition:e.process(me),value:e.process(me)}}const t=e.process(me);return{type:"ObjectAttributeValue",name:ke(t),value:t}},object_pair(e){const t=e.process(me);if("Value"!==t.type)throw new Error("name must be string");const r=e.process(me);return{type:"ObjectAttributeValue",name:t.value,value:r}},object_splat:e=>({type:"ObjectSplat",value:e.process(me)}),object_splat_this:()=>({type:"ObjectSplat",value:{type:"This"}})},ge={square_bracket(e){const t=e.process(me),r=P(t);return r&&"number"===r.type?e=>function(e,t){if(!t)return{type:"a-b",build:e};switch(t.type){case"a-a":case"b-a":return{type:"a-a",build:ue(e,t.build)};case"a-b":case"b-b":return{type:"a-b",build:ue(e,t.build)};default:throw new Error(`unknown type: ${t.type}`)}}((e=>({type:"AccessElement",base:e,index:r.data})),e):r&&"string"===r.type?e=>fe((e=>({type:"AccessAttribute",base:e,name:r.data})),e):e=>le((e=>({type:"Filter",base:e,expr:t})),e)},slice(e){const t="inc_range"===e.getMark().name;e.shift();const r=e.process(me),n=e.process(me),o=P(r),i=P(n);if(!o||!i||"number"!==o.type||"number"!==i.type)throw new he("slicing must use constant numbers");return e=>le((e=>({type:"Slice",base:e,left:o.data,right:i.data,isInclusive:t})),e)},projection(e){const t=e.process(me);return e=>function(e,t){if(!t)return{type:"b-b",build:e};switch(t.type){case"a-a":return{type:"a-a",build:ue(pe(e),t.build)};case"a-b":return{type:"a-b",build:ue(pe(e),t.build)};case"b-a":return{type:"b-a",build:ue(e,t.build)};case"b-b":return{type:"b-b",build:ue(e,t.build)};default:throw new Error(`unknown type: ${t.type}`)}}((e=>({type:"Projection",base:e,expr:t})),e)},attr_access(e){const t=e.processString();return e=>fe((e=>({type:"AccessAttribute",base:e,name:t})),e)},deref(e){let t=null;"deref_attr"===e.getMark().name&&(e.shift(),t=e.processString());return e=>fe((e=>(e=>t?{type:"AccessAttribute",base:e,name:t}:e)({type:"Deref",base:e})),e)},array_postfix:()=>e=>le((e=>({type:"ArrayCoerce",base:e})),e)},we={group:e=>(e.process(we),null),everything(){throw new Error("Invalid selector syntax")},this(){throw new Error("Invalid selector syntax")},parent(){throw new Error("Invalid selector syntax")},dblparent(){throw new Error("Invalid selector syntax")},traverse(e){for(e.process(we);"traversal_end"!==e.getMark().name;)e.process(ge);return e.shift(),null},this_attr:e=>(e.processString(),null),neg(){throw new Error("Invalid selector syntax")},pos(){throw new Error("Invalid selector syntax")},add(){throw new Error("Invalid selector syntax")},sub(){throw new Error("Invalid selector syntax")},mul(){throw new Error("Invalid selector syntax")},div(){throw new Error("Invalid selector syntax")},mod(){throw new Error("Invalid selector syntax")},pow(){throw new Error("Invalid selector syntax")},comp(){throw new Error("Invalid selector syntax")},in_range(){throw new Error("Invalid selector syntax")},str(){throw new Error("Invalid selector syntax")},integer(){throw new Error("Invalid selector syntax")},float(){throw new Error("Invalid selector syntax")},sci(){throw new Error("Invalid selector syntax")},object(){throw new Error("Invalid selector syntax")},array(){throw new Error("Invalid selector syntax")},tuple(){throw new Error("Invalid selector syntax")},func_call(e,t){const r=me.func_call(e,t);if("anywhere"===r.name&&1===r.args.length)return null;throw new Error("Invalid selector syntax")},pipecall(){throw new Error("Invalid selector syntax")},pair(){throw new Error("Invalid selector syntax")},and(){throw new Error("Invalid selector syntax")},or(){throw new Error("Invalid selector syntax")},not(){throw new Error("Invalid selector syntax")},asc(){throw new Error("Invalid selector syntax")},desc(){throw new Error("Invalid selector syntax")},param(){throw new Error("Invalid selector syntax")}};function ke(e){if("AccessAttribute"===e.type&&!e.base)return e.name;if("PipeFuncCall"===e.type||"Deref"===e.type||"Map"===e.type||"Projection"===e.type||"Slice"===e.type||"Filter"===e.type||"AccessElement"===e.type||"ArrayCoerce"===e.type||"Group"===e.type)return ke(e.base);throw new he(`Cannot determine property key for type: ${e.type}`)}function ve(e,t,r){if("number"==typeof t){if(r!==t)throw new he(`Incorrect number of arguments to function ${e}(). Expected ${t}, got ${r}.`)}else if(t&&!t(r))throw new he(`Incorrect number of arguments to function ${e}().`)}function xe(e,t,r){return"diff"==e&&2==r&&["changedAny","changedOnly"].includes(t)}class _e extends Error{position;name="GroqSyntaxError";constructor(e){super(`Syntax error in GROQ query at position ${e}`),this.position=e}}function Ae(e,t={}){const r=function(e){let t=0;t=se(e,t);let r=re(e,t,0);return"error"===r.type?r:(t=se(e,r.position),t!==e.length?(r.failPosition&&(t=r.failPosition-1),{type:"error",position:t}):(delete r.position,delete r.failPosition,r))}(e);if("error"===r.type)throw new _e(r.position);return new K(e,r.marks,t).process(me)}export{C as evaluateSync,Ae as parse};
@@ -1,12 +1,13 @@
1
- import {getAuthState} from '@sanity/sdk'
1
+ import {type AuthState, getAuthState} from '@sanity/sdk'
2
2
 
3
3
  import {createStateSourceHook} from '../helpers/createStateSourceHook'
4
4
 
5
5
  /**
6
+ * @internal
6
7
  * A React hook that subscribes to authentication state changes.
7
8
  *
8
9
  * This hook provides access to the current authentication state type from the Sanity auth store.
9
- * It automatically re-renders the component when the authentication state changes.
10
+ * It automatically re-renders when the authentication state changes.
10
11
  *
11
12
  * @remarks
12
13
  * The hook uses `useSyncExternalStore` to safely subscribe to auth state changes
@@ -21,7 +22,5 @@ import {createStateSourceHook} from '../helpers/createStateSourceHook'
21
22
  * return <div>Current auth state: {authState}</div>
22
23
  * }
23
24
  * ```
24
- *
25
- * @public
26
25
  */
27
- export const useAuthState = createStateSourceHook(getAuthState)
26
+ export const useAuthState: () => AuthState = createStateSourceHook(getAuthState)
@@ -4,7 +4,7 @@ import {createStateSourceHook} from '../helpers/createStateSourceHook'
4
4
 
5
5
  /**
6
6
  * Hook to get the currently logged in user
7
- * @public
7
+ * @internal
8
8
  * @returns The current user or null if not authenticated
9
9
  */
10
10
  export const useAuthToken = createStateSourceHook(getTokenState)