@roko-app/instant-react-common 0.0.0-stage → 1.0.67-roko.1

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 (77) hide show
  1. package/.tshy/build.json +8 -0
  2. package/.tshy/commonjs.json +16 -0
  3. package/.tshy/esm.json +15 -0
  4. package/LICENSE +202 -0
  5. package/README.md +59 -2
  6. package/dist/commonjs/InstantReactAbstractDatabase.d.ts +283 -0
  7. package/dist/commonjs/InstantReactAbstractDatabase.d.ts.map +1 -0
  8. package/dist/commonjs/InstantReactAbstractDatabase.js +390 -0
  9. package/dist/commonjs/InstantReactAbstractDatabase.js.map +1 -0
  10. package/dist/commonjs/InstantReactRoom.d.ts +183 -0
  11. package/dist/commonjs/InstantReactRoom.d.ts.map +1 -0
  12. package/dist/commonjs/InstantReactRoom.js +290 -0
  13. package/dist/commonjs/InstantReactRoom.js.map +1 -0
  14. package/dist/commonjs/index.d.ts +5 -0
  15. package/dist/commonjs/index.d.ts.map +1 -0
  16. package/dist/commonjs/index.js +11 -0
  17. package/dist/commonjs/index.js.map +1 -0
  18. package/dist/commonjs/package.json +3 -0
  19. package/dist/commonjs/useInfiniteQuerySubscription.d.ts +28 -0
  20. package/dist/commonjs/useInfiniteQuerySubscription.d.ts.map +1 -0
  21. package/dist/commonjs/useInfiniteQuerySubscription.js +57 -0
  22. package/dist/commonjs/useInfiniteQuerySubscription.js.map +1 -0
  23. package/dist/commonjs/useQuery.d.ts +7 -0
  24. package/dist/commonjs/useQuery.d.ts.map +1 -0
  25. package/dist/commonjs/useQuery.js +79 -0
  26. package/dist/commonjs/useQuery.js.map +1 -0
  27. package/dist/commonjs/useTimeout.d.ts +5 -0
  28. package/dist/commonjs/useTimeout.d.ts.map +1 -0
  29. package/dist/commonjs/useTimeout.js +21 -0
  30. package/dist/commonjs/useTimeout.js.map +1 -0
  31. package/dist/commonjs/version.d.ts +3 -0
  32. package/dist/commonjs/version.d.ts.map +1 -0
  33. package/dist/commonjs/version.js +5 -0
  34. package/dist/commonjs/version.js.map +1 -0
  35. package/dist/esm/InstantReactAbstractDatabase.d.ts +283 -0
  36. package/dist/esm/InstantReactAbstractDatabase.d.ts.map +1 -0
  37. package/dist/esm/InstantReactAbstractDatabase.js +387 -0
  38. package/dist/esm/InstantReactAbstractDatabase.js.map +1 -0
  39. package/dist/esm/InstantReactRoom.d.ts +183 -0
  40. package/dist/esm/InstantReactRoom.d.ts.map +1 -0
  41. package/dist/esm/InstantReactRoom.js +281 -0
  42. package/dist/esm/InstantReactRoom.js.map +1 -0
  43. package/dist/esm/index.d.ts +5 -0
  44. package/dist/esm/index.d.ts.map +1 -0
  45. package/dist/esm/index.js +4 -0
  46. package/dist/esm/index.js.map +1 -0
  47. package/dist/esm/package.json +3 -0
  48. package/dist/esm/useInfiniteQuerySubscription.d.ts +28 -0
  49. package/dist/esm/useInfiniteQuerySubscription.d.ts.map +1 -0
  50. package/dist/esm/useInfiniteQuerySubscription.js +54 -0
  51. package/dist/esm/useInfiniteQuerySubscription.js.map +1 -0
  52. package/dist/esm/useQuery.d.ts +7 -0
  53. package/dist/esm/useQuery.d.ts.map +1 -0
  54. package/dist/esm/useQuery.js +76 -0
  55. package/dist/esm/useQuery.js.map +1 -0
  56. package/dist/esm/useTimeout.d.ts +5 -0
  57. package/dist/esm/useTimeout.d.ts.map +1 -0
  58. package/dist/esm/useTimeout.js +18 -0
  59. package/dist/esm/useTimeout.js.map +1 -0
  60. package/dist/esm/version.d.ts +3 -0
  61. package/dist/esm/version.d.ts.map +1 -0
  62. package/dist/esm/version.js +3 -0
  63. package/dist/esm/version.js.map +1 -0
  64. package/dist/standalone/index.js +8718 -0
  65. package/dist/standalone/index.umd.cjs +36 -0
  66. package/package.json +43 -3
  67. package/src/InstantReactAbstractDatabase.tsx +510 -0
  68. package/src/InstantReactRoom.ts +451 -0
  69. package/src/index.ts +9 -0
  70. package/src/useInfiniteQuerySubscription.ts +128 -0
  71. package/src/useQuery.ts +124 -0
  72. package/src/useTimeout.ts +22 -0
  73. package/src/version.ts +3 -0
  74. package/tsconfig.cjs.dev.json +15 -0
  75. package/tsconfig.dev.json +14 -0
  76. package/tsconfig.json +12 -0
  77. package/vite.config.ts +35 -0
@@ -0,0 +1,390 @@
1
+ 'use client';
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const core_1 = require("@instantdb/core");
6
+ const react_1 = require("react");
7
+ const useQuery_ts_1 = require("./useQuery.js");
8
+ const useInfiniteQuerySubscription_ts_1 = require("./useInfiniteQuerySubscription.js");
9
+ const InstantReactRoom_ts_1 = require("./InstantReactRoom.js");
10
+ const defaultAuthState = {
11
+ isLoading: true,
12
+ user: undefined,
13
+ error: undefined,
14
+ };
15
+ const defaultAppStatusState = {
16
+ isLoading: true,
17
+ isReadOnly: undefined,
18
+ };
19
+ class InstantReactAbstractDatabase {
20
+ tx = (0, core_1.txInit)();
21
+ auth;
22
+ storage;
23
+ streams;
24
+ core;
25
+ /** @deprecated use `core` instead */
26
+ _core;
27
+ static Store;
28
+ static NetworkListener;
29
+ static EventSourceImpl;
30
+ constructor(config, versions) {
31
+ this.core = (0, core_1.init)(config,
32
+ // @ts-expect-error because TS can't resolve subclass statics
33
+ config.Store || this.constructor.Store,
34
+ // @ts-expect-error because TS can't resolve subclass statics
35
+ this.constructor.NetworkListener, versions,
36
+ // @ts-expect-error because TS can't resolve subclass statics
37
+ this.constructor.EventSourceImpl);
38
+ this._core = this.core;
39
+ this.auth = this.core.auth;
40
+ this.storage = this.core.storage;
41
+ this.streams = this.core.streams;
42
+ }
43
+ /**
44
+ * Returns a unique ID for a given `name`. It's stored in local storage,
45
+ * so you will get the same ID across sessions.
46
+ *
47
+ * This is useful for generating IDs that could identify a local device or user.
48
+ *
49
+ * @example
50
+ * const deviceId = await db.getLocalId('device');
51
+ */
52
+ getLocalId = (name) => {
53
+ return this.core.getLocalId(name);
54
+ };
55
+ /**
56
+ * A hook that returns a unique ID for a given `name`. localIds are
57
+ * stored in local storage, so you will get the same ID across sessions.
58
+ *
59
+ * Initially returns `null`, and then loads the localId.
60
+ *
61
+ * @example
62
+ * const deviceId = db.useLocalId('device');
63
+ * if (!deviceId) return null; // loading
64
+ * console.log('Device ID:', deviceId)
65
+ */
66
+ useLocalId = (name) => {
67
+ const [localId, setLocalId] = (0, react_1.useState)(null);
68
+ (0, react_1.useEffect)(() => {
69
+ let mounted = true;
70
+ const f = async () => {
71
+ const id = await this.getLocalId(name);
72
+ if (!mounted)
73
+ return;
74
+ setLocalId(id);
75
+ };
76
+ f();
77
+ return;
78
+ }, [name]);
79
+ return localId;
80
+ };
81
+ /**
82
+ * Obtain a handle to a room, which allows you to listen to topics and presence data
83
+ *
84
+ * If you don't provide a `type` or `id`, Instant will default to `_defaultRoomType` and `_defaultRoomId`
85
+ * as the room type and id, respectively.
86
+ *
87
+ * @see https://instantdb.com/docs/presence-and-topics
88
+ *
89
+ * @example
90
+ * const room = db.room('chat', roomId);
91
+ * const { peers } = db.rooms.usePresence(room);
92
+ */
93
+ room(type = '_defaultRoomType', id = '_defaultRoomId') {
94
+ return new InstantReactRoom_ts_1.InstantReactRoom(this.core, type, id);
95
+ }
96
+ /**
97
+ * Hooks for working with rooms
98
+ *
99
+ * @see https://instantdb.com/docs/presence-and-topics
100
+ *
101
+ * @example
102
+ * const room = db.room('chat', roomId);
103
+ * const { peers } = db.rooms.usePresence(room);
104
+ * const publish = db.rooms.usePublishTopic(room, 'emoji');
105
+ * // ...
106
+ */
107
+ rooms = InstantReactRoom_ts_1.rooms;
108
+ /**
109
+ * Use this to write data! You can create, update, delete, and link objects
110
+ *
111
+ * @see https://instantdb.com/docs/instaml
112
+ *
113
+ * @example
114
+ * // Create a new object in the `goals` namespace
115
+ * const goalId = id();
116
+ * db.transact(db.tx.goals[goalId].update({title: "Get fit"}))
117
+ *
118
+ * // Update the title
119
+ * db.transact(db.tx.goals[goalId].update({title: "Get super fit"}))
120
+ *
121
+ * // Delete it
122
+ * db.transact(db.tx.goals[goalId].delete())
123
+ *
124
+ * // Or create an association:
125
+ * todoId = id();
126
+ * db.transact([
127
+ * db.tx.todos[todoId].update({ title: 'Go on a run' }),
128
+ * db.tx.goals[goalId].link({todos: todoId}),
129
+ * ])
130
+ */
131
+ transact = (chunks) => {
132
+ return this.core.transact(chunks);
133
+ };
134
+ /**
135
+ * Use this to query your data!
136
+ *
137
+ * @see https://instantdb.com/docs/instaql
138
+ *
139
+ * @example
140
+ * // listen to all goals
141
+ * const { isLoading, error, data } = db.useQuery({ goals: {} });
142
+ *
143
+ * // goals where the title is "Get Fit"
144
+ * const { isLoading, error, data } = db.useQuery({
145
+ * goals: { $: { where: { title: 'Get Fit' } } },
146
+ * });
147
+ *
148
+ * // all goals, _alongside_ their todos
149
+ * const { isLoading, error, data } = db.useQuery({
150
+ * goals: { todos: {} },
151
+ * });
152
+ *
153
+ * // skip if `user` is not logged in
154
+ * const { isLoading, error, data } = db.useQuery(
155
+ * auth.user ? { goals: {} } : null,
156
+ * );
157
+ */
158
+ useQuery = (query, opts) => {
159
+ return (0, useQuery_ts_1.useQueryInternal)(this.core, query, opts).state;
160
+ };
161
+ /**
162
+ * Listen for the logged in state. This is useful
163
+ * for deciding when to show a login screen.
164
+ *
165
+ * Check out the docs for an example `Login` component too!
166
+ *
167
+ * @see https://instantdb.com/docs/auth
168
+ * @example
169
+ * function App() {
170
+ * const { isLoading, user, error } = db.useAuth()
171
+ * if (isLoading) {
172
+ * return <div>Loading...</div>
173
+ * }
174
+ * if (error) {
175
+ * return <div>Uh oh! {error.message}</div>
176
+ * }
177
+ * if (user) {
178
+ * return <Main user={user} />
179
+ * }
180
+ * return <Login />
181
+ * }
182
+ *
183
+ */
184
+ useAuth = () => {
185
+ return this._useAuth();
186
+ };
187
+ _useAuth() {
188
+ // We use a ref to store the result of the query.
189
+ // This is becuase `useSyncExternalStore` uses `Object.is`
190
+ // to compare the previous and next state.
191
+ // If we don't use a ref, the state will always be considered different, so
192
+ // the component will always re-render.
193
+ const resultCacheRef = (0, react_1.useRef)(this.core._reactor._currentUserCached);
194
+ // Similar to `resultCacheRef`, `useSyncExternalStore` will unsubscribe
195
+ // if `subscribe` changes, so we use `useCallback` to memoize the function.
196
+ const subscribe = (0, react_1.useCallback)((cb) => {
197
+ const unsubscribe = this.core.subscribeAuth((auth) => {
198
+ resultCacheRef.current = { isLoading: false, ...auth };
199
+ cb();
200
+ });
201
+ return unsubscribe;
202
+ }, []);
203
+ const state = (0, react_1.useSyncExternalStore)(subscribe, () => resultCacheRef.current, () => defaultAuthState);
204
+ return state;
205
+ }
206
+ /**
207
+ * Subscribe to the currently logged in user.
208
+ * If the user is not logged in, this hook with throw an Error.
209
+ * You will want to protect any calls of this hook with a
210
+ * <db.SignedIn> component, or your own logic based on db.useAuth()
211
+ *
212
+ * @see https://instantdb.com/docs/auth
213
+ * @throws Error indicating user not signed in
214
+ * @example
215
+ * function UserDisplay() {
216
+ * const user = db.useUser()
217
+ * return <div>Logged in as: {user.email}</div>
218
+ * }
219
+ *
220
+ * <db.SignedIn>
221
+ * <UserDisplay />
222
+ * </db.SignedIn>
223
+ *
224
+ */
225
+ useUser = () => {
226
+ const { user } = this.useAuth();
227
+ if (!user) {
228
+ throw new core_1.InstantError('useUser must be used within an auth-protected route');
229
+ }
230
+ return user;
231
+ };
232
+ /**
233
+ * One time query for the logged in state. This is useful
234
+ * for scenarios where you want to know the current auth
235
+ * state without subscribing to changes.
236
+ *
237
+ * @see https://instantdb.com/docs/auth
238
+ * @example
239
+ * const user = await db.getAuth();
240
+ * console.log('logged in as', user.email)
241
+ */
242
+ getAuth() {
243
+ return this.core.getAuth();
244
+ }
245
+ /**
246
+ * Listen for connection status changes to Instant. Use this for things like
247
+ * showing connection state to users
248
+ *
249
+ * @see https://www.instantdb.com/docs/patterns#connection-status
250
+ * @example
251
+ * function App() {
252
+ * const status = db.useConnectionStatus()
253
+ * const connectionState =
254
+ * status === 'connecting' || status === 'opened'
255
+ * ? 'authenticating'
256
+ * : status === 'authenticated'
257
+ * ? 'connected'
258
+ * : status === 'closed'
259
+ * ? 'closed'
260
+ * : status === 'errored'
261
+ * ? 'errored'
262
+ * : 'unexpected state';
263
+ *
264
+ * return <div>Connection state: {connectionState}</div>
265
+ * }
266
+ */
267
+ useConnectionStatus = () => {
268
+ const statusRef = (0, react_1.useRef)(this.core._reactor.status);
269
+ const subscribe = (0, react_1.useCallback)((cb) => {
270
+ const unsubscribe = this.core.subscribeConnectionStatus((newStatus) => {
271
+ if (newStatus !== statusRef.current) {
272
+ statusRef.current = newStatus;
273
+ cb();
274
+ }
275
+ });
276
+ return unsubscribe;
277
+ }, []);
278
+ const status = (0, react_1.useSyncExternalStore)(subscribe, () => statusRef.current,
279
+ // For SSR, always return 'connecting' as the initial state
280
+ () => 'connecting');
281
+ return status;
282
+ };
283
+ /**
284
+ * Observe the app's maintenance-mode state. While read-only, reads and
285
+ * live queries keep working but writes are rejected.
286
+ *
287
+ * @example
288
+ * function App() {
289
+ * const { isLoading, isReadOnly } = db.useAppStatus()
290
+ * if (isLoading) return null
291
+ * if (isReadOnly) return <MaintenanceBanner />
292
+ * // ...
293
+ * }
294
+ */
295
+ useAppStatus = () => {
296
+ const stateRef = (0, react_1.useRef)(this.core._reactor._appStatusState);
297
+ const subscribe = (0, react_1.useCallback)((cb) => {
298
+ return this.core.subscribeAppStatus((state) => {
299
+ if (state.isLoading !== stateRef.current.isLoading ||
300
+ state.isReadOnly !== stateRef.current.isReadOnly) {
301
+ stateRef.current = state;
302
+ cb();
303
+ }
304
+ });
305
+ }, []);
306
+ const state = (0, react_1.useSyncExternalStore)(subscribe, () => stateRef.current, () => defaultAppStatusState);
307
+ return state;
308
+ };
309
+ /**
310
+ * Use this for one-off queries.
311
+ * Returns local data if available, otherwise fetches from the server.
312
+ * Because we want to avoid stale data, this method will throw an error
313
+ * if the user is offline or there is no active connection to the server.
314
+ *
315
+ * @see https://instantdb.com/docs/instaql
316
+ *
317
+ * @example
318
+ *
319
+ * const resp = await db.queryOnce({ goals: {} });
320
+ * console.log(resp.data.goals)
321
+ */
322
+ queryOnce = (query, opts) => {
323
+ return this.core.queryOnce(query, opts);
324
+ };
325
+ /**
326
+ * Subscribe to a query and incrementally load more items
327
+ *
328
+ * Only one top level namespace in the query is allowed.
329
+ *
330
+ * Changing the query or options while the subscription is active will
331
+ * reset the subscription and start over with new data.
332
+ * @example
333
+ * const {
334
+ * data,
335
+ * loadNextPage,
336
+ * canLoadNextPage,
337
+ * } = db.useInfiniteQuery({
338
+ * posts: {
339
+ * $: {
340
+ * limit: 20, // Load 20 posts at a time
341
+ * order: {
342
+ * createdAt: 'desc',
343
+ * },
344
+ * },
345
+ * },
346
+ * });
347
+ */
348
+ useInfiniteQuery = (query, opts) => {
349
+ const result = (0, useInfiniteQuerySubscription_ts_1.useInfiniteQuerySubscription)({
350
+ core: this.core,
351
+ query: query,
352
+ opts,
353
+ });
354
+ return result;
355
+ };
356
+ /**
357
+ * Only render children if the user is signed in.
358
+ * @see https://instantdb.com/docs/auth
359
+ *
360
+ * @example
361
+ * <db.SignedIn>
362
+ * <MyComponent />
363
+ * </db.SignedIn>
364
+ *
365
+ */
366
+ SignedIn = ({ children }) => {
367
+ const auth = this.useAuth();
368
+ if (auth.isLoading || auth.error || !auth.user)
369
+ return null;
370
+ return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children });
371
+ };
372
+ /**
373
+ * Only render children if the user is signed out.
374
+ * @see https://instantdb.com/docs/auth
375
+ *
376
+ * @example
377
+ * <db.SignedOut>
378
+ * <MyComponent />
379
+ * </db.SignedOut>
380
+ *
381
+ */
382
+ SignedOut = ({ children }) => {
383
+ const auth = this.useAuth();
384
+ if (auth.isLoading || auth.error || auth.user)
385
+ return null;
386
+ return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children });
387
+ };
388
+ }
389
+ exports.default = InstantReactAbstractDatabase;
390
+ //# sourceMappingURL=InstantReactAbstractDatabase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InstantReactAbstractDatabase.js","sourceRoot":"","sources":["../../src/InstantReactAbstractDatabase.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;AACb,0CAwByB;AACzB,iCAOe;AACf,+CAAiD;AACjD,uFAG2C;AAC3C,+DAAgE;AAEhE,MAAM,gBAAgB,GAAG;IACvB,SAAS,EAAE,IAAI;IACf,IAAI,EAAE,SAAS;IACf,KAAK,EAAE,SAAS;CACjB,CAAC;AAEF,MAAM,qBAAqB,GAAmB;IAC5C,SAAS,EAAE,IAAI;IACf,UAAU,EAAE,SAAS;CACtB,CAAC;AAEF,MAA8B,4BAA4B;IAWjD,EAAE,GAAG,IAAA,aAAM,GAAU,CAAC;IAEtB,IAAI,CAAO;IACX,OAAO,CAAU;IACjB,OAAO,CAAU;IACjB,IAAI,CAAwC;IAEnD,qCAAqC;IAC9B,KAAK,CAAwC;IAEpD,MAAM,CAAC,KAAK,CAAO;IACnB,MAAM,CAAC,eAAe,CAAO;IAC7B,MAAM,CAAC,eAAe,CAAO;IAE7B,YACE,MAEC,EACD,QAAoC;QAEpC,IAAI,CAAC,IAAI,GAAG,IAAA,WAAS,EACnB,MAAM;QACN,6DAA6D;QAC7D,MAAM,CAAC,KAAK,IAAI,IAAI,CAAC,WAAW,CAAC,KAAK;QACtC,6DAA6D;QAC7D,IAAI,CAAC,WAAW,CAAC,eAAe,EAChC,QAAQ;QACR,6DAA6D;QAC7D,IAAI,CAAC,WAAW,CAAC,eAAe,CACjC,CAAC;QACF,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC;QACjC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC;IACnC,CAAC;IAED;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AAI,CAAC,SAAS,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,IAAI;YAAE,OAAO,IAAI,CAAC;QAC3D,OAAO,2DAAG,QAAQ,GAAI,CAAC;IACzB,CAAC,CAAC;CACH;AAzcD,+CAycC","sourcesContent":["'use client';\nimport {\n // types\n Auth,\n Storage,\n txInit,\n type AuthState,\n type User,\n type ConnectionStatus,\n type AppStatusState,\n type TransactionChunk,\n type RoomSchemaShape,\n type InstaQLOptions,\n type InstantConfig,\n type PageInfoResponse,\n InstantCoreDatabase,\n init as core_init,\n InstaQLLifecycleState,\n InstaQLResponse,\n RoomsOf,\n InstantSchemaDef,\n IInstantDatabase,\n InstantError,\n ValidQuery,\n Streams,\n} from '@instantdb/core';\nimport {\n ReactNode,\n useCallback,\n useEffect,\n useRef,\n useState,\n useSyncExternalStore,\n} from 'react';\nimport { useQueryInternal } from './useQuery.ts';\nimport {\n type InfiniteQueryResult,\n useInfiniteQuerySubscription,\n} from './useInfiniteQuerySubscription.ts';\nimport { InstantReactRoom, rooms } from './InstantReactRoom.ts';\n\nconst defaultAuthState = {\n isLoading: true,\n user: undefined,\n error: undefined,\n};\n\nconst defaultAppStatusState: AppStatusState = {\n isLoading: true,\n isReadOnly: undefined,\n};\n\nexport default abstract class InstantReactAbstractDatabase<\n // need to pull this schema out to another generic for query params, not sure why\n Schema extends InstantSchemaDef<any, any, any>,\n UseDates extends boolean = false,\n Config extends InstantConfig<Schema, boolean> = InstantConfig<\n Schema,\n UseDates\n >,\n Rooms extends RoomSchemaShape = RoomsOf<Schema>,\n> implements IInstantDatabase<Schema>\n{\n public tx = txInit<Schema>();\n\n public auth: Auth;\n public storage: Storage;\n public streams: Streams;\n public core: InstantCoreDatabase<Schema, UseDates>;\n\n /** @deprecated use `core` instead */\n public _core: InstantCoreDatabase<Schema, UseDates>;\n\n static Store?: any;\n static NetworkListener?: any;\n static EventSourceImpl?: any;\n\n constructor(\n config: Omit<InstantConfig<Schema, UseDates>, 'useDateObjects'> & {\n useDateObjects?: UseDates;\n },\n versions?: { [key: string]: string },\n ) {\n this.core = core_init<Schema, UseDates>(\n config,\n // @ts-expect-error because TS can't resolve subclass statics\n config.Store || this.constructor.Store,\n // @ts-expect-error because TS can't resolve subclass statics\n this.constructor.NetworkListener,\n versions,\n // @ts-expect-error because TS can't resolve subclass statics\n this.constructor.EventSourceImpl,\n );\n this._core = this.core;\n this.auth = this.core.auth;\n this.storage = this.core.storage;\n this.streams = this.core.streams;\n }\n\n /**\n * Returns a unique ID for a given `name`. It's stored in local storage,\n * so you will get the same ID across sessions.\n *\n * This is useful for generating IDs that could identify a local device or user.\n *\n * @example\n * const deviceId = await db.getLocalId('device');\n */\n getLocalId = (name: string): Promise<string> => {\n return this.core.getLocalId(name);\n };\n\n /**\n * A hook that returns a unique ID for a given `name`. localIds are\n * stored in local storage, so you will get the same ID across sessions.\n *\n * Initially returns `null`, and then loads the localId.\n *\n * @example\n * const deviceId = db.useLocalId('device');\n * if (!deviceId) return null; // loading\n * console.log('Device ID:', deviceId)\n */\n useLocalId = (name: string): string | null => {\n const [localId, setLocalId] = useState<string | null>(null);\n\n useEffect(() => {\n let mounted = true;\n const f = async () => {\n const id = await this.getLocalId(name);\n if (!mounted) return;\n setLocalId(id);\n };\n f();\n return;\n }, [name]);\n\n return localId;\n };\n\n /**\n * Obtain a handle to a room, which allows you to listen to topics and presence data\n *\n * If you don't provide a `type` or `id`, Instant will default to `_defaultRoomType` and `_defaultRoomId`\n * as the room type and id, respectively.\n *\n * @see https://instantdb.com/docs/presence-and-topics\n *\n * @example\n * const room = db.room('chat', roomId);\n * const { peers } = db.rooms.usePresence(room);\n */\n room<RoomType extends string & keyof Rooms>(\n type: RoomType = '_defaultRoomType' as RoomType,\n id: string = '_defaultRoomId',\n ) {\n return new InstantReactRoom<Schema, Rooms, RoomType>(this.core, type, id);\n }\n\n /**\n * Hooks for working with rooms\n *\n * @see https://instantdb.com/docs/presence-and-topics\n *\n * @example\n * const room = db.room('chat', roomId);\n * const { peers } = db.rooms.usePresence(room);\n * const publish = db.rooms.usePublishTopic(room, 'emoji');\n * // ...\n */\n rooms = rooms;\n\n /**\n * Use this to write data! You can create, update, delete, and link objects\n *\n * @see https://instantdb.com/docs/instaml\n *\n * @example\n * // Create a new object in the `goals` namespace\n * const goalId = id();\n * db.transact(db.tx.goals[goalId].update({title: \"Get fit\"}))\n *\n * // Update the title\n * db.transact(db.tx.goals[goalId].update({title: \"Get super fit\"}))\n *\n * // Delete it\n * db.transact(db.tx.goals[goalId].delete())\n *\n * // Or create an association:\n * todoId = id();\n * db.transact([\n * db.tx.todos[todoId].update({ title: 'Go on a run' }),\n * db.tx.goals[goalId].link({todos: todoId}),\n * ])\n */\n transact = (\n chunks: TransactionChunk<any, any> | TransactionChunk<any, any>[],\n ) => {\n return this.core.transact(chunks);\n };\n\n /**\n * Use this to query your data!\n *\n * @see https://instantdb.com/docs/instaql\n *\n * @example\n * // listen to all goals\n * const { isLoading, error, data } = db.useQuery({ goals: {} });\n *\n * // goals where the title is \"Get Fit\"\n * const { isLoading, error, data } = db.useQuery({\n * goals: { $: { where: { title: 'Get Fit' } } },\n * });\n *\n * // all goals, _alongside_ their todos\n * const { isLoading, error, data } = db.useQuery({\n * goals: { todos: {} },\n * });\n *\n * // skip if `user` is not logged in\n * const { isLoading, error, data } = db.useQuery(\n * auth.user ? { goals: {} } : null,\n * );\n */\n useQuery = <Q extends ValidQuery<Q, Schema>>(\n query: null | Q,\n opts?: InstaQLOptions,\n ): InstaQLLifecycleState<Schema, Q, UseDates> => {\n return useQueryInternal<Q, Schema, UseDates>(this.core, query, opts).state;\n };\n\n /**\n * Listen for the logged in state. This is useful\n * for deciding when to show a login screen.\n *\n * Check out the docs for an example `Login` component too!\n *\n * @see https://instantdb.com/docs/auth\n * @example\n * function App() {\n * const { isLoading, user, error } = db.useAuth()\n * if (isLoading) {\n * return <div>Loading...</div>\n * }\n * if (error) {\n * return <div>Uh oh! {error.message}</div>\n * }\n * if (user) {\n * return <Main user={user} />\n * }\n * return <Login />\n * }\n *\n */\n useAuth = (): AuthState => {\n return this._useAuth();\n };\n\n protected _useAuth(): AuthState {\n // We use a ref to store the result of the query.\n // This is becuase `useSyncExternalStore` uses `Object.is`\n // to compare the previous and next state.\n // If we don't use a ref, the state will always be considered different, so\n // the component will always re-render.\n const resultCacheRef = useRef<AuthState>(\n this.core._reactor._currentUserCached,\n );\n\n // Similar to `resultCacheRef`, `useSyncExternalStore` will unsubscribe\n // if `subscribe` changes, so we use `useCallback` to memoize the function.\n const subscribe = useCallback((cb: Function) => {\n const unsubscribe = this.core.subscribeAuth((auth) => {\n resultCacheRef.current = { isLoading: false, ...auth };\n cb();\n });\n\n return unsubscribe;\n }, []);\n\n const state = useSyncExternalStore<AuthState>(\n subscribe,\n () => resultCacheRef.current,\n () => defaultAuthState,\n );\n return state;\n }\n\n /**\n * Subscribe to the currently logged in user.\n * If the user is not logged in, this hook with throw an Error.\n * You will want to protect any calls of this hook with a\n * <db.SignedIn> component, or your own logic based on db.useAuth()\n *\n * @see https://instantdb.com/docs/auth\n * @throws Error indicating user not signed in\n * @example\n * function UserDisplay() {\n * const user = db.useUser()\n * return <div>Logged in as: {user.email}</div>\n * }\n *\n * <db.SignedIn>\n * <UserDisplay />\n * </db.SignedIn>\n *\n */\n useUser = (): User => {\n const { user } = this.useAuth();\n if (!user) {\n throw new InstantError(\n 'useUser must be used within an auth-protected route',\n );\n }\n return user;\n };\n\n /**\n * One time query for the logged in state. This is useful\n * for scenarios where you want to know the current auth\n * state without subscribing to changes.\n *\n * @see https://instantdb.com/docs/auth\n * @example\n * const user = await db.getAuth();\n * console.log('logged in as', user.email)\n */\n getAuth(): Promise<User | null> {\n return this.core.getAuth();\n }\n\n /**\n * Listen for connection status changes to Instant. Use this for things like\n * showing connection state to users\n *\n * @see https://www.instantdb.com/docs/patterns#connection-status\n * @example\n * function App() {\n * const status = db.useConnectionStatus()\n * const connectionState =\n * status === 'connecting' || status === 'opened'\n * ? 'authenticating'\n * : status === 'authenticated'\n * ? 'connected'\n * : status === 'closed'\n * ? 'closed'\n * : status === 'errored'\n * ? 'errored'\n * : 'unexpected state';\n *\n * return <div>Connection state: {connectionState}</div>\n * }\n */\n useConnectionStatus = (): ConnectionStatus => {\n const statusRef = useRef<ConnectionStatus>(\n this.core._reactor.status as ConnectionStatus,\n );\n\n const subscribe = useCallback((cb: Function) => {\n const unsubscribe = this.core.subscribeConnectionStatus((newStatus) => {\n if (newStatus !== statusRef.current) {\n statusRef.current = newStatus;\n cb();\n }\n });\n\n return unsubscribe;\n }, []);\n\n const status = useSyncExternalStore<ConnectionStatus>(\n subscribe,\n () => statusRef.current,\n // For SSR, always return 'connecting' as the initial state\n () => 'connecting',\n );\n\n return status;\n };\n\n /**\n * Observe the app's maintenance-mode state. While read-only, reads and\n * live queries keep working but writes are rejected.\n *\n * @example\n * function App() {\n * const { isLoading, isReadOnly } = db.useAppStatus()\n * if (isLoading) return null\n * if (isReadOnly) return <MaintenanceBanner />\n * // ...\n * }\n */\n useAppStatus = (): AppStatusState => {\n const stateRef = useRef<AppStatusState>(this.core._reactor._appStatusState);\n\n const subscribe = useCallback((cb: () => void) => {\n return this.core.subscribeAppStatus((state) => {\n if (\n state.isLoading !== stateRef.current.isLoading ||\n state.isReadOnly !== stateRef.current.isReadOnly\n ) {\n stateRef.current = state;\n cb();\n }\n });\n }, []);\n\n const state = useSyncExternalStore<AppStatusState>(\n subscribe,\n () => stateRef.current,\n () => defaultAppStatusState,\n );\n\n return state;\n };\n\n /**\n * Use this for one-off queries.\n * Returns local data if available, otherwise fetches from the server.\n * Because we want to avoid stale data, this method will throw an error\n * if the user is offline or there is no active connection to the server.\n *\n * @see https://instantdb.com/docs/instaql\n *\n * @example\n *\n * const resp = await db.queryOnce({ goals: {} });\n * console.log(resp.data.goals)\n */\n queryOnce = <Q extends ValidQuery<Q, Schema>>(\n query: Q,\n opts?: InstaQLOptions,\n ): Promise<{\n data: InstaQLResponse<Schema, Q, UseDates>;\n pageInfo: PageInfoResponse<Q>;\n }> => {\n return this.core.queryOnce(query, opts);\n };\n\n /**\n * Subscribe to a query and incrementally load more items\n *\n * Only one top level namespace in the query is allowed.\n *\n * Changing the query or options while the subscription is active will\n * reset the subscription and start over with new data.\n * @example\n * const {\n * data,\n * loadNextPage,\n * canLoadNextPage,\n * } = db.useInfiniteQuery({\n * posts: {\n * $: {\n * limit: 20, // Load 20 posts at a time\n * order: {\n * createdAt: 'desc',\n * },\n * },\n * },\n * });\n */\n useInfiniteQuery = <Q extends ValidQuery<Q, Schema>>(\n query: Q,\n opts?: InstaQLOptions,\n ): InfiniteQueryResult<Schema, Q, UseDates> => {\n const result = useInfiniteQuerySubscription<Schema, Q, UseDates>({\n core: this.core,\n query: query,\n opts,\n });\n return result;\n };\n\n /**\n * Only render children if the user is signed in.\n * @see https://instantdb.com/docs/auth\n *\n * @example\n * <db.SignedIn>\n * <MyComponent />\n * </db.SignedIn>\n *\n */\n SignedIn: React.FC<{\n children: ReactNode;\n }> = ({ children }) => {\n const auth = this.useAuth();\n if (auth.isLoading || auth.error || !auth.user) return null;\n\n return <>{children}</>;\n };\n\n /**\n * Only render children if the user is signed out.\n * @see https://instantdb.com/docs/auth\n *\n * @example\n * <db.SignedOut>\n * <MyComponent />\n * </db.SignedOut>\n *\n */\n SignedOut: React.FC<{\n children: ReactNode;\n }> = ({ children }) => {\n const auth = this.useAuth();\n if (auth.isLoading || auth.error || auth.user) return null;\n return <>{children}</>;\n };\n}\n"]}
@@ -0,0 +1,183 @@
1
+ import { type PresenceOpts, type PresenceResponse, type RoomSchemaShape, InstantCoreDatabase, InstantSchemaDef } from '@instantdb/core';
2
+ import { KeyboardEvent } from 'react';
3
+ export type PresenceHandle<PresenceShape, Keys extends keyof PresenceShape> = PresenceResponse<PresenceShape, Keys> & {
4
+ publishPresence: (data: Partial<PresenceShape>) => void;
5
+ };
6
+ export type TypingIndicatorOpts = {
7
+ timeout?: number | null;
8
+ stopOnEnter?: boolean;
9
+ writeOnly?: boolean;
10
+ };
11
+ export type TypingIndicatorHandle<PresenceShape> = {
12
+ active: PresenceShape[];
13
+ setActive(active: boolean): void;
14
+ inputProps: {
15
+ onKeyDown: (e: KeyboardEvent) => void;
16
+ onBlur: () => void;
17
+ };
18
+ };
19
+ export declare const defaultActivityStopTimeout = 1000;
20
+ /**
21
+ * Listen for broadcasted events given a room and topic.
22
+ *
23
+ * @see https://instantdb.com/docs/presence-and-topics
24
+ * @example
25
+ * function App({ roomId }) {
26
+ * const room = db.room('chats', roomId);
27
+ * db.rooms.useTopicEffect(room, 'emoji', (message, peer) => {
28
+ * console.log(peer.name, 'sent', message);
29
+ * });
30
+ * // ...
31
+ * }
32
+ */
33
+ export declare function useTopicEffect<RoomSchema extends RoomSchemaShape, RoomType extends string & keyof RoomSchema, TopicType extends keyof RoomSchema[RoomType]['topics']>(room: InstantReactRoom<any, RoomSchema, RoomType>, topic: TopicType, onEvent: (event: RoomSchema[RoomType]['topics'][TopicType], peer: RoomSchema[RoomType]['presence']) => any): void;
34
+ /**
35
+ * Broadcast an event to a room.
36
+ *
37
+ * @see https://instantdb.com/docs/presence-and-topics
38
+ * @example
39
+ * function App({ roomId }) {
40
+ * const room = db.room('chat', roomId);
41
+ * const publishTopic = db.rooms.usePublishTopic(room, "emoji");
42
+ *
43
+ * return (
44
+ * <button onClick={() => publishTopic({ emoji: "🔥" })}>Send emoji</button>
45
+ * );
46
+ * }
47
+ *
48
+ */
49
+ export declare function usePublishTopic<RoomSchema extends RoomSchemaShape, RoomType extends string & keyof RoomSchema, TopicType extends keyof RoomSchema[RoomType]['topics']>(room: InstantReactRoom<any, RoomSchema, RoomType>, topic: TopicType): (data: RoomSchema[RoomType]['topics'][TopicType]) => void;
50
+ /**
51
+ * Listen for peer's presence data in a room, and publish the current user's presence.
52
+ *
53
+ * @see https://instantdb.com/docs/presence-and-topics
54
+ * @example
55
+ * function App({ roomId }) {
56
+ * const {
57
+ * peers,
58
+ * publishPresence
59
+ * } = db.room(roomType, roomId).usePresence({ keys: ["name", "avatar"] });
60
+ *
61
+ * // ...
62
+ * }
63
+ */
64
+ export declare function usePresence<RoomSchema extends RoomSchemaShape, RoomType extends string & keyof RoomSchema, Keys extends keyof RoomSchema[RoomType]['presence']>(room: InstantReactRoom<any, RoomSchema, RoomType>, opts?: PresenceOpts<RoomSchema[RoomType]['presence'], Keys>): PresenceHandle<RoomSchema[RoomType]['presence'], Keys>;
65
+ /**
66
+ * Publishes presence data to a room
67
+ *
68
+ * @see https://instantdb.com/docs/presence-and-topics
69
+ * @example
70
+ * function App({ roomId, nickname }) {
71
+ * const room = db.room('chat', roomId);
72
+ * db.rooms.useSyncPresence(room, { nickname });
73
+ * }
74
+ */
75
+ export declare function useSyncPresence<RoomSchema extends RoomSchemaShape, RoomType extends string & keyof RoomSchema>(room: InstantReactRoom<any, RoomSchema, RoomType>, data: Partial<RoomSchema[RoomType]['presence']>, deps?: any[]): void;
76
+ /**
77
+ * Manage typing indicator state
78
+ *
79
+ * @see https://instantdb.com/docs/presence-and-topics
80
+ * @example
81
+ * function App({ roomId }) {
82
+ * const room = db.room('chat', roomId);
83
+ * const {
84
+ * active,
85
+ * setActive,
86
+ * inputProps,
87
+ * } = db.rooms.useTypingIndicator(room, "chat-input");
88
+ *
89
+ * return <input {...inputProps} />;
90
+ * }
91
+ */
92
+ export declare function useTypingIndicator<RoomSchema extends RoomSchemaShape, RoomType extends string & keyof RoomSchema>(room: InstantReactRoom<any, RoomSchema, RoomType>, inputName: string, opts?: TypingIndicatorOpts): TypingIndicatorHandle<RoomSchema[RoomType]['presence']>;
93
+ export declare const rooms: {
94
+ useTopicEffect: typeof useTopicEffect;
95
+ usePublishTopic: typeof usePublishTopic;
96
+ usePresence: typeof usePresence;
97
+ useSyncPresence: typeof useSyncPresence;
98
+ useTypingIndicator: typeof useTypingIndicator;
99
+ };
100
+ export declare class InstantReactRoom<Schema extends InstantSchemaDef<any, any, any>, RoomSchema extends RoomSchemaShape, RoomType extends string & keyof RoomSchema> {
101
+ core: InstantCoreDatabase<Schema, boolean>;
102
+ /** @deprecated use `core` instead */
103
+ _core: InstantCoreDatabase<Schema, boolean>;
104
+ type: RoomType;
105
+ id: string;
106
+ constructor(core: InstantCoreDatabase<Schema, boolean>, type: RoomType, id: string);
107
+ /**
108
+ * @deprecated
109
+ * `db.room(...).useTopicEffect` is deprecated. You can replace it with `db.rooms.useTopicEffect`.
110
+ *
111
+ * @example
112
+ *
113
+ * // Before
114
+ * const room = db.room('chat', 'room-id');
115
+ * room.useTopicEffect('emoji', (message, peer) => { });
116
+ *
117
+ * // After
118
+ * const room = db.room('chat', 'room-id');
119
+ * db.rooms.useTopicEffect(room, 'emoji', (message, peer) => { });
120
+ */
121
+ useTopicEffect: <TopicType extends keyof RoomSchema[RoomType]["topics"]>(topic: TopicType, onEvent: (event: RoomSchema[RoomType]["topics"][TopicType], peer: RoomSchema[RoomType]["presence"]) => any) => void;
122
+ /**
123
+ * @deprecated
124
+ * `db.room(...).usePublishTopic` is deprecated. You can replace it with `db.rooms.usePublishTopic`.
125
+ *
126
+ * @example
127
+ *
128
+ * // Before
129
+ * const room = db.room('chat', 'room-id');
130
+ * const publish = room.usePublishTopic('emoji');
131
+ *
132
+ * // After
133
+ * const room = db.room('chat', 'room-id');
134
+ * const publish = db.rooms.usePublishTopic(room, 'emoji');
135
+ */
136
+ usePublishTopic: <Topic extends keyof RoomSchema[RoomType]["topics"]>(topic: Topic) => ((data: RoomSchema[RoomType]["topics"][Topic]) => void);
137
+ /**
138
+ * @deprecated
139
+ * `db.room(...).usePresence` is deprecated. You can replace it with `db.rooms.usePresence`.
140
+ *
141
+ * @example
142
+ *
143
+ * // Before
144
+ * const room = db.room('chat', 'room-id');
145
+ * const { peers } = room.usePresence({ keys: ["name", "avatar"] });
146
+ *
147
+ * // After
148
+ * const room = db.room('chat', 'room-id');
149
+ * const { peers } = db.rooms.usePresence(room, { keys: ["name", "avatar"] });
150
+ */
151
+ usePresence: <Keys extends keyof RoomSchema[RoomType]["presence"]>(opts?: PresenceOpts<RoomSchema[RoomType]["presence"], Keys>) => PresenceHandle<RoomSchema[RoomType]["presence"], Keys>;
152
+ /**
153
+ * @deprecated
154
+ * `db.room(...).useSyncPresence` is deprecated. You can replace it with `db.rooms.useSyncPresence`.
155
+ *
156
+ * @example
157
+ *
158
+ * // Before
159
+ * const room = db.room('chat', 'room-id');
160
+ * room.useSyncPresence(room, { nickname });
161
+ *
162
+ * // After
163
+ * const room = db.room('chat', 'room-id');
164
+ * db.rooms.useSyncPresence(room, { nickname });
165
+ */
166
+ useSyncPresence: (data: Partial<RoomSchema[RoomType]["presence"]>, deps?: any[]) => void;
167
+ /**
168
+ * @deprecated
169
+ * `db.room(...).useTypingIndicator` is deprecated. You can replace it with `db.rooms.useTypingIndicator`.
170
+ *
171
+ * @example
172
+ *
173
+ * // Before
174
+ * const room = db.room('chat', 'room-id');
175
+ * const typing = room.useTypingIndiactor(room, 'chat-input');
176
+ *
177
+ * // After
178
+ * const room = db.room('chat', 'room-id');
179
+ * const typing = db.rooms.useTypingIndiactor(room, 'chat-input');
180
+ */
181
+ useTypingIndicator: (inputName: string, opts?: TypingIndicatorOpts) => TypingIndicatorHandle<RoomSchema[RoomType]["presence"]>;
182
+ }
183
+ //# sourceMappingURL=InstantReactRoom.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InstantReactRoom.d.ts","sourceRoot":"","sources":["../../src/InstantReactRoom.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,mBAAmB,EACnB,gBAAgB,EACjB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,aAAa,EAMd,MAAM,OAAO,CAAC;AAIf,MAAM,MAAM,cAAc,CACxB,aAAa,EACb,IAAI,SAAS,MAAM,aAAa,IAC9B,gBAAgB,CAAC,aAAa,EAAE,IAAI,CAAC,GAAG;IAC1C,eAAe,EAAE,CAAC,IAAI,EAAE,OAA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