@superlayer/svelte 1.0.67

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/LICENSE.md ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,4 @@
1
+ InterfaceDB SDK
2
+ Derived from Instant (https://github.com/instantdb/instant), revision 7607eda60547e0068f05aeb2c43ac92c6356f65d.
3
+ Original source copyrights and licence notices are retained.
4
+ Modified by InterfaceDB: npm package names, service defaults, tooling and documentation.
package/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # @superlayer/svelte
2
+
3
+ Svelte client for Superlayer.
4
+
5
+ [Documentation](https://interfacedb.com/docs) · [Source](https://github.com/InterfaceLDN/Superlayer)
6
+
7
+ Maintained by Superlayer, based on the Instant source. See LICENSE.md and NOTICE for attribution.
8
+
9
+ Welcome to [Superlayer’s](https://interfacedb.com) Svelte SDK.
10
+
11
+ ```svelte
12
+ <!-- ༼ つ ◕_◕ ༽つ Real-time Chat -->
13
+ <!-- ---------------------------------- -->
14
+ <!-- * Updates instantly -->
15
+ <!-- * Multiplayer -->
16
+ <!-- * Works offline -->
17
+
18
+ <script lang="ts">
19
+ import { init, id } from '@superlayer/svelte';
20
+
21
+ const db = init({ appId: import.meta.env.VITE_INSTANT_APP_ID });
22
+
23
+ // 1. Read
24
+ const query = db.useQuery({ messages: {} });
25
+
26
+ // 2. Write
27
+ const addMessage = (message) => {
28
+ db.transact(db.tx.messages[id()].update(message));
29
+ };
30
+ </script>
31
+
32
+ <!-- 3. Render! -->
33
+ <UI data={query.data} onAdd={addMessage} />
34
+ ```
35
+
36
+ # Get Started
37
+
38
+ Follow the [getting started](https://www.interfacedb.com/docs/start-svelte) tutorial to set up a live Svelte app in under 5 minutes!
39
+
40
+ # Questions?
41
+
42
+ If you have any questions, feel free to drop us a line on our [issue tracker](https://github.com/InterfaceLDN/Superlayer/issues)
@@ -0,0 +1,152 @@
1
+ <script lang="ts" generics="RoomSchema extends RoomSchemaShape, RoomType extends string & keyof RoomSchema">
2
+ import type { RoomSchemaShape } from '@superlayer/core';
3
+ import type { InstantSvelteRoom } from './InstantSvelteRoom.svelte.js';
4
+ import { usePresence } from './InstantSvelteRoom.svelte.js';
5
+ import type { Snippet } from 'svelte';
6
+
7
+ let {
8
+ room,
9
+ spaceId: _spaceId,
10
+ as = 'div',
11
+ className,
12
+ style,
13
+ userCursorColor,
14
+ children,
15
+ renderCursor,
16
+ propagate,
17
+ zIndex,
18
+ }: {
19
+ room: InstantSvelteRoom<any, RoomSchema, RoomType>;
20
+ spaceId?: string;
21
+ as?: string;
22
+ className?: string;
23
+ style?: string;
24
+ userCursorColor?: string;
25
+ children?: Snippet;
26
+ renderCursor?: Snippet<[{ color: string; presence: RoomSchema[RoomType]['presence'] }]>;
27
+ propagate?: boolean;
28
+ zIndex?: number;
29
+ } = $props();
30
+
31
+ // svelte-ignore state_referenced_locally
32
+ const spaceId = _spaceId || `cursors-space-default--${String(room.type)}-${room.id}`;
33
+
34
+ // svelte-ignore state_referenced_locally
35
+ const cursorsPresence = usePresence(room, {
36
+ keys: [spaceId] as (keyof RoomSchema[RoomType]['presence'])[],
37
+ });
38
+
39
+ function publishCursor(rect: DOMRect, touch: { clientX: number; clientY: number }) {
40
+ const x = touch.clientX;
41
+ const y = touch.clientY;
42
+ const xPercent = ((x - rect.left) / rect.width) * 100;
43
+ const yPercent = ((y - rect.top) / rect.height) * 100;
44
+ cursorsPresence.publishPresence({
45
+ [spaceId]: { x, y, xPercent, yPercent, color: userCursorColor },
46
+ } as RoomSchema[RoomType]['presence']);
47
+ }
48
+
49
+ function onMouseMove(e: MouseEvent) {
50
+ if (!propagate) {
51
+ e.stopPropagation();
52
+ }
53
+ const rect = (e.currentTarget as Element).getBoundingClientRect();
54
+ publishCursor(rect, e);
55
+ }
56
+
57
+ function onMouseOut() {
58
+ cursorsPresence.publishPresence({
59
+ [spaceId]: undefined,
60
+ } as RoomSchema[RoomType]['presence']);
61
+ }
62
+
63
+ function onTouchMove(e: TouchEvent) {
64
+ if (e.touches.length !== 1) return;
65
+ const touch = e.touches[0];
66
+ if (touch.target instanceof Element) {
67
+ if (!propagate) {
68
+ e.stopPropagation();
69
+ }
70
+ const rect = touch.target.getBoundingClientRect();
71
+ publishCursor(rect, touch);
72
+ }
73
+ }
74
+
75
+ function onTouchEnd() {
76
+ cursorsPresence.publishPresence({
77
+ [spaceId]: undefined,
78
+ } as RoomSchema[RoomType]['presence']);
79
+ }
80
+
81
+ const defaultZ = 99999;
82
+
83
+ const peers = $derived(Object.entries(cursorsPresence.peers));
84
+ const fullPresence = $derived(
85
+ room.core._reactor.getPresence(room.type, room.id),
86
+ );
87
+ </script>
88
+
89
+ <!-- svelte-ignore a11y_no_static_element_interactions -->
90
+ <svelte:element
91
+ this={as}
92
+ class={className}
93
+ style="position: relative; {style ?? ''}"
94
+ onmousemove={onMouseMove}
95
+ onmouseout={onMouseOut}
96
+ onblur={onMouseOut}
97
+ ontouchmove={onTouchMove}
98
+ ontouchend={onTouchEnd}
99
+ >
100
+ {#if children}
101
+ {@render children()}
102
+ {/if}
103
+ <div
104
+ style="position: absolute; top: 0; left: 0; bottom: 0; right: 0; overflow: hidden; pointer-events: none; user-select: none; z-index: {zIndex ?? defaultZ};"
105
+ >
106
+ {#each peers as [peerId, presence] (peerId)}
107
+ {@const cursor = presence[spaceId]}
108
+ {#if cursor}
109
+ <div
110
+ style="position: absolute; top: 0; left: 0; bottom: 0; right: 0; transform: translate({cursor.xPercent}%, {cursor.yPercent}%); transform-origin: 0 0; transition: transform 100ms;"
111
+ >
112
+ {#if renderCursor}
113
+ {@render renderCursor({
114
+ color: cursor.color,
115
+ presence: fullPresence?.peers[peerId],
116
+ })}
117
+ {:else}
118
+ {@const fill = cursor.color || 'black'}
119
+ <svg
120
+ style="height: 35px; width: 35px;"
121
+ viewBox="0 0 35 35"
122
+ fill="none"
123
+ xmlns="http://www.w3.org/2000/svg"
124
+ >
125
+ <g
126
+ fill="rgba(0,0,0,.2)"
127
+ transform="matrix(1, 0, 0, 1, -11.999999046325684, -8.406899452209473)"
128
+ >
129
+ <path d="m12 24.4219v-16.015l11.591 11.619h-6.781l-.411.124z" />
130
+ <path d="m21.0845 25.0962-3.605 1.535-4.682-11.089 3.686-1.553z" />
131
+ </g>
132
+ <g
133
+ fill="white"
134
+ transform="matrix(1, 0, 0, 1, -11.999999046325684, -8.406899452209473)"
135
+ >
136
+ <path d="m12 24.4219v-16.015l11.591 11.619h-6.781l-.411.124z" />
137
+ <path d="m21.0845 25.0962-3.605 1.535-4.682-11.089 3.686-1.553z" />
138
+ </g>
139
+ <g
140
+ fill={fill}
141
+ transform="matrix(1, 0, 0, 1, -11.999999046325684, -8.406899452209473)"
142
+ >
143
+ <path d="m19.751 24.4155-1.844.774-3.1-7.374 1.841-.775z" />
144
+ <path d="m13 10.814v11.188l2.969-2.866.428-.139h4.768z" />
145
+ </g>
146
+ </svg>
147
+ {/if}
148
+ </div>
149
+ {/if}
150
+ {/each}
151
+ </div>
152
+ </svelte:element>
@@ -0,0 +1,42 @@
1
+ import type { RoomSchemaShape } from '@superlayer/core';
2
+ import type { InstantSvelteRoom } from './InstantSvelteRoom.svelte.js';
3
+ import type { Snippet } from 'svelte';
4
+ declare function $$render<RoomSchema extends RoomSchemaShape, RoomType extends string & keyof RoomSchema>(): {
5
+ props: {
6
+ room: InstantSvelteRoom<any, RoomSchema, RoomType>;
7
+ spaceId?: string;
8
+ as?: string;
9
+ className?: string;
10
+ style?: string;
11
+ userCursorColor?: string;
12
+ children?: Snippet;
13
+ renderCursor?: Snippet<[{
14
+ color: string;
15
+ presence: RoomSchema[RoomType]["presence"];
16
+ }]>;
17
+ propagate?: boolean;
18
+ zIndex?: number;
19
+ };
20
+ exports: {};
21
+ bindings: "";
22
+ slots: {};
23
+ events: {};
24
+ };
25
+ declare class __sveltets_Render<RoomSchema extends RoomSchemaShape, RoomType extends string & keyof RoomSchema> {
26
+ props(): ReturnType<typeof $$render<RoomSchema, RoomType>>['props'];
27
+ events(): ReturnType<typeof $$render<RoomSchema, RoomType>>['events'];
28
+ slots(): ReturnType<typeof $$render<RoomSchema, RoomType>>['slots'];
29
+ bindings(): "";
30
+ exports(): {};
31
+ }
32
+ interface $$IsomorphicComponent {
33
+ new <RoomSchema extends RoomSchemaShape, RoomType extends string & keyof RoomSchema>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<RoomSchema, RoomType>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<RoomSchema, RoomType>['props']>, ReturnType<__sveltets_Render<RoomSchema, RoomType>['events']>, ReturnType<__sveltets_Render<RoomSchema, RoomType>['slots']>> & {
34
+ $$bindings?: ReturnType<__sveltets_Render<RoomSchema, RoomType>['bindings']>;
35
+ } & ReturnType<__sveltets_Render<RoomSchema, RoomType>['exports']>;
36
+ <RoomSchema extends RoomSchemaShape, RoomType extends string & keyof RoomSchema>(internal: unknown, props: ReturnType<__sveltets_Render<RoomSchema, RoomType>['props']> & {}): ReturnType<__sveltets_Render<RoomSchema, RoomType>['exports']>;
37
+ z_$$bindings?: ReturnType<__sveltets_Render<any, any>['bindings']>;
38
+ }
39
+ declare const Cursors: $$IsomorphicComponent;
40
+ type Cursors<RoomSchema extends RoomSchemaShape, RoomType extends string & keyof RoomSchema> = InstanceType<typeof Cursors<RoomSchema, RoomType>>;
41
+ export default Cursors;
42
+ //# sourceMappingURL=Cursors.svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Cursors.svelte.d.ts","sourceRoot":"","sources":["../src/lib/Cursors.svelte.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAEvE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAA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AC,CAAC,EAAE,UAAU,CAAC,iBAAiB,CAAC,UAAU,EAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG;QAAE,UAAU,CAAC,EAAE,UAAU,CAAC,iBAAiB,CAAC,UAAU,EAAC,QAAQ,CAAC,CAAC,UAAU,CAAC,CAAC,CAAA;KAAE,GAAG,UAAU,CAAC,iBAAiB,CAAC,UAAU,EAAC,QAAQ,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;IACpjB,CAAC,UAAU,SAAS,eAAe,EAAC,QAAQ,SAAS,MAAM,GAAG,MAAM,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,CAAC,iBAAiB,CAAC,UAAU,EAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,GAAG,UAAU,CAAC,iBAAiB,CAAC,UAAU,EAAC,QAAQ,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;IAC3O,YAAY,CAAC,EAAE,UAAU,CAAC,iBAAiB,CAAC,GAAG,EAAC,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;CACrE;AACD,QAAA,MAAM,OAAO,EAAE,qBAAmC,CAAC;AACjC,KAAK,OAAO,CAAC,UAAU,SAAS,eAAe,EAAC,QAAQ,SAAS,MAAM,GAAG,MAAM,UAAU,IAAI,YAAY,CAAC,OAAO,OAAO,CAAC,UAAU,EAAC,QAAQ,CAAC,CAAC,CAAC;AAClJ,eAAe,OAAO,CAAC"}
@@ -0,0 +1,199 @@
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, Streams, InstantCoreDatabase, InstantSchemaDef, RoomsOf, IInstantDatabase } from '@superlayer/core';
2
+ import { InstantSvelteRoom } from './InstantSvelteRoom.svelte.js';
3
+ export type InfiniteQueryState<Schema extends InstantSchemaDef<any, any, any>, Q extends ValidQuery<Q, Schema>, UseDates extends boolean> = {
4
+ isLoading: boolean;
5
+ error: {
6
+ message: string;
7
+ } | undefined;
8
+ data: InstaQLResponse<Schema, Q, UseDates> | undefined;
9
+ canLoadNextPage: boolean;
10
+ loadNextPage: () => void;
11
+ };
12
+ export declare class InstantSvelteDatabase<Schema extends InstantSchemaDef<any, any, any>, UseDates extends boolean = false, Rooms extends RoomSchemaShape = RoomsOf<Schema>> implements IInstantDatabase<Schema> {
13
+ tx: import("@superlayer/core").TxChunk<Schema>;
14
+ auth: Auth;
15
+ storage: Storage;
16
+ streams: Streams;
17
+ core: InstantCoreDatabase<Schema, UseDates>;
18
+ constructor(core: InstantCoreDatabase<Schema, UseDates>);
19
+ /**
20
+ * Returns a unique ID for a given `name`. It's stored in local storage,
21
+ * so you will get the same ID across sessions.
22
+ *
23
+ * @example
24
+ * const deviceId = await db.getLocalId('device');
25
+ */
26
+ getLocalId: (name: string) => Promise<string>;
27
+ /**
28
+ * Use this to write data! You can create, update, delete, and link objects
29
+ *
30
+ * @see https://interfacedb.com/docs/instaml
31
+ *
32
+ * @example
33
+ * const goalId = id();
34
+ * db.transact(db.tx.goals[goalId].update({title: "Get fit"}))
35
+ */
36
+ transact: (chunks: TransactionChunk<any, any> | TransactionChunk<any, any>[]) => Promise<import("@superlayer/core").TransactionResult>;
37
+ /**
38
+ * One time query for the logged in state.
39
+ *
40
+ * @see https://interfacedb.com/docs/auth
41
+ * @example
42
+ * const user = await db.getAuth();
43
+ * console.log('logged in as', user.email)
44
+ */
45
+ getAuth(): Promise<User | null>;
46
+ /**
47
+ * Use this for one-off queries.
48
+ * Returns local data if available, otherwise fetches from the server.
49
+ *
50
+ * @see https://interfacedb.com/docs/instaql
51
+ *
52
+ * @example
53
+ * const resp = await db.queryOnce({ goals: {} });
54
+ * console.log(resp.data.goals)
55
+ */
56
+ queryOnce: <Q extends ValidQuery<Q, Schema>>(query: Q, opts?: InstaQLOptions) => Promise<{
57
+ data: InstaQLResponse<Schema, Q, UseDates>;
58
+ pageInfo: PageInfoResponse<Q>;
59
+ }>;
60
+ /**
61
+ * Use this to query your data!
62
+ *
63
+ * @see https://interfacedb.com/docs/instaql
64
+ *
65
+ * @example
66
+ * // basic query
67
+ * const state = db.useQuery({ goals: {} });
68
+ * // state.isLoading, state.error, state.data
69
+ *
70
+ * @example
71
+ * // conditional query (pass a function that returns null to skip)
72
+ * const auth = db.useAuth();
73
+ * const state = db.useQuery(() =>
74
+ * auth.user ? { todos: { $: { where: { 'owner.id': auth.user.id } } } } : null
75
+ * );
76
+ *
77
+ * @example
78
+ * // reactive query (re-runs when $state variables change)
79
+ * let filter = $state<'all' | 'done'>('all');
80
+ * const state = db.useQuery(() => {
81
+ * if (filter === 'all') return { todos: {} };
82
+ * return { todos: { $: { where: { done: true } } } };
83
+ * });
84
+ */
85
+ useQuery: <Q extends ValidQuery<Q, Schema>>(query: (() => null | Q) | null | Q, opts?: InstaQLOptions) => InstaQLLifecycleState<Schema, Q, UseDates>;
86
+ /**
87
+ * Subscribe to a query and incrementally load more items.
88
+ *
89
+ * Only one top level namespace in the query is allowed.
90
+ *
91
+ * @see https://interfacedb.com/docs/instaql
92
+ *
93
+ * @example
94
+ * const state = db.useInfiniteQuery({
95
+ * posts: {
96
+ * $: {
97
+ * limit: 20,
98
+ * order: { createdAt: 'desc' },
99
+ * },
100
+ * },
101
+ * });
102
+ * // state.data, state.isLoading, state.error,
103
+ * // state.canLoadNextPage, state.loadNextPage()
104
+ */
105
+ useInfiniteQuery: <Q extends ValidQuery<Q, Schema>>(query: (() => null | Q) | null | Q, opts?: InstaQLOptions) => InfiniteQueryState<Schema, Q, UseDates>;
106
+ /**
107
+ * Listen for the logged in state. This is useful
108
+ * for deciding when to show a login screen.
109
+ *
110
+ * @see https://interfacedb.com/docs/auth
111
+ * @example
112
+ * const auth = db.useAuth();
113
+ * // auth.isLoading, auth.user, auth.error
114
+ */
115
+ useAuth: () => AuthState;
116
+ /**
117
+ * Subscribe to the currently logged in user.
118
+ * If the user is not logged in, this will throw an Error.
119
+ *
120
+ * @see https://interfacedb.com/docs/auth
121
+ * @example
122
+ * const user = db.useUser();
123
+ * // user.email, user.id, etc.
124
+ * // Throws if not logged in
125
+ */
126
+ useUser: () => User;
127
+ /**
128
+ * Listen for connection status changes to Instant.
129
+ *
130
+ * @see https://www.interfacedb.com/docs/patterns#connection-status
131
+ * @example
132
+ * const status = db.useConnectionStatus();
133
+ * // status.current
134
+ */
135
+ useConnectionStatus: () => {
136
+ current: ConnectionStatus;
137
+ };
138
+ /**
139
+ * A hook that returns a unique ID for a given `name`. localIds are
140
+ * stored in local storage, so you will get the same ID across sessions.
141
+ *
142
+ * Initially returns `null`, and then loads the localId.
143
+ *
144
+ * @example
145
+ * const deviceId = db.useLocalId('device');
146
+ * // deviceId.current is null initially, then the ID string
147
+ */
148
+ useLocalId: (name: string) => {
149
+ current: string | null;
150
+ };
151
+ /**
152
+ * Obtain a handle to a room, which allows you to listen to topics and presence data
153
+ *
154
+ * @see https://interfacedb.com/docs/presence-and-topics
155
+ *
156
+ * @example
157
+ * const room = db.room('chat', roomId);
158
+ * const presence = db.rooms.usePresence(room);
159
+ */
160
+ room<RoomType extends keyof Rooms>(type?: RoomType, id?: string): InstantSvelteRoom<Schema, Rooms, RoomType>;
161
+ /**
162
+ * Hooks for working with rooms
163
+ *
164
+ * @see https://interfacedb.com/docs/presence-and-topics
165
+ *
166
+ * @example
167
+ * const room = db.room('chat', roomId);
168
+ * const presence = db.rooms.usePresence(room);
169
+ * const publish = db.rooms.usePublishTopic(room, 'emoji');
170
+ */
171
+ rooms: {
172
+ useTopicEffect: typeof import("./InstantSvelteRoom.svelte.js").useTopicEffect;
173
+ usePublishTopic: typeof import("./InstantSvelteRoom.svelte.js").usePublishTopic;
174
+ usePresence: typeof import("./InstantSvelteRoom.svelte.js").usePresence;
175
+ useSyncPresence: typeof import("./InstantSvelteRoom.svelte.js").useSyncPresence;
176
+ useTypingIndicator: typeof import("./InstantSvelteRoom.svelte.js").useTypingIndicator;
177
+ };
178
+ }
179
+ /**
180
+ * The first step: init your application!
181
+ *
182
+ * Visit https://interfacedb.com/dash to get your `appId` :)
183
+ *
184
+ * @example
185
+ * import { init } from "@superlayer/svelte"
186
+ *
187
+ * const db = init({ appId: "my-app-id" })
188
+ *
189
+ * // You can also provide a schema for type safety and editor autocomplete!
190
+ *
191
+ * import { init } from "@superlayer/svelte"
192
+ * import schema from "../instant.schema.ts";
193
+ *
194
+ * const db = init({ appId: "my-app-id", schema })
195
+ */
196
+ export declare function init<Schema extends InstantSchemaDef<any, any, any>, UseDates extends boolean = false>(config: Omit<InstantConfig<Schema, UseDates>, 'useDateObjects'> & {
197
+ useDateObjects?: UseDates;
198
+ }): InstantSvelteDatabase<Schema, UseDates>;
199
+ //# sourceMappingURL=InstantSvelteDatabase.svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InstantSvelteDatabase.svelte.d.ts","sourceRoot":"","sources":["../src/lib/InstantSvelteDatabase.svelte.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,EAClB,KAAK,gBAAgB,EACrB,KAAK,qBAAqB,EAC1B,KAAK,eAAe,EAEpB,KAAK,UAAU,EAEf,IAAI,EACJ,OAAO,EACP,OAAO,EAEP,mBAAmB,EAInB,gBAAgB,EAChB,OAAO,EAEP,gBAAgB,EACjB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,iBAAiB,EAAS,MAAM,+BAA+B,CAAC;AAUzE,MAAM,MAAM,kBAAkB,CAC5B,MAAM,SAAS,gBAAgB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAC9C,CAAC,SAAS,UAAU,CAAC,CAAC,EAAE,MAAM,CAAC,EAC/B,QAAQ,SAAS,OAAO,IAC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