@instantdb/solidjs 0.0.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.
- package/.tshy/build.json +8 -0
- package/.tshy/commonjs.json +16 -0
- package/.tshy/esm.json +15 -0
- package/.turbo/turbo-build.log +69 -0
- package/dist/commonjs/InstantSolidDatabase.d.ts +156 -0
- package/dist/commonjs/InstantSolidDatabase.d.ts.map +1 -0
- package/dist/commonjs/InstantSolidDatabase.js +265 -0
- package/dist/commonjs/InstantSolidDatabase.js.map +1 -0
- package/dist/commonjs/InstantSolidRoom.d.ts +97 -0
- package/dist/commonjs/InstantSolidRoom.d.ts.map +1 -0
- package/dist/commonjs/InstantSolidRoom.js +200 -0
- package/dist/commonjs/InstantSolidRoom.js.map +1 -0
- package/dist/commonjs/index.d.ts +6 -0
- package/dist/commonjs/index.d.ts.map +1 -0
- package/dist/commonjs/index.js +24 -0
- package/dist/commonjs/index.js.map +1 -0
- package/dist/commonjs/package.json +3 -0
- package/dist/commonjs/version.d.ts +3 -0
- package/dist/commonjs/version.d.ts.map +1 -0
- package/dist/commonjs/version.js +5 -0
- package/dist/commonjs/version.js.map +1 -0
- package/dist/esm/InstantSolidDatabase.d.ts +156 -0
- package/dist/esm/InstantSolidDatabase.d.ts.map +1 -0
- package/dist/esm/InstantSolidDatabase.js +257 -0
- package/dist/esm/InstantSolidDatabase.js.map +1 -0
- package/dist/esm/InstantSolidRoom.d.ts +97 -0
- package/dist/esm/InstantSolidRoom.d.ts.map +1 -0
- package/dist/esm/InstantSolidRoom.js +191 -0
- package/dist/esm/InstantSolidRoom.js.map +1 -0
- package/dist/esm/index.d.ts +6 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +18 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/version.d.ts +3 -0
- package/dist/esm/version.d.ts.map +1 -0
- package/dist/esm/version.js +3 -0
- package/dist/esm/version.js.map +1 -0
- package/dist/standalone/index.js +7010 -0
- package/dist/standalone/index.umd.cjs +7 -0
- package/package.json +63 -0
- package/src/InstantSolidDatabase.ts +363 -0
- package/src/InstantSolidRoom.ts +319 -0
- package/src/index.ts +191 -0
- package/src/version.ts +2 -0
- package/tsconfig.dev.json +14 -0
- package/tsconfig.json +45 -0
- package/vite.config.ts +20 -0
package/.tshy/build.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./build.json",
|
|
3
|
+
"include": [
|
|
4
|
+
"../src/**/*.ts",
|
|
5
|
+
"../src/**/*.cts",
|
|
6
|
+
"../src/**/*.tsx",
|
|
7
|
+
"../src/**/*.json"
|
|
8
|
+
],
|
|
9
|
+
"exclude": [
|
|
10
|
+
"../src/**/*.mts",
|
|
11
|
+
"../src/package.json"
|
|
12
|
+
],
|
|
13
|
+
"compilerOptions": {
|
|
14
|
+
"outDir": "../.tshy-build/commonjs"
|
|
15
|
+
}
|
|
16
|
+
}
|
package/.tshy/esm.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
> @instantdb/solidjs@0.0.0 build /Users/drew/programs/instant/client/packages/solidjs
|
|
4
|
+
> rm -rf dist; npm run build:tshy && npm run build:standalone && npm run check-exports
|
|
5
|
+
|
|
6
|
+
[1mnpm[22m [33mwarn[39m [94mUnknown env config "verify-deps-before-run". This will stop working in the next major version of npm.[39m
|
|
7
|
+
|
|
8
|
+
> @instantdb/solidjs@0.0.0 build:tshy
|
|
9
|
+
> tshy
|
|
10
|
+
|
|
11
|
+
[1G[0K[96msrc/InstantSolidRoom.ts[0m:[93m69[0m:[93m38[0m - [91merror[0m[90m TS2554: [0mExpected 4 arguments, but got 3.
|
|
12
|
+
|
|
13
|
+
[7m69[0m const unsub = room.core._reactor.subscribeTopic(
|
|
14
|
+
[7m [0m [91m ~~~~~~~~~~~~~~[0m
|
|
15
|
+
|
|
16
|
+
[96m../core/dist/esm/Reactor.d.ts[0m:[93m358[0m:[93m60[0m
|
|
17
|
+
[7m358[0m subscribeTopic(roomType: any, roomId: any, topic: any, cb: any): () => void;
|
|
18
|
+
[7m [0m [96m ~~~~~~~[0m
|
|
19
|
+
An argument for 'cb' was not provided.
|
|
20
|
+
|
|
21
|
+
[96msrc/InstantSolidRoom.ts[0m:[93m105[0m:[93m38[0m - [91merror[0m[90m TS2554: [0mExpected 2-3 arguments, but got 1.
|
|
22
|
+
|
|
23
|
+
[7m105[0m const unsub = room.core._reactor.joinRoom(room.id);
|
|
24
|
+
[7m [0m [91m ~~~~~~~~[0m
|
|
25
|
+
|
|
26
|
+
[96m../core/dist/esm/Reactor.d.ts[0m:[93m327[0m:[93m32[0m
|
|
27
|
+
[7m327[0m joinRoom(roomType: string, roomId: string, initialPresence?: any | null | undefined): () => void;
|
|
28
|
+
[7m [0m [96m ~~~~~~~~~~~~~~[0m
|
|
29
|
+
An argument for 'roomId' was not provided.
|
|
30
|
+
|
|
31
|
+
[96msrc/InstantSolidRoom.ts[0m:[93m191[0m:[93m56[0m - [91merror[0m[90m TS2345: [0mArgument of type 'Partial<RoomSchema[RoomType]["presence"]>' is not assignable to parameter of type 'string'.
|
|
32
|
+
|
|
33
|
+
[7m191[0m const unsub = room.core._reactor.joinRoom(room.id, data);
|
|
34
|
+
[7m [0m [91m ~~~~[0m
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
Found 3 errors in the same file, starting at: src/InstantSolidRoom.ts[90m:69[0m
|
|
38
|
+
|
|
39
|
+
[36m[2mwriting tsconfig files...[22m[39m
|
|
40
|
+
using existing tsconfig.json
|
|
41
|
+
[33m[1mbuilding[22m[39m /Users/drew/programs/instant/client/packages/solidjs
|
|
42
|
+
[36m[2mtshy config[22m[39m {
|
|
43
|
+
selfLink: [33mfalse[39m,
|
|
44
|
+
main: [33mtrue[39m,
|
|
45
|
+
module: [33mtrue[39m,
|
|
46
|
+
project: [32m'./tsconfig.json'[39m,
|
|
47
|
+
exports: { [32m'./package.json'[39m: [32m'./package.json'[39m, [32m'.'[39m: [32m'./src/index.ts'[39m }
|
|
48
|
+
}
|
|
49
|
+
[36m[2mexports[22m[39m {
|
|
50
|
+
[32m'./package.json'[39m: [32m'./package.json'[39m,
|
|
51
|
+
[32m'.'[39m: {
|
|
52
|
+
import: { types: [32m'./dist/esm/index.d.ts'[39m, default: [32m'./dist/esm/index.js'[39m },
|
|
53
|
+
require: {
|
|
54
|
+
types: [32m'./dist/commonjs/index.d.ts'[39m,
|
|
55
|
+
default: [32m'./dist/commonjs/index.js'[39m
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
[36m[2mset dialect[22m[39m { where: [32m'src'[39m, mode: [32m'esm'[39m }
|
|
60
|
+
[36m[2mbuilding esm[22m[39m
|
|
61
|
+
[31m[1mbuild failed[22m[39m
|
|
62
|
+
[1G[0Kâ ™[1G[0K[1mnpm[22m [31merror[39m Lifecycle script `build:tshy` failed with error:
|
|
63
|
+
[1G[0Kâ ™[1G[0K[1mnpm[22m [31merror[39m [94mcode[39m [33m1[39m
|
|
64
|
+
[1G[0Kâ ™[1G[0K[1mnpm[22m [31merror[39m [94mpath[39m /Users/drew/programs/instant/client/packages/solidjs
|
|
65
|
+
[1G[0Kâ ™[1G[0K[1mnpm[22m [31merror[39m [94mworkspace[39m @instantdb/solidjs@0.0.0
|
|
66
|
+
[1G[0Kâ ™[1G[0K[1mnpm[22m [31merror[39m [94mlocation[39m /Users/drew/programs/instant/client/packages/solidjs
|
|
67
|
+
[1G[0Kâ ™[1G[0K[1mnpm[22m [31merror[39m command failed
|
|
68
|
+
[1G[0Kâ ™[1G[0K[1mnpm[22m [31merror[39m [94mcommand[39m sh -c tshy
|
|
69
|
+
[1G[0K⠙[1G[0K[41m[30m ELIFECYCLE [39m[49m [31mCommand failed with exit code 1.[39m
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { type AuthState, type User, type ConnectionStatus, type TransactionChunk, type RoomSchemaShape, type InstaQLOptions, type InstantConfig, type PageInfoResponse, type InstaQLLifecycleState, type InstaQLResponse, type ValidQuery, Auth, Storage, InstantCoreDatabase, InstantSchemaDef, RoomsOf, IInstantDatabase } from '@instantdb/core';
|
|
2
|
+
import type { Accessor } from 'solid-js';
|
|
3
|
+
import { InstantSolidRoom } from './InstantSolidRoom.js';
|
|
4
|
+
export declare class InstantSolidDatabase<Schema extends InstantSchemaDef<any, any, any>, UseDates extends boolean = false, Rooms extends RoomSchemaShape = RoomsOf<Schema>> implements IInstantDatabase<Schema> {
|
|
5
|
+
tx: import("@instantdb/core").TxChunk<Schema>;
|
|
6
|
+
auth: Auth;
|
|
7
|
+
storage: Storage;
|
|
8
|
+
core: InstantCoreDatabase<Schema, UseDates>;
|
|
9
|
+
constructor(core: InstantCoreDatabase<Schema, UseDates>);
|
|
10
|
+
/**
|
|
11
|
+
* Returns a unique ID for a given `name`. It's stored in local storage,
|
|
12
|
+
* so you will get the same ID across sessions.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* const deviceId = await db.getLocalId('device');
|
|
16
|
+
*/
|
|
17
|
+
getLocalId: (name: string) => Promise<string>;
|
|
18
|
+
/**
|
|
19
|
+
* Use this to write data! You can create, update, delete, and link objects
|
|
20
|
+
*
|
|
21
|
+
* @see https://instantdb.com/docs/instaml
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* const goalId = id();
|
|
25
|
+
* db.transact(db.tx.goals[goalId].update({title: "Get fit"}))
|
|
26
|
+
*/
|
|
27
|
+
transact: (chunks: TransactionChunk<any, any> | TransactionChunk<any, any>[]) => Promise<import("@instantdb/core").TransactionResult>;
|
|
28
|
+
/**
|
|
29
|
+
* One time query for the logged in state.
|
|
30
|
+
*
|
|
31
|
+
* @see https://instantdb.com/docs/auth
|
|
32
|
+
* @example
|
|
33
|
+
* const user = await db.getAuth();
|
|
34
|
+
* console.log('logged in as', user.email)
|
|
35
|
+
*/
|
|
36
|
+
getAuth(): Promise<User | null>;
|
|
37
|
+
/**
|
|
38
|
+
* Use this for one-off queries.
|
|
39
|
+
* Returns local data if available, otherwise fetches from the server.
|
|
40
|
+
*
|
|
41
|
+
* @see https://instantdb.com/docs/instaql
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* const resp = await db.queryOnce({ goals: {} });
|
|
45
|
+
* console.log(resp.data.goals)
|
|
46
|
+
*/
|
|
47
|
+
queryOnce: <Q extends ValidQuery<Q, Schema>>(query: Q, opts?: InstaQLOptions) => Promise<{
|
|
48
|
+
data: InstaQLResponse<Schema, Q, UseDates>;
|
|
49
|
+
pageInfo: PageInfoResponse<Q>;
|
|
50
|
+
}>;
|
|
51
|
+
/**
|
|
52
|
+
* Use this to query your data!
|
|
53
|
+
*
|
|
54
|
+
* @see https://instantdb.com/docs/instaql
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* const state = db.useQuery({ goals: {} });
|
|
58
|
+
* // state().isLoading, state().error, state().data
|
|
59
|
+
*/
|
|
60
|
+
useQuery: <Q extends ValidQuery<Q, Schema>>(query: null | Q, opts?: InstaQLOptions) => Accessor<InstaQLLifecycleState<Schema, Q, UseDates>>;
|
|
61
|
+
/**
|
|
62
|
+
* Listen for the logged in state. This is useful
|
|
63
|
+
* for deciding when to show a login screen.
|
|
64
|
+
*
|
|
65
|
+
* @see https://instantdb.com/docs/auth
|
|
66
|
+
* @example
|
|
67
|
+
* function App() {
|
|
68
|
+
* const auth = db.useAuth();
|
|
69
|
+
* // auth().isLoading, auth().user, auth().error
|
|
70
|
+
* }
|
|
71
|
+
*/
|
|
72
|
+
useAuth: () => Accessor<AuthState>;
|
|
73
|
+
/**
|
|
74
|
+
* Subscribe to the currently logged in user.
|
|
75
|
+
* If the user is not logged in, this will throw an Error.
|
|
76
|
+
*
|
|
77
|
+
* @see https://instantdb.com/docs/auth
|
|
78
|
+
* @example
|
|
79
|
+
* function UserDisplay() {
|
|
80
|
+
* const user = db.useUser();
|
|
81
|
+
* return <div>Logged in as: {user().email}</div>
|
|
82
|
+
* }
|
|
83
|
+
*/
|
|
84
|
+
useUser: () => Accessor<User>;
|
|
85
|
+
/**
|
|
86
|
+
* Listen for connection status changes to Instant.
|
|
87
|
+
*
|
|
88
|
+
* @see https://www.instantdb.com/docs/patterns#connection-status
|
|
89
|
+
* @example
|
|
90
|
+
* function App() {
|
|
91
|
+
* const status = db.useConnectionStatus();
|
|
92
|
+
* return <div>Connection state: {status()}</div>
|
|
93
|
+
* }
|
|
94
|
+
*/
|
|
95
|
+
useConnectionStatus: () => Accessor<ConnectionStatus>;
|
|
96
|
+
/**
|
|
97
|
+
* A hook that returns a unique ID for a given `name`. localIds are
|
|
98
|
+
* stored in local storage, so you will get the same ID across sessions.
|
|
99
|
+
*
|
|
100
|
+
* Initially returns `null`, and then loads the localId.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* const deviceId = db.useLocalId('device');
|
|
104
|
+
* // deviceId() is null initially, then the ID string
|
|
105
|
+
*/
|
|
106
|
+
useLocalId: (name: string) => Accessor<string | null>;
|
|
107
|
+
/**
|
|
108
|
+
* Obtain a handle to a room, which allows you to listen to topics and presence data
|
|
109
|
+
*
|
|
110
|
+
* @see https://instantdb.com/docs/presence-and-topics
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* const room = db.room('chat', roomId);
|
|
114
|
+
* const presence = db.rooms.usePresence(room);
|
|
115
|
+
*/
|
|
116
|
+
room<RoomType extends keyof Rooms>(type?: RoomType, id?: string): InstantSolidRoom<Schema, Rooms, RoomType>;
|
|
117
|
+
/**
|
|
118
|
+
* Hooks for working with rooms
|
|
119
|
+
*
|
|
120
|
+
* @see https://instantdb.com/docs/presence-and-topics
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* const room = db.room('chat', roomId);
|
|
124
|
+
* const presence = db.rooms.usePresence(room);
|
|
125
|
+
* const publish = db.rooms.usePublishTopic(room, 'emoji');
|
|
126
|
+
*/
|
|
127
|
+
rooms: {
|
|
128
|
+
useTopicEffect: typeof import("./InstantSolidRoom.js").useTopicEffect;
|
|
129
|
+
usePublishTopic: typeof import("./InstantSolidRoom.js").usePublishTopic;
|
|
130
|
+
usePresence: typeof import("./InstantSolidRoom.js").usePresence;
|
|
131
|
+
useSyncPresence: typeof import("./InstantSolidRoom.js").useSyncPresence;
|
|
132
|
+
useTypingIndicator: typeof import("./InstantSolidRoom.js").useTypingIndicator;
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* The first step: init your application!
|
|
137
|
+
*
|
|
138
|
+
* Visit https://instantdb.com/dash to get your `appId` :)
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* import { init } from "@instantdb/solidjs"
|
|
142
|
+
*
|
|
143
|
+
* const db = init({ appId: "my-app-id" })
|
|
144
|
+
*
|
|
145
|
+
* // You can also provide a schema for type safety and editor autocomplete!
|
|
146
|
+
*
|
|
147
|
+
* import { init } from "@instantdb/solidjs"
|
|
148
|
+
* import schema from "../instant.schema.ts";
|
|
149
|
+
*
|
|
150
|
+
* const db = init({ appId: "my-app-id", schema })
|
|
151
|
+
*/
|
|
152
|
+
export declare function init<Schema extends InstantSchemaDef<any, any, any>, UseDates extends boolean = false>(config: Omit<InstantConfig<Schema, UseDates>, 'useDateObjects'> & {
|
|
153
|
+
useDateObjects?: UseDates;
|
|
154
|
+
}): InstantSolidDatabase<Schema, UseDates>;
|
|
155
|
+
export declare const init_experimental: typeof init;
|
|
156
|
+
//# sourceMappingURL=InstantSolidDatabase.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InstantSolidDatabase.d.ts","sourceRoot":"","sources":["../../src/InstantSolidDatabase.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,IAAI,EACT,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,aAAa,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importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.init_experimental = exports.InstantSolidDatabase = void 0;
|
|
7
|
+
exports.init = init;
|
|
8
|
+
const core_1 = require("@instantdb/core");
|
|
9
|
+
const solid_js_1 = require("solid-js");
|
|
10
|
+
const InstantSolidRoom_js_1 = require("./InstantSolidRoom.js");
|
|
11
|
+
const version_js_1 = __importDefault(require("./version.js"));
|
|
12
|
+
const defaultState = {
|
|
13
|
+
isLoading: true,
|
|
14
|
+
data: undefined,
|
|
15
|
+
pageInfo: undefined,
|
|
16
|
+
error: undefined,
|
|
17
|
+
};
|
|
18
|
+
const defaultAuthState = {
|
|
19
|
+
isLoading: true,
|
|
20
|
+
user: undefined,
|
|
21
|
+
error: undefined,
|
|
22
|
+
};
|
|
23
|
+
function stateForResult(result) {
|
|
24
|
+
return {
|
|
25
|
+
isLoading: !Boolean(result),
|
|
26
|
+
data: undefined,
|
|
27
|
+
pageInfo: undefined,
|
|
28
|
+
error: undefined,
|
|
29
|
+
...(result ? result : {}),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
class InstantSolidDatabase {
|
|
33
|
+
tx = (0, core_1.txInit)();
|
|
34
|
+
auth;
|
|
35
|
+
storage;
|
|
36
|
+
core;
|
|
37
|
+
constructor(core) {
|
|
38
|
+
this.core = core;
|
|
39
|
+
this.auth = this.core.auth;
|
|
40
|
+
this.storage = this.core.storage;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Returns a unique ID for a given `name`. It's stored in local storage,
|
|
44
|
+
* so you will get the same ID across sessions.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* const deviceId = await db.getLocalId('device');
|
|
48
|
+
*/
|
|
49
|
+
getLocalId = (name) => {
|
|
50
|
+
return this.core.getLocalId(name);
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Use this to write data! You can create, update, delete, and link objects
|
|
54
|
+
*
|
|
55
|
+
* @see https://instantdb.com/docs/instaml
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* const goalId = id();
|
|
59
|
+
* db.transact(db.tx.goals[goalId].update({title: "Get fit"}))
|
|
60
|
+
*/
|
|
61
|
+
transact = (chunks) => {
|
|
62
|
+
return this.core.transact(chunks);
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* One time query for the logged in state.
|
|
66
|
+
*
|
|
67
|
+
* @see https://instantdb.com/docs/auth
|
|
68
|
+
* @example
|
|
69
|
+
* const user = await db.getAuth();
|
|
70
|
+
* console.log('logged in as', user.email)
|
|
71
|
+
*/
|
|
72
|
+
getAuth() {
|
|
73
|
+
return this.core.getAuth();
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Use this for one-off queries.
|
|
77
|
+
* Returns local data if available, otherwise fetches from the server.
|
|
78
|
+
*
|
|
79
|
+
* @see https://instantdb.com/docs/instaql
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* const resp = await db.queryOnce({ goals: {} });
|
|
83
|
+
* console.log(resp.data.goals)
|
|
84
|
+
*/
|
|
85
|
+
queryOnce = (query, opts) => {
|
|
86
|
+
return this.core.queryOnce(query, opts);
|
|
87
|
+
};
|
|
88
|
+
// -----------
|
|
89
|
+
// Solid reactive hooks
|
|
90
|
+
/**
|
|
91
|
+
* Use this to query your data!
|
|
92
|
+
*
|
|
93
|
+
* @see https://instantdb.com/docs/instaql
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* const state = db.useQuery({ goals: {} });
|
|
97
|
+
* // state().isLoading, state().error, state().data
|
|
98
|
+
*/
|
|
99
|
+
useQuery = (query, opts) => {
|
|
100
|
+
const [state, setState] = (0, solid_js_1.createSignal)(defaultState);
|
|
101
|
+
(0, solid_js_1.createEffect)(() => {
|
|
102
|
+
if (!query) {
|
|
103
|
+
setState(() => defaultState);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
let q = query;
|
|
107
|
+
if (opts && 'ruleParams' in opts) {
|
|
108
|
+
q = { $$ruleParams: opts['ruleParams'], ...q };
|
|
109
|
+
}
|
|
110
|
+
const coerced = (0, core_1.coerceQuery)(q);
|
|
111
|
+
const prev = this.core._reactor.getPreviousResult(coerced);
|
|
112
|
+
if (prev) {
|
|
113
|
+
setState(() => stateForResult(prev));
|
|
114
|
+
}
|
|
115
|
+
const unsub = this.core.subscribeQuery(coerced, (result) => {
|
|
116
|
+
setState(() => Object.assign({
|
|
117
|
+
isLoading: false,
|
|
118
|
+
data: undefined,
|
|
119
|
+
pageInfo: undefined,
|
|
120
|
+
error: undefined,
|
|
121
|
+
}, result));
|
|
122
|
+
});
|
|
123
|
+
(0, solid_js_1.onCleanup)(unsub);
|
|
124
|
+
});
|
|
125
|
+
return state;
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* Listen for the logged in state. This is useful
|
|
129
|
+
* for deciding when to show a login screen.
|
|
130
|
+
*
|
|
131
|
+
* @see https://instantdb.com/docs/auth
|
|
132
|
+
* @example
|
|
133
|
+
* function App() {
|
|
134
|
+
* const auth = db.useAuth();
|
|
135
|
+
* // auth().isLoading, auth().user, auth().error
|
|
136
|
+
* }
|
|
137
|
+
*/
|
|
138
|
+
useAuth = () => {
|
|
139
|
+
const [state, setState] = (0, solid_js_1.createSignal)(this.core._reactor._currentUserCached ?? defaultAuthState);
|
|
140
|
+
(0, solid_js_1.createEffect)(() => {
|
|
141
|
+
const unsub = this.core.subscribeAuth((auth) => {
|
|
142
|
+
setState({ isLoading: false, ...auth });
|
|
143
|
+
});
|
|
144
|
+
(0, solid_js_1.onCleanup)(unsub);
|
|
145
|
+
});
|
|
146
|
+
return state;
|
|
147
|
+
};
|
|
148
|
+
/**
|
|
149
|
+
* Subscribe to the currently logged in user.
|
|
150
|
+
* If the user is not logged in, this will throw an Error.
|
|
151
|
+
*
|
|
152
|
+
* @see https://instantdb.com/docs/auth
|
|
153
|
+
* @example
|
|
154
|
+
* function UserDisplay() {
|
|
155
|
+
* const user = db.useUser();
|
|
156
|
+
* return <div>Logged in as: {user().email}</div>
|
|
157
|
+
* }
|
|
158
|
+
*/
|
|
159
|
+
useUser = () => {
|
|
160
|
+
const auth = this.useAuth();
|
|
161
|
+
return (0, solid_js_1.createMemo)(() => {
|
|
162
|
+
const { user } = auth();
|
|
163
|
+
if (!user) {
|
|
164
|
+
throw new core_1.InstantError('useUser must be used within an auth-protected route');
|
|
165
|
+
}
|
|
166
|
+
return user;
|
|
167
|
+
});
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* Listen for connection status changes to Instant.
|
|
171
|
+
*
|
|
172
|
+
* @see https://www.instantdb.com/docs/patterns#connection-status
|
|
173
|
+
* @example
|
|
174
|
+
* function App() {
|
|
175
|
+
* const status = db.useConnectionStatus();
|
|
176
|
+
* return <div>Connection state: {status()}</div>
|
|
177
|
+
* }
|
|
178
|
+
*/
|
|
179
|
+
useConnectionStatus = () => {
|
|
180
|
+
const [status, setStatus] = (0, solid_js_1.createSignal)(this.core._reactor.status);
|
|
181
|
+
(0, solid_js_1.createEffect)(() => {
|
|
182
|
+
const unsub = this.core.subscribeConnectionStatus((newStatus) => {
|
|
183
|
+
setStatus(() => newStatus);
|
|
184
|
+
});
|
|
185
|
+
(0, solid_js_1.onCleanup)(unsub);
|
|
186
|
+
});
|
|
187
|
+
return status;
|
|
188
|
+
};
|
|
189
|
+
/**
|
|
190
|
+
* A hook that returns a unique ID for a given `name`. localIds are
|
|
191
|
+
* stored in local storage, so you will get the same ID across sessions.
|
|
192
|
+
*
|
|
193
|
+
* Initially returns `null`, and then loads the localId.
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* const deviceId = db.useLocalId('device');
|
|
197
|
+
* // deviceId() is null initially, then the ID string
|
|
198
|
+
*/
|
|
199
|
+
useLocalId = (name) => {
|
|
200
|
+
const [localId, setLocalId] = (0, solid_js_1.createSignal)(null);
|
|
201
|
+
(0, solid_js_1.createEffect)(() => {
|
|
202
|
+
let mounted = true;
|
|
203
|
+
this.getLocalId(name).then((id) => {
|
|
204
|
+
if (mounted) {
|
|
205
|
+
setLocalId(() => id);
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
(0, solid_js_1.onCleanup)(() => {
|
|
209
|
+
mounted = false;
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
return localId;
|
|
213
|
+
};
|
|
214
|
+
/**
|
|
215
|
+
* Obtain a handle to a room, which allows you to listen to topics and presence data
|
|
216
|
+
*
|
|
217
|
+
* @see https://instantdb.com/docs/presence-and-topics
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* const room = db.room('chat', roomId);
|
|
221
|
+
* const presence = db.rooms.usePresence(room);
|
|
222
|
+
*/
|
|
223
|
+
room(type = '_defaultRoomType', id = '_defaultRoomId') {
|
|
224
|
+
return new InstantSolidRoom_js_1.InstantSolidRoom(this.core, type, id);
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Hooks for working with rooms
|
|
228
|
+
*
|
|
229
|
+
* @see https://instantdb.com/docs/presence-and-topics
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* const room = db.room('chat', roomId);
|
|
233
|
+
* const presence = db.rooms.usePresence(room);
|
|
234
|
+
* const publish = db.rooms.usePublishTopic(room, 'emoji');
|
|
235
|
+
*/
|
|
236
|
+
rooms = InstantSolidRoom_js_1.rooms;
|
|
237
|
+
}
|
|
238
|
+
exports.InstantSolidDatabase = InstantSolidDatabase;
|
|
239
|
+
// -----------
|
|
240
|
+
// init
|
|
241
|
+
/**
|
|
242
|
+
* The first step: init your application!
|
|
243
|
+
*
|
|
244
|
+
* Visit https://instantdb.com/dash to get your `appId` :)
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
* import { init } from "@instantdb/solidjs"
|
|
248
|
+
*
|
|
249
|
+
* const db = init({ appId: "my-app-id" })
|
|
250
|
+
*
|
|
251
|
+
* // You can also provide a schema for type safety and editor autocomplete!
|
|
252
|
+
*
|
|
253
|
+
* import { init } from "@instantdb/solidjs"
|
|
254
|
+
* import schema from "../instant.schema.ts";
|
|
255
|
+
*
|
|
256
|
+
* const db = init({ appId: "my-app-id", schema })
|
|
257
|
+
*/
|
|
258
|
+
function init(config) {
|
|
259
|
+
const coreDb = (0, core_1.init)(config, undefined, undefined, {
|
|
260
|
+
'@instantdb/solidjs': version_js_1.default,
|
|
261
|
+
});
|
|
262
|
+
return new InstantSolidDatabase(coreDb);
|
|
263
|
+
}
|
|
264
|
+
exports.init_experimental = init;
|
|
265
|
+
//# sourceMappingURL=InstantSolidDatabase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InstantSolidDatabase.js","sourceRoot":"","sources":["../../src/InstantSolidDatabase.ts"],"names":[],"mappings":";;;;;;AA4VA,oBAYC;AAxWD,0CAwByB;AAEzB,uCAA6E;AAG7E,+DAAgE;AAChE,8DAAmC;AAEnC,MAAM,YAAY,GAAG;IACnB,SAAS,EAAE,IAAI;IACf,IAAI,EAAE,SAAS;IACf,QAAQ,EAAE,SAAS;IACnB,KAAK,EAAE,SAAS;CACR,CAAC;AAEX,MAAM,gBAAgB,GAAc;IAClC,SAAS,EAAE,IAAI;IACf,IAAI,EAAE,SAAS;IACf,KAAK,EAAE,SAAS;CACjB,CAAC;AAEF,SAAS,cAAc,CAAC,MAAW;IACjC,OAAO;QACL,SAAS,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC;QAC3B,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,SAAS;QACnB,KAAK,EAAE,SAAS;QAChB,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;KAC1B,CAAC;AACJ,CAAC;AAED,MAAa,oBAAoB;IAMxB,EAAE,GAAG,IAAA,aAAM,GAA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U,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE;gBAChC,IAAI,OAAO,EAAE,CAAC;oBACZ,UAAU,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;gBACvB,CAAC;YACH,CAAC,CAAC,CAAC;YACH,IAAA,oBAAS,EAAC,GAAG,EAAE;gBACb,OAAO,GAAG,KAAK,CAAC;YAClB,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,OAAO,OAAO,CAAC;IACjB,CAAC,CAAC;IAEF;;;;;;;;OAQG;IACH,IAAI,CACF,OAAiB,kBAA8B,EAC/C,KAAa,gBAAgB;QAE7B,OAAO,IAAI,sCAAgB,CAA0B,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;IAC5E,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,GAAG,2BAAK,CAAC;CACf;AA/QD,oDA+QC;AAED,cAAc;AACd,OAAO;AAEP;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,IAAI,CAIlB,MAEC;IAED,MAAM,MAAM,GAAG,IAAA,WAAS,EAAmB,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE;QACvE,oBAAoB,EAAE,oBAAO;KAC9B,CAAC,CAAC;IACH,OAAO,IAAI,oBAAoB,CAAmB,MAAM,CAAC,CAAC;AAC5D,CAAC;AAEY,QAAA,iBAAiB,GAAG,IAAI,CAAC","sourcesContent":["import {\n // types\n type AuthState,\n type User,\n type ConnectionStatus,\n type TransactionChunk,\n type RoomSchemaShape,\n type InstaQLOptions,\n type InstantConfig,\n type PageInfoResponse,\n type InstaQLLifecycleState,\n type InstaQLResponse,\n type ValidQuery,\n // classes\n Auth,\n Storage,\n txInit,\n InstantCoreDatabase,\n init as core_init,\n coerceQuery,\n InstantSchemaDef,\n RoomsOf,\n InstantError,\n IInstantDatabase,\n} from '@instantdb/core';\n\nimport { createSignal, createEffect, onCleanup, createMemo } from 'solid-js';\nimport type { Accessor } from 'solid-js';\n\nimport { InstantSolidRoom, rooms } from './InstantSolidRoom.js';\nimport version from './version.js';\n\nconst defaultState = {\n isLoading: true,\n data: undefined,\n pageInfo: undefined,\n error: undefined,\n} as const;\n\nconst defaultAuthState: AuthState = {\n isLoading: true,\n user: undefined,\n error: undefined,\n};\n\nfunction stateForResult(result: any) {\n return {\n isLoading: !Boolean(result),\n data: undefined,\n pageInfo: undefined,\n error: undefined,\n ...(result ? result : {}),\n };\n}\n\nexport class InstantSolidDatabase<\n Schema extends InstantSchemaDef<any, any, any>,\n UseDates extends boolean = false,\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 core: InstantCoreDatabase<Schema, UseDates>;\n\n constructor(core: InstantCoreDatabase<Schema, UseDates>) {\n this.core = core;\n this.auth = this.core.auth;\n this.storage = this.core.storage;\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 * @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 * 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 * const goalId = id();\n * db.transact(db.tx.goals[goalId].update({title: \"Get fit\"}))\n */\n transact = (\n chunks: TransactionChunk<any, any> | TransactionChunk<any, any>[],\n ) => {\n return this.core.transact(chunks);\n };\n\n /**\n * One time query for the logged in state.\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 * Use this for one-off queries.\n * Returns local data if available, otherwise fetches from the server.\n *\n * @see https://instantdb.com/docs/instaql\n *\n * @example\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 // Solid reactive hooks\n\n /**\n * Use this to query your data!\n *\n * @see https://instantdb.com/docs/instaql\n *\n * @example\n * const state = db.useQuery({ goals: {} });\n * // state().isLoading, state().error, state().data\n */\n useQuery = <Q extends ValidQuery<Q, Schema>>(\n query: null | Q,\n opts?: InstaQLOptions,\n ): Accessor<InstaQLLifecycleState<Schema, Q, UseDates>> => {\n const [state, setState] = createSignal<\n InstaQLLifecycleState<Schema, Q, UseDates>\n >(defaultState as InstaQLLifecycleState<Schema, Q, UseDates>);\n\n createEffect(() => {\n if (!query) {\n setState(\n () => defaultState as InstaQLLifecycleState<Schema, Q, UseDates>,\n );\n return;\n }\n\n let q = query;\n if (opts && 'ruleParams' in opts) {\n q = { $$ruleParams: (opts as any)['ruleParams'], ...q };\n }\n\n const coerced = coerceQuery(q);\n const prev = this.core._reactor.getPreviousResult(coerced);\n if (prev) {\n setState(\n () =>\n stateForResult(prev) as InstaQLLifecycleState<Schema, Q, UseDates>,\n );\n }\n\n const unsub = this.core.subscribeQuery<Q, UseDates>(coerced, (result) => {\n setState(\n () =>\n Object.assign(\n {\n isLoading: false,\n data: undefined,\n pageInfo: undefined,\n error: undefined,\n },\n result,\n ) as InstaQLLifecycleState<Schema, Q, UseDates>,\n );\n });\n\n onCleanup(unsub);\n });\n\n return 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 * @see https://instantdb.com/docs/auth\n * @example\n * function App() {\n * const auth = db.useAuth();\n * // auth().isLoading, auth().user, auth().error\n * }\n */\n useAuth = (): Accessor<AuthState> => {\n const [state, setState] = createSignal<AuthState>(\n this.core._reactor._currentUserCached ?? defaultAuthState,\n );\n\n createEffect(() => {\n const unsub = this.core.subscribeAuth((auth) => {\n setState({ isLoading: false, ...auth });\n });\n\n onCleanup(unsub);\n });\n\n return state;\n };\n\n /**\n * Subscribe to the currently logged in user.\n * If the user is not logged in, this will throw an Error.\n *\n * @see https://instantdb.com/docs/auth\n * @example\n * function UserDisplay() {\n * const user = db.useUser();\n * return <div>Logged in as: {user().email}</div>\n * }\n */\n useUser = (): Accessor<User> => {\n const auth = this.useAuth();\n return createMemo(() => {\n const { user } = auth();\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 /**\n * Listen for connection status changes to Instant.\n *\n * @see https://www.instantdb.com/docs/patterns#connection-status\n * @example\n * function App() {\n * const status = db.useConnectionStatus();\n * return <div>Connection state: {status()}</div>\n * }\n */\n useConnectionStatus = (): Accessor<ConnectionStatus> => {\n const [status, setStatus] = createSignal<ConnectionStatus>(\n this.core._reactor.status as ConnectionStatus,\n );\n\n createEffect(() => {\n const unsub = this.core.subscribeConnectionStatus((newStatus) => {\n setStatus(() => newStatus);\n });\n\n onCleanup(unsub);\n });\n\n return status;\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 * // deviceId() is null initially, then the ID string\n */\n useLocalId = (name: string): Accessor<string | null> => {\n const [localId, setLocalId] = createSignal<string | null>(null);\n\n createEffect(() => {\n let mounted = true;\n this.getLocalId(name).then((id) => {\n if (mounted) {\n setLocalId(() => id);\n }\n });\n onCleanup(() => {\n mounted = false;\n });\n });\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 * @see https://instantdb.com/docs/presence-and-topics\n *\n * @example\n * const room = db.room('chat', roomId);\n * const presence = db.rooms.usePresence(room);\n */\n room<RoomType extends keyof Rooms>(\n type: RoomType = '_defaultRoomType' as RoomType,\n id: string = '_defaultRoomId',\n ) {\n return new InstantSolidRoom<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 presence = db.rooms.usePresence(room);\n * const publish = db.rooms.usePublishTopic(room, 'emoji');\n */\n rooms = rooms;\n}\n\n// -----------\n// init\n\n/**\n * The first step: init your application!\n *\n * Visit https://instantdb.com/dash to get your `appId` :)\n *\n * @example\n * import { init } from \"@instantdb/solidjs\"\n *\n * const db = init({ appId: \"my-app-id\" })\n *\n * // You can also provide a schema for type safety and editor autocomplete!\n *\n * import { init } from \"@instantdb/solidjs\"\n * import schema from \"../instant.schema.ts\";\n *\n * const db = init({ appId: \"my-app-id\", schema })\n */\nexport function init<\n Schema extends InstantSchemaDef<any, any, any>,\n UseDates extends boolean = false,\n>(\n config: Omit<InstantConfig<Schema, UseDates>, 'useDateObjects'> & {\n useDateObjects?: UseDates;\n },\n): InstantSolidDatabase<Schema, UseDates> {\n const coreDb = core_init<Schema, UseDates>(config, undefined, undefined, {\n '@instantdb/solidjs': version,\n });\n return new InstantSolidDatabase<Schema, UseDates>(coreDb);\n}\n\nexport const init_experimental = init;\n"]}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { type PresenceOpts, type PresenceResponse, type RoomSchemaShape, InstantCoreDatabase, InstantSchemaDef } from '@instantdb/core';
|
|
2
|
+
import type { Accessor } from 'solid-js';
|
|
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: Accessor<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 keyof RoomSchema, TopicType extends keyof RoomSchema[RoomType]['topics']>(room: InstantSolidRoom<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 keyof RoomSchema, TopicType extends keyof RoomSchema[RoomType]['topics']>(room: InstantSolidRoom<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 presence = db.rooms.usePresence(room, { keys: ["name", "avatar"] });
|
|
57
|
+
* // presence().peers, presence().isLoading, presence().publishPresence
|
|
58
|
+
* }
|
|
59
|
+
*/
|
|
60
|
+
export declare function usePresence<RoomSchema extends RoomSchemaShape, RoomType extends keyof RoomSchema, Keys extends keyof RoomSchema[RoomType]['presence']>(room: InstantSolidRoom<any, RoomSchema, RoomType>, opts?: PresenceOpts<RoomSchema[RoomType]['presence'], Keys>): Accessor<PresenceHandle<RoomSchema[RoomType]['presence'], Keys>>;
|
|
61
|
+
/**
|
|
62
|
+
* Publishes presence data to a room
|
|
63
|
+
*
|
|
64
|
+
* @see https://instantdb.com/docs/presence-and-topics
|
|
65
|
+
* @example
|
|
66
|
+
* function App({ roomId, nickname }) {
|
|
67
|
+
* const room = db.room('chat', roomId);
|
|
68
|
+
* db.rooms.useSyncPresence(room, { nickname });
|
|
69
|
+
* }
|
|
70
|
+
*/
|
|
71
|
+
export declare function useSyncPresence<RoomSchema extends RoomSchemaShape, RoomType extends keyof RoomSchema>(room: InstantSolidRoom<any, RoomSchema, RoomType>, data: Partial<RoomSchema[RoomType]['presence']>, deps?: any[]): void;
|
|
72
|
+
/**
|
|
73
|
+
* Manage typing indicator state
|
|
74
|
+
*
|
|
75
|
+
* @see https://instantdb.com/docs/presence-and-topics
|
|
76
|
+
* @example
|
|
77
|
+
* function App({ roomId }) {
|
|
78
|
+
* const room = db.room('chat', roomId);
|
|
79
|
+
* const typing = db.rooms.useTypingIndicator(room, "chat-input");
|
|
80
|
+
* // typing.active(), typing.setActive(bool), typing.inputProps
|
|
81
|
+
* }
|
|
82
|
+
*/
|
|
83
|
+
export declare function useTypingIndicator<RoomSchema extends RoomSchemaShape, RoomType extends keyof RoomSchema>(room: InstantSolidRoom<any, RoomSchema, RoomType>, inputName: string, opts?: TypingIndicatorOpts): TypingIndicatorHandle<RoomSchema[RoomType]['presence']>;
|
|
84
|
+
export declare const rooms: {
|
|
85
|
+
useTopicEffect: typeof useTopicEffect;
|
|
86
|
+
usePublishTopic: typeof usePublishTopic;
|
|
87
|
+
usePresence: typeof usePresence;
|
|
88
|
+
useSyncPresence: typeof useSyncPresence;
|
|
89
|
+
useTypingIndicator: typeof useTypingIndicator;
|
|
90
|
+
};
|
|
91
|
+
export declare class InstantSolidRoom<Schema extends InstantSchemaDef<any, any, any>, RoomSchema extends RoomSchemaShape, RoomType extends keyof RoomSchema> {
|
|
92
|
+
core: InstantCoreDatabase<Schema, boolean>;
|
|
93
|
+
type: RoomType;
|
|
94
|
+
id: string;
|
|
95
|
+
constructor(core: InstantCoreDatabase<Schema, boolean>, type: RoomType, id: string);
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=InstantSolidRoom.d.ts.map
|