@lunora/angular 1.0.0-alpha.13 → 1.0.0-alpha.15
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/dist/index.mjs +1 -19
- package/dist/packem_shared/LUNORA_CLIENT-B0pGE0Tv.mjs +1 -0
- package/dist/packem_shared/agent-C-GavfBl.mjs +1 -0
- package/dist/packem_shared/agentChat-HRYt8rOf.mjs +1 -0
- package/dist/packem_shared/agentState-BAfa0QuC.mjs +1 -0
- package/dist/packem_shared/agentToolEvents-CBTZ_DsO.mjs +1 -0
- package/dist/packem_shared/auth-wTtWvuVS.mjs +1 -0
- package/dist/packem_shared/connectionStatus-C53UhkPi.mjs +1 -0
- package/dist/packem_shared/flag-BYFWoQTg.mjs +1 -0
- package/dist/packem_shared/hydratePreloaded-BKHgpXzQ.mjs +1 -0
- package/dist/packem_shared/infiniteQuery-YvF0in16.mjs +1 -0
- package/dist/packem_shared/liveQuery-DEIqmTPj.mjs +1 -0
- package/dist/packem_shared/mutate-DR8Uo8Hs.mjs +1 -0
- package/dist/packem_shared/mutator-Cw6jpG06.mjs +1 -0
- package/dist/packem_shared/platform-BGZypnc9.mjs +1 -0
- package/dist/packem_shared/presence-BMrTlOCF.mjs +1 -0
- package/dist/packem_shared/rateLimit-CQazDrPJ.mjs +1 -0
- package/dist/packem_shared/stream-CcvHiJf2.mjs +1 -0
- package/dist/packem_shared/subscription-DJeoGEDR.mjs +1 -0
- package/dist/packem_shared/voiceAgent-CwlzrEjH.mjs +1 -0
- package/package.json +3 -3
- package/dist/packem_shared/LUNORA_CLIENT-DHUfNu9x.mjs +0 -23
- package/dist/packem_shared/agent-DDKvrG4u.mjs +0 -31
- package/dist/packem_shared/agentChat-DDZlxK1v.mjs +0 -111
- package/dist/packem_shared/agentState-C8GWf3t3.mjs +0 -10
- package/dist/packem_shared/agentToolEvents-sXgYggvi.mjs +0 -59
- package/dist/packem_shared/auth-Df9N87Z4.mjs +0 -27
- package/dist/packem_shared/connectionStatus-BlLodleK.mjs +0 -15
- package/dist/packem_shared/flag-CGBo90HJ.mjs +0 -70
- package/dist/packem_shared/hydratePreloaded-DIpD1cAM.mjs +0 -33
- package/dist/packem_shared/infiniteQuery-nboKfr5E.mjs +0 -221
- package/dist/packem_shared/liveQuery-DVxKidjM.mjs +0 -32
- package/dist/packem_shared/mutate-D3rEHwbb.mjs +0 -8
- package/dist/packem_shared/mutator-BHL8bakL.mjs +0 -19
- package/dist/packem_shared/platform-Dg8Bppgq.mjs +0 -14
- package/dist/packem_shared/presence-BTuq19dS.mjs +0 -77
- package/dist/packem_shared/rateLimit-I4kRT9qV.mjs +0 -58
- package/dist/packem_shared/stream-PL64AghO.mjs +0 -47
- package/dist/packem_shared/subscription-oZ-WTmpp.mjs +0 -39
- package/dist/packem_shared/voiceAgent-DwbrDnB9.mjs +0 -401
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
import { computed, inject, DestroyRef, signal } from '@angular/core';
|
|
2
|
-
import { initialPages, derivePaginationStatus, applyLoadMore, rebalance } from '@lunora/client/pagination';
|
|
3
|
-
import { resolveLunoraClient } from './LUNORA_CLIENT-DHUfNu9x.mjs';
|
|
4
|
-
import { s as shouldOpenSubscription } from './platform-Dg8Bppgq.mjs';
|
|
5
|
-
|
|
6
|
-
const buildPageKey = (functionPath, pageArgs) => `${functionPath}::${JSON.stringify(pageArgs)}`;
|
|
7
|
-
const buildPageArgs = (page, baseArgs) => {
|
|
8
|
-
return {
|
|
9
|
-
...baseArgs,
|
|
10
|
-
paginationOpts: { cursor: page.lower, endCursor: page.upper, numItems: page.numItems }
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
const usePaginatedCore = (reference, baseArgs, options) => {
|
|
14
|
-
const client = resolveLunoraClient(options.client);
|
|
15
|
-
const fromInjectionContext = options.destroyRef === void 0;
|
|
16
|
-
const destroyRef = options.destroyRef ?? inject(DestroyRef);
|
|
17
|
-
const { initialNumItems, shardKey } = options;
|
|
18
|
-
const functionPath = reference["__lunoraRef"];
|
|
19
|
-
const narrowedArgs = baseArgs === "skip" ? {} : baseArgs;
|
|
20
|
-
const pages = signal(initialPages(initialNumItems));
|
|
21
|
-
const pageResults = signal([]);
|
|
22
|
-
const status = signal("LoadingFirstPage");
|
|
23
|
-
const activeSubs = /* @__PURE__ */ new Map();
|
|
24
|
-
const resultsByKey = /* @__PURE__ */ new Map();
|
|
25
|
-
const pendingPageKeys = /* @__PURE__ */ new Set();
|
|
26
|
-
const doRebuildPageResults = () => {
|
|
27
|
-
const currentPages = pages();
|
|
28
|
-
const items = currentPages.map((page) => {
|
|
29
|
-
const key = buildPageKey(functionPath, buildPageArgs(page, narrowedArgs));
|
|
30
|
-
return resultsByKey.get(key);
|
|
31
|
-
});
|
|
32
|
-
pageResults.set(items);
|
|
33
|
-
const { status: derivedStatus } = derivePaginationStatus(baseArgs === "skip", items);
|
|
34
|
-
status.set(derivedStatus);
|
|
35
|
-
};
|
|
36
|
-
const migrateResultsForRebalance = (oldPages, newPages) => {
|
|
37
|
-
const keyOf = (page) => buildPageKey(functionPath, buildPageArgs(page, narrowedArgs));
|
|
38
|
-
for (const newPage of newPages) {
|
|
39
|
-
const newKey = keyOf(newPage);
|
|
40
|
-
if (resultsByKey.has(newKey)) {
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
const donor = oldPages.find((op) => op.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 syncPass = (currentPages) => {
|
|
53
|
-
const wantedKeys = /* @__PURE__ */ new Set();
|
|
54
|
-
for (const page of currentPages) {
|
|
55
|
-
wantedKeys.add(buildPageKey(functionPath, buildPageArgs(page, narrowedArgs)));
|
|
56
|
-
}
|
|
57
|
-
for (const [originalKey, entry] of activeSubs) {
|
|
58
|
-
if (!wantedKeys.has(entry.currentKey)) {
|
|
59
|
-
entry.unsub();
|
|
60
|
-
activeSubs.delete(originalKey);
|
|
61
|
-
resultsByKey.delete(entry.currentKey);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
const coveredKeys = new Set([...activeSubs.values()].map((subEntry) => subEntry.currentKey));
|
|
65
|
-
for (const page of currentPages) {
|
|
66
|
-
const pageArgs = buildPageArgs(page, narrowedArgs);
|
|
67
|
-
const key = buildPageKey(functionPath, pageArgs);
|
|
68
|
-
if (coveredKeys.has(key)) {
|
|
69
|
-
continue;
|
|
70
|
-
}
|
|
71
|
-
const entry = {
|
|
72
|
-
currentKey: key,
|
|
73
|
-
unsub: void 0
|
|
74
|
-
};
|
|
75
|
-
pendingPageKeys.add(key);
|
|
76
|
-
const unsub = client.subscribe(
|
|
77
|
-
reference,
|
|
78
|
-
pageArgs,
|
|
79
|
-
(value) => {
|
|
80
|
-
resultsByKey.set(entry.currentKey, value);
|
|
81
|
-
pendingPageKeys.delete(entry.currentKey);
|
|
82
|
-
doRebuildPageResults();
|
|
83
|
-
if (pendingPageKeys.size === 0) {
|
|
84
|
-
const latestPages = pages();
|
|
85
|
-
const next = rebalance(latestPages, pageResults());
|
|
86
|
-
if (next) {
|
|
87
|
-
migrateResultsForRebalance(latestPages, next);
|
|
88
|
-
pages.set(next);
|
|
89
|
-
syncSubscriptions(next);
|
|
90
|
-
doRebuildPageResults();
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
},
|
|
94
|
-
{
|
|
95
|
-
onError: () => {
|
|
96
|
-
pendingPageKeys.delete(entry.currentKey);
|
|
97
|
-
doRebuildPageResults();
|
|
98
|
-
},
|
|
99
|
-
shardKey
|
|
100
|
-
}
|
|
101
|
-
);
|
|
102
|
-
entry.unsub = unsub;
|
|
103
|
-
activeSubs.set(key, entry);
|
|
104
|
-
coveredKeys.add(key);
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
let syncing = false;
|
|
108
|
-
let resyncRequested = false;
|
|
109
|
-
const syncSubscriptions = (currentPages) => {
|
|
110
|
-
if (syncing) {
|
|
111
|
-
resyncRequested = true;
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
syncing = true;
|
|
115
|
-
try {
|
|
116
|
-
let pagesToSync = currentPages;
|
|
117
|
-
do {
|
|
118
|
-
resyncRequested = false;
|
|
119
|
-
syncPass(pagesToSync);
|
|
120
|
-
pagesToSync = pages();
|
|
121
|
-
} while (resyncRequested);
|
|
122
|
-
} finally {
|
|
123
|
-
syncing = false;
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
if (baseArgs !== "skip" && shouldOpenSubscription(fromInjectionContext)) {
|
|
127
|
-
syncSubscriptions(pages());
|
|
128
|
-
}
|
|
129
|
-
doRebuildPageResults();
|
|
130
|
-
destroyRef.onDestroy(() => {
|
|
131
|
-
for (const entry of activeSubs.values()) {
|
|
132
|
-
entry.unsub();
|
|
133
|
-
}
|
|
134
|
-
activeSubs.clear();
|
|
135
|
-
resultsByKey.clear();
|
|
136
|
-
});
|
|
137
|
-
const loadMore = (numberItems) => {
|
|
138
|
-
if (baseArgs === "skip") {
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
const { nextCursor, status: currentStatus } = derivePaginationStatus(false, pageResults());
|
|
142
|
-
if (currentStatus !== "CanLoadMore") {
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
const next = applyLoadMore(pages(), nextCursor, numberItems);
|
|
146
|
-
if (!next) {
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
const oldTail = pages().at(-1);
|
|
150
|
-
const newPinnedPage = next.at(-2);
|
|
151
|
-
if (oldTail && newPinnedPage) {
|
|
152
|
-
const oldKey = buildPageKey(functionPath, buildPageArgs(oldTail, narrowedArgs));
|
|
153
|
-
const newKey = buildPageKey(functionPath, buildPageArgs(newPinnedPage, narrowedArgs));
|
|
154
|
-
const entry = activeSubs.get(oldKey);
|
|
155
|
-
if (entry && oldKey !== newKey) {
|
|
156
|
-
const carried = resultsByKey.get(oldKey);
|
|
157
|
-
if (carried) {
|
|
158
|
-
resultsByKey.set(newKey, carried);
|
|
159
|
-
}
|
|
160
|
-
entry.unsub();
|
|
161
|
-
activeSubs.delete(oldKey);
|
|
162
|
-
resultsByKey.delete(oldKey);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
pages.set(next);
|
|
166
|
-
syncSubscriptions(pages());
|
|
167
|
-
doRebuildPageResults();
|
|
168
|
-
};
|
|
169
|
-
return { loadMore, pageResults, status };
|
|
170
|
-
};
|
|
171
|
-
const paginatedQuery = (reference, args, options) => {
|
|
172
|
-
const core = usePaginatedCore(reference, args, options);
|
|
173
|
-
const results = computed(() => {
|
|
174
|
-
const items = [];
|
|
175
|
-
for (const result of core.pageResults()) {
|
|
176
|
-
if (result) {
|
|
177
|
-
items.push(...result.page);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
return items;
|
|
181
|
-
});
|
|
182
|
-
const isLoading = computed(() => {
|
|
183
|
-
const statusValue = core.status();
|
|
184
|
-
return statusValue === "LoadingFirstPage" || statusValue === "LoadingMore";
|
|
185
|
-
});
|
|
186
|
-
return {
|
|
187
|
-
isLoading,
|
|
188
|
-
loadMore: core.loadMore,
|
|
189
|
-
results,
|
|
190
|
-
status: core.status
|
|
191
|
-
};
|
|
192
|
-
};
|
|
193
|
-
const infiniteQuery = (reference, args, options) => {
|
|
194
|
-
const { initialNumItems } = options;
|
|
195
|
-
const core = usePaginatedCore(reference, args, options);
|
|
196
|
-
const pages = computed(() => {
|
|
197
|
-
const resultArrays = [];
|
|
198
|
-
for (const page of core.pageResults()) {
|
|
199
|
-
if (page) {
|
|
200
|
-
resultArrays.push(page.page);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
return resultArrays;
|
|
204
|
-
});
|
|
205
|
-
const isLoading = computed(() => core.status() === "LoadingFirstPage");
|
|
206
|
-
const hasNextPage = computed(() => core.status() === "CanLoadMore");
|
|
207
|
-
const isFetchingNextPage = computed(() => core.status() === "LoadingMore");
|
|
208
|
-
const fetchNextPage = (numberItems) => {
|
|
209
|
-
core.loadMore(numberItems ?? initialNumItems);
|
|
210
|
-
};
|
|
211
|
-
return {
|
|
212
|
-
fetchNextPage,
|
|
213
|
-
hasNextPage,
|
|
214
|
-
isFetchingNextPage,
|
|
215
|
-
isLoading,
|
|
216
|
-
pages,
|
|
217
|
-
status: core.status
|
|
218
|
-
};
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
export { infiniteQuery, paginatedQuery };
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { inject, DestroyRef, signal } from '@angular/core';
|
|
2
|
-
import { createQuerySubscription } from '@lunora/client/query';
|
|
3
|
-
import { resolveLunoraClient } from './LUNORA_CLIENT-DHUfNu9x.mjs';
|
|
4
|
-
import { s as shouldOpenSubscription } from './platform-Dg8Bppgq.mjs';
|
|
5
|
-
|
|
6
|
-
const liveQuery = (reference, args, options = {}) => {
|
|
7
|
-
const client = resolveLunoraClient(options.client);
|
|
8
|
-
const fromInjectionContext = options.destroyRef === void 0;
|
|
9
|
-
const destroyRef = options.destroyRef ?? inject(DestroyRef);
|
|
10
|
-
const value = signal(void 0);
|
|
11
|
-
if (shouldOpenSubscription(fromInjectionContext)) {
|
|
12
|
-
const unsubscribe = createQuerySubscription(
|
|
13
|
-
client,
|
|
14
|
-
reference,
|
|
15
|
-
args,
|
|
16
|
-
{
|
|
17
|
-
onData: (next) => {
|
|
18
|
-
value.set(next);
|
|
19
|
-
},
|
|
20
|
-
onError: options.onError,
|
|
21
|
-
onReset: () => {
|
|
22
|
-
value.set(void 0);
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
{ shardKey: options.shardKey }
|
|
26
|
-
);
|
|
27
|
-
destroyRef.onDestroy(unsubscribe);
|
|
28
|
-
}
|
|
29
|
-
return value.asReadonly();
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export { liveQuery };
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { resolveLunoraClient } from './LUNORA_CLIENT-DHUfNu9x.mjs';
|
|
2
|
-
|
|
3
|
-
const mutate = (reference, args, options = {}) => {
|
|
4
|
-
const { client, ...callOptions } = options;
|
|
5
|
-
return resolveLunoraClient(client).mutation(reference, args, callOptions);
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export { mutate };
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { signal, computed } from '@angular/core';
|
|
2
|
-
import { createMutatorRunner } from '@lunora/client';
|
|
3
|
-
|
|
4
|
-
const mutator = (handle) => {
|
|
5
|
-
const error = signal(void 0);
|
|
6
|
-
const pending = signal(false);
|
|
7
|
-
const isError = computed(() => 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: error.asReadonly(), isError, mutate, pending: pending.asReadonly(), reset };
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export { mutator };
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { inject, PLATFORM_ID, NgZone } from '@angular/core';
|
|
2
|
-
|
|
3
|
-
const shouldOpenSubscription = (fromInjectionContext) => {
|
|
4
|
-
if (!fromInjectionContext) {
|
|
5
|
-
return true;
|
|
6
|
-
}
|
|
7
|
-
return inject(PLATFORM_ID, { optional: true }) !== "server";
|
|
8
|
-
};
|
|
9
|
-
const runOutsideAngular = (fromInjectionContext, register) => {
|
|
10
|
-
const zone = fromInjectionContext ? inject(NgZone, { optional: true }) : void 0;
|
|
11
|
-
return zone ? zone.runOutsideAngular(register) : register();
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export { runOutsideAngular as r, shouldOpenSubscription as s };
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { inject, DestroyRef, signal } from '@angular/core';
|
|
2
|
-
import { resolveLunoraClient } from './LUNORA_CLIENT-DHUfNu9x.mjs';
|
|
3
|
-
import { s as shouldOpenSubscription, r as runOutsideAngular } from './platform-Dg8Bppgq.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 presence = (roomId, options) => {
|
|
20
|
-
const client = resolveLunoraClient(options.client);
|
|
21
|
-
const fromInjectionContext = options.destroyRef === void 0;
|
|
22
|
-
const destroyRef = options.destroyRef ?? inject(DestroyRef);
|
|
23
|
-
const { heartbeat, listPresent, shardKey } = options;
|
|
24
|
-
const intervalMs = options.intervalMs ?? DEFAULT_INTERVAL_MS;
|
|
25
|
-
const sessionId = options.sessionId ?? randomSessionId();
|
|
26
|
-
const present = signal(void 0);
|
|
27
|
-
if (!Number.isFinite(intervalMs) || intervalMs <= 0) {
|
|
28
|
-
throw new RangeError(`presence intervalMs must be a positive number, got ${String(intervalMs)}`);
|
|
29
|
-
}
|
|
30
|
-
let latestData = options.data;
|
|
31
|
-
const sendHeartbeat = () => {
|
|
32
|
-
const args = { roomId, sessionId };
|
|
33
|
-
if (latestData !== void 0) {
|
|
34
|
-
args.data = latestData;
|
|
35
|
-
}
|
|
36
|
-
client.mutation(heartbeat, args, { shardKey }).catch(() => void 0);
|
|
37
|
-
};
|
|
38
|
-
const setData = (next) => {
|
|
39
|
-
latestData = next;
|
|
40
|
-
sendHeartbeat();
|
|
41
|
-
};
|
|
42
|
-
if (shouldOpenSubscription(fromInjectionContext)) {
|
|
43
|
-
const releaseConnectionContext = client.acquireConnectionContext({ roomId, sessionId }, { shardKey });
|
|
44
|
-
sendHeartbeat();
|
|
45
|
-
const onVisible = () => {
|
|
46
|
-
if (typeof document !== "undefined" && document.visibilityState === "visible") {
|
|
47
|
-
sendHeartbeat();
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
const intervalHandle = runOutsideAngular(fromInjectionContext, () => {
|
|
51
|
-
if (typeof document !== "undefined") {
|
|
52
|
-
document.addEventListener("visibilitychange", onVisible);
|
|
53
|
-
}
|
|
54
|
-
return setInterval(sendHeartbeat, intervalMs);
|
|
55
|
-
});
|
|
56
|
-
const listArgs = { roomId };
|
|
57
|
-
const unsubscribe = client.subscribe(
|
|
58
|
-
listPresent,
|
|
59
|
-
listArgs,
|
|
60
|
-
(value) => {
|
|
61
|
-
present.set(value);
|
|
62
|
-
},
|
|
63
|
-
{ shardKey }
|
|
64
|
-
);
|
|
65
|
-
destroyRef.onDestroy(() => {
|
|
66
|
-
clearInterval(intervalHandle);
|
|
67
|
-
if (typeof document !== "undefined") {
|
|
68
|
-
document.removeEventListener("visibilitychange", onVisible);
|
|
69
|
-
}
|
|
70
|
-
releaseConnectionContext();
|
|
71
|
-
unsubscribe();
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
return { present: present.asReadonly(), sessionId, setData };
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
export { presence };
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { inject, DestroyRef, signal, computed } from '@angular/core';
|
|
2
|
-
import { evaluate } from '@lunora/ratelimit';
|
|
3
|
-
|
|
4
|
-
const rateLimit = (config, options = {}) => {
|
|
5
|
-
const destroyRef = options.destroyRef ?? inject(DestroyRef);
|
|
6
|
-
const now = options.now ?? Date.now;
|
|
7
|
-
const tickMs = options.tickMs ?? 1e3;
|
|
8
|
-
let value;
|
|
9
|
-
const computeStatus = () => evaluate(config, value, { consume: false, count: 1, now: now(), reserve: false }).status;
|
|
10
|
-
const status = signal(computeStatus());
|
|
11
|
-
const bump = () => {
|
|
12
|
-
status.set(computeStatus());
|
|
13
|
-
};
|
|
14
|
-
let intervalHandle;
|
|
15
|
-
const stopInterval = () => {
|
|
16
|
-
if (intervalHandle !== void 0) {
|
|
17
|
-
clearInterval(intervalHandle);
|
|
18
|
-
intervalHandle = void 0;
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
const startIntervalIfThrottled = () => {
|
|
22
|
-
if (status().ok || intervalHandle !== void 0) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
intervalHandle = setInterval(() => {
|
|
26
|
-
bump();
|
|
27
|
-
if (status().ok) {
|
|
28
|
-
stopInterval();
|
|
29
|
-
}
|
|
30
|
-
}, tickMs);
|
|
31
|
-
};
|
|
32
|
-
startIntervalIfThrottled();
|
|
33
|
-
destroyRef.onDestroy(() => {
|
|
34
|
-
stopInterval();
|
|
35
|
-
});
|
|
36
|
-
return {
|
|
37
|
-
check: (count = 1) => evaluate(config, value, { consume: false, count, now: now(), reserve: false }).status.ok,
|
|
38
|
-
consume: (count = 1) => {
|
|
39
|
-
const result = evaluate(config, value, { consume: true, count, now: now(), reserve: false });
|
|
40
|
-
if (result.value !== void 0) {
|
|
41
|
-
value = result.value;
|
|
42
|
-
}
|
|
43
|
-
bump();
|
|
44
|
-
startIntervalIfThrottled();
|
|
45
|
-
return result.status;
|
|
46
|
-
},
|
|
47
|
-
disabled: computed(() => !status().ok),
|
|
48
|
-
ok: computed(() => status().ok),
|
|
49
|
-
reset: () => {
|
|
50
|
-
value = void 0;
|
|
51
|
-
stopInterval();
|
|
52
|
-
bump();
|
|
53
|
-
},
|
|
54
|
-
retryAfter: computed(() => status().retryAfter)
|
|
55
|
-
};
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
export { rateLimit };
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { inject, DestroyRef, signal } from '@angular/core';
|
|
2
|
-
import { resolveLunoraClient } from './LUNORA_CLIENT-DHUfNu9x.mjs';
|
|
3
|
-
|
|
4
|
-
const stream = (reference, args, options = {}) => {
|
|
5
|
-
const client = resolveLunoraClient(options.client);
|
|
6
|
-
const destroyRef = options.destroyRef ?? inject(DestroyRef);
|
|
7
|
-
const chunks = signal([]);
|
|
8
|
-
const error = signal(void 0);
|
|
9
|
-
const status = signal("idle");
|
|
10
|
-
let active = true;
|
|
11
|
-
let cancelIterable;
|
|
12
|
-
const cancel = () => {
|
|
13
|
-
active = false;
|
|
14
|
-
cancelIterable?.();
|
|
15
|
-
};
|
|
16
|
-
if (args !== "skip") {
|
|
17
|
-
status.set("streaming");
|
|
18
|
-
const iterable = client.stream(reference, args, { maxBuffer: options.maxBuffer, shardKey: options.shardKey });
|
|
19
|
-
cancelIterable = () => {
|
|
20
|
-
iterable.cancel();
|
|
21
|
-
};
|
|
22
|
-
(async () => {
|
|
23
|
-
try {
|
|
24
|
-
for await (const chunk of iterable) {
|
|
25
|
-
if (!active) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
chunks.update((current) => [...current, chunk]);
|
|
29
|
-
}
|
|
30
|
-
if (active) {
|
|
31
|
-
status.set("complete");
|
|
32
|
-
}
|
|
33
|
-
} catch (streamError) {
|
|
34
|
-
if (!active) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
error.set(streamError instanceof Error ? streamError : new Error(String(streamError)));
|
|
38
|
-
status.set("error");
|
|
39
|
-
}
|
|
40
|
-
})().catch(() => {
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
destroyRef.onDestroy(cancel);
|
|
44
|
-
return { cancel, chunks: chunks.asReadonly(), error: error.asReadonly(), status: status.asReadonly() };
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export { stream };
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { inject, DestroyRef, signal } from '@angular/core';
|
|
2
|
-
import { createQuerySubscription } from '@lunora/client/query';
|
|
3
|
-
import { resolveLunoraClient } from './LUNORA_CLIENT-DHUfNu9x.mjs';
|
|
4
|
-
import { s as shouldOpenSubscription } from './platform-Dg8Bppgq.mjs';
|
|
5
|
-
|
|
6
|
-
const subscription = (reference, args, options = {}) => {
|
|
7
|
-
const client = resolveLunoraClient(options.client);
|
|
8
|
-
const fromInjectionContext = options.destroyRef === void 0;
|
|
9
|
-
const destroyRef = options.destroyRef ?? inject(DestroyRef);
|
|
10
|
-
const data = signal(void 0);
|
|
11
|
-
const error = signal(void 0);
|
|
12
|
-
if (args !== "skip" && shouldOpenSubscription(fromInjectionContext)) {
|
|
13
|
-
const userOnError = options.onError;
|
|
14
|
-
const unsubscribe = createQuerySubscription(
|
|
15
|
-
client,
|
|
16
|
-
reference,
|
|
17
|
-
args,
|
|
18
|
-
{
|
|
19
|
-
onData: (next) => {
|
|
20
|
-
data.set(next);
|
|
21
|
-
error.set(void 0);
|
|
22
|
-
},
|
|
23
|
-
onError: (error_) => {
|
|
24
|
-
error.set(error_);
|
|
25
|
-
data.set(void 0);
|
|
26
|
-
userOnError?.(error_);
|
|
27
|
-
},
|
|
28
|
-
onReset: () => {
|
|
29
|
-
data.set(void 0);
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
{ shardKey: options.shardKey }
|
|
33
|
-
);
|
|
34
|
-
destroyRef.onDestroy(unsubscribe);
|
|
35
|
-
}
|
|
36
|
-
return { data: data.asReadonly(), error: error.asReadonly() };
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export { subscription };
|