@fidscript/instant-vue 0.1.0

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 (53) hide show
  1. package/dist/InstantVueDatabase.d.ts +190 -0
  2. package/dist/InstantVueDatabase.d.ts.map +1 -0
  3. package/dist/InstantVueDatabase.js +267 -0
  4. package/dist/InstantVueDatabase.js.map +1 -0
  5. package/dist/InstantVueRoom.d.ts +90 -0
  6. package/dist/InstantVueRoom.d.ts.map +1 -0
  7. package/dist/InstantVueRoom.js +180 -0
  8. package/dist/InstantVueRoom.js.map +1 -0
  9. package/dist/chunks/Cursor.vue_vue_type_script_setup_true_lang-Bs0W_w4T.js +32 -0
  10. package/dist/chunks/Cursor.vue_vue_type_script_setup_true_lang-Bs0W_w4T.js.map +1 -0
  11. package/dist/chunks/Cursors.vue_vue_type_script_setup_true_lang-Byc_ohVH.js +128 -0
  12. package/dist/chunks/Cursors.vue_vue_type_script_setup_true_lang-Byc_ohVH.js.map +1 -0
  13. package/dist/chunks/SignedIn.vue_vue_type_script_setup_true_lang-DyvMK-NN.js +18 -0
  14. package/dist/chunks/SignedIn.vue_vue_type_script_setup_true_lang-DyvMK-NN.js.map +1 -0
  15. package/dist/chunks/SignedOut.vue_vue_type_script_setup_true_lang-BlDXVRKk.js +18 -0
  16. package/dist/chunks/SignedOut.vue_vue_type_script_setup_true_lang-BlDXVRKk.js.map +1 -0
  17. package/dist/cli.d.ts +2 -0
  18. package/dist/cli.d.ts.map +1 -0
  19. package/dist/cli.js +2 -0
  20. package/dist/cli.js.map +1 -0
  21. package/dist/components/Cursor.js +5 -0
  22. package/dist/components/Cursor.js.map +1 -0
  23. package/dist/components/Cursor.vue.d.ts +6 -0
  24. package/dist/components/Cursor.vue.d.ts.map +1 -0
  25. package/dist/components/Cursors.js +5 -0
  26. package/dist/components/Cursors.js.map +1 -0
  27. package/dist/components/Cursors.vue.d.ts +32 -0
  28. package/dist/components/Cursors.vue.d.ts.map +1 -0
  29. package/dist/components/SignedIn.js +5 -0
  30. package/dist/components/SignedIn.js.map +1 -0
  31. package/dist/components/SignedIn.vue.d.ts +18 -0
  32. package/dist/components/SignedIn.vue.d.ts.map +1 -0
  33. package/dist/components/SignedOut.js +5 -0
  34. package/dist/components/SignedOut.js.map +1 -0
  35. package/dist/components/SignedOut.vue.d.ts +18 -0
  36. package/dist/components/SignedOut.vue.d.ts.map +1 -0
  37. package/dist/index.d.ts +8 -0
  38. package/dist/index.d.ts.map +1 -0
  39. package/dist/index.js +23 -0
  40. package/dist/index.js.map +1 -0
  41. package/dist/useInfiniteQuery.d.ts +25 -0
  42. package/dist/useInfiniteQuery.d.ts.map +1 -0
  43. package/dist/useInfiniteQuery.js +57 -0
  44. package/dist/useInfiniteQuery.js.map +1 -0
  45. package/dist/utils.d.ts +8 -0
  46. package/dist/utils.d.ts.map +1 -0
  47. package/dist/utils.js +12 -0
  48. package/dist/utils.js.map +1 -0
  49. package/dist/version.d.ts +3 -0
  50. package/dist/version.d.ts.map +1 -0
  51. package/dist/version.js +5 -0
  52. package/dist/version.js.map +1 -0
  53. package/package.json +47 -0
@@ -0,0 +1,190 @@
1
+ import { type User, type ConnectionStatus, type TransactionChunk, type RoomSchemaShape, type InstaQLOptions, type InstantConfig, type PageInfoResponse, type InstaQLResponse, type ValidQuery, Auth, Storage, Streams, InstantCoreDatabase, InstantSchemaDef, RoomsOf, IInstantDatabase } from '@fidscript/instant-sdk';
2
+ import type { Ref, ShallowRef, ComputedRef, MaybeRefOrGetter } from 'vue';
3
+ import { InstantVueRoom } from './InstantVueRoom.js';
4
+ import type { InfiniteQueryResult } from './useInfiniteQuery.js';
5
+ export type UseQueryReturn<Schema extends InstantSchemaDef<any, any, any>, Q extends ValidQuery<Q, Schema>, UseDates extends boolean> = {
6
+ isLoading: Ref<boolean>;
7
+ data: ShallowRef<InstaQLResponse<Schema, Q, UseDates> | undefined>;
8
+ pageInfo: ShallowRef<PageInfoResponse<Q> | undefined>;
9
+ error: ShallowRef<{
10
+ message: string;
11
+ } | undefined>;
12
+ };
13
+ export type UseAuthReturn = {
14
+ isLoading: Ref<boolean>;
15
+ user: ShallowRef<User | null | undefined>;
16
+ error: ShallowRef<{
17
+ message: string;
18
+ } | undefined>;
19
+ };
20
+ export declare class InstantVueDatabase<Schema extends InstantSchemaDef<any, any, any>, UseDates extends boolean = false, Rooms extends RoomSchemaShape = RoomsOf<Schema>> implements IInstantDatabase<Schema> {
21
+ tx: import("@fidscript/instant-sdk").TxChunk<Schema>;
22
+ auth: Auth;
23
+ storage: Storage;
24
+ streams: Streams;
25
+ core: InstantCoreDatabase<Schema, UseDates>;
26
+ constructor(core: InstantCoreDatabase<Schema, UseDates>);
27
+ /**
28
+ * Returns a unique ID for a given `name`. It's stored in local storage,
29
+ * so you will get the same ID across sessions.
30
+ *
31
+ * @example
32
+ * const deviceId = await db.getLocalId('device');
33
+ */
34
+ getLocalId: (name: string) => Promise<string>;
35
+ /**
36
+ * Use this to write data! You can create, update, delete, and link objects
37
+ *
38
+ * @see https://instantdb.com/docs/instaml
39
+ *
40
+ * @example
41
+ * const goalId = id();
42
+ * db.transact(db.tx.goals[goalId].update({title: "Get fit"}))
43
+ */
44
+ transact: (chunks: TransactionChunk<any, any> | TransactionChunk<any, any>[]) => Promise<import("@fidscript/instant-sdk").TransactionResult>;
45
+ /**
46
+ * One time query for the logged in state.
47
+ *
48
+ * @see https://instantdb.com/docs/auth
49
+ * @example
50
+ * const user = await db.getAuth();
51
+ * console.log('logged in as', user.email)
52
+ */
53
+ getAuth(): Promise<User | null>;
54
+ /**
55
+ * Use this for one-off queries.
56
+ * Returns local data if available, otherwise fetches from the server.
57
+ *
58
+ * @see https://instantdb.com/docs/instaql
59
+ *
60
+ * @example
61
+ * const resp = await db.queryOnce({ goals: {} });
62
+ * console.log(resp.data.goals)
63
+ */
64
+ queryOnce: <Q extends ValidQuery<Q, Schema>>(query: Q, opts?: InstaQLOptions) => Promise<{
65
+ data: InstaQLResponse<Schema, Q, UseDates>;
66
+ pageInfo: PageInfoResponse<Q>;
67
+ }>;
68
+ /**
69
+ * Use this to query your data!
70
+ *
71
+ * @see https://instantdb.com/docs/instaql
72
+ *
73
+ * @example
74
+ * // basic query — refs auto-unwrap in templates
75
+ * const { isLoading, error, data } = db.useQuery({ goals: {} });
76
+ *
77
+ * @example
78
+ * // reactive query — pass a getter that returns null to skip
79
+ * const { user } = db.useAuth();
80
+ * const { data } = db.useQuery(() =>
81
+ * user.value ? { todos: { $: { where: { 'owner.id': user.value.id } } } } : null,
82
+ * );
83
+ *
84
+ * @example
85
+ * // pass a ref directly
86
+ * const query = ref<{ todos: {} } | null>({ todos: {} });
87
+ * const { data } = db.useQuery(query);
88
+ */
89
+ useQuery: <Q extends ValidQuery<Q, Schema>>(query: MaybeRefOrGetter<Q | null>, opts?: MaybeRefOrGetter<InstaQLOptions | null | undefined>) => UseQueryReturn<Schema, Q, UseDates>;
90
+ /**
91
+ * Subscribe to a query and incrementally load more items.
92
+ *
93
+ * Only one top-level namespace in the query is allowed.
94
+ *
95
+ * @example
96
+ * const { data, isLoading, error, loadNextPage, canLoadNextPage } =
97
+ * db.useInfiniteQuery({
98
+ * posts: { $: { limit: 20, order: { createdAt: 'desc' } } },
99
+ * });
100
+ */
101
+ useInfiniteQuery: <Q extends ValidQuery<Q, Schema>>(query: MaybeRefOrGetter<Q | null>, opts?: MaybeRefOrGetter<InstaQLOptions | undefined>) => InfiniteQueryResult<Schema, Q, UseDates>;
102
+ /**
103
+ * Listen for the logged in state. This is useful
104
+ * for deciding when to show a login screen.
105
+ *
106
+ * @see https://instantdb.com/docs/auth
107
+ * @example
108
+ * const { isLoading, user, error } = db.useAuth();
109
+ */
110
+ useAuth: () => UseAuthReturn;
111
+ /**
112
+ * Subscribe to the currently logged in user. Throws if the user isn't
113
+ * signed in when `.value` is accessed — wrap callers with `<SignedIn>` or
114
+ * a `useAuth` check.
115
+ *
116
+ * @see https://instantdb.com/docs/auth
117
+ * @example
118
+ * const user = db.useUser();
119
+ * // user.value.email
120
+ */
121
+ useUser: () => ComputedRef<User>;
122
+ /**
123
+ * Listen for connection status changes to Instant.
124
+ *
125
+ * @see https://www.instantdb.com/docs/patterns#connection-status
126
+ * @example
127
+ * const status = db.useConnectionStatus();
128
+ * // status.value
129
+ */
130
+ useConnectionStatus: () => Ref<ConnectionStatus>;
131
+ /**
132
+ * A hook that returns a unique ID for a given `name`. localIds are stored in
133
+ * local storage, so you get the same ID across sessions.
134
+ *
135
+ * Returns `null` initially, then the loaded ID.
136
+ *
137
+ * @example
138
+ * const deviceId = db.useLocalId('device');
139
+ * // deviceId.value is null initially, then the ID string
140
+ */
141
+ useLocalId: (name: MaybeRefOrGetter<string>) => Ref<string | null>;
142
+ /**
143
+ * Obtain a handle to a room, which allows you to listen to topics and presence data
144
+ *
145
+ * @see https://instantdb.com/docs/presence-and-topics
146
+ *
147
+ * @example
148
+ * const room = db.room('chat', roomId);
149
+ * const { peers } = db.rooms.usePresence(room);
150
+ */
151
+ room<RoomType extends string & keyof Rooms>(type?: MaybeRefOrGetter<RoomType | undefined>, id?: MaybeRefOrGetter<string | undefined>): InstantVueRoom<Schema, Rooms, RoomType>;
152
+ /**
153
+ * Hooks for working with rooms
154
+ *
155
+ * @see https://instantdb.com/docs/presence-and-topics
156
+ *
157
+ * @example
158
+ * const room = db.room('chat', roomId);
159
+ * const { peers } = db.rooms.usePresence(room);
160
+ * const publish = db.rooms.usePublishTopic(room, 'emoji');
161
+ */
162
+ rooms: {
163
+ useTopicEffect: typeof import("./InstantVueRoom.js").useTopicEffect;
164
+ usePublishTopic: typeof import("./InstantVueRoom.js").usePublishTopic;
165
+ usePresence: typeof import("./InstantVueRoom.js").usePresence;
166
+ useSyncPresence: typeof import("./InstantVueRoom.js").useSyncPresence;
167
+ useTypingIndicator: typeof import("./InstantVueRoom.js").useTypingIndicator;
168
+ };
169
+ }
170
+ /**
171
+ * The first step: init your application!
172
+ *
173
+ * Visit https://instantdb.com/dash to get your `appId` :)
174
+ *
175
+ * @example
176
+ * import { init } from "@instantdb/vue"
177
+ *
178
+ * const db = init({ appId: "my-app-id" })
179
+ *
180
+ * // You can also provide a schema for type safety and editor autocomplete!
181
+ *
182
+ * import { init } from "@instantdb/vue"
183
+ * import schema from "../instant.schema.ts";
184
+ *
185
+ * const db = init({ appId: "my-app-id", schema })
186
+ */
187
+ export declare function init<Schema extends InstantSchemaDef<any, any, any>, UseDates extends boolean = false>(config: Omit<InstantConfig<Schema, UseDates>, 'useDateObjects'> & {
188
+ useDateObjects?: UseDates;
189
+ }): InstantVueDatabase<Schema, UseDates>;
190
+ //# sourceMappingURL=InstantVueDatabase.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InstantVueDatabase.d.ts","sourceRoot":"","sources":["../src/InstantVueDatabase.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,IAAI,EACT,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,UAAU,EAEf,IAAI,EACJ,OAAO,EACP,OAAO,EAEP,mBAAmB,EAInB,gBAAgB,EAChB,OAAO,EAEP,gBAAgB,EACjB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,KAAK,EAAE,GAAG,EAAE,UAAU,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,KAAK,CAAC;AAE1E,OAAO,EAAE,cAAc,EAAS,MAAM,qBAAqB,CAAC;AAG5D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAMjE,MAAM,MAAM,cAAc,CACxB,MAAM,SAAS,gBAAgB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAC9C,CAAC,SAAS,UAAU,CAAC,CAAC,EAAE,MAAM,CAAC,EAC/B,QAAQ,SAAS,OAAO,IACtB;IACF,SAAS,EAAE,GAAG,CAAC,OAAO,CAA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ACH,IAAI,CAAC,QAAQ,SAAS,MAAM,GAAG,MAAM,KAAK,EACxC,IAAI,CAAC,EAAE,gBAAgB,CAAC,QAAQ,GAAG,SAAS,CAAC,EAC7C,EAAE,CAAC,EAAE,gBAAgB,CAAC,MAAM,GAAG,SAAS,CAAC;IAS3C;;;;;;;;;OASG;IACH,KAAK;;;;;;MAAS;CACf;AAKD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,IAAI,CAClB,MAAM,SAAS,gBAAgB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAC9C,QAAQ,SAAS,OAAO,GAAG,KAAK,EAEhC,MAAM,EAAE,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,QAAQ,CAAC,EAAE,gBAAgB,CAAC,GAAG;IAChE,cAAc,CAAC,EAAE,QAAQ,CAAC;CAC3B,GACA,kBAAkB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAKtC"}
@@ -0,0 +1,267 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
+ import { txInit, coerceQuery, weakHash, InstantError, init as init$1 } from "@fidscript/instant-sdk";
5
+ import { ref, shallowRef, computed, toValue, watch } from "vue";
6
+ import { InstantVueRoom, rooms } from "./InstantVueRoom.js";
7
+ import { tryOnScopeDispose } from "./utils.js";
8
+ import { useInfiniteQuery } from "./useInfiniteQuery.js";
9
+ import version from "./version.js";
10
+ class InstantVueDatabase {
11
+ constructor(core) {
12
+ __publicField(this, "tx", txInit());
13
+ __publicField(this, "auth");
14
+ __publicField(this, "storage");
15
+ __publicField(this, "streams");
16
+ __publicField(this, "core");
17
+ /**
18
+ * Returns a unique ID for a given `name`. It's stored in local storage,
19
+ * so you will get the same ID across sessions.
20
+ *
21
+ * @example
22
+ * const deviceId = await db.getLocalId('device');
23
+ */
24
+ __publicField(this, "getLocalId", (name) => {
25
+ return this.core.getLocalId(name);
26
+ });
27
+ /**
28
+ * Use this to write data! You can create, update, delete, and link objects
29
+ *
30
+ * @see https://instantdb.com/docs/instaml
31
+ *
32
+ * @example
33
+ * const goalId = id();
34
+ * db.transact(db.tx.goals[goalId].update({title: "Get fit"}))
35
+ */
36
+ __publicField(this, "transact", (chunks) => {
37
+ return this.core.transact(chunks);
38
+ });
39
+ /**
40
+ * Use this for one-off queries.
41
+ * Returns local data if available, otherwise fetches from the server.
42
+ *
43
+ * @see https://instantdb.com/docs/instaql
44
+ *
45
+ * @example
46
+ * const resp = await db.queryOnce({ goals: {} });
47
+ * console.log(resp.data.goals)
48
+ */
49
+ __publicField(this, "queryOnce", (query, opts) => {
50
+ return this.core.queryOnce(query, opts);
51
+ });
52
+ // -----------
53
+ // Vue reactive hooks
54
+ /**
55
+ * Use this to query your data!
56
+ *
57
+ * @see https://instantdb.com/docs/instaql
58
+ *
59
+ * @example
60
+ * // basic query — refs auto-unwrap in templates
61
+ * const { isLoading, error, data } = db.useQuery({ goals: {} });
62
+ *
63
+ * @example
64
+ * // reactive query — pass a getter that returns null to skip
65
+ * const { user } = db.useAuth();
66
+ * const { data } = db.useQuery(() =>
67
+ * user.value ? { todos: { $: { where: { 'owner.id': user.value.id } } } } : null,
68
+ * );
69
+ *
70
+ * @example
71
+ * // pass a ref directly
72
+ * const query = ref<{ todos: {} } | null>({ todos: {} });
73
+ * const { data } = db.useQuery(query);
74
+ */
75
+ __publicField(this, "useQuery", (query, opts) => {
76
+ const isLoading = ref(true);
77
+ const data = shallowRef(
78
+ void 0
79
+ );
80
+ const pageInfo = shallowRef(void 0);
81
+ const error = shallowRef(void 0);
82
+ const resolvedQuery = computed(() => {
83
+ const q = toValue(query);
84
+ if (!q) return null;
85
+ const o = toValue(opts);
86
+ const withParams = o && "ruleParams" in o ? { $$ruleParams: o.ruleParams, ...q } : q;
87
+ return coerceQuery(withParams);
88
+ });
89
+ const queryHash = computed(() => weakHash(resolvedQuery.value));
90
+ const stop = watch(
91
+ queryHash,
92
+ (_, __, onCleanup) => {
93
+ const q = resolvedQuery.value;
94
+ const cached = q ? this.core._reactor.getPreviousResult(q) : null;
95
+ isLoading.value = !cached;
96
+ data.value = cached == null ? void 0 : cached.data;
97
+ pageInfo.value = cached == null ? void 0 : cached.pageInfo;
98
+ error.value = cached == null ? void 0 : cached.error;
99
+ if (!q) return;
100
+ const unsub = this.core.subscribeQuery(q, (r) => {
101
+ isLoading.value = false;
102
+ data.value = r.data;
103
+ pageInfo.value = r.pageInfo;
104
+ error.value = r.error;
105
+ });
106
+ onCleanup(unsub);
107
+ },
108
+ { immediate: true }
109
+ );
110
+ tryOnScopeDispose(stop);
111
+ return { isLoading, data, pageInfo, error };
112
+ });
113
+ /**
114
+ * Subscribe to a query and incrementally load more items.
115
+ *
116
+ * Only one top-level namespace in the query is allowed.
117
+ *
118
+ * @example
119
+ * const { data, isLoading, error, loadNextPage, canLoadNextPage } =
120
+ * db.useInfiniteQuery({
121
+ * posts: { $: { limit: 20, order: { createdAt: 'desc' } } },
122
+ * });
123
+ */
124
+ __publicField(this, "useInfiniteQuery", (query, opts) => {
125
+ return useInfiniteQuery(this.core, query, opts);
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
+ * const { isLoading, user, error } = db.useAuth();
134
+ */
135
+ __publicField(this, "useAuth", () => {
136
+ const cached = this.core._reactor._currentUserCached;
137
+ const isLoading = ref((cached == null ? void 0 : cached.isLoading) ?? true);
138
+ const user = shallowRef(cached == null ? void 0 : cached.user);
139
+ const error = shallowRef(cached == null ? void 0 : cached.error);
140
+ const unsub = this.core.subscribeAuth((auth) => {
141
+ isLoading.value = false;
142
+ user.value = auth.user ?? null;
143
+ error.value = auth.error;
144
+ });
145
+ tryOnScopeDispose(unsub);
146
+ return { isLoading, user, error };
147
+ });
148
+ /**
149
+ * Subscribe to the currently logged in user. Throws if the user isn't
150
+ * signed in when `.value` is accessed — wrap callers with `<SignedIn>` or
151
+ * a `useAuth` check.
152
+ *
153
+ * @see https://instantdb.com/docs/auth
154
+ * @example
155
+ * const user = db.useUser();
156
+ * // user.value.email
157
+ */
158
+ __publicField(this, "useUser", () => {
159
+ const { user } = this.useAuth();
160
+ return computed(() => {
161
+ if (!user.value) {
162
+ throw new InstantError(
163
+ "useUser must be used within an auth-protected route"
164
+ );
165
+ }
166
+ return user.value;
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
+ * const status = db.useConnectionStatus();
175
+ * // status.value
176
+ */
177
+ __publicField(this, "useConnectionStatus", () => {
178
+ const status = ref(
179
+ this.core._reactor.status
180
+ );
181
+ const unsub = this.core.subscribeConnectionStatus((newStatus) => {
182
+ status.value = newStatus;
183
+ });
184
+ tryOnScopeDispose(unsub);
185
+ return status;
186
+ });
187
+ /**
188
+ * A hook that returns a unique ID for a given `name`. localIds are stored in
189
+ * local storage, so you get the same ID across sessions.
190
+ *
191
+ * Returns `null` initially, then the loaded ID.
192
+ *
193
+ * @example
194
+ * const deviceId = db.useLocalId('device');
195
+ * // deviceId.value is null initially, then the ID string
196
+ */
197
+ __publicField(this, "useLocalId", (name) => {
198
+ const localId = ref(null);
199
+ const stop = watch(
200
+ () => toValue(name),
201
+ (currentName) => {
202
+ this.getLocalId(currentName).then((id) => {
203
+ if (toValue(name) === currentName) {
204
+ localId.value = id;
205
+ }
206
+ });
207
+ },
208
+ { immediate: true }
209
+ );
210
+ tryOnScopeDispose(stop);
211
+ return localId;
212
+ });
213
+ /**
214
+ * Hooks for working with rooms
215
+ *
216
+ * @see https://instantdb.com/docs/presence-and-topics
217
+ *
218
+ * @example
219
+ * const room = db.room('chat', roomId);
220
+ * const { peers } = db.rooms.usePresence(room);
221
+ * const publish = db.rooms.usePublishTopic(room, 'emoji');
222
+ */
223
+ __publicField(this, "rooms", rooms);
224
+ this.core = core;
225
+ this.auth = this.core.auth;
226
+ this.storage = this.core.storage;
227
+ this.streams = this.core.streams;
228
+ }
229
+ /**
230
+ * One time query for the logged in state.
231
+ *
232
+ * @see https://instantdb.com/docs/auth
233
+ * @example
234
+ * const user = await db.getAuth();
235
+ * console.log('logged in as', user.email)
236
+ */
237
+ getAuth() {
238
+ return this.core.getAuth();
239
+ }
240
+ /**
241
+ * Obtain a handle to a room, which allows you to listen to topics and presence data
242
+ *
243
+ * @see https://instantdb.com/docs/presence-and-topics
244
+ *
245
+ * @example
246
+ * const room = db.room('chat', roomId);
247
+ * const { peers } = db.rooms.usePresence(room);
248
+ */
249
+ room(type, id) {
250
+ const _type = computed(
251
+ () => toValue(type) ?? "_defaultRoomType"
252
+ );
253
+ const _id = computed(() => toValue(id) ?? "_defaultRoomId");
254
+ return new InstantVueRoom(this.core, _type, _id);
255
+ }
256
+ }
257
+ function init(config) {
258
+ const coreDb = init$1(config, void 0, void 0, {
259
+ "@instantdb/vue": version
260
+ });
261
+ return new InstantVueDatabase(coreDb);
262
+ }
263
+ export {
264
+ InstantVueDatabase,
265
+ init
266
+ };
267
+ //# sourceMappingURL=InstantVueDatabase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InstantVueDatabase.js","sources":["../src/InstantVueDatabase.ts"],"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 InstaQLResponse,\n type ValidQuery,\n // classes\n Auth,\n Storage,\n Streams,\n txInit,\n InstantCoreDatabase,\n init as core_init,\n coerceQuery,\n weakHash,\n InstantSchemaDef,\n RoomsOf,\n InstantError,\n IInstantDatabase,\n} from '@fidscript/instant-sdk';\n\nimport { ref, shallowRef, computed, watch, toValue } from 'vue';\nimport type { Ref, ShallowRef, ComputedRef, MaybeRefOrGetter } from 'vue';\n\nimport { InstantVueRoom, rooms } from './InstantVueRoom.js';\nimport { tryOnScopeDispose } from './utils.js';\nimport { useInfiniteQuery } from './useInfiniteQuery.js';\nimport type { InfiniteQueryResult } from './useInfiniteQuery.js';\nimport version from './version.js';\n\n// ------\n// Types\n\nexport type UseQueryReturn<\n Schema extends InstantSchemaDef<any, any, any>,\n Q extends ValidQuery<Q, Schema>,\n UseDates extends boolean,\n> = {\n isLoading: Ref<boolean>;\n data: ShallowRef<InstaQLResponse<Schema, Q, UseDates> | undefined>;\n pageInfo: ShallowRef<PageInfoResponse<Q> | undefined>;\n error: ShallowRef<{ message: string } | undefined>;\n};\n\nexport type UseAuthReturn = {\n isLoading: Ref<boolean>;\n user: ShallowRef<User | null | undefined>;\n error: ShallowRef<{ message: string } | undefined>;\n};\n\nexport class InstantVueDatabase<\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 streams: Streams;\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 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 * @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 // Vue reactive hooks\n\n /**\n * Use this to query your data!\n *\n * @see https://instantdb.com/docs/instaql\n *\n * @example\n * // basic query — refs auto-unwrap in templates\n * const { isLoading, error, data } = db.useQuery({ goals: {} });\n *\n * @example\n * // reactive query — pass a getter that returns null to skip\n * const { user } = db.useAuth();\n * const { data } = db.useQuery(() =>\n * user.value ? { todos: { $: { where: { 'owner.id': user.value.id } } } } : null,\n * );\n *\n * @example\n * // pass a ref directly\n * const query = ref<{ todos: {} } | null>({ todos: {} });\n * const { data } = db.useQuery(query);\n */\n useQuery = <Q extends ValidQuery<Q, Schema>>(\n query: MaybeRefOrGetter<Q | null>,\n opts?: MaybeRefOrGetter<InstaQLOptions | null | undefined>,\n ): UseQueryReturn<Schema, Q, UseDates> => {\n const isLoading = ref(true);\n const data = shallowRef<InstaQLResponse<Schema, Q, UseDates> | undefined>(\n undefined,\n );\n const pageInfo = shallowRef<PageInfoResponse<Q> | undefined>(undefined);\n const error = shallowRef<{ message: string } | undefined>(undefined);\n\n const resolvedQuery = computed(() => {\n const q = toValue(query);\n if (!q) return null;\n const o = toValue(opts);\n const withParams =\n o && 'ruleParams' in o\n ? ({ $$ruleParams: (o as any).ruleParams, ...q } as Q)\n : q;\n return coerceQuery(withParams);\n });\n\n const queryHash = computed(() => weakHash(resolvedQuery.value));\n\n const stop = watch(\n queryHash,\n (_, __, onCleanup) => {\n const q = resolvedQuery.value;\n const cached: any = q ? this.core._reactor.getPreviousResult(q) : null;\n isLoading.value = !cached;\n data.value = cached?.data;\n pageInfo.value = cached?.pageInfo;\n error.value = cached?.error;\n\n if (!q) return;\n\n const unsub = this.core.subscribeQuery<Q, UseDates>(q, (r: any) => {\n isLoading.value = false;\n data.value = r.data;\n pageInfo.value = r.pageInfo;\n error.value = r.error;\n });\n onCleanup(unsub);\n },\n { immediate: true },\n );\n\n tryOnScopeDispose(stop);\n\n return { isLoading, data, pageInfo, error } as UseQueryReturn<\n Schema,\n Q,\n UseDates\n >;\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 * @example\n * const { data, isLoading, error, loadNextPage, canLoadNextPage } =\n * db.useInfiniteQuery({\n * posts: { $: { limit: 20, order: { createdAt: 'desc' } } },\n * });\n */\n useInfiniteQuery = <Q extends ValidQuery<Q, Schema>>(\n query: MaybeRefOrGetter<Q | null>,\n opts?: MaybeRefOrGetter<InstaQLOptions | undefined>,\n ): InfiniteQueryResult<Schema, Q, UseDates> => {\n return useInfiniteQuery<Schema, Q, UseDates>(this.core, query, opts);\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 * const { isLoading, user, error } = db.useAuth();\n */\n useAuth = (): UseAuthReturn => {\n const cached = this.core._reactor._currentUserCached as\n | AuthState\n | undefined;\n\n const isLoading = ref(cached?.isLoading ?? true);\n const user = shallowRef<User | null | undefined>(cached?.user);\n const error = shallowRef<{ message: string } | undefined>(cached?.error);\n\n const unsub = this.core.subscribeAuth((auth: any) => {\n isLoading.value = false;\n user.value = auth.user ?? null;\n error.value = auth.error;\n });\n\n tryOnScopeDispose(unsub);\n\n return { isLoading, user, error };\n };\n\n /**\n * Subscribe to the currently logged in user. Throws if the user isn't\n * signed in when `.value` is accessed — wrap callers with `<SignedIn>` or\n * a `useAuth` check.\n *\n * @see https://instantdb.com/docs/auth\n * @example\n * const user = db.useUser();\n * // user.value.email\n */\n useUser = (): ComputedRef<User> => {\n const { user } = this.useAuth();\n return computed(() => {\n if (!user.value) {\n throw new InstantError(\n 'useUser must be used within an auth-protected route',\n );\n }\n return user.value;\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 * const status = db.useConnectionStatus();\n * // status.value\n */\n useConnectionStatus = (): Ref<ConnectionStatus> => {\n const status = ref<ConnectionStatus>(\n this.core._reactor.status as ConnectionStatus,\n );\n\n const unsub = this.core.subscribeConnectionStatus((newStatus) => {\n status.value = newStatus;\n });\n\n tryOnScopeDispose(unsub);\n\n return status;\n };\n\n /**\n * A hook that returns a unique ID for a given `name`. localIds are stored in\n * local storage, so you get the same ID across sessions.\n *\n * Returns `null` initially, then the loaded ID.\n *\n * @example\n * const deviceId = db.useLocalId('device');\n * // deviceId.value is null initially, then the ID string\n */\n useLocalId = (name: MaybeRefOrGetter<string>): Ref<string | null> => {\n const localId = ref<string | null>(null);\n\n const stop = watch(\n () => toValue(name),\n (currentName) => {\n this.getLocalId(currentName).then((id) => {\n // Drop a late resolve if `name` has since changed.\n if (toValue(name) === currentName) {\n localId.value = id;\n }\n });\n },\n { immediate: true },\n );\n\n tryOnScopeDispose(stop);\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 { peers } = db.rooms.usePresence(room);\n */\n room<RoomType extends string & keyof Rooms>(\n type?: MaybeRefOrGetter<RoomType | undefined>,\n id?: MaybeRefOrGetter<string | undefined>,\n ) {\n const _type = computed(\n () => (toValue(type) ?? '_defaultRoomType') as RoomType,\n );\n const _id = computed(() => toValue(id) ?? '_defaultRoomId');\n return new InstantVueRoom<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 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/vue\"\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/vue\"\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): InstantVueDatabase<Schema, UseDates> {\n const coreDb = core_init<Schema, UseDates>(config, undefined, undefined, {\n '@instantdb/vue': version,\n });\n return new InstantVueDatabase<Schema, UseDates>(coreDb);\n}\n"],"names":["core_init"],"mappings":";;;;;;;;;AAwDO,MAAM,mBAKb;AAAA,EAQE,YAAY,MAA6C;AAPlD,8BAAK,OAAA;AAEL;AACA;AACA;AACA;AAgBP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sCAAa,CAAC,SAAkC;AAC9C,aAAO,KAAK,KAAK,WAAW,IAAI;AAAA,IAClC;AAWA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oCAAW,CACT,WACG;AACH,aAAO,KAAK,KAAK,SAAS,MAAM;AAAA,IAClC;AAwBA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qCAAY,CACV,OACA,SAII;AACJ,aAAO,KAAK,KAAK,UAAU,OAAO,IAAI;AAAA,IACxC;AA0BA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA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f,eAAK,WAAW,WAAW,EAAE,KAAK,CAAC,OAAO;AAExC,gBAAI,QAAQ,IAAI,MAAM,aAAa;AACjC,sBAAQ,QAAQ;AAAA,YAClB;AAAA,UACF,CAAC;AAAA,QACH;AAAA,QACA,EAAE,WAAW,KAAA;AAAA,MAAK;AAGpB,wBAAkB,IAAI;AACtB,aAAO;AAAA,IACT;AAgCA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iCAAQ;AAtSN,SAAK,OAAO;AACZ,SAAK,OAAO,KAAK,KAAK;AACtB,SAAK,UAAU,KAAK,KAAK;AACzB,SAAK,UAAU,KAAK,KAAK;AAAA,EAC3B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoCA,UAAgC;AAC9B,WAAO,KAAK,KAAK,QAAA;AAAA,EACnB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAuOA,KACE,MACA,IACA;AACA,UAAM,QAAQ;AAAA,MACZ,MAAO,QAAQ,IAAI,KAAK;AAAA,IAAA;AAE1B,UAAM,MAAM,SAAS,MAAM,QAAQ,EAAE,KAAK,gBAAgB;AAC1D,WAAO,IAAI,eAAwC,KAAK,MAAM,OAAO,GAAG;AAAA,EAC1E;AAaF;AAsBO,SAAS,KAId,QAGsC;AACtC,QAAM,SAASA,OAA4B,QAAQ,QAAW,QAAW;AAAA,IACvE,kBAAkB;AAAA,EAAA,CACnB;AACD,SAAO,IAAI,mBAAqC,MAAM;AACxD;"}
@@ -0,0 +1,90 @@
1
+ import { type PresenceOpts, type PresenceResponse, type RoomSchemaShape, InstantCoreDatabase, InstantSchemaDef } from '@fidscript/instant-sdk';
2
+ import type { Ref, ShallowRef, MaybeRefOrGetter, ComputedRef } from 'vue';
3
+ export type PresenceHandle<PresenceShape, Keys extends keyof PresenceShape> = {
4
+ [K in keyof PresenceResponse<PresenceShape, Keys>]: ShallowRef<PresenceResponse<PresenceShape, Keys>[K]>;
5
+ } & {
6
+ publishPresence: (data: Partial<PresenceShape>) => void;
7
+ };
8
+ export type TypingIndicatorOpts = {
9
+ timeout?: number | null;
10
+ stopOnEnter?: boolean;
11
+ writeOnly?: boolean;
12
+ };
13
+ export type TypingIndicatorHandle<PresenceShape> = {
14
+ active: Ref<PresenceShape[]>;
15
+ setActive(active: boolean): void;
16
+ /**
17
+ * Listener keys are lowercased (`onKeydown`, not `onKeyDown`) so that
18
+ * Vue's `v-bind` spread hyphenates them correctly to native DOM events
19
+ * (`keydown`). With camelCase Vue would emit a non-existent `key-down`
20
+ * listener and the indicator would never fire.
21
+ */
22
+ inputProps: {
23
+ onKeydown: (e: KeyboardEvent) => void;
24
+ onBlur: () => void;
25
+ };
26
+ };
27
+ export declare const defaultActivityStopTimeout = 1000;
28
+ /**
29
+ * Listen for broadcasted events given a room and topic.
30
+ *
31
+ * @see https://instantdb.com/docs/presence-and-topics
32
+ * @example
33
+ * const room = db.room('chats', roomId);
34
+ * db.rooms.useTopicEffect(room, 'emoji', (message, peer) => {
35
+ * console.log(peer.name, 'sent', message);
36
+ * });
37
+ */
38
+ export declare function useTopicEffect<RoomSchema extends RoomSchemaShape, RoomType extends keyof RoomSchema, TopicType extends keyof RoomSchema[RoomType]['topics']>(room: InstantVueRoom<any, RoomSchema, RoomType>, topic: TopicType, onEvent: (event: RoomSchema[RoomType]['topics'][TopicType], peer: RoomSchema[RoomType]['presence']) => any): void;
39
+ /**
40
+ * Broadcast an event to a room.
41
+ *
42
+ * @see https://instantdb.com/docs/presence-and-topics
43
+ * @example
44
+ * const room = db.room('chat', roomId);
45
+ * const publishTopic = db.rooms.usePublishTopic(room, 'emoji');
46
+ * publishTopic({ emoji: "🔥" });
47
+ */
48
+ export declare function usePublishTopic<RoomSchema extends RoomSchemaShape, RoomType extends keyof RoomSchema, TopicType extends keyof RoomSchema[RoomType]['topics']>(room: InstantVueRoom<any, RoomSchema, RoomType>, topic: TopicType): (data: RoomSchema[RoomType]['topics'][TopicType]) => void;
49
+ /**
50
+ * Listen for peer's presence data in a room, and publish the current user's presence.
51
+ *
52
+ * @see https://instantdb.com/docs/presence-and-topics
53
+ * @example
54
+ * const room = db.room('chat', roomId);
55
+ * const { peers, isLoading, publishPresence } = db.rooms.usePresence(room, { keys: ["name", "avatar"] });
56
+ */
57
+ export declare function usePresence<RoomSchema extends RoomSchemaShape, RoomType extends keyof RoomSchema, Keys extends keyof RoomSchema[RoomType]['presence']>(room: InstantVueRoom<any, RoomSchema, RoomType>, opts?: PresenceOpts<RoomSchema[RoomType]['presence'], Keys>): PresenceHandle<RoomSchema[RoomType]['presence'], Keys>;
58
+ /**
59
+ * Publishes presence data to a room
60
+ *
61
+ * @see https://instantdb.com/docs/presence-and-topics
62
+ * @example
63
+ * const room = db.room('chat', roomId);
64
+ * db.rooms.useSyncPresence(room, { nickname });
65
+ */
66
+ export declare function useSyncPresence<RoomSchema extends RoomSchemaShape, RoomType extends keyof RoomSchema>(room: InstantVueRoom<any, RoomSchema, RoomType>, data: MaybeRefOrGetter<Partial<RoomSchema[RoomType]['presence']>>): void;
67
+ /**
68
+ * Manage typing indicator state
69
+ *
70
+ * @see https://instantdb.com/docs/presence-and-topics
71
+ * @example
72
+ * const room = db.room('chat', roomId);
73
+ * const typing = db.rooms.useTypingIndicator(room, 'chat-input');
74
+ * // typing.active.value, typing.setActive(bool), typing.inputProps
75
+ */
76
+ export declare function useTypingIndicator<RoomSchema extends RoomSchemaShape, RoomType extends keyof RoomSchema>(room: InstantVueRoom<any, RoomSchema, RoomType>, inputName: string, opts?: TypingIndicatorOpts): TypingIndicatorHandle<RoomSchema[RoomType]['presence']>;
77
+ export declare const rooms: {
78
+ useTopicEffect: typeof useTopicEffect;
79
+ usePublishTopic: typeof usePublishTopic;
80
+ usePresence: typeof usePresence;
81
+ useSyncPresence: typeof useSyncPresence;
82
+ useTypingIndicator: typeof useTypingIndicator;
83
+ };
84
+ export declare class InstantVueRoom<Schema extends InstantSchemaDef<any, any, any>, RoomSchema extends RoomSchemaShape, RoomType extends keyof RoomSchema> {
85
+ core: InstantCoreDatabase<Schema, boolean>;
86
+ type: ComputedRef<RoomType> | RoomType;
87
+ id: ComputedRef<string> | string;
88
+ constructor(core: InstantCoreDatabase<Schema, boolean>, type: ComputedRef<RoomType> | RoomType, id: ComputedRef<string> | string);
89
+ }
90
+ //# sourceMappingURL=InstantVueRoom.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InstantVueRoom.d.ts","sourceRoot":"","sources":["../src/InstantVueRoom.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,mBAAmB,EACnB,gBAAgB,EACjB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,KAAK,EAAE,GAAG,EAAE,UAAU,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,KAAK,CAAC;AAO1E,MAAM,MAAM,cAAc,CAAC,aAAa,EAAE,IAAI,SAAS,MAAM,aAAa,IAAI;KAC3E,CAAC,IAAI,MAAM,gBAAgB,CAAC,aAAa,EAAE,IAAI,CAAC,GAAG,UAAU,CAC5D,gBAAgB,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CACzC;CACF,GAAG;IACF,eAAe,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,aAAa,CAAC,KAAK,IAAI,CAAC;CACzD,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,qBAAqB,CAAC,aAAa,IAAI;IACjD,MAAM,EAAE,GAAG,CAAC,aAAa,EAAE,CAAC,CAAC;IAC7B,SAAS,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI,CAAC;IACjC;;;;;OAKG;IACH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