@lunora/solid 1.0.0-alpha.24 → 1.0.0-alpha.241
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/README.md +26 -17
- package/dist/index.d.mts +713 -466
- package/dist/index.d.ts +713 -466
- package/dist/index.mjs +1 -19
- package/dist/packem_shared/AuthLoading-DjUnIaP5.mjs +1 -0
- package/dist/packem_shared/LunoraContext-BWsj_3CK.mjs +1 -0
- package/dist/packem_shared/LunoraProvider-DMhpuxvx.mjs +1 -0
- package/dist/packem_shared/createAction-BZkayM2R.mjs +1 -0
- package/dist/packem_shared/createAgent-CWckPY7u.mjs +1 -0
- package/dist/packem_shared/createAgentChat-jPhnwbdQ.mjs +1 -0
- package/dist/packem_shared/createAgentState-BPo1e_ih.mjs +1 -0
- package/dist/packem_shared/createAgentToolEvents-WUQRSY8o.mjs +1 -0
- package/dist/packem_shared/createConnectionStatus-D8bC05Jn.mjs +1 -0
- package/dist/packem_shared/createFlag-BwBkDAcT.mjs +1 -0
- package/dist/packem_shared/createInfiniteQuery-CwGPFeuc.mjs +1 -0
- package/dist/packem_shared/createLiveTopic-CgkjI8l8.mjs +1 -0
- package/dist/packem_shared/createMutation-DM2mXpq3.mjs +1 -0
- package/dist/packem_shared/createMutator-q9cMjGKv.mjs +1 -0
- package/dist/packem_shared/createPresence-DkTotieP.mjs +1 -0
- package/dist/packem_shared/createQuery-oNQqVGjE.mjs +1 -0
- package/dist/packem_shared/createRateLimit-CIVWrD5H.mjs +1 -0
- package/dist/packem_shared/createStream-CCAOb9q1.mjs +1 -0
- package/dist/packem_shared/createSubscription-CF_00S2O.mjs +1 -0
- package/dist/packem_shared/createVoiceAgent-CEuW4ux5.mjs +1 -0
- package/dist/packem_shared/hydratePreloaded-DCi296oW.mjs +1 -0
- package/dist/packem_shared/reactive-args-qKMBsFpd.mjs +1 -0
- package/dist/packem_shared/solid-compat-ByG5HD_F.mjs +1 -0
- package/dist/server.mjs +1 -1
- package/dist/upload.d.mts +2 -0
- package/dist/upload.d.ts +2 -0
- package/dist/upload.mjs +1 -0
- package/package.json +11 -5
- package/dist/packem_shared/AuthLoading-u5QJoV-J.mjs +0 -73
- package/dist/packem_shared/LunoraContext-C59PzHhN.mjs +0 -13
- package/dist/packem_shared/LunoraProvider-CzB3zGhy.mjs +0 -17
- package/dist/packem_shared/createAgent-D7EZBeql.mjs +0 -55
- package/dist/packem_shared/createAgentChat-CsoyE3RE.mjs +0 -150
- package/dist/packem_shared/createAgentState-DckYu3G8.mjs +0 -21
- package/dist/packem_shared/createAgentToolEvents-UavTO16u.mjs +0 -99
- package/dist/packem_shared/createConnectionStatus-1poqwqR9.mjs +0 -14
- package/dist/packem_shared/createFlag-Bu9YfzcJ.mjs +0 -78
- package/dist/packem_shared/createInfiniteQuery-Dy9k7Px2.mjs +0 -216
- package/dist/packem_shared/createMutation-LkrbhItI.mjs +0 -36
- package/dist/packem_shared/createMutator-foSnPJPt.mjs +0 -24
- package/dist/packem_shared/createPresence-DM2cVkiG.mjs +0 -85
- package/dist/packem_shared/createQuery-BUldvZXj.mjs +0 -28
- package/dist/packem_shared/createRateLimit-BA2f8XyF.mjs +0 -76
- package/dist/packem_shared/createStream-D9ONbGAw.mjs +0 -70
- package/dist/packem_shared/createSubscription-D3HbChGe.mjs +0 -41
- package/dist/packem_shared/createVoiceAgent-hu59SaDl.mjs +0 -418
- package/dist/packem_shared/hydratePreloaded-CWny5-2J.mjs +0 -25
- package/dist/packem_shared/stable-key-CGp4e2Ux.mjs +0 -38
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { createSignal, onCleanup } from 'solid-js';
|
|
2
|
-
import { useLunora } from './LunoraContext-C59PzHhN.mjs';
|
|
3
|
-
|
|
4
|
-
const createConnectionStatus = () => {
|
|
5
|
-
const client = useLunora();
|
|
6
|
-
const [status, setStatus] = createSignal(client.connectionStatus());
|
|
7
|
-
const unsubscribe = client.onConnectionStatus((next) => {
|
|
8
|
-
setStatus(next);
|
|
9
|
-
});
|
|
10
|
-
onCleanup(unsubscribe);
|
|
11
|
-
return status;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export { createConnectionStatus as default };
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { createSignal, createEffect, on, onCleanup } from 'solid-js';
|
|
2
|
-
import { s as stableStringify } from './stable-key-CGp4e2Ux.mjs';
|
|
3
|
-
import { useLunora } from './LunoraContext-C59PzHhN.mjs';
|
|
4
|
-
|
|
5
|
-
const FLAGS_EVAL_PATH = "__lunora_flags__:eval";
|
|
6
|
-
const flagKind = (value) => {
|
|
7
|
-
const kind = typeof value;
|
|
8
|
-
if (kind === "boolean" || kind === "number" || kind === "string") {
|
|
9
|
-
return kind;
|
|
10
|
-
}
|
|
11
|
-
return "object";
|
|
12
|
-
};
|
|
13
|
-
const flagsReference = {
|
|
14
|
-
__lunoraRef: FLAGS_EVAL_PATH
|
|
15
|
-
};
|
|
16
|
-
const resolveMaybe = (value) => typeof value === "function" ? value() : value;
|
|
17
|
-
const serializeContext = (context) => context === void 0 ? "" : stableStringify(context);
|
|
18
|
-
const createFlag = (key, defaultValue, context) => {
|
|
19
|
-
const client = useLunora();
|
|
20
|
-
const type = flagKind(defaultValue);
|
|
21
|
-
const [value, setValue] = createSignal(defaultValue);
|
|
22
|
-
createEffect(on(() => `${resolveMaybe(key)} ${serializeContext(resolveMaybe(context))}`, () => {
|
|
23
|
-
const currentKey = resolveMaybe(key);
|
|
24
|
-
const currentContext = resolveMaybe(context);
|
|
25
|
-
setValue(() => defaultValue);
|
|
26
|
-
let unsubscribe;
|
|
27
|
-
try {
|
|
28
|
-
unsubscribe = client.subscribe(flagsReference, {
|
|
29
|
-
context: currentContext,
|
|
30
|
-
default: defaultValue,
|
|
31
|
-
key: currentKey,
|
|
32
|
-
type
|
|
33
|
-
}, (next) => {
|
|
34
|
-
setValue(() => next);
|
|
35
|
-
});
|
|
36
|
-
} catch {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
onCleanup(unsubscribe);
|
|
40
|
-
}));
|
|
41
|
-
return value;
|
|
42
|
-
};
|
|
43
|
-
const createFlags = (flags, context) => {
|
|
44
|
-
const client = useLunora();
|
|
45
|
-
const [values, setValues] = createSignal(flags);
|
|
46
|
-
const spec = stableStringify(flags);
|
|
47
|
-
createEffect(on(() => `${spec} ${serializeContext(resolveMaybe(context))}`, () => {
|
|
48
|
-
const currentContext = resolveMaybe(context);
|
|
49
|
-
setValues(() => flags);
|
|
50
|
-
const unsubscribes = [];
|
|
51
|
-
for (const [key, defaultValue] of Object.entries(flags)) {
|
|
52
|
-
try {
|
|
53
|
-
unsubscribes.push(client.subscribe(flagsReference, {
|
|
54
|
-
context: currentContext,
|
|
55
|
-
default: defaultValue,
|
|
56
|
-
key,
|
|
57
|
-
type: flagKind(defaultValue)
|
|
58
|
-
}, (next) => {
|
|
59
|
-
setValues((previous) => {
|
|
60
|
-
return {
|
|
61
|
-
...previous,
|
|
62
|
-
[key]: next
|
|
63
|
-
};
|
|
64
|
-
});
|
|
65
|
-
}));
|
|
66
|
-
} catch {
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
onCleanup(() => {
|
|
70
|
-
for (const unsubscribe of unsubscribes) {
|
|
71
|
-
unsubscribe();
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
}));
|
|
75
|
-
return values;
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
export { createFlag, createFlags };
|
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
import { initialPages, derivePaginationStatus, rebalance, applyLoadMore } from '@lunora/client/pagination';
|
|
2
|
-
import { createMemo, createSignal, createEffect, on, onCleanup } from 'solid-js';
|
|
3
|
-
import { s as stableStringify } from './stable-key-CGp4e2Ux.mjs';
|
|
4
|
-
import { useLunora } from './LunoraContext-C59PzHhN.mjs';
|
|
5
|
-
|
|
6
|
-
const buildPageArgs = (page, baseArgs) => {
|
|
7
|
-
return {
|
|
8
|
-
...baseArgs,
|
|
9
|
-
paginationOpts: {
|
|
10
|
-
cursor: page.lower,
|
|
11
|
-
endCursor: page.upper,
|
|
12
|
-
numItems: page.numItems
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
const buildPageKey = (functionPath, pageArgs) => `${functionPath}::${stableStringify(pageArgs)}`;
|
|
17
|
-
const createPaginatedCore = (function_, args, options) => {
|
|
18
|
-
const client = useLunora();
|
|
19
|
-
const {
|
|
20
|
-
initialNumItems,
|
|
21
|
-
shardKey
|
|
22
|
-
} = options;
|
|
23
|
-
const resolveArgs = () => typeof args === "function" ? args() : args;
|
|
24
|
-
const [pages, setPages] = createSignal(initialPages(initialNumItems));
|
|
25
|
-
const resultsByKey = /* @__PURE__ */ new Map();
|
|
26
|
-
const [pageResults, setPageResults] = createSignal([]);
|
|
27
|
-
const activeSubs = /* @__PURE__ */ new Map();
|
|
28
|
-
const pendingPageKeys = /* @__PURE__ */ new Set();
|
|
29
|
-
const rebuildPageResults = (currentPages, baseArgs) => {
|
|
30
|
-
const updated = currentPages.map((page) => {
|
|
31
|
-
const key = buildPageKey(function_["__lunoraRef"], buildPageArgs(page, baseArgs));
|
|
32
|
-
return resultsByKey.get(key);
|
|
33
|
-
});
|
|
34
|
-
setPageResults(updated);
|
|
35
|
-
};
|
|
36
|
-
const migrateResultsForRebalance = (oldPages, newPages, baseArgs) => {
|
|
37
|
-
const keyOf = (page) => buildPageKey(function_["__lunoraRef"], buildPageArgs(page, baseArgs));
|
|
38
|
-
for (const newPage of newPages) {
|
|
39
|
-
const newKey = keyOf(newPage);
|
|
40
|
-
if (resultsByKey.has(newKey)) {
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
const donor = oldPages.find((oldPage) => oldPage.lower === newPage.lower);
|
|
44
|
-
if (donor) {
|
|
45
|
-
const carried = resultsByKey.get(keyOf(donor));
|
|
46
|
-
if (carried) {
|
|
47
|
-
resultsByKey.set(newKey, carried);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
const syncSubscriptions = (currentPages, baseArgs) => {
|
|
53
|
-
const wantedKeys = /* @__PURE__ */ new Set();
|
|
54
|
-
for (const page of currentPages) {
|
|
55
|
-
wantedKeys.add(buildPageKey(function_["__lunoraRef"], buildPageArgs(page, baseArgs)));
|
|
56
|
-
}
|
|
57
|
-
for (const [key, unsub] of activeSubs) {
|
|
58
|
-
if (!wantedKeys.has(key)) {
|
|
59
|
-
unsub();
|
|
60
|
-
activeSubs.delete(key);
|
|
61
|
-
pendingPageKeys.delete(key);
|
|
62
|
-
resultsByKey.delete(key);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
for (const page of currentPages) {
|
|
66
|
-
const pageArgs = buildPageArgs(page, baseArgs);
|
|
67
|
-
const key = buildPageKey(function_["__lunoraRef"], pageArgs);
|
|
68
|
-
if (activeSubs.has(key)) {
|
|
69
|
-
continue;
|
|
70
|
-
}
|
|
71
|
-
pendingPageKeys.add(key);
|
|
72
|
-
const unsub = client.subscribe(function_, pageArgs, (value) => {
|
|
73
|
-
resultsByKey.set(key, value);
|
|
74
|
-
pendingPageKeys.delete(key);
|
|
75
|
-
const currentArgs = resolveArgs();
|
|
76
|
-
if (currentArgs === "skip") {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
rebuildPageResults(pages(), currentArgs);
|
|
80
|
-
if (pendingPageKeys.size === 0) {
|
|
81
|
-
const latestPages = pages();
|
|
82
|
-
const next = rebalance(latestPages, pageResults());
|
|
83
|
-
if (next) {
|
|
84
|
-
migrateResultsForRebalance(latestPages, next, currentArgs);
|
|
85
|
-
setPages(next);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}, {
|
|
89
|
-
shardKey
|
|
90
|
-
});
|
|
91
|
-
activeSubs.set(key, unsub);
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
const teardownAll = () => {
|
|
95
|
-
for (const unsub of activeSubs.values()) {
|
|
96
|
-
unsub();
|
|
97
|
-
}
|
|
98
|
-
activeSubs.clear();
|
|
99
|
-
resultsByKey.clear();
|
|
100
|
-
pendingPageKeys.clear();
|
|
101
|
-
};
|
|
102
|
-
createEffect(on(resolveArgs, (current) => {
|
|
103
|
-
teardownAll();
|
|
104
|
-
setPages(initialPages(initialNumItems));
|
|
105
|
-
setPageResults([]);
|
|
106
|
-
if (current !== "skip") {
|
|
107
|
-
syncSubscriptions(pages(), current);
|
|
108
|
-
rebuildPageResults(pages(), current);
|
|
109
|
-
}
|
|
110
|
-
onCleanup(teardownAll);
|
|
111
|
-
}));
|
|
112
|
-
createEffect(on(pages, (currentPages) => {
|
|
113
|
-
const current = resolveArgs();
|
|
114
|
-
if (current !== "skip") {
|
|
115
|
-
syncSubscriptions(currentPages, current);
|
|
116
|
-
rebuildPageResults(currentPages, current);
|
|
117
|
-
}
|
|
118
|
-
}));
|
|
119
|
-
const status = createMemo(() => {
|
|
120
|
-
const skipped = resolveArgs() === "skip";
|
|
121
|
-
return derivePaginationStatus(skipped, pageResults()).status;
|
|
122
|
-
});
|
|
123
|
-
const loadMore = (numberItems) => {
|
|
124
|
-
const current = resolveArgs();
|
|
125
|
-
if (current === "skip") {
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
const {
|
|
129
|
-
nextCursor,
|
|
130
|
-
status: currentStatus
|
|
131
|
-
} = derivePaginationStatus(false, pageResults());
|
|
132
|
-
if (currentStatus !== "CanLoadMore") {
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
const next = applyLoadMore(pages(), nextCursor, numberItems);
|
|
136
|
-
if (!next) {
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
const oldTail = pages().at(-1);
|
|
140
|
-
const newPinnedPage = next.at(-2);
|
|
141
|
-
if (oldTail && newPinnedPage) {
|
|
142
|
-
const oldKey = buildPageKey(function_["__lunoraRef"], buildPageArgs(oldTail, current));
|
|
143
|
-
const newKey = buildPageKey(function_["__lunoraRef"], buildPageArgs(newPinnedPage, current));
|
|
144
|
-
if (oldKey !== newKey) {
|
|
145
|
-
const carried = resultsByKey.get(oldKey);
|
|
146
|
-
if (carried) {
|
|
147
|
-
resultsByKey.set(newKey, carried);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
setPages(next);
|
|
152
|
-
};
|
|
153
|
-
return {
|
|
154
|
-
loadMore,
|
|
155
|
-
pageResults,
|
|
156
|
-
status
|
|
157
|
-
};
|
|
158
|
-
};
|
|
159
|
-
const createPaginatedQuery = (function_, args, options) => {
|
|
160
|
-
const {
|
|
161
|
-
loadMore,
|
|
162
|
-
pageResults,
|
|
163
|
-
status
|
|
164
|
-
} = createPaginatedCore(function_, args, options);
|
|
165
|
-
const results = createMemo(() => {
|
|
166
|
-
const items = [];
|
|
167
|
-
for (const page of pageResults()) {
|
|
168
|
-
if (page) {
|
|
169
|
-
items.push(...page.page);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
return items;
|
|
173
|
-
});
|
|
174
|
-
const isLoading = createMemo(() => status() === "LoadingFirstPage" || status() === "LoadingMore");
|
|
175
|
-
return {
|
|
176
|
-
isLoading,
|
|
177
|
-
loadMore,
|
|
178
|
-
results,
|
|
179
|
-
status
|
|
180
|
-
};
|
|
181
|
-
};
|
|
182
|
-
const createInfiniteQuery = (function_, args, options) => {
|
|
183
|
-
const {
|
|
184
|
-
initialNumItems
|
|
185
|
-
} = options;
|
|
186
|
-
const {
|
|
187
|
-
loadMore,
|
|
188
|
-
pageResults,
|
|
189
|
-
status
|
|
190
|
-
} = createPaginatedCore(function_, args, options);
|
|
191
|
-
const pages = createMemo(() => {
|
|
192
|
-
const result = [];
|
|
193
|
-
for (const page of pageResults()) {
|
|
194
|
-
if (page) {
|
|
195
|
-
result.push(page.page);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
return result;
|
|
199
|
-
});
|
|
200
|
-
const isLoading = createMemo(() => status() === "LoadingFirstPage");
|
|
201
|
-
const hasNextPage = createMemo(() => status() === "CanLoadMore");
|
|
202
|
-
const isFetchingNextPage = createMemo(() => status() === "LoadingMore");
|
|
203
|
-
const fetchNextPage = (numberItems) => {
|
|
204
|
-
loadMore(numberItems ?? initialNumItems);
|
|
205
|
-
};
|
|
206
|
-
return {
|
|
207
|
-
fetchNextPage,
|
|
208
|
-
hasNextPage,
|
|
209
|
-
isFetchingNextPage,
|
|
210
|
-
isLoading,
|
|
211
|
-
pages,
|
|
212
|
-
status
|
|
213
|
-
};
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
export { createInfiniteQuery, createPaginatedQuery };
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { createMutationRunner } from '@lunora/client';
|
|
2
|
-
import { createSignal } from 'solid-js';
|
|
3
|
-
import { useLunora } from './LunoraContext-C59PzHhN.mjs';
|
|
4
|
-
|
|
5
|
-
const createMutationForClient = (client, function_) => {
|
|
6
|
-
const [data, setData] = createSignal(void 0);
|
|
7
|
-
const [error, setError] = createSignal(void 0);
|
|
8
|
-
const [pending, setPending] = createSignal(false);
|
|
9
|
-
const mutate = createMutationRunner(client, function_, {
|
|
10
|
-
setError,
|
|
11
|
-
setPending,
|
|
12
|
-
setResult: (result) => {
|
|
13
|
-
setData(() => result);
|
|
14
|
-
setError(void 0);
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
const reset = () => {
|
|
18
|
-
setData(() => void 0);
|
|
19
|
-
setError(void 0);
|
|
20
|
-
};
|
|
21
|
-
return {
|
|
22
|
-
data,
|
|
23
|
-
error,
|
|
24
|
-
mutate,
|
|
25
|
-
pending,
|
|
26
|
-
reset
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
const createMutation = (function_) => {
|
|
30
|
-
const client = useLunora();
|
|
31
|
-
return createMutationForClient({
|
|
32
|
-
mutation: (reference, args, options) => client.mutation(reference, args, options)
|
|
33
|
-
}, function_);
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export { createMutation, createMutationForClient };
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { createMutatorRunner } from '@lunora/client';
|
|
2
|
-
import { createSignal } from 'solid-js';
|
|
3
|
-
|
|
4
|
-
const createMutator = (handle) => {
|
|
5
|
-
const [error, setError] = createSignal(void 0);
|
|
6
|
-
const [pending, setPending] = createSignal(false);
|
|
7
|
-
const {
|
|
8
|
-
mutate,
|
|
9
|
-
reset
|
|
10
|
-
} = createMutatorRunner(handle, {
|
|
11
|
-
setError,
|
|
12
|
-
setPending
|
|
13
|
-
});
|
|
14
|
-
const isError = () => error() !== void 0;
|
|
15
|
-
return {
|
|
16
|
-
error,
|
|
17
|
-
isError,
|
|
18
|
-
mutate,
|
|
19
|
-
pending,
|
|
20
|
-
reset
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export { createMutator };
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { createSignal, onMount, onCleanup } from 'solid-js';
|
|
2
|
-
import { useLunora } from './LunoraContext-C59PzHhN.mjs';
|
|
3
|
-
|
|
4
|
-
const randomSessionId = (prefix = "sess") => {
|
|
5
|
-
if (typeof crypto !== "undefined") {
|
|
6
|
-
if (typeof crypto.randomUUID === "function") {
|
|
7
|
-
return crypto.randomUUID();
|
|
8
|
-
}
|
|
9
|
-
if (typeof crypto.getRandomValues === "function") {
|
|
10
|
-
const bytes = crypto.getRandomValues(new Uint8Array(16));
|
|
11
|
-
return `${prefix}-${Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("")}`;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
return `${prefix}-${Date.now().toString(36)}`;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
const DEFAULT_INTERVAL_MS = 1e4;
|
|
18
|
-
const createPresence = (roomId, options) => {
|
|
19
|
-
const client = useLunora();
|
|
20
|
-
const {
|
|
21
|
-
heartbeat,
|
|
22
|
-
intervalMs = DEFAULT_INTERVAL_MS,
|
|
23
|
-
listPresent,
|
|
24
|
-
shardKey
|
|
25
|
-
} = options;
|
|
26
|
-
const sessionId = options.sessionId ?? randomSessionId();
|
|
27
|
-
const [present, setPresent] = createSignal(void 0);
|
|
28
|
-
let latestData = options.data;
|
|
29
|
-
const sendHeartbeat = () => {
|
|
30
|
-
const args = {
|
|
31
|
-
roomId,
|
|
32
|
-
sessionId,
|
|
33
|
-
...latestData === void 0 ? {} : {
|
|
34
|
-
data: latestData
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
client.mutation(heartbeat, args, {
|
|
38
|
-
shardKey
|
|
39
|
-
}).catch(() => void 0);
|
|
40
|
-
};
|
|
41
|
-
const setData = (next) => {
|
|
42
|
-
latestData = next;
|
|
43
|
-
sendHeartbeat();
|
|
44
|
-
};
|
|
45
|
-
onMount(() => {
|
|
46
|
-
sendHeartbeat();
|
|
47
|
-
const intervalHandle = setInterval(sendHeartbeat, intervalMs);
|
|
48
|
-
const onVisible = () => {
|
|
49
|
-
if (typeof document !== "undefined" && document.visibilityState === "visible") {
|
|
50
|
-
sendHeartbeat();
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
if (typeof document !== "undefined") {
|
|
54
|
-
document.addEventListener("visibilitychange", onVisible);
|
|
55
|
-
}
|
|
56
|
-
const releaseConnectionContext = client.acquireConnectionContext({
|
|
57
|
-
roomId,
|
|
58
|
-
sessionId
|
|
59
|
-
}, {
|
|
60
|
-
shardKey
|
|
61
|
-
});
|
|
62
|
-
const unsubscribe = client.subscribe(listPresent, {
|
|
63
|
-
roomId
|
|
64
|
-
}, (value) => {
|
|
65
|
-
setPresent(() => value);
|
|
66
|
-
}, {
|
|
67
|
-
shardKey
|
|
68
|
-
});
|
|
69
|
-
onCleanup(() => {
|
|
70
|
-
clearInterval(intervalHandle);
|
|
71
|
-
if (typeof document !== "undefined") {
|
|
72
|
-
document.removeEventListener("visibilitychange", onVisible);
|
|
73
|
-
}
|
|
74
|
-
releaseConnectionContext();
|
|
75
|
-
unsubscribe();
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
return {
|
|
79
|
-
present,
|
|
80
|
-
sessionId,
|
|
81
|
-
setData
|
|
82
|
-
};
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
export { createPresence };
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { createQuerySubscription } from '@lunora/client/query';
|
|
2
|
-
import { createSignal, createEffect, on, onCleanup } from 'solid-js';
|
|
3
|
-
import { useLunora } from './LunoraContext-C59PzHhN.mjs';
|
|
4
|
-
|
|
5
|
-
const createQuery = (function_, args, options = {}) => {
|
|
6
|
-
const client = useLunora();
|
|
7
|
-
const {
|
|
8
|
-
shardKey
|
|
9
|
-
} = options;
|
|
10
|
-
const [value, setValue] = createSignal(void 0);
|
|
11
|
-
const resolveArgs = () => typeof args === "function" ? args() : args;
|
|
12
|
-
createEffect(on(resolveArgs, (current) => {
|
|
13
|
-
const unsubscribe = createQuerySubscription(client, function_, current, {
|
|
14
|
-
onData: (next) => {
|
|
15
|
-
setValue(() => next);
|
|
16
|
-
},
|
|
17
|
-
onReset: () => {
|
|
18
|
-
setValue(() => void 0);
|
|
19
|
-
}
|
|
20
|
-
}, {
|
|
21
|
-
shardKey
|
|
22
|
-
});
|
|
23
|
-
onCleanup(unsubscribe);
|
|
24
|
-
}));
|
|
25
|
-
return value;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export { createQuery };
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { evaluate } from '@lunora/ratelimit';
|
|
2
|
-
import { createSignal, createMemo, onCleanup } from 'solid-js';
|
|
3
|
-
|
|
4
|
-
const createRateLimit = (config, options = {}) => {
|
|
5
|
-
const now = options.now ?? Date.now;
|
|
6
|
-
const tickMs = options.tickMs ?? 1e3;
|
|
7
|
-
let value;
|
|
8
|
-
const [epoch, setEpoch] = createSignal(0);
|
|
9
|
-
const bump = () => {
|
|
10
|
-
setEpoch((n) => n + 1);
|
|
11
|
-
};
|
|
12
|
-
const status = createMemo(() => {
|
|
13
|
-
const ts = now() + epoch() * 0;
|
|
14
|
-
return evaluate(config, value, {
|
|
15
|
-
consume: false,
|
|
16
|
-
count: 1,
|
|
17
|
-
now: ts,
|
|
18
|
-
reserve: false
|
|
19
|
-
}).status;
|
|
20
|
-
});
|
|
21
|
-
let intervalHandle;
|
|
22
|
-
const stopInterval = () => {
|
|
23
|
-
if (intervalHandle !== void 0) {
|
|
24
|
-
clearInterval(intervalHandle);
|
|
25
|
-
intervalHandle = void 0;
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
const startIntervalIfThrottled = () => {
|
|
29
|
-
if (status().ok || intervalHandle !== void 0) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
intervalHandle = setInterval(() => {
|
|
33
|
-
bump();
|
|
34
|
-
if (status().ok) {
|
|
35
|
-
stopInterval();
|
|
36
|
-
}
|
|
37
|
-
}, tickMs);
|
|
38
|
-
};
|
|
39
|
-
onCleanup(stopInterval);
|
|
40
|
-
startIntervalIfThrottled();
|
|
41
|
-
const consume = (count = 1) => {
|
|
42
|
-
const result = evaluate(config, value, {
|
|
43
|
-
consume: true,
|
|
44
|
-
count,
|
|
45
|
-
now: now(),
|
|
46
|
-
reserve: false
|
|
47
|
-
});
|
|
48
|
-
if (result.value !== void 0) {
|
|
49
|
-
value = result.value;
|
|
50
|
-
}
|
|
51
|
-
bump();
|
|
52
|
-
startIntervalIfThrottled();
|
|
53
|
-
return result.status;
|
|
54
|
-
};
|
|
55
|
-
const check = (count = 1) => evaluate(config, value, {
|
|
56
|
-
consume: false,
|
|
57
|
-
count,
|
|
58
|
-
now: now(),
|
|
59
|
-
reserve: false
|
|
60
|
-
}).status.ok;
|
|
61
|
-
const reset = () => {
|
|
62
|
-
value = void 0;
|
|
63
|
-
stopInterval();
|
|
64
|
-
bump();
|
|
65
|
-
};
|
|
66
|
-
return {
|
|
67
|
-
check,
|
|
68
|
-
consume,
|
|
69
|
-
disabled: () => !status().ok,
|
|
70
|
-
ok: () => status().ok,
|
|
71
|
-
reset,
|
|
72
|
-
retryAfter: () => status().retryAfter
|
|
73
|
-
};
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
export { createRateLimit };
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { createSignal, createEffect, on, onCleanup } from 'solid-js';
|
|
2
|
-
import { useLunora } from './LunoraContext-C59PzHhN.mjs';
|
|
3
|
-
|
|
4
|
-
const createStream = (function_, args, options = {}) => {
|
|
5
|
-
const client = useLunora();
|
|
6
|
-
const [chunks, setChunks] = createSignal([]);
|
|
7
|
-
const [error, setError] = createSignal(void 0);
|
|
8
|
-
const [status, setStatus] = createSignal("idle");
|
|
9
|
-
const resolveArgs = typeof args === "function" ? args : () => args;
|
|
10
|
-
let cancelCurrent;
|
|
11
|
-
const cancel = () => {
|
|
12
|
-
cancelCurrent?.();
|
|
13
|
-
};
|
|
14
|
-
createEffect(on(resolveArgs, (currentArgs) => {
|
|
15
|
-
setChunks(() => []);
|
|
16
|
-
setError(() => void 0);
|
|
17
|
-
if (currentArgs === "skip") {
|
|
18
|
-
setStatus("idle");
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
setStatus("streaming");
|
|
22
|
-
let active = true;
|
|
23
|
-
const iterable = client.stream(function_, currentArgs, {
|
|
24
|
-
maxBuffer: options.maxBuffer,
|
|
25
|
-
shardKey: options.shardKey
|
|
26
|
-
});
|
|
27
|
-
const cancelIterable = () => {
|
|
28
|
-
iterable.cancel();
|
|
29
|
-
};
|
|
30
|
-
cancelCurrent = cancelIterable;
|
|
31
|
-
(async () => {
|
|
32
|
-
try {
|
|
33
|
-
for await (const chunk of iterable) {
|
|
34
|
-
if (!active) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
setChunks((previous) => [...previous, chunk]);
|
|
38
|
-
}
|
|
39
|
-
if (active) {
|
|
40
|
-
setStatus("complete");
|
|
41
|
-
}
|
|
42
|
-
} catch (streamError) {
|
|
43
|
-
if (!active) {
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
setError(() => streamError instanceof Error ? streamError : new Error(String(streamError)));
|
|
47
|
-
setStatus("error");
|
|
48
|
-
}
|
|
49
|
-
})().catch(() => {
|
|
50
|
-
});
|
|
51
|
-
onCleanup(() => {
|
|
52
|
-
active = false;
|
|
53
|
-
cancelIterable();
|
|
54
|
-
if (cancelCurrent === cancelIterable) {
|
|
55
|
-
cancelCurrent = void 0;
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
}));
|
|
59
|
-
onCleanup(() => {
|
|
60
|
-
cancel();
|
|
61
|
-
});
|
|
62
|
-
return {
|
|
63
|
-
cancel,
|
|
64
|
-
chunks,
|
|
65
|
-
error,
|
|
66
|
-
status
|
|
67
|
-
};
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export { createStream };
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { createQuerySubscription } from '@lunora/client/query';
|
|
2
|
-
import { LunoraError } from '@lunora/errors';
|
|
3
|
-
import { createSignal, createEffect, on, onCleanup } from 'solid-js';
|
|
4
|
-
import { useLunora } from './LunoraContext-C59PzHhN.mjs';
|
|
5
|
-
|
|
6
|
-
const createSubscription = (function_, args, options = {}) => {
|
|
7
|
-
const client = useLunora();
|
|
8
|
-
const [data, setData] = createSignal(void 0);
|
|
9
|
-
const [error, setError] = createSignal(void 0);
|
|
10
|
-
const resolveArgs = typeof args === "function" ? args : () => args;
|
|
11
|
-
createEffect(on(resolveArgs, (currentArgs) => {
|
|
12
|
-
if (currentArgs === "skip") {
|
|
13
|
-
setData(() => void 0);
|
|
14
|
-
setError(() => void 0);
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
const unsubscribe = createQuerySubscription(client, function_, currentArgs, {
|
|
18
|
-
onData: (value) => {
|
|
19
|
-
setData(() => value);
|
|
20
|
-
setError(() => void 0);
|
|
21
|
-
},
|
|
22
|
-
onError: (subscriptionError) => {
|
|
23
|
-
const normalized = subscriptionError.code ? new LunoraError(subscriptionError.code, subscriptionError.message) : new Error(subscriptionError.message);
|
|
24
|
-
setError(() => normalized);
|
|
25
|
-
setData(() => void 0);
|
|
26
|
-
},
|
|
27
|
-
onReset: () => {
|
|
28
|
-
setData(() => void 0);
|
|
29
|
-
}
|
|
30
|
-
}, {
|
|
31
|
-
shardKey: options.shardKey
|
|
32
|
-
});
|
|
33
|
-
onCleanup(unsubscribe);
|
|
34
|
-
}));
|
|
35
|
-
return {
|
|
36
|
-
data,
|
|
37
|
-
error
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export { createSubscription };
|