over-zero 0.0.34 → 0.0.35

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 (44) hide show
  1. package/dist/cjs/createUseQuery.cjs +72 -0
  2. package/dist/cjs/createUseQuery.js +46 -0
  3. package/dist/cjs/createUseQuery.js.map +6 -0
  4. package/dist/cjs/createUseQuery.native.js +88 -0
  5. package/dist/cjs/createUseQuery.native.js.map +1 -0
  6. package/dist/cjs/createZeroClient.cjs +9 -35
  7. package/dist/cjs/createZeroClient.js +7 -17
  8. package/dist/cjs/createZeroClient.js.map +2 -2
  9. package/dist/cjs/createZeroClient.native.js +8 -46
  10. package/dist/cjs/createZeroClient.native.js.map +1 -1
  11. package/dist/cjs/index.cjs +1 -0
  12. package/dist/cjs/index.js +1 -0
  13. package/dist/cjs/index.js.map +1 -1
  14. package/dist/cjs/index.native.js +1 -0
  15. package/dist/cjs/index.native.js.map +1 -1
  16. package/dist/esm/createUseQuery.js +34 -0
  17. package/dist/esm/createUseQuery.js.map +6 -0
  18. package/dist/esm/createUseQuery.mjs +49 -0
  19. package/dist/esm/createUseQuery.mjs.map +1 -0
  20. package/dist/esm/createUseQuery.native.js +62 -0
  21. package/dist/esm/createUseQuery.native.js.map +1 -0
  22. package/dist/esm/createZeroClient.js +9 -20
  23. package/dist/esm/createZeroClient.js.map +1 -1
  24. package/dist/esm/createZeroClient.mjs +10 -36
  25. package/dist/esm/createZeroClient.mjs.map +1 -1
  26. package/dist/esm/createZeroClient.native.js +10 -48
  27. package/dist/esm/createZeroClient.native.js.map +1 -1
  28. package/dist/esm/index.js +1 -0
  29. package/dist/esm/index.js.map +1 -1
  30. package/dist/esm/index.mjs +1 -0
  31. package/dist/esm/index.mjs.map +1 -1
  32. package/dist/esm/index.native.js +1 -0
  33. package/dist/esm/index.native.js.map +1 -1
  34. package/package.json +1 -1
  35. package/readme.md +23 -0
  36. package/src/createUseQuery.tsx +141 -0
  37. package/src/createZeroClient.tsx +16 -115
  38. package/src/index.ts +1 -0
  39. package/types/createUseQuery.d.ts +22 -0
  40. package/types/createUseQuery.d.ts.map +1 -0
  41. package/types/createZeroClient.d.ts +4 -16
  42. package/types/createZeroClient.d.ts.map +1 -1
  43. package/types/index.d.ts +1 -0
  44. package/types/index.d.ts.map +1 -1
@@ -0,0 +1,141 @@
1
+ import { syncedQuery } from '@rocicorp/zero'
2
+ import { useQuery as zeroUseQuery } from '@rocicorp/zero/react'
3
+ import { use, useMemo, type Context } from 'react'
4
+
5
+ import { useZeroDebug } from './helpers/useZeroDebug'
6
+ import { getQueryName } from './queryRegistry'
7
+
8
+ import type {
9
+ HumanReadable,
10
+ Query,
11
+ ReadonlyJSONValue,
12
+ SyncedQuery,
13
+ Schema as ZeroSchema,
14
+ } from '@rocicorp/zero'
15
+
16
+ export type UseQueryOptions = {
17
+ enabled?: boolean | undefined
18
+ ttl?: 'always' | 'never' | number | undefined
19
+ }
20
+
21
+ type QueryResultDetails = ReturnType<typeof zeroUseQuery>[1]
22
+ export type QueryResult<TReturn> = readonly [HumanReadable<TReturn>, QueryResultDetails]
23
+
24
+ export type PlainQueryFn<
25
+ TArg = any,
26
+ TReturn extends Query<any, any, any> = Query<any, any, any>,
27
+ > = (args: TArg) => TReturn
28
+
29
+ // inline query type - only available when DisableInline is false
30
+ type InlineQuery<
31
+ Schema extends ZeroSchema,
32
+ TTable extends keyof Schema['tables'] & string,
33
+ TReturn,
34
+ > =
35
+ | Query<Schema, TTable, TReturn>
36
+ | SyncedQuery<any, any, any, any, Query<Schema, TTable, TReturn>>
37
+
38
+ // the useQuery hook type with conditional inline overload
39
+ export type UseQueryHook<
40
+ Schema extends ZeroSchema,
41
+ DisableInline extends boolean = false,
42
+ > = {
43
+ // overload 1: inline query (only when DisableInline is false)
44
+ <TTable extends keyof Schema['tables'] & string, TReturn>(
45
+ query: DisableInline extends true ? never : InlineQuery<Schema, TTable, TReturn>,
46
+ options?: UseQueryOptions | boolean
47
+ ): QueryResult<TReturn>;
48
+
49
+ // overload 2: plain function with params
50
+ <TArg, TTable extends keyof Schema['tables'] & string, TReturn>(
51
+ fn: PlainQueryFn<TArg, Query<Schema, TTable, TReturn>>,
52
+ params: TArg,
53
+ options?: UseQueryOptions | boolean
54
+ ): QueryResult<TReturn>;
55
+
56
+ // overload 3: plain function with no params
57
+ <TTable extends keyof Schema['tables'] & string, TReturn>(
58
+ fn: PlainQueryFn<void, Query<Schema, TTable, TReturn>>,
59
+ options?: UseQueryOptions | boolean
60
+ ): QueryResult<TReturn>
61
+ }
62
+
63
+ export function createUseQuery<
64
+ Schema extends ZeroSchema,
65
+ const DisableInline extends boolean = false,
66
+ >({
67
+ DisabledContext,
68
+ disableInlineQueries = false as DisableInline,
69
+ }: {
70
+ DisabledContext: Context<boolean>
71
+ disableInlineQueries?: DisableInline
72
+ }): UseQueryHook<Schema, DisableInline> {
73
+ const queryCache = new Map<string, SyncedQuery<any, any, any, any, any>>()
74
+ const parseAny = (x: unknown[]): [ReadonlyJSONValue] => [x[0] as ReadonlyJSONValue]
75
+
76
+ function useQuery(...args: any[]): any {
77
+ const disabled = use(DisabledContext)
78
+ const [queryOrFn, paramsOrOptions, optionsArg] = args
79
+
80
+ // detect which calling pattern is being used
81
+ const isPlainFunction = typeof queryOrFn === 'function' && !('queryName' in queryOrFn)
82
+
83
+ const { actualQuery, options } = useMemo(() => {
84
+ if (!isPlainFunction) {
85
+ // pattern 1: original api - useQuery(query, options)
86
+ return {
87
+ actualQuery: queryOrFn,
88
+ options: paramsOrOptions,
89
+ }
90
+ }
91
+
92
+ const fn = queryOrFn
93
+ const queryName = getQueryName(fn)
94
+
95
+ if (!queryName) {
96
+ throw new Error(`No query name?`)
97
+ }
98
+
99
+ // determine if this is pattern 2 (with params) or pattern 3 (no params)
100
+ const hasParams =
101
+ optionsArg !== undefined ||
102
+ (paramsOrOptions &&
103
+ typeof paramsOrOptions === 'object' &&
104
+ !('enabled' in paramsOrOptions) &&
105
+ !('ttl' in paramsOrOptions))
106
+
107
+ const params = hasParams ? paramsOrOptions : undefined
108
+ const opts = hasParams ? optionsArg : paramsOrOptions
109
+
110
+ let synced = queryCache.get(queryName)
111
+ if (!synced) {
112
+ synced = syncedQuery(queryName, parseAny, (arg: ReadonlyJSONValue) => {
113
+ return fn(arg)
114
+ })
115
+ queryCache.set(queryName, synced)
116
+ }
117
+
118
+ // call the SyncedQuery with params if provided
119
+ const query = params !== undefined ? (synced as any)(params) : synced
120
+
121
+ return { actualQuery: query, options: opts }
122
+ }, [queryOrFn, paramsOrOptions, optionsArg, isPlainFunction])
123
+
124
+ console.info('running', { actualQuery, options, queryOrFn })
125
+
126
+ const out = zeroUseQuery(actualQuery, options)
127
+
128
+ if (process.env.NODE_ENV === 'development') {
129
+ // eslint-disable-next-line react-hooks/rules-of-hooks
130
+ useZeroDebug(actualQuery, options, out)
131
+ }
132
+
133
+ if (disabled) {
134
+ return [null, { type: 'unknown' }] as never
135
+ }
136
+
137
+ return out
138
+ }
139
+
140
+ return useQuery as UseQueryHook<Schema, DisableInline>
141
+ }
@@ -1,42 +1,33 @@
1
- import { syncedQuery } from '@rocicorp/zero'
2
- import { useZero, ZeroProvider, useQuery as zeroUseQuery } from '@rocicorp/zero/react'
1
+ import { useZero, ZeroProvider } from '@rocicorp/zero/react'
3
2
  import { createEmitter, mapObject } from '@vxrn/helpers'
4
3
  import { createContext, use, useMemo, type ReactNode } from 'react'
5
4
 
6
5
  import { createPermissions } from './createPermissions'
6
+ import { createUseQuery } from './createUseQuery'
7
7
  import { createMutators } from './helpers/createMutators'
8
8
  import { prettyFormatZeroQuery } from './helpers/prettyFormatZeroQuery'
9
- import { useZeroDebug } from './helpers/useZeroDebug'
10
- import { registerQuery, getQueryName } from './queryRegistry'
9
+ import { registerQuery } from './queryRegistry'
11
10
  import { setAuthData, setSchema } from './state'
12
11
 
13
12
  import type { AuthData, GenericModels, GetZeroMutators, ZeroEvent } from './types'
14
- import type {
15
- HumanReadable,
16
- Query,
17
- ReadonlyJSONValue,
18
- Row,
19
- SyncedQuery,
20
- Zero,
21
- ZeroOptions,
22
- Schema as ZeroSchema,
23
- } from '@rocicorp/zero'
24
-
25
- // grouped queries: { namespace: { queryName: queryFn } }
26
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
13
+ import type { Row, Zero, ZeroOptions, Schema as ZeroSchema } from '@rocicorp/zero'
14
+
27
15
  export type GroupedQueries = Record<string, Record<string, (...args: any[]) => any>>
28
16
 
29
17
  export function createZeroClient<
30
18
  Schema extends ZeroSchema,
31
19
  Models extends GenericModels,
20
+ const DisableInlineQueries extends boolean = false,
32
21
  >({
33
22
  schema,
34
23
  models,
35
24
  groupedQueries,
25
+ disableInlineQueries = false as DisableInlineQueries,
36
26
  }: {
37
27
  schema: Schema
38
28
  models: Models
39
29
  groupedQueries: GroupedQueries
30
+ disableInlineQueries?: DisableInlineQueries
40
31
  }) {
41
32
  type ZeroMutators = GetZeroMutators<Models>
42
33
  type ZeroInstance = Zero<Schema, ZeroMutators>
@@ -81,6 +72,11 @@ export function createZeroClient<
81
72
  const AuthDataContext = createContext<AuthData>({} as AuthData)
82
73
  const useAuthData = () => use(AuthDataContext)
83
74
 
75
+ const useQuery = createUseQuery<Schema, DisableInlineQueries>({
76
+ DisabledContext,
77
+ disableInlineQueries,
78
+ })
79
+
84
80
  // we don't want flickers as you move around and these queries are re-run
85
81
  // and things generally aren't changing with permissions rapidly, so lets
86
82
  // cache the last results and use that when first rendering, they will
@@ -113,7 +109,9 @@ export function createZeroClient<
113
109
  })
114
110
  })()
115
111
 
116
- const [data, status] = useQuery(query, {
112
+ // note: usePermission is internal and uses inline queries intentionally
113
+ // if disableInlineQueries is enabled, this will error and need a cast
114
+ const [data, status] = useQuery(query as any, {
117
115
  enabled: Boolean(enabled && permission && authData && objOrId),
118
116
  })
119
117
 
@@ -136,103 +134,6 @@ export function createZeroClient<
136
134
  return allowed
137
135
  }
138
136
 
139
- type PlainQueryFn<
140
- TArg = any,
141
- TReturn extends Query<any, any, any> = Query<any, any, any>,
142
- > = (args: TArg) => TReturn
143
-
144
- type UseQueryOptions = {
145
- enabled?: boolean | undefined
146
- ttl?: 'always' | 'never' | number | undefined
147
- }
148
-
149
- type QueryResultDetails = ReturnType<typeof zeroUseQuery>[1]
150
- type QueryResult<TReturn> = readonly [HumanReadable<TReturn>, QueryResultDetails]
151
-
152
- const queryCache = new Map<string, SyncedQuery<any, any, any, any, any>>()
153
-
154
- const parseAny = (x: unknown[]): [ReadonlyJSONValue] => [x[0] as ReadonlyJSONValue]
155
-
156
- // Overload 1: Original API - Query or SyncedQuery with options
157
- function useQuery<TTable extends keyof Schema['tables'] & string, TReturn>(
158
- query:
159
- | Query<Schema, TTable, TReturn>
160
- | SyncedQuery<any, any, any, any, Query<Schema, TTable, TReturn>>,
161
- options?: UseQueryOptions | boolean
162
- ): QueryResult<TReturn>
163
-
164
- // Overload 2: Plain function with params
165
- function useQuery<TArg, TTable extends keyof Schema['tables'] & string, TReturn>(
166
- fn: PlainQueryFn<TArg, Query<Schema, TTable, TReturn>>,
167
- params: TArg,
168
- options?: UseQueryOptions | boolean
169
- ): QueryResult<TReturn>
170
-
171
- // Overload 3: Plain function with no params
172
- function useQuery<TTable extends keyof Schema['tables'] & string, TReturn>(
173
- fn: PlainQueryFn<void, Query<Schema, TTable, TReturn>>,
174
- options?: UseQueryOptions | boolean
175
- ): QueryResult<TReturn>
176
-
177
- // Implementation - keep it simple with any
178
- function useQuery(...args: any[]): any {
179
- const disabled = use(DisabledContext)
180
- const [queryOrFn, paramsOrOptions, optionsArg] = args
181
-
182
- // Detect which calling pattern is being used
183
- const isPlainFunction = typeof queryOrFn === 'function' && !('queryName' in queryOrFn)
184
-
185
- const { actualQuery, options } = useMemo(() => {
186
- if (!isPlainFunction) {
187
- // Pattern 1: Original API - useQuery(query, options)
188
- return {
189
- actualQuery: queryOrFn,
190
- options: paramsOrOptions,
191
- }
192
- }
193
-
194
- const fn = queryOrFn
195
- const queryName = getQueryName(fn) || fn.name || 'anonymousQuery'
196
-
197
- // Determine if this is Pattern 2 (with params) or Pattern 3 (no params)
198
- const hasParams =
199
- optionsArg !== undefined ||
200
- (paramsOrOptions &&
201
- typeof paramsOrOptions === 'object' &&
202
- !('enabled' in paramsOrOptions) &&
203
- !('ttl' in paramsOrOptions))
204
-
205
- const params = hasParams ? paramsOrOptions : undefined
206
- const opts = hasParams ? optionsArg : paramsOrOptions
207
-
208
- let synced = queryCache.get(queryName)
209
- if (!synced) {
210
- synced = syncedQuery(queryName, parseAny, (arg: ReadonlyJSONValue) => {
211
- return fn(arg)
212
- })
213
- queryCache.set(queryName, synced)
214
- }
215
-
216
- // Call the SyncedQuery with params if provided
217
- const query = params !== undefined ? (synced as any)(params) : synced
218
-
219
- return { actualQuery: query, options: opts }
220
- }, [queryOrFn, paramsOrOptions, optionsArg, isPlainFunction])
221
-
222
- const out = zeroUseQuery(actualQuery, options)
223
-
224
- if (process.env.NODE_ENV === 'development') {
225
- // eslint-disable-next-line react-hooks/rules-of-hooks
226
- useZeroDebug(actualQuery, options, out)
227
- }
228
-
229
- if (disabled) {
230
- return [null, { type: 'unknown' }] as never
231
- }
232
-
233
- return out
234
- }
235
-
236
137
  const ProvideZero = ({
237
138
  children,
238
139
  authData: authDataIn,
package/src/index.ts CHANGED
@@ -6,6 +6,7 @@ export * from './helpers/ensureLoggedIn'
6
6
  export * from './helpers/mutatorContext'
7
7
 
8
8
  export * from './createZeroClient'
9
+ export * from './createUseQuery'
9
10
  export * from './mutations'
10
11
  export * from './where'
11
12
  export * from './serverWhere'
@@ -0,0 +1,22 @@
1
+ import { useQuery as zeroUseQuery } from '@rocicorp/zero/react';
2
+ import { type Context } from 'react';
3
+ import type { HumanReadable, Query, SyncedQuery, Schema as ZeroSchema } from '@rocicorp/zero';
4
+ export type UseQueryOptions = {
5
+ enabled?: boolean | undefined;
6
+ ttl?: 'always' | 'never' | number | undefined;
7
+ };
8
+ type QueryResultDetails = ReturnType<typeof zeroUseQuery>[1];
9
+ export type QueryResult<TReturn> = readonly [HumanReadable<TReturn>, QueryResultDetails];
10
+ export type PlainQueryFn<TArg = any, TReturn extends Query<any, any, any> = Query<any, any, any>> = (args: TArg) => TReturn;
11
+ type InlineQuery<Schema extends ZeroSchema, TTable extends keyof Schema['tables'] & string, TReturn> = Query<Schema, TTable, TReturn> | SyncedQuery<any, any, any, any, Query<Schema, TTable, TReturn>>;
12
+ export type UseQueryHook<Schema extends ZeroSchema, DisableInline extends boolean = false> = {
13
+ <TTable extends keyof Schema['tables'] & string, TReturn>(query: DisableInline extends true ? never : InlineQuery<Schema, TTable, TReturn>, options?: UseQueryOptions | boolean): QueryResult<TReturn>;
14
+ <TArg, TTable extends keyof Schema['tables'] & string, TReturn>(fn: PlainQueryFn<TArg, Query<Schema, TTable, TReturn>>, params: TArg, options?: UseQueryOptions | boolean): QueryResult<TReturn>;
15
+ <TTable extends keyof Schema['tables'] & string, TReturn>(fn: PlainQueryFn<void, Query<Schema, TTable, TReturn>>, options?: UseQueryOptions | boolean): QueryResult<TReturn>;
16
+ };
17
+ export declare function createUseQuery<Schema extends ZeroSchema, const DisableInline extends boolean = false>({ DisabledContext, disableInlineQueries, }: {
18
+ DisabledContext: Context<boolean>;
19
+ disableInlineQueries?: DisableInline;
20
+ }): UseQueryHook<Schema, DisableInline>;
21
+ export {};
22
+ //# sourceMappingURL=createUseQuery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createUseQuery.d.ts","sourceRoot":"","sources":["../src/createUseQuery.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,IAAI,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAC/D,OAAO,EAAgB,KAAK,OAAO,EAAE,MAAM,OAAO,CAAA;AAKlD,OAAO,KAAK,EACV,aAAa,EACb,KAAK,EAEL,WAAW,EACX,MAAM,IAAI,UAAU,EACrB,MAAM,gBAAgB,CAAA;AAEvB,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,CAAC,EAAE,OAAO,GAAG,SA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E,OAAO,EAC5D,EAAE,EAAE,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,EACtD,MAAM,EAAE,IAAI,EACZ,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,GAClC,WAAW,CAAC,OAAO,CAAC,CAAC;IAGxB,CAAC,MAAM,SAAS,MAAM,MAAM,CAAC,QAAQ,CAAC,GAAG,MAAM,EAAE,OAAO,EACtD,EAAE,EAAE,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,EACtD,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,GAClC,WAAW,CAAC,OAAO,CAAC,CAAA;CACxB,CAAA;AAED,wBAAgB,cAAc,CAC5B,MAAM,SAAS,UAAU,EACzB,KAAK,CAAC,aAAa,SAAS,OAAO,GAAG,KAAK,EAC3C,EACA,eAAe,EACf,oBAA6C,GAC9C,EAAE;IACD,eAAe,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;IACjC,oBAAoB,CAAC,EAAE,aAAa,CAAA;CACrC,GAAG,YAAY,CAAC,MAAM,EAAE,aAAa,CAAC,CAqEtC"}
@@ -1,11 +1,12 @@
1
1
  import { type ReactNode } from 'react';
2
2
  import type { AuthData, GenericModels, GetZeroMutators, ZeroEvent } from './types';
3
- import type { HumanReadable, Query, Row, SyncedQuery, Zero, ZeroOptions, Schema as ZeroSchema } from '@rocicorp/zero';
3
+ import type { Row, Zero, ZeroOptions, Schema as ZeroSchema } from '@rocicorp/zero';
4
4
  export type GroupedQueries = Record<string, Record<string, (...args: any[]) => any>>;
5
- export declare function createZeroClient<Schema extends ZeroSchema, Models extends GenericModels>({ schema, models, groupedQueries, }: {
5
+ export declare function createZeroClient<Schema extends ZeroSchema, Models extends GenericModels, const DisableInlineQueries extends boolean = false>({ schema, models, groupedQueries, disableInlineQueries, }: {
6
6
  schema: Schema;
7
7
  models: Models;
8
8
  groupedQueries: GroupedQueries;
9
+ disableInlineQueries?: DisableInlineQueries;
9
10
  }): {
10
11
  zeroEvents: import("@vxrn/helpers").Emitter<ZeroEvent | null>;
11
12
  ProvideZero: ({ children, authData: authDataIn, disable, ...props }: Omit<ZeroOptions<Schema, GetZeroMutators<Models>>, "schema" | "mutators"> & {
@@ -13,20 +14,7 @@ export declare function createZeroClient<Schema extends ZeroSchema, Models exten
13
14
  authData?: AuthData | null;
14
15
  disable?: boolean;
15
16
  }) => string | number | bigint | boolean | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | import("react/jsx-runtime").JSX.Element | null | undefined;
16
- useQuery: {
17
- <TTable extends keyof Schema["tables"] & string, TReturn>(query: Query<Schema, TTable, TReturn> | SyncedQuery<any, any, any, any, Query<Schema, TTable, TReturn>>, options?: {
18
- enabled?: boolean | undefined;
19
- ttl?: "always" | "never" | number | undefined;
20
- } | boolean): readonly [HumanReadable<TReturn>, import("@rocicorp/zero/react").QueryResultDetails];
21
- <TArg, TTable extends keyof Schema["tables"] & string, TReturn>(fn: (args: TArg) => Query<Schema, TTable, TReturn>, params: TArg, options?: {
22
- enabled?: boolean | undefined;
23
- ttl?: "always" | "never" | number | undefined;
24
- } | boolean): readonly [HumanReadable<TReturn>, import("@rocicorp/zero/react").QueryResultDetails];
25
- <TTable extends keyof Schema["tables"] & string, TReturn>(fn: (args: void) => Query<Schema, TTable, TReturn>, options?: {
26
- enabled?: boolean | undefined;
27
- ttl?: "always" | "never" | number | undefined;
28
- } | boolean): readonly [HumanReadable<TReturn>, import("@rocicorp/zero/react").QueryResultDetails];
29
- };
17
+ useQuery: import("./createUseQuery").UseQueryHook<Schema, DisableInlineQueries>;
30
18
  usePermission: <K extends keyof Schema["tables"] & string>(table: K, objOrId: string | Partial<Row<Schema["tables"][K]>> | undefined, enabled?: boolean, debug?: boolean) => boolean | null;
31
19
  z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AAG,KAAK,EAClD,EACA,MAAM,EACN,MAAM,EACN,cAAc,EACd,oBAAoD,GACrD,EAAE;IACD,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,cAAc,EAAE,cAAc,CAAA;IAC9B,oBAAoB,CAAC,EAAE,oBAAoB,CAAA;CAC5C;;yEA+GI,IAAI,CAAC,WAAW,CAAC,MAAM,0BAAe,EAAE,QAAQ,GAAG,UAAU,CAAC,GAAG;QAClE,QAAQ,EAAE,SAAS,CAAA;QACnB,QAAQ,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAA;QAC1B,OAAO,CAAC,EAAE,OAAO,CAAA;KAClB;;oBA9DsB,CAAC,iDACf,CAAC,WACC,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,yCAG9D,OAAO,GAAG,IAAI;;EAyHlB"}
package/types/index.d.ts CHANGED
@@ -5,6 +5,7 @@ export * from './helpers/createMutators';
5
5
  export * from './helpers/ensureLoggedIn';
6
6
  export * from './helpers/mutatorContext';
7
7
  export * from './createZeroClient';
8
+ export * from './createUseQuery';
8
9
  export * from './mutations';
9
10
  export * from './where';
10
11
  export * from './serverWhere';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,sBAAsB,CAAA;AACpC,cAAc,0BAA0B,CAAA;AACxC,cAAc,0BAA0B,CAAA;AACxC,cAAc,0BAA0B,CAAA;AAExC,cAAc,oBAAoB,CAAA;AAClC,cAAc,aAAa,CAAA;AAC3B,cAAc,SAAS,CAAA;AACvB,cAAc,eAAe,CAAA;AAC7B,cAAc,OAAO,CAAA;AAErB,mBAAmB,SAAS,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,sBAAsB,CAAA;AACpC,cAAc,0BAA0B,CAAA;AACxC,cAAc,0BAA0B,CAAA;AACxC,cAAc,0BAA0B,CAAA;AAExC,cAAc,oBAAoB,CAAA;AAClC,cAAc,kBAAkB,CAAA;AAChC,cAAc,aAAa,CAAA;AAC3B,cAAc,SAAS,CAAA;AACvB,cAAc,eAAe,CAAA;AAC7B,cAAc,OAAO,CAAA;AAErB,mBAAmB,SAAS,CAAA"}