@lunora/angular 1.0.0-alpha.4 → 1.0.0-alpha.40

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/README.md +27 -0
  2. package/dist/index.d.mts +1214 -279
  3. package/dist/index.d.ts +1214 -279
  4. package/dist/index.mjs +1 -13
  5. package/dist/packem_shared/LUNORA_CLIENT-B0toApHY.mjs +1 -0
  6. package/dist/packem_shared/agent-BPvUvuXh.mjs +1 -0
  7. package/dist/packem_shared/agentChat-BgD9zNFw.mjs +1 -0
  8. package/dist/packem_shared/agentState-BBAruY2b.mjs +1 -0
  9. package/dist/packem_shared/agentToolEvents-CUwrn-Nu.mjs +1 -0
  10. package/dist/packem_shared/auth-BgwruT_M.mjs +1 -0
  11. package/dist/packem_shared/connectionStatus-UhmuwzMa.mjs +1 -0
  12. package/dist/packem_shared/flag-orUoJY7A.mjs +1 -0
  13. package/dist/packem_shared/hydratePreloaded-C8lNoww0.mjs +1 -0
  14. package/dist/packem_shared/infiniteQuery-CIprZdJt.mjs +1 -0
  15. package/dist/packem_shared/liveQuery-BvA2co81.mjs +1 -0
  16. package/dist/packem_shared/mutate-BZvLQLyu.mjs +1 -0
  17. package/dist/packem_shared/mutator-DjG1yGk8.mjs +1 -0
  18. package/dist/packem_shared/platform-I2VyCEIl.mjs +1 -0
  19. package/dist/packem_shared/presence-vJUxsR5f.mjs +1 -0
  20. package/dist/packem_shared/rateLimit-B3h9qzh-.mjs +1 -0
  21. package/dist/packem_shared/runAction-BfiPq4Xz.mjs +1 -0
  22. package/dist/packem_shared/stream-CcjYdpzt.mjs +1 -0
  23. package/dist/packem_shared/subscription-DqtYnats.mjs +1 -0
  24. package/dist/packem_shared/voiceAgent-CzyUcUKj.mjs +1 -0
  25. package/dist/server.d.mts +1 -0
  26. package/dist/server.d.ts +1 -0
  27. package/dist/server.mjs +1 -0
  28. package/dist/upload.d.mts +57 -0
  29. package/dist/upload.d.ts +57 -0
  30. package/dist/upload.mjs +1 -0
  31. package/package.json +12 -3
  32. package/dist/packem_shared/LUNORA_CLIENT-DHUfNu9x.mjs +0 -23
  33. package/dist/packem_shared/auth-Df9N87Z4.mjs +0 -27
  34. package/dist/packem_shared/connectionStatus-BlLodleK.mjs +0 -15
  35. package/dist/packem_shared/flag-CGBo90HJ.mjs +0 -70
  36. package/dist/packem_shared/hydratePreloaded-ClRc-7rL.mjs +0 -29
  37. package/dist/packem_shared/infiniteQuery-DUV60k-n.mjs +0 -200
  38. package/dist/packem_shared/liveQuery-D5VQBOgf.mjs +0 -28
  39. package/dist/packem_shared/mutate-D3rEHwbb.mjs +0 -8
  40. package/dist/packem_shared/mutator-BHL8bakL.mjs +0 -19
  41. package/dist/packem_shared/presence-h2xonCZM.mjs +0 -59
  42. package/dist/packem_shared/rateLimit-CKcAig4M.mjs +0 -60
  43. package/dist/packem_shared/subscription-Dd9dQiBB.mjs +0 -37
@@ -1,200 +0,0 @@
1
- import { computed, inject, DestroyRef, signal } from '@angular/core';
2
- import { initialPages, rebalance, derivePaginationStatus, applyLoadMore } from '@lunora/client/pagination';
3
- import { resolveLunoraClient } from './LUNORA_CLIENT-DHUfNu9x.mjs';
4
-
5
- const buildPageKey = (functionPath, pageArgs) => `${functionPath}::${JSON.stringify(pageArgs)}`;
6
- const buildPageArgs = (page, baseArgs) => {
7
- return {
8
- ...baseArgs,
9
- paginationOpts: { cursor: page.lower, endCursor: page.upper, numItems: page.numItems }
10
- };
11
- };
12
- const usePaginatedCore = (reference, baseArgs, options) => {
13
- const client = resolveLunoraClient(options.client);
14
- const destroyRef = options.destroyRef ?? inject(DestroyRef);
15
- const { initialNumItems, shardKey } = options;
16
- const functionPath = reference["__lunoraRef"];
17
- const narrowedArgs = baseArgs === "skip" ? {} : baseArgs;
18
- const pages = signal(initialPages(initialNumItems));
19
- const pageResults = signal([]);
20
- const status = signal("LoadingFirstPage");
21
- const activeSubs = /* @__PURE__ */ new Map();
22
- const resultsByKey = /* @__PURE__ */ new Map();
23
- const pendingPageKeys = /* @__PURE__ */ new Set();
24
- const doRebuildPageResults = () => {
25
- const currentPages = pages();
26
- const items = currentPages.map((page) => {
27
- const key = buildPageKey(functionPath, buildPageArgs(page, narrowedArgs));
28
- return resultsByKey.get(key);
29
- });
30
- pageResults.set(items);
31
- const { status: derivedStatus } = derivePaginationStatus(baseArgs === "skip", items);
32
- status.set(derivedStatus);
33
- };
34
- const migrateResultsForRebalance = (oldPages, newPages) => {
35
- const keyOf = (page) => buildPageKey(functionPath, buildPageArgs(page, narrowedArgs));
36
- for (const newPage of newPages) {
37
- const newKey = keyOf(newPage);
38
- if (resultsByKey.has(newKey)) {
39
- continue;
40
- }
41
- const donor = oldPages.find((op) => op.lower === newPage.lower);
42
- if (donor) {
43
- const carried = resultsByKey.get(keyOf(donor));
44
- if (carried) {
45
- resultsByKey.set(newKey, carried);
46
- }
47
- }
48
- }
49
- };
50
- const syncSubscriptions = (currentPages) => {
51
- const wantedKeys = /* @__PURE__ */ new Set();
52
- for (const page of currentPages) {
53
- wantedKeys.add(buildPageKey(functionPath, buildPageArgs(page, narrowedArgs)));
54
- }
55
- for (const [originalKey, entry] of activeSubs) {
56
- if (!wantedKeys.has(entry.currentKey)) {
57
- entry.unsub();
58
- activeSubs.delete(originalKey);
59
- resultsByKey.delete(entry.currentKey);
60
- }
61
- }
62
- const coveredKeys = new Set([...activeSubs.values()].map((subEntry) => subEntry.currentKey));
63
- for (const page of currentPages) {
64
- const pageArgs = buildPageArgs(page, narrowedArgs);
65
- const key = buildPageKey(functionPath, pageArgs);
66
- if (coveredKeys.has(key)) {
67
- continue;
68
- }
69
- const entry = {
70
- currentKey: key,
71
- unsub: void 0
72
- };
73
- pendingPageKeys.add(key);
74
- const unsub = client.subscribe(
75
- reference,
76
- pageArgs,
77
- (value) => {
78
- resultsByKey.set(entry.currentKey, value);
79
- pendingPageKeys.delete(entry.currentKey);
80
- doRebuildPageResults();
81
- if (pendingPageKeys.size === 0) {
82
- const latestPages = pages();
83
- const next = rebalance(latestPages, pageResults());
84
- if (next) {
85
- migrateResultsForRebalance(latestPages, next);
86
- pages.set(next);
87
- syncSubscriptions(next);
88
- doRebuildPageResults();
89
- }
90
- }
91
- },
92
- {
93
- onError: () => {
94
- pendingPageKeys.delete(entry.currentKey);
95
- doRebuildPageResults();
96
- },
97
- shardKey
98
- }
99
- );
100
- entry.unsub = unsub;
101
- activeSubs.set(key, entry);
102
- coveredKeys.add(key);
103
- }
104
- };
105
- if (baseArgs !== "skip") {
106
- syncSubscriptions(pages());
107
- }
108
- doRebuildPageResults();
109
- destroyRef.onDestroy(() => {
110
- for (const entry of activeSubs.values()) {
111
- entry.unsub();
112
- }
113
- activeSubs.clear();
114
- resultsByKey.clear();
115
- });
116
- const loadMore = (numberItems) => {
117
- if (baseArgs === "skip") {
118
- return;
119
- }
120
- const { nextCursor, status: currentStatus } = derivePaginationStatus(false, pageResults());
121
- if (currentStatus !== "CanLoadMore") {
122
- return;
123
- }
124
- const next = applyLoadMore(pages(), nextCursor, numberItems);
125
- if (!next) {
126
- return;
127
- }
128
- const oldTail = pages().at(-1);
129
- const newPinnedPage = next.at(-2);
130
- if (oldTail && newPinnedPage) {
131
- const oldKey = buildPageKey(functionPath, buildPageArgs(oldTail, narrowedArgs));
132
- const newKey = buildPageKey(functionPath, buildPageArgs(newPinnedPage, narrowedArgs));
133
- const entry = activeSubs.get(oldKey);
134
- if (entry && oldKey !== newKey) {
135
- const carried = resultsByKey.get(oldKey);
136
- if (carried) {
137
- resultsByKey.set(newKey, carried);
138
- }
139
- entry.unsub();
140
- activeSubs.delete(oldKey);
141
- resultsByKey.delete(oldKey);
142
- }
143
- }
144
- pages.set(next);
145
- syncSubscriptions(pages());
146
- doRebuildPageResults();
147
- };
148
- return { loadMore, pageResults, status };
149
- };
150
- const paginatedQuery = (reference, args, options) => {
151
- const core = usePaginatedCore(reference, args, options);
152
- const results = computed(() => {
153
- const items = [];
154
- for (const result of core.pageResults()) {
155
- if (result) {
156
- items.push(...result.page);
157
- }
158
- }
159
- return items;
160
- });
161
- const isLoading = computed(() => {
162
- const statusValue = core.status();
163
- return statusValue === "LoadingFirstPage" || statusValue === "LoadingMore";
164
- });
165
- return {
166
- isLoading,
167
- loadMore: core.loadMore,
168
- results,
169
- status: core.status
170
- };
171
- };
172
- const infiniteQuery = (reference, args, options) => {
173
- const { initialNumItems } = options;
174
- const core = usePaginatedCore(reference, args, options);
175
- const pages = computed(() => {
176
- const resultArrays = [];
177
- for (const page of core.pageResults()) {
178
- if (page) {
179
- resultArrays.push(page.page);
180
- }
181
- }
182
- return resultArrays;
183
- });
184
- const isLoading = computed(() => core.status() === "LoadingFirstPage");
185
- const hasNextPage = computed(() => core.status() === "CanLoadMore");
186
- const isFetchingNextPage = computed(() => core.status() === "LoadingMore");
187
- const fetchNextPage = (numberItems) => {
188
- core.loadMore(numberItems ?? initialNumItems);
189
- };
190
- return {
191
- fetchNextPage,
192
- hasNextPage,
193
- isFetchingNextPage,
194
- isLoading,
195
- pages,
196
- status: core.status
197
- };
198
- };
199
-
200
- export { infiniteQuery, paginatedQuery };
@@ -1,28 +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
-
5
- const liveQuery = (reference, args, options = {}) => {
6
- const client = resolveLunoraClient(options.client);
7
- const destroyRef = options.destroyRef ?? inject(DestroyRef);
8
- const value = signal(void 0);
9
- const unsubscribe = createQuerySubscription(
10
- client,
11
- reference,
12
- args,
13
- {
14
- onData: (next) => {
15
- value.set(next);
16
- },
17
- onError: options.onError,
18
- onReset: () => {
19
- value.set(void 0);
20
- }
21
- },
22
- { shardKey: options.shardKey }
23
- );
24
- destroyRef.onDestroy(unsubscribe);
25
- return value.asReadonly();
26
- };
27
-
28
- 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,59 +0,0 @@
1
- import { inject, DestroyRef, signal } from '@angular/core';
2
- import { resolveLunoraClient } from './LUNORA_CLIENT-DHUfNu9x.mjs';
3
-
4
- const makeSessionId = () => crypto.randomUUID();
5
- const DEFAULT_INTERVAL_MS = 1e4;
6
- const presence = (roomId, options) => {
7
- const client = resolveLunoraClient(options.client);
8
- const destroyRef = options.destroyRef ?? inject(DestroyRef);
9
- const { heartbeat, listPresent, shardKey } = options;
10
- const intervalMs = options.intervalMs ?? DEFAULT_INTERVAL_MS;
11
- const sessionId = options.sessionId ?? makeSessionId();
12
- const present = signal(void 0);
13
- if (!Number.isFinite(intervalMs) || intervalMs <= 0) {
14
- throw new RangeError(`presence intervalMs must be a positive number, got ${String(intervalMs)}`);
15
- }
16
- let latestData = options.data;
17
- const releaseConnectionContext = client.acquireConnectionContext({ roomId, sessionId }, { shardKey });
18
- const sendHeartbeat = () => {
19
- const args = { roomId, sessionId };
20
- if (latestData !== void 0) {
21
- args.data = latestData;
22
- }
23
- client.mutation(heartbeat, args, { shardKey }).catch(() => void 0);
24
- };
25
- const setData = (next) => {
26
- latestData = next;
27
- sendHeartbeat();
28
- };
29
- sendHeartbeat();
30
- const intervalHandle = setInterval(sendHeartbeat, intervalMs);
31
- const onVisible = () => {
32
- if (typeof document !== "undefined" && document.visibilityState === "visible") {
33
- sendHeartbeat();
34
- }
35
- };
36
- if (typeof document !== "undefined") {
37
- document.addEventListener("visibilitychange", onVisible);
38
- }
39
- const listArgs = { roomId };
40
- const unsubscribe = client.subscribe(
41
- listPresent,
42
- listArgs,
43
- (value) => {
44
- present.set(value);
45
- },
46
- { shardKey }
47
- );
48
- destroyRef.onDestroy(() => {
49
- clearInterval(intervalHandle);
50
- if (typeof document !== "undefined") {
51
- document.removeEventListener("visibilitychange", onVisible);
52
- }
53
- releaseConnectionContext();
54
- unsubscribe();
55
- });
56
- return { present: present.asReadonly(), sessionId, setData };
57
- };
58
-
59
- export { presence };
@@ -1,60 +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 epoch = signal(0);
10
- const computeStatus = () => evaluate(config, value, { consume: false, count: 1, now: now(), reserve: false }).status;
11
- const status = signal(computeStatus());
12
- const bump = () => {
13
- epoch.update((v) => v + 1);
14
- status.set(computeStatus());
15
- };
16
- let intervalHandle;
17
- const stopInterval = () => {
18
- if (intervalHandle !== void 0) {
19
- clearInterval(intervalHandle);
20
- intervalHandle = void 0;
21
- }
22
- };
23
- const startIntervalIfThrottled = () => {
24
- if (status().ok || intervalHandle !== void 0) {
25
- return;
26
- }
27
- intervalHandle = setInterval(() => {
28
- bump();
29
- if (status().ok) {
30
- stopInterval();
31
- }
32
- }, tickMs);
33
- };
34
- startIntervalIfThrottled();
35
- destroyRef.onDestroy(() => {
36
- stopInterval();
37
- });
38
- return {
39
- check: (count = 1) => evaluate(config, value, { consume: false, count, now: now(), reserve: false }).status.ok,
40
- consume: (count = 1) => {
41
- const result = evaluate(config, value, { consume: true, count, now: now(), reserve: false });
42
- if (result.value !== void 0) {
43
- value = result.value;
44
- }
45
- bump();
46
- startIntervalIfThrottled();
47
- return result.status;
48
- },
49
- disabled: computed(() => !status().ok),
50
- ok: computed(() => status().ok),
51
- reset: () => {
52
- value = void 0;
53
- stopInterval();
54
- bump();
55
- },
56
- retryAfter: computed(() => status().retryAfter)
57
- };
58
- };
59
-
60
- export { rateLimit };
@@ -1,37 +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
-
5
- const subscription = (reference, args, options = {}) => {
6
- const client = resolveLunoraClient(options.client);
7
- const destroyRef = options.destroyRef ?? inject(DestroyRef);
8
- const data = signal(void 0);
9
- const error = signal(void 0);
10
- if (args !== "skip") {
11
- const userOnError = options.onError;
12
- const unsubscribe = createQuerySubscription(
13
- client,
14
- reference,
15
- args,
16
- {
17
- onData: (next) => {
18
- data.set(next);
19
- error.set(void 0);
20
- },
21
- onError: (error_) => {
22
- error.set(error_);
23
- data.set(void 0);
24
- userOnError?.(error_);
25
- },
26
- onReset: () => {
27
- data.set(void 0);
28
- }
29
- },
30
- { shardKey: options.shardKey }
31
- );
32
- destroyRef.onDestroy(unsubscribe);
33
- }
34
- return { data: data.asReadonly(), error: error.asReadonly() };
35
- };
36
-
37
- export { subscription };