@instantdb/react-common 0.22.75 → 0.22.76

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instantdb/react-common",
3
- "version": "0.22.75",
3
+ "version": "0.22.76",
4
4
  "description": "Instant DB shared components for React and React Native",
5
5
  "homepage": "https://github.com/instantdb/instant/tree/main/client/packages/react-common",
6
6
  "repository": {
@@ -53,11 +53,12 @@
53
53
  "react": ">=16"
54
54
  },
55
55
  "dependencies": {
56
- "@instantdb/core": "0.22.75",
57
- "@instantdb/version": "0.22.75"
56
+ "@instantdb/core": "0.22.76",
57
+ "@instantdb/version": "0.22.76"
58
58
  },
59
59
  "scripts": {
60
60
  "test": "vitest",
61
+ "check": "tsc --noEmit",
61
62
  "check-exports": "attw --pack .",
62
63
  "dev:module": "tsc --watch --preserveWatchOutput -p tsconfig.dev.json",
63
64
  "dev:main": "tsc --watch --preserveWatchOutput -p tsconfig.cjs.dev.json",
@@ -42,9 +42,10 @@ const defaultAuthState = {
42
42
  export default abstract class InstantReactAbstractDatabase<
43
43
  // need to pull this schema out to another generic for query params, not sure why
44
44
  Schema extends InstantSchemaDef<any, any, any>,
45
- Config extends InstantConfig<Schema, boolean | undefined> = InstantConfig<
45
+ UseDates extends boolean = false,
46
+ Config extends InstantConfig<Schema, boolean> = InstantConfig<
46
47
  Schema,
47
- boolean
48
+ UseDates
48
49
  >,
49
50
  Rooms extends RoomSchemaShape = RoomsOf<Schema>,
50
51
  > implements IInstantDatabase<Schema>
@@ -53,17 +54,22 @@ export default abstract class InstantReactAbstractDatabase<
53
54
 
54
55
  public auth: Auth;
55
56
  public storage: Storage;
56
- public core: InstantCoreDatabase<Schema, Config['useDateObjects']>;
57
+ public core: InstantCoreDatabase<Schema, UseDates>;
57
58
 
58
59
  /** @deprecated use `core` instead */
59
- public _core: InstantCoreDatabase<Schema, Config['useDateObjects']>;
60
+ public _core: InstantCoreDatabase<Schema, UseDates>;
60
61
 
61
62
  static Storage?: any;
62
63
  static NetworkListener?: any;
63
64
  static EventSourceImpl?: any;
64
65
 
65
- constructor(config: Config, versions?: { [key: string]: string }) {
66
- this.core = core_init<Schema, Config['useDateObjects']>(
66
+ constructor(
67
+ config: Omit<InstantConfig<Schema, UseDates>, 'useDateObjects'> & {
68
+ useDateObjects?: UseDates;
69
+ },
70
+ versions?: { [key: string]: string },
71
+ ) {
72
+ this.core = core_init<Schema, UseDates>(
67
73
  config,
68
74
  // @ts-expect-error because TS can't resolve subclass statics
69
75
  this.constructor.Storage,
@@ -207,12 +213,8 @@ export default abstract class InstantReactAbstractDatabase<
207
213
  useQuery = <Q extends ValidQuery<Q, Schema>>(
208
214
  query: null | Q,
209
215
  opts?: InstaQLOptions,
210
- ): InstaQLLifecycleState<Schema, Q, Config['useDateObjects']> => {
211
- return useQueryInternal<Q, Schema, Config['useDateObjects']>(
212
- this.core,
213
- query,
214
- opts,
215
- ).state;
216
+ ): InstaQLLifecycleState<Schema, Q, UseDates> => {
217
+ return useQueryInternal<Q, Schema, UseDates>(this.core, query, opts).state;
216
218
  };
217
219
 
218
220
  /**
@@ -375,7 +377,7 @@ export default abstract class InstantReactAbstractDatabase<
375
377
  query: Q,
376
378
  opts?: InstaQLOptions,
377
379
  ): Promise<{
378
- data: InstaQLResponse<Schema, Q, Config['useDateObjects']>;
380
+ data: InstaQLResponse<Schema, Q, UseDates>;
379
381
  pageInfo: PageInfoResponse<Q>;
380
382
  }> => {
381
383
  return this.core.queryOnce(query, opts);
@@ -245,7 +245,7 @@ export function useTypingIndicator<
245
245
  const timeout = useTimeout();
246
246
 
247
247
  const observedPresence = rooms.usePresence(room, {
248
- keys: [inputName],
248
+ keys: [inputName] as (keyof RoomSchema[RoomType]['presence'])[],
249
249
  });
250
250
 
251
251
  const active = useMemo(() => {
package/src/useQuery.ts CHANGED
@@ -16,7 +16,7 @@ const defaultState = {
16
16
  data: undefined,
17
17
  pageInfo: undefined,
18
18
  error: undefined,
19
- };
19
+ } as const;
20
20
 
21
21
  function stateForResult(result: any) {
22
22
  return {
@@ -73,8 +73,11 @@ export function useQueryInternal<
73
73
  const unsubscribe = _core.subscribeQuery<Q, UseDates>(query, (result) => {
74
74
  resultCacheRef.current = {
75
75
  isLoading: !Boolean(result),
76
+ // @ts-expect-error: ts thinks this will always be overwritten
76
77
  data: undefined,
78
+ // @ts-expect-error: ts thinks this will always be overwritten
77
79
  pageInfo: undefined,
80
+ // @ts-expect-error: ts thinks this will always be overwritten
78
81
  error: undefined,
79
82
  ...result,
80
83
  };
package/src/useTimeout.ts CHANGED
@@ -1,19 +1,21 @@
1
1
  import { useEffect, useRef } from 'react';
2
2
 
3
3
  export function useTimeout() {
4
- const timeoutRef = useRef(null);
4
+ const timeoutRef = useRef<null | ReturnType<typeof setTimeout>>(null);
5
5
 
6
6
  useEffect(() => {
7
7
  clear();
8
8
  }, []);
9
9
 
10
10
  function set(delay: number, fn: () => void) {
11
- clearTimeout(timeoutRef.current);
11
+ clear();
12
12
  timeoutRef.current = setTimeout(fn, delay);
13
13
  }
14
14
 
15
15
  function clear() {
16
- clearTimeout(timeoutRef.current);
16
+ if (timeoutRef.current) {
17
+ clearTimeout(timeoutRef.current);
18
+ }
17
19
  }
18
20
 
19
21
  return { set, clear };
package/tsconfig.json CHANGED
@@ -6,6 +6,7 @@
6
6
  "outDir": "dist/tsc",
7
7
  "rewriteRelativeImportExtensions": true,
8
8
  "rootDir": "src",
9
- "jsx": "react-jsx"
9
+ "jsx": "react-jsx",
10
+ "strictNullChecks": true
10
11
  }
11
12
  }