@lunora/angular 0.0.1 → 1.0.0-alpha.10

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 ADDED
@@ -0,0 +1,19 @@
1
+ export { agent } from './packem_shared/agent-DDKvrG4u.mjs';
2
+ export { agentChat } from './packem_shared/agentChat-DDZlxK1v.mjs';
3
+ export { agentState } from './packem_shared/agentState-C8GWf3t3.mjs';
4
+ export { agentToolEvents } from './packem_shared/agentToolEvents-sXgYggvi.mjs';
5
+ export { auth } from './packem_shared/auth-Df9N87Z4.mjs';
6
+ export { LUNORA_CLIENT, injectLunoraClient, provideLunora } from './packem_shared/LUNORA_CLIENT-DHUfNu9x.mjs';
7
+ export { connectionStatus } from './packem_shared/connectionStatus-BlLodleK.mjs';
8
+ export { flag, flags } from './packem_shared/flag-CGBo90HJ.mjs';
9
+ export { hydratePreloaded } from './packem_shared/hydratePreloaded-DIpD1cAM.mjs';
10
+ export { liveQuery } from './packem_shared/liveQuery-DVxKidjM.mjs';
11
+ export { mutate } from './packem_shared/mutate-D3rEHwbb.mjs';
12
+ export { mutator } from './packem_shared/mutator-BHL8bakL.mjs';
13
+ export { infiniteQuery, paginatedQuery } from './packem_shared/infiniteQuery-nboKfr5E.mjs';
14
+ export { presence } from './packem_shared/presence-BTuq19dS.mjs';
15
+ export { rateLimit } from './packem_shared/rateLimit-I4kRT9qV.mjs';
16
+ export { stream } from './packem_shared/stream-PL64AghO.mjs';
17
+ export { subscription } from './packem_shared/subscription-oZ-WTmpp.mjs';
18
+ export { voiceAgent } from './packem_shared/voiceAgent-DwbrDnB9.mjs';
19
+ export { SKIP } from '@lunora/client/query';
@@ -0,0 +1,23 @@
1
+ import { InjectionToken, makeEnvironmentProviders, inject } from '@angular/core';
2
+ import { LunoraClient } from '@lunora/client';
3
+
4
+ const sameOriginUrl = () => globalThis.location?.origin ?? "";
5
+ const LUNORA_CLIENT = new InjectionToken("lunora.client", {
6
+ factory: () => new LunoraClient({ url: sameOriginUrl() }),
7
+ providedIn: "root"
8
+ });
9
+ const provideLunora = (optionsOrClient = {}) => makeEnvironmentProviders([
10
+ {
11
+ provide: LUNORA_CLIENT,
12
+ useFactory: () => {
13
+ if (optionsOrClient instanceof LunoraClient) {
14
+ return optionsOrClient;
15
+ }
16
+ return new LunoraClient({ ...optionsOrClient, url: optionsOrClient.url ?? sameOriginUrl() });
17
+ }
18
+ }
19
+ ]);
20
+ const injectLunoraClient = () => inject(LUNORA_CLIENT);
21
+ const resolveLunoraClient = (client) => client ?? injectLunoraClient();
22
+
23
+ export { LUNORA_CLIENT, injectLunoraClient, provideLunora, resolveLunoraClient };
@@ -0,0 +1,31 @@
1
+ import { inject, DestroyRef, computed, signal } from '@angular/core';
2
+ import { resolveLunoraClient } from './LUNORA_CLIENT-DHUfNu9x.mjs';
3
+ import { subscription } from './subscription-oZ-WTmpp.mjs';
4
+
5
+ const agent = (options) => {
6
+ const { api, cancel: cancelReference, run: runReference, runArgs, threadKey } = options;
7
+ const client = resolveLunoraClient(options.client);
8
+ const destroyRef = options.destroyRef ?? inject(DestroyRef);
9
+ const { data: threadData } = subscription(api.agents.agentThread, { key: threadKey }, { client, destroyRef });
10
+ const thread = computed(() => threadData());
11
+ const status = computed(() => thread()?.status);
12
+ const pending = signal(false);
13
+ const run = async (input, arguments_) => {
14
+ pending.set(true);
15
+ try {
16
+ await client.mutation(runReference, { input, threadKey, ...runArgs, ...arguments_ });
17
+ } finally {
18
+ pending.set(false);
19
+ }
20
+ };
21
+ const cancel = async () => {
22
+ const instanceId = thread()?.instanceId;
23
+ if (cancelReference === void 0 || instanceId === void 0) {
24
+ return;
25
+ }
26
+ await client.mutation(cancelReference, { instanceId, threadKey });
27
+ };
28
+ return { cancel, pending: pending.asReadonly(), run, status, thread };
29
+ };
30
+
31
+ export { agent };
@@ -0,0 +1,111 @@
1
+ import { inject, DestroyRef, signal, computed } from '@angular/core';
2
+ import { resolveLunoraClient } from './LUNORA_CLIENT-DHUfNu9x.mjs';
3
+ import { stream } from './stream-PL64AghO.mjs';
4
+ import { subscription } from './subscription-oZ-WTmpp.mjs';
5
+
6
+ const NO_STREAM_REF = { __lunoraRef: "" };
7
+ const reconcileOptimistic = (optimistic, durable) => {
8
+ const durableUserRows = durable.filter((message) => message.role === "user");
9
+ const consumed = /* @__PURE__ */ new Set();
10
+ return optimistic.filter((pending) => {
11
+ for (let index = pending.durableUserCountAtSend; index < durableUserRows.length; index += 1) {
12
+ const row = durableUserRows[index];
13
+ if (row !== void 0 && !consumed.has(index) && row.content === pending.content) {
14
+ consumed.add(index);
15
+ return false;
16
+ }
17
+ }
18
+ return true;
19
+ });
20
+ };
21
+ const agentChat = (options) => {
22
+ const { api, cancel: cancelReference, limit, send: sendReference, sendArgs, stream: streamReference, threadKey } = options;
23
+ const client = resolveLunoraClient(options.client);
24
+ const destroyRef = options.destroyRef ?? inject(DestroyRef);
25
+ const messagesArguments = limit === void 0 ? { key: threadKey } : { key: threadKey, limit };
26
+ const { data: history } = subscription(api.agents.agentMessages, messagesArguments, { client, destroyRef });
27
+ const { data: threadData } = subscription(api.agents.agentThread, { key: threadKey }, { client, destroyRef });
28
+ const streamArguments = streamReference === void 0 ? "skip" : { key: threadKey };
29
+ const { chunks } = stream(streamReference ?? NO_STREAM_REF, streamArguments, { client, destroyRef });
30
+ const optimistic = signal([]);
31
+ let nextId = 0;
32
+ const thread = computed(() => threadData());
33
+ const status = computed(() => thread()?.status);
34
+ const durable = computed(() => history() ?? []);
35
+ const messages = computed(() => {
36
+ const rows = durable();
37
+ const visible = reconcileOptimistic(optimistic(), rows);
38
+ if (visible.length === 0) {
39
+ return rows;
40
+ }
41
+ let maxDurableSeq = -1;
42
+ for (const message of rows) {
43
+ if (message.seq > maxDurableSeq) {
44
+ maxDurableSeq = message.seq;
45
+ }
46
+ }
47
+ return [
48
+ ...rows,
49
+ ...visible.map((pending, index) => {
50
+ return {
51
+ content: pending.content,
52
+ optimistic: true,
53
+ role: "user",
54
+ seq: maxDurableSeq + 1 + index
55
+ };
56
+ })
57
+ ];
58
+ });
59
+ const streamingText = computed(() => {
60
+ const assistantCount = durable().filter((message) => message.role === "assistant").length;
61
+ return chunks().filter((event) => event.kind !== "progress" && event.threadKey === threadKey && event.turn >= assistantCount).map((delta) => delta.text).join("");
62
+ });
63
+ const send = async (input, arguments_) => {
64
+ const id = nextId;
65
+ nextId += 1;
66
+ const durableUserCountAtSend = durable().filter((message) => message.role === "user").length;
67
+ optimistic.set([...reconcileOptimistic(optimistic(), durable()), { content: input, durableUserCountAtSend, id }]);
68
+ try {
69
+ await client.mutation(sendReference, { input, threadKey, ...sendArgs, ...arguments_ });
70
+ } catch (error) {
71
+ optimistic.set(optimistic().filter((pending) => pending.id !== id));
72
+ throw error;
73
+ }
74
+ };
75
+ const approve = async (toolCallId, note) => {
76
+ const instanceId = thread()?.instanceId;
77
+ if (instanceId === void 0) {
78
+ throw new Error("agentChat: cannot approve — no in-flight run (thread has no instanceId)");
79
+ }
80
+ await client.mutation(api.agents.agentResolveApproval, {
81
+ decision: "approve",
82
+ instanceId,
83
+ threadKey,
84
+ toolCallId,
85
+ ...note === void 0 ? {} : { note }
86
+ });
87
+ };
88
+ const reject = async (toolCallId, note) => {
89
+ const instanceId = thread()?.instanceId;
90
+ if (instanceId === void 0) {
91
+ throw new Error("agentChat: cannot reject — no in-flight run (thread has no instanceId)");
92
+ }
93
+ await client.mutation(api.agents.agentResolveApproval, {
94
+ decision: "reject",
95
+ instanceId,
96
+ threadKey,
97
+ toolCallId,
98
+ ...note === void 0 ? {} : { note }
99
+ });
100
+ };
101
+ const cancel = async () => {
102
+ const instanceId = thread()?.instanceId;
103
+ if (cancelReference === void 0 || instanceId === void 0) {
104
+ return;
105
+ }
106
+ await client.mutation(cancelReference, { instanceId, threadKey });
107
+ };
108
+ return { approve, cancel, messages, reject, send, status, streamingText };
109
+ };
110
+
111
+ export { agentChat };
@@ -0,0 +1,10 @@
1
+ import { computed } from '@angular/core';
2
+ import { subscription } from './subscription-oZ-WTmpp.mjs';
3
+
4
+ const agentState = (options) => {
5
+ const { data, error } = subscription(options.api.agents.agentState, { key: options.threadKey }, { client: options.client, destroyRef: options.destroyRef });
6
+ const state = computed(() => data());
7
+ return { error, state };
8
+ };
9
+
10
+ export { agentState };
@@ -0,0 +1,59 @@
1
+ import { inject, DestroyRef, computed } from '@angular/core';
2
+ import { resolveLunoraClient } from './LUNORA_CLIENT-DHUfNu9x.mjs';
3
+ import { stream } from './stream-PL64AghO.mjs';
4
+ import { subscription } from './subscription-oZ-WTmpp.mjs';
5
+
6
+ const NO_STREAM_REF = { __lunoraRef: "" };
7
+ const EMPTY_MESSAGES = [];
8
+ const toDurableEvent = (message) => {
9
+ if (message.role === "assistant" && message.toolCalls) {
10
+ return message.toolCalls.map((call) => {
11
+ return { input: call.input, seq: message.seq, toolCallId: call.id, toolName: call.name, type: "call" };
12
+ });
13
+ }
14
+ if (message.role !== "tool") {
15
+ return void 0;
16
+ }
17
+ if (message.status === "awaiting_approval") {
18
+ return [
19
+ {
20
+ seq: message.seq,
21
+ type: "awaiting-approval",
22
+ ...message.toolCallId === void 0 ? {} : { toolCallId: message.toolCallId },
23
+ ...message.toolName === void 0 ? {} : { toolName: message.toolName }
24
+ }
25
+ ];
26
+ }
27
+ return [
28
+ {
29
+ output: message.content,
30
+ seq: message.seq,
31
+ type: "result",
32
+ ...message.status === "approved" || message.status === "rejected" ? { status: message.status } : {},
33
+ ...message.toolCallId === void 0 ? {} : { toolCallId: message.toolCallId },
34
+ ...message.toolName === void 0 ? {} : { toolName: message.toolName }
35
+ }
36
+ ];
37
+ };
38
+ const agentToolEvents = (options) => {
39
+ const { api, limit, stream: streamReference, threadKey } = options;
40
+ const client = resolveLunoraClient(options.client);
41
+ const destroyRef = options.destroyRef ?? inject(DestroyRef);
42
+ const messagesArguments = limit === void 0 ? { key: threadKey } : { key: threadKey, limit };
43
+ const { data: history } = subscription(api.agents.agentMessages, messagesArguments, { client, destroyRef });
44
+ const streamArguments = streamReference === void 0 ? "skip" : { key: threadKey };
45
+ const { chunks } = stream(streamReference ?? NO_STREAM_REF, streamArguments, { client, destroyRef });
46
+ const events = computed(() => {
47
+ const durable = history() ?? EMPTY_MESSAGES;
48
+ const derived = durable.flatMap((message) => toDurableEvent(message) ?? []);
49
+ for (const event of chunks()) {
50
+ if (event.kind === "progress" && event.threadKey === threadKey) {
51
+ derived.push({ data: event.data, toolCallId: event.toolCallId, type: "progress" });
52
+ }
53
+ }
54
+ return derived;
55
+ });
56
+ return { events };
57
+ };
58
+
59
+ export { agentToolEvents };
@@ -0,0 +1,27 @@
1
+ import { inject, DestroyRef, signal } from '@angular/core';
2
+ import { getIdentityStore } from '@lunora/client/auth';
3
+ import { resolveLunoraClient } from './LUNORA_CLIENT-DHUfNu9x.mjs';
4
+
5
+ const auth = (options = {}) => {
6
+ const client = resolveLunoraClient(options.client);
7
+ const destroyRef = options.destroyRef ?? inject(DestroyRef);
8
+ const store = getIdentityStore(client);
9
+ const token = signal(client.getAuthToken());
10
+ const user = signal(store.getUser());
11
+ const unsubToken = client.onAuthTokenChange(() => {
12
+ token.set(client.getAuthToken());
13
+ });
14
+ const unsubUser = store.subscribe(() => {
15
+ user.set(store.getUser());
16
+ });
17
+ destroyRef.onDestroy(() => {
18
+ unsubToken();
19
+ unsubUser();
20
+ });
21
+ const setToken = (next) => {
22
+ client.setAuthToken(next);
23
+ };
24
+ return { setToken, token: token.asReadonly(), user: user.asReadonly() };
25
+ };
26
+
27
+ export { auth };
@@ -0,0 +1,15 @@
1
+ import { inject, DestroyRef, signal } from '@angular/core';
2
+ import { resolveLunoraClient } from './LUNORA_CLIENT-DHUfNu9x.mjs';
3
+
4
+ const connectionStatus = (options = {}) => {
5
+ const client = resolveLunoraClient(options.client);
6
+ const destroyRef = options.destroyRef ?? inject(DestroyRef);
7
+ const status = signal(client.connectionStatus());
8
+ const unsubscribe = client.onConnectionStatus((next) => {
9
+ status.set(next);
10
+ });
11
+ destroyRef.onDestroy(unsubscribe);
12
+ return status.asReadonly();
13
+ };
14
+
15
+ export { connectionStatus };
@@ -0,0 +1,70 @@
1
+ import { inject, DestroyRef, signal } from '@angular/core';
2
+ import { resolveLunoraClient } from './LUNORA_CLIENT-DHUfNu9x.mjs';
3
+
4
+ const FLAGS_EVAL_PATH = "__lunora_flags__:eval";
5
+ const flagKind = (value) => {
6
+ const kind = typeof value;
7
+ if (kind === "boolean" || kind === "number" || kind === "string") {
8
+ return kind;
9
+ }
10
+ return "object";
11
+ };
12
+ const flagsReference = { __lunoraRef: FLAGS_EVAL_PATH };
13
+ const flag = (key, defaultValue, options = {}) => {
14
+ const client = resolveLunoraClient(options.client);
15
+ const destroyRef = options.destroyRef ?? inject(DestroyRef);
16
+ const type = flagKind(defaultValue);
17
+ const value = signal(defaultValue);
18
+ let unsubscribe;
19
+ try {
20
+ unsubscribe = client.subscribe(
21
+ flagsReference,
22
+ { context: options.context, default: defaultValue, key, type },
23
+ (next) => {
24
+ value.set(next);
25
+ },
26
+ {
27
+ onError: () => {
28
+ value.set(defaultValue);
29
+ }
30
+ }
31
+ );
32
+ } catch {
33
+ }
34
+ if (unsubscribe) {
35
+ destroyRef.onDestroy(unsubscribe);
36
+ }
37
+ return value.asReadonly();
38
+ };
39
+ const flags = (flagDefaults, options = {}) => {
40
+ const client = resolveLunoraClient(options.client);
41
+ const destroyRef = options.destroyRef ?? inject(DestroyRef);
42
+ const values = signal({ ...flagDefaults });
43
+ const unsubscribes = [];
44
+ for (const [key, defaultValue] of Object.entries(flagDefaults)) {
45
+ try {
46
+ const unsub = client.subscribe(
47
+ flagsReference,
48
+ { context: options.context, default: defaultValue, key, type: flagKind(defaultValue) },
49
+ (next) => {
50
+ values.set({ ...values(), [key]: next });
51
+ },
52
+ {
53
+ onError: () => {
54
+ values.set({ ...values(), [key]: defaultValue });
55
+ }
56
+ }
57
+ );
58
+ unsubscribes.push(unsub);
59
+ } catch {
60
+ }
61
+ }
62
+ destroyRef.onDestroy(() => {
63
+ for (const unsubscribe of unsubscribes) {
64
+ unsubscribe();
65
+ }
66
+ });
67
+ return values.asReadonly();
68
+ };
69
+
70
+ export { flag, flags };
@@ -0,0 +1,33 @@
1
+ import { inject, DestroyRef, signal } from '@angular/core';
2
+ import { resolveLunoraClient } from './LUNORA_CLIENT-DHUfNu9x.mjs';
3
+ import { s as shouldOpenSubscription } from './platform-Dg8Bppgq.mjs';
4
+
5
+ const hydratePreloaded = (preloaded, options = {}) => {
6
+ const client = resolveLunoraClient(options.client);
7
+ const fromInjectionContext = options.destroyRef === void 0;
8
+ const destroyRef = options.destroyRef ?? inject(DestroyRef);
9
+ const { args, functionPath, shardKey, value } = preloaded;
10
+ const data = signal(value);
11
+ const error = signal(void 0);
12
+ const functionReference = { __lunoraRef: functionPath };
13
+ if (shouldOpenSubscription(fromInjectionContext)) {
14
+ const unsubscribe = client.subscribe(
15
+ functionReference,
16
+ args,
17
+ (next) => {
18
+ data.set(next);
19
+ error.set(void 0);
20
+ },
21
+ {
22
+ onError: (error_) => {
23
+ error.set(error_);
24
+ },
25
+ shardKey
26
+ }
27
+ );
28
+ destroyRef.onDestroy(unsubscribe);
29
+ }
30
+ return { data: data.asReadonly(), error: error.asReadonly() };
31
+ };
32
+
33
+ export { hydratePreloaded };
@@ -0,0 +1,221 @@
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 };
@@ -0,0 +1,32 @@
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 };
@@ -0,0 +1,8 @@
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 };