@lunora/svelte 1.0.0-alpha.48 → 1.0.0-alpha.49

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 (43) hide show
  1. package/dist/index.mjs +1 -18
  2. package/dist/packem_shared/agent-BEqcvTwb.mjs +1 -0
  3. package/dist/packem_shared/agentChat-3IXHbOEE.mjs +1 -0
  4. package/dist/packem_shared/agentState-ZGfPOSwK.mjs +1 -0
  5. package/dist/packem_shared/agentToolEvents-BYjBe2-X.mjs +1 -0
  6. package/dist/packem_shared/auth-DNOb_Wm7.mjs +1 -0
  7. package/dist/packem_shared/connectionStatus-BHVAskxU.mjs +1 -0
  8. package/dist/packem_shared/flag-kAz4soTW.mjs +1 -0
  9. package/dist/packem_shared/getLunoraClient-DU7BmZy1.mjs +1 -0
  10. package/dist/packem_shared/hydratePreloaded-Bbm6vwbA.mjs +1 -0
  11. package/dist/packem_shared/infiniteQuery-CIxf7GMM.mjs +1 -0
  12. package/dist/packem_shared/is-function-reference-ByqJF30w.mjs +1 -0
  13. package/dist/packem_shared/mutation-fa0Bj5Bo.mjs +1 -0
  14. package/dist/packem_shared/mutator-cvH3UrNm.mjs +1 -0
  15. package/dist/packem_shared/presence-D-m3S1lu.mjs +1 -0
  16. package/dist/packem_shared/query-BEQBdOJ2.mjs +1 -0
  17. package/dist/packem_shared/rateLimit-CwhxlHqx.mjs +1 -0
  18. package/dist/packem_shared/stream-DItOnXt6.mjs +1 -0
  19. package/dist/packem_shared/subscription-Dbz9sy8N.mjs +1 -0
  20. package/dist/packem_shared/voiceAgent-BxIYZRin.mjs +1 -0
  21. package/dist/server.mjs +1 -1
  22. package/dist/upload.mjs +1 -2
  23. package/dist/worker.mjs +1 -1
  24. package/package.json +3 -3
  25. package/dist/packem_shared/agent-KLsxO_Uw.mjs +0 -48
  26. package/dist/packem_shared/agentChat-BlwlNfDg.mjs +0 -138
  27. package/dist/packem_shared/agentState-DBXc_3RM.mjs +0 -15
  28. package/dist/packem_shared/agentToolEvents-qYM1CdTV.mjs +0 -60
  29. package/dist/packem_shared/auth-BeYqYP9S.mjs +0 -28
  30. package/dist/packem_shared/connectionStatus-BrICpw9d.mjs +0 -14
  31. package/dist/packem_shared/flag-CqMU07WH.mjs +0 -56
  32. package/dist/packem_shared/getLunoraClient-Prczj1gU.mjs +0 -17
  33. package/dist/packem_shared/hydratePreloaded-Djsf_C8Q.mjs +0 -21
  34. package/dist/packem_shared/infiniteQuery-Bemu7Um1.mjs +0 -227
  35. package/dist/packem_shared/is-function-reference-ycLAcI79.mjs +0 -3
  36. package/dist/packem_shared/mutation-BmkCZnTd.mjs +0 -31
  37. package/dist/packem_shared/mutator-B5LchgMS.mjs +0 -19
  38. package/dist/packem_shared/presence-BvChXqiB.mjs +0 -83
  39. package/dist/packem_shared/query-B-Gu6KQw.mjs +0 -42
  40. package/dist/packem_shared/rateLimit-Cdw1kp8t.mjs +0 -66
  41. package/dist/packem_shared/stream-BebZbIaD.mjs +0 -68
  42. package/dist/packem_shared/subscription-COqqiMPX.mjs +0 -43
  43. package/dist/packem_shared/voiceAgent-Cxib7eCK.mjs +0 -405
@@ -1,227 +0,0 @@
1
- import { initialPages, derivePaginationStatus, applyLoadMore, rebalance } from '@lunora/client/pagination';
2
- import { derived, writable, readable, get } from 'svelte/store';
3
- import { getLunoraClient } from './getLunoraClient-Prczj1gU.mjs';
4
- import { i as isFunctionReference } from './is-function-reference-ycLAcI79.mjs';
5
-
6
- const buildPageArgs = (page, baseArgs) => {
7
- return {
8
- ...baseArgs,
9
- paginationOpts: { cursor: page.lower, endCursor: page.upper, numItems: page.numItems }
10
- };
11
- };
12
- const buildPageKey = (functionPath, pageArgs) => `${functionPath}::${JSON.stringify(pageArgs)}`;
13
- const createPaginatedEngine = (client, function_, baseArgs, options) => {
14
- const { initialNumItems, shardKey } = options;
15
- const pagesStore = writable(initialPages(initialNumItems));
16
- const pageResultsInternal = writable([]);
17
- const resultsByKey = /* @__PURE__ */ new Map();
18
- const activeSubs = /* @__PURE__ */ new Map();
19
- const pendingPageKeys = /* @__PURE__ */ new Set();
20
- const currentBaseArgs = baseArgs;
21
- const rebuildPageResults = () => {
22
- if (currentBaseArgs === "skip") {
23
- pageResultsInternal.set([]);
24
- return;
25
- }
26
- const updated = get(pagesStore).map((page) => {
27
- const key = buildPageKey(function_["__lunoraRef"], buildPageArgs(page, currentBaseArgs));
28
- return resultsByKey.get(key);
29
- });
30
- pageResultsInternal.set(updated);
31
- };
32
- const migrateResultsForRebalance = (oldPages, newPages) => {
33
- if (currentBaseArgs === "skip") {
34
- return;
35
- }
36
- const keyOf = (page) => buildPageKey(function_["__lunoraRef"], buildPageArgs(page, currentBaseArgs));
37
- for (const newPage of newPages) {
38
- const newKey = keyOf(newPage);
39
- if (resultsByKey.has(newKey)) {
40
- continue;
41
- }
42
- const donor = oldPages.find((op) => op.lower === newPage.lower);
43
- if (donor) {
44
- const carried = resultsByKey.get(keyOf(donor));
45
- if (carried) {
46
- resultsByKey.set(newKey, carried);
47
- }
48
- }
49
- }
50
- };
51
- const syncPass = () => {
52
- if (currentBaseArgs === "skip") {
53
- for (const unsub of activeSubs.values()) {
54
- unsub();
55
- }
56
- activeSubs.clear();
57
- pageResultsInternal.set([]);
58
- return;
59
- }
60
- const baseArgsRecord = currentBaseArgs;
61
- const pages = get(pagesStore);
62
- const wantedKeys = /* @__PURE__ */ new Set();
63
- for (const page of pages) {
64
- wantedKeys.add(buildPageKey(function_["__lunoraRef"], buildPageArgs(page, baseArgsRecord)));
65
- }
66
- for (const [key, unsub] of activeSubs) {
67
- if (!wantedKeys.has(key)) {
68
- unsub();
69
- activeSubs.delete(key);
70
- pendingPageKeys.delete(key);
71
- resultsByKey.delete(key);
72
- }
73
- }
74
- for (const page of pages) {
75
- const pageArgs = buildPageArgs(page, baseArgsRecord);
76
- const key = buildPageKey(function_["__lunoraRef"], pageArgs);
77
- if (activeSubs.has(key)) {
78
- continue;
79
- }
80
- pendingPageKeys.add(key);
81
- const unsub = client.subscribe(
82
- function_,
83
- pageArgs,
84
- (value) => {
85
- resultsByKey.set(key, value);
86
- pendingPageKeys.delete(key);
87
- rebuildPageResults();
88
- if (pendingPageKeys.size === 0) {
89
- const latestPages = get(pagesStore);
90
- const next = rebalance(latestPages, get(pageResultsInternal));
91
- if (next) {
92
- migrateResultsForRebalance(latestPages, next);
93
- pagesStore.set(next);
94
- syncSubscriptions();
95
- rebuildPageResults();
96
- }
97
- }
98
- },
99
- { shardKey }
100
- );
101
- activeSubs.set(key, unsub);
102
- }
103
- };
104
- let syncing = false;
105
- let resyncRequested = false;
106
- const syncSubscriptions = () => {
107
- if (syncing) {
108
- resyncRequested = true;
109
- return;
110
- }
111
- syncing = true;
112
- try {
113
- do {
114
- resyncRequested = false;
115
- syncPass();
116
- } while (resyncRequested);
117
- } finally {
118
- syncing = false;
119
- }
120
- };
121
- const teardownAll = () => {
122
- for (const unsub of activeSubs.values()) {
123
- unsub();
124
- }
125
- activeSubs.clear();
126
- resultsByKey.clear();
127
- pendingPageKeys.clear();
128
- };
129
- const pageResults = readable([], (set) => {
130
- const unsubInternal = pageResultsInternal.subscribe(set);
131
- if (currentBaseArgs !== "skip") {
132
- syncSubscriptions();
133
- rebuildPageResults();
134
- }
135
- return () => {
136
- unsubInternal();
137
- teardownAll();
138
- pagesStore.set(initialPages(initialNumItems));
139
- pageResultsInternal.set([]);
140
- };
141
- });
142
- const status = derived(
143
- pageResults,
144
- (results) => derivePaginationStatus(currentBaseArgs === "skip", results).status
145
- );
146
- const loadMore = (numberItems) => {
147
- if (currentBaseArgs === "skip") {
148
- return;
149
- }
150
- const currentResults = get(pageResultsInternal);
151
- const { nextCursor, status: currentStatus } = derivePaginationStatus(false, currentResults);
152
- if (currentStatus !== "CanLoadMore") {
153
- return;
154
- }
155
- const currentPages = get(pagesStore);
156
- const next = applyLoadMore(currentPages, nextCursor, numberItems);
157
- if (!next) {
158
- return;
159
- }
160
- const oldTail = currentPages.at(-1);
161
- const newPinnedPage = next.at(-2);
162
- if (oldTail && newPinnedPage) {
163
- const oldKey = buildPageKey(function_["__lunoraRef"], buildPageArgs(oldTail, currentBaseArgs));
164
- const newKey = buildPageKey(function_["__lunoraRef"], buildPageArgs(newPinnedPage, currentBaseArgs));
165
- if (oldKey !== newKey) {
166
- const carried = resultsByKey.get(oldKey);
167
- if (carried) {
168
- resultsByKey.set(newKey, carried);
169
- resultsByKey.delete(oldKey);
170
- }
171
- }
172
- }
173
- pagesStore.set(next);
174
- syncSubscriptions();
175
- rebuildPageResults();
176
- };
177
- return { loadMore, pageResults, status };
178
- };
179
- function paginatedQuery(clientOrFunction, functionOrArguments, argumentsOrOptions, maybeOptions) {
180
- const hasExplicitClient = !isFunctionReference(clientOrFunction);
181
- const client = hasExplicitClient ? clientOrFunction : getLunoraClient();
182
- const functionRef = hasExplicitClient ? functionOrArguments : clientOrFunction;
183
- const args = hasExplicitClient ? argumentsOrOptions : functionOrArguments;
184
- const options = hasExplicitClient ? maybeOptions : argumentsOrOptions;
185
- const { loadMore, pageResults, status } = createPaginatedEngine(client, functionRef, args, options);
186
- const results = derived(pageResults, (currentResults) => {
187
- const items = [];
188
- for (const page of currentResults) {
189
- if (page) {
190
- items.push(...page.page);
191
- }
192
- }
193
- return items;
194
- });
195
- const isLoading = derived(
196
- status,
197
- (currentStatus) => currentStatus === "LoadingFirstPage" || currentStatus === "LoadingMore"
198
- );
199
- return { isLoading, loadMore, results, status };
200
- }
201
- function infiniteQuery(clientOrFunction, functionOrArguments, argumentsOrOptions, maybeOptions) {
202
- const hasExplicitClient = !isFunctionReference(clientOrFunction);
203
- const client = hasExplicitClient ? clientOrFunction : getLunoraClient();
204
- const functionRef = hasExplicitClient ? functionOrArguments : clientOrFunction;
205
- const args = hasExplicitClient ? argumentsOrOptions : functionOrArguments;
206
- const options = hasExplicitClient ? maybeOptions : argumentsOrOptions;
207
- const { initialNumItems } = options;
208
- const { loadMore, pageResults, status } = createPaginatedEngine(client, functionRef, args, options);
209
- const pages = derived(pageResults, (currentResults) => {
210
- const result = [];
211
- for (const page of currentResults) {
212
- if (page) {
213
- result.push(page.page);
214
- }
215
- }
216
- return result;
217
- });
218
- const isLoading = derived(status, (s) => s === "LoadingFirstPage");
219
- const hasNextPage = derived(status, (s) => s === "CanLoadMore");
220
- const isFetchingNextPage = derived(status, (s) => s === "LoadingMore");
221
- const fetchNextPage = (numberItems) => {
222
- loadMore(numberItems ?? initialNumItems);
223
- };
224
- return { fetchNextPage, hasNextPage, isFetchingNextPage, isLoading, pages, status };
225
- }
226
-
227
- export { infiniteQuery, paginatedQuery };
@@ -1,3 +0,0 @@
1
- const isFunctionReference = (value) => typeof value === "object" && value !== null && typeof value.__lunoraRef === "string";
2
-
3
- export { isFunctionReference as i };
@@ -1,31 +0,0 @@
1
- import { createMutationRunner } from '@lunora/client';
2
- import { writable } from 'svelte/store';
3
- import { getLunoraClient } from './getLunoraClient-Prczj1gU.mjs';
4
-
5
- function mutation(clientOrFunction, maybeFunction) {
6
- const hasExplicitClient = maybeFunction !== void 0;
7
- const client = hasExplicitClient ? clientOrFunction : getLunoraClient();
8
- const functionRef = hasExplicitClient ? maybeFunction : clientOrFunction;
9
- const data = writable();
10
- const error = writable();
11
- const pending = writable(false);
12
- const mutate = createMutationRunner(client, functionRef, {
13
- setError: (next) => {
14
- error.set(next);
15
- },
16
- setPending: (next) => {
17
- pending.set(next);
18
- },
19
- setResult: (result) => {
20
- data.set(result);
21
- error.set(void 0);
22
- }
23
- });
24
- const reset = () => {
25
- data.set(void 0);
26
- error.set(void 0);
27
- };
28
- return { data, error, mutate, pending, reset };
29
- }
30
-
31
- export { mutation };
@@ -1,19 +0,0 @@
1
- import { createMutatorRunner } from '@lunora/client';
2
- import { writable, derived } from 'svelte/store';
3
-
4
- const mutator = (handle) => {
5
- const error = writable();
6
- const pending = writable(false);
7
- const isError = derived(error, ($error) => $error !== void 0);
8
- const { mutate, reset } = createMutatorRunner(handle, {
9
- setError: (value) => {
10
- error.set(value);
11
- },
12
- setPending: (value) => {
13
- pending.set(value);
14
- }
15
- });
16
- return { error, isError, mutate, pending, reset };
17
- };
18
-
19
- export { mutator };
@@ -1,83 +0,0 @@
1
- import { onDestroy } from 'svelte';
2
- import { readable } from 'svelte/store';
3
- import { getLunoraClient } from './getLunoraClient-Prczj1gU.mjs';
4
-
5
- const randomSessionId = (prefix = "sess") => {
6
- if (typeof crypto !== "undefined") {
7
- if (typeof crypto.randomUUID === "function") {
8
- return crypto.randomUUID();
9
- }
10
- if (typeof crypto.getRandomValues === "function") {
11
- const bytes = crypto.getRandomValues(new Uint8Array(16));
12
- return `${prefix}-${Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("")}`;
13
- }
14
- }
15
- return `${prefix}-${Date.now().toString(36)}`;
16
- };
17
-
18
- const DEFAULT_INTERVAL_MS = 1e4;
19
- const createPresenceHandle = (client, roomId, options) => {
20
- const { heartbeat, intervalMs = DEFAULT_INTERVAL_MS, listPresent, shardKey } = options;
21
- const sessionId = options.sessionId ?? randomSessionId();
22
- let latestData = options.data;
23
- const sendHeartbeat = () => {
24
- const args = {
25
- roomId,
26
- sessionId,
27
- ...latestData === void 0 ? {} : { data: latestData }
28
- };
29
- client.mutation(heartbeat, args, { shardKey }).catch(() => void 0);
30
- };
31
- const setData = (next) => {
32
- latestData = next;
33
- sendHeartbeat();
34
- };
35
- sendHeartbeat();
36
- const intervalHandle = setInterval(sendHeartbeat, intervalMs);
37
- const onVisible = () => {
38
- if (typeof document !== "undefined" && document.visibilityState === "visible") {
39
- sendHeartbeat();
40
- }
41
- };
42
- if (typeof document !== "undefined") {
43
- document.addEventListener("visibilitychange", onVisible);
44
- }
45
- const releaseConnectionContext = client.acquireConnectionContext({ roomId, sessionId }, { shardKey });
46
- const present = readable(void 0, (set) => {
47
- const unsubscribe = client.subscribe(
48
- listPresent,
49
- { roomId },
50
- (value) => {
51
- set(value);
52
- },
53
- { shardKey }
54
- );
55
- return unsubscribe;
56
- });
57
- let torndown = false;
58
- const teardown = () => {
59
- if (torndown) {
60
- return;
61
- }
62
- torndown = true;
63
- clearInterval(intervalHandle);
64
- if (typeof document !== "undefined") {
65
- document.removeEventListener("visibilitychange", onVisible);
66
- }
67
- releaseConnectionContext();
68
- };
69
- try {
70
- onDestroy(teardown);
71
- } catch {
72
- }
73
- return { present, sessionId, setData, teardown };
74
- };
75
- function presence(clientOrRoomId, roomIdOrOptions, maybeOptions) {
76
- const hasExplicitClient = typeof clientOrRoomId !== "string";
77
- const client = hasExplicitClient ? clientOrRoomId : getLunoraClient();
78
- const roomId = hasExplicitClient ? roomIdOrOptions : clientOrRoomId;
79
- const options = hasExplicitClient ? maybeOptions : roomIdOrOptions;
80
- return createPresenceHandle(client, roomId, options);
81
- }
82
-
83
- export { presence };
@@ -1,42 +0,0 @@
1
- import { createQuerySubscription } from '@lunora/client/query';
2
- import { readable } from 'svelte/store';
3
- import { getLunoraClient } from './getLunoraClient-Prczj1gU.mjs';
4
- import { i as isFunctionReference } from './is-function-reference-ycLAcI79.mjs';
5
-
6
- function query(clientOrFunction, functionOrArguments, argumentsOrOptions, maybeOptions) {
7
- const hasExplicitClient = !isFunctionReference(clientOrFunction);
8
- const client = hasExplicitClient ? clientOrFunction : getLunoraClient();
9
- const functionRef = hasExplicitClient ? functionOrArguments : clientOrFunction;
10
- const args = hasExplicitClient ? argumentsOrOptions : functionOrArguments;
11
- const options = (hasExplicitClient ? maybeOptions : argumentsOrOptions) ?? {};
12
- return readable(
13
- void 0,
14
- (set) => (
15
- // The shared `@lunora/client/query` state machine owns the subscribe +
16
- // cleanup: it replays the last value synchronously when one exists and
17
- // pushes every subsequent delta into the store, and its returned teardown
18
- // is the store's stop callback, so the WS subscription closes when the
19
- // last `$`-reader detaches.
20
- createQuerySubscription(
21
- client,
22
- functionRef,
23
- args,
24
- {
25
- onData: (value) => {
26
- set(value);
27
- },
28
- onError: options.onError,
29
- // `args === "skip"` short-circuits inside the shared helper and
30
- // fires this reset — clear any prior value so a store that flips
31
- // to `"skip"` does not retain stale data.
32
- onReset: () => {
33
- set(void 0);
34
- }
35
- },
36
- { shardKey: options.shardKey }
37
- )
38
- )
39
- );
40
- }
41
-
42
- export { query };
@@ -1,66 +0,0 @@
1
- import { evaluate } from '@lunora/ratelimit';
2
- import { writable, derived } from 'svelte/store';
3
-
4
- const rateLimit = (config, options = {}) => {
5
- const now = options.now ?? Date.now;
6
- const tickMs = options.tickMs ?? 1e3;
7
- let value;
8
- const epoch = writable(0);
9
- const bump = () => {
10
- epoch.update((n) => n + 1);
11
- };
12
- const status = derived(epoch, () => evaluate(config, value, { consume: false, count: 1, now: now(), reserve: false }).status);
13
- let intervalHandle;
14
- const stopInterval = () => {
15
- if (intervalHandle !== void 0) {
16
- clearInterval(intervalHandle);
17
- intervalHandle = void 0;
18
- }
19
- };
20
- let latestOk = true;
21
- const unsubStatus = status.subscribe((s) => {
22
- latestOk = s.ok;
23
- });
24
- const startIntervalIfThrottled = () => {
25
- if (latestOk || intervalHandle !== void 0) {
26
- return;
27
- }
28
- intervalHandle = setInterval(() => {
29
- bump();
30
- if (latestOk) {
31
- stopInterval();
32
- }
33
- }, tickMs);
34
- };
35
- startIntervalIfThrottled();
36
- const consume = (count = 1) => {
37
- const result = evaluate(config, value, { consume: true, count, now: now(), reserve: false });
38
- if (result.value !== void 0) {
39
- value = result.value;
40
- }
41
- bump();
42
- startIntervalIfThrottled();
43
- return result.status;
44
- };
45
- const check = (count = 1) => evaluate(config, value, { consume: false, count, now: now(), reserve: false }).status.ok;
46
- const reset = () => {
47
- value = void 0;
48
- stopInterval();
49
- bump();
50
- };
51
- const teardown = () => {
52
- stopInterval();
53
- unsubStatus();
54
- };
55
- return {
56
- check,
57
- consume,
58
- disabled: derived(status, (s) => !s.ok),
59
- ok: derived(status, (s) => s.ok),
60
- reset,
61
- retryAfter: derived(status, (s) => s.retryAfter),
62
- teardown
63
- };
64
- };
65
-
66
- export { rateLimit };
@@ -1,68 +0,0 @@
1
- import { writable, readable } from 'svelte/store';
2
- import { getLunoraClient } from './getLunoraClient-Prczj1gU.mjs';
3
- import { i as isFunctionReference } from './is-function-reference-ycLAcI79.mjs';
4
-
5
- function stream(clientOrFunction, functionOrArgs, argsOrOptions, maybeOptions) {
6
- const hasExplicitClient = !isFunctionReference(clientOrFunction);
7
- const client = hasExplicitClient ? clientOrFunction : getLunoraClient();
8
- const functionRef = hasExplicitClient ? functionOrArgs : clientOrFunction;
9
- const args = hasExplicitClient ? argsOrOptions : functionOrArgs;
10
- const options = (hasExplicitClient ? maybeOptions : argsOrOptions) ?? {};
11
- const { maxBuffer, shardKey } = options;
12
- const statusStore = writable("idle");
13
- const errorStore = writable();
14
- let cancelCurrent;
15
- const cancel = () => {
16
- cancelCurrent?.();
17
- };
18
- const chunks = readable([], (set) => {
19
- set([]);
20
- errorStore.set(void 0);
21
- if (args === "skip") {
22
- statusStore.set("idle");
23
- return () => void 0;
24
- }
25
- statusStore.set("streaming");
26
- let active = true;
27
- let current = [];
28
- const iterable = client.stream(functionRef, args, { maxBuffer, shardKey });
29
- const cancelIterable = () => {
30
- iterable.cancel();
31
- };
32
- cancelCurrent = cancelIterable;
33
- (async () => {
34
- try {
35
- for await (const chunk of iterable) {
36
- if (!active) {
37
- return;
38
- }
39
- current = [...current, chunk];
40
- set(current);
41
- }
42
- if (active) {
43
- statusStore.set("complete");
44
- }
45
- } catch (streamError) {
46
- if (!active) {
47
- return;
48
- }
49
- errorStore.set(streamError instanceof Error ? streamError : new Error(String(streamError)));
50
- statusStore.set("error");
51
- }
52
- })().catch(() => {
53
- });
54
- return () => {
55
- active = false;
56
- cancelIterable();
57
- if (cancelCurrent === cancelIterable) {
58
- cancelCurrent = void 0;
59
- }
60
- };
61
- });
62
- const teardown = () => {
63
- cancel();
64
- };
65
- return { cancel, chunks, error: { subscribe: errorStore.subscribe }, status: { subscribe: statusStore.subscribe }, teardown };
66
- }
67
-
68
- export { stream };
@@ -1,43 +0,0 @@
1
- import { createQuerySubscription } from '@lunora/client/query';
2
- import { writable, readable } from 'svelte/store';
3
- import { getLunoraClient } from './getLunoraClient-Prczj1gU.mjs';
4
- import { i as isFunctionReference } from './is-function-reference-ycLAcI79.mjs';
5
-
6
- function subscription(clientOrFunction, functionOrArgs, argsOrOptions, maybeOptions) {
7
- const hasExplicitClient = !isFunctionReference(clientOrFunction);
8
- const client = hasExplicitClient ? clientOrFunction : getLunoraClient();
9
- const functionRef = hasExplicitClient ? functionOrArgs : clientOrFunction;
10
- const args = hasExplicitClient ? argsOrOptions : functionOrArgs;
11
- const options = (hasExplicitClient ? maybeOptions : argsOrOptions) ?? {};
12
- const { shardKey, onError } = options;
13
- const errorStore = writable();
14
- const data = readable(void 0, (set) => {
15
- const unsubscribe = createQuerySubscription(
16
- client,
17
- functionRef,
18
- args,
19
- {
20
- onData: (value) => {
21
- set(value);
22
- errorStore.set(void 0);
23
- },
24
- onError: (subscriptionError) => {
25
- const error = new Error(subscriptionError.message);
26
- errorStore.set(error);
27
- onError?.(error);
28
- },
29
- onReset: () => {
30
- set(void 0);
31
- }
32
- },
33
- { shardKey }
34
- );
35
- return () => {
36
- unsubscribe();
37
- errorStore.set(void 0);
38
- };
39
- });
40
- return { data, error: { subscribe: errorStore.subscribe } };
41
- }
42
-
43
- export { subscription };