@arcote.tech/arc 0.3.1 → 0.3.3

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.
@@ -16,7 +16,8 @@ export type LiveQueryResult<T> = {
16
16
  *
17
17
  * Creates a live query that watches views and calls a callback when data changes.
18
18
  * Uses view's queryContext directly (applies protectBy restrictions).
19
- * Uses dataStorage.observeQueries() for reactivity.
19
+ * Uses dataStorage.observeQueries() for reactivity when available.
20
+ * Falls back to streaming mode (SSE) when no local storage.
20
21
  *
21
22
  * @example
22
23
  * ```typescript
@@ -2,12 +2,17 @@ import type { AuthAdapter } from "../adapters/auth-adapter";
2
2
  import type { CommandWire } from "../adapters/command-wire";
3
3
  import type { EventPublisher } from "../adapters/event-publisher";
4
4
  import type { EventWire } from "../adapters/event-wire";
5
+ import type { QueryWire } from "../adapters/query-wire";
5
6
  import type { DataStorage } from "../data-storage";
7
+ import type { StreamingQueryCache } from "../streaming";
6
8
  export type ModelAdapters = {
7
9
  dataStorage?: DataStorage;
8
10
  commandWire?: CommandWire;
9
11
  eventPublisher?: EventPublisher;
10
12
  eventWire?: EventWire;
11
13
  authAdapter?: AuthAdapter;
14
+ queryWire?: QueryWire;
15
+ /** Streaming mode cache - used when no local dataStorage */
16
+ streamingCache?: StreamingQueryCache;
12
17
  };
13
18
  //# sourceMappingURL=model-adapters.d.ts.map
@@ -0,0 +1,6 @@
1
+ export { StreamingQueryCache } from "./streaming-query-cache";
2
+ export type { CacheChangeListener, StreamingQueryCacheStore, } from "./streaming-query-cache";
3
+ export { StreamingEventPublisher } from "./streaming-event-publisher";
4
+ export { streamingLiveQuery } from "./streaming-live-query";
5
+ export type { StreamingLiveQueryOptions } from "./streaming-live-query";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,51 @@
1
+ /**
2
+ * StreamingEventPublisher - Event publisher for streaming mode (no local database)
3
+ *
4
+ * When events are emitted:
5
+ * 1. Apply to local cache (optimistic update)
6
+ * 2. Send to server via EventWire
7
+ *
8
+ * This enables instant UI updates while syncing with server.
9
+ */
10
+ import type { EventPublisher, EventWithSyncStatus } from "../adapters/event-publisher";
11
+ import type { EventWire } from "../adapters/event-wire";
12
+ import type { ArcEventAny } from "../context-element/event/event";
13
+ import type { ArcEventInstance } from "../context-element/event/instance";
14
+ import type { ArcViewAny } from "../context-element/view/view";
15
+ import type { StreamingQueryCache } from "./streaming-query-cache";
16
+ /**
17
+ * StreamingEventPublisher
18
+ */
19
+ export declare class StreamingEventPublisher implements EventPublisher {
20
+ private readonly cache;
21
+ private readonly eventWire;
22
+ private views;
23
+ private subscribers;
24
+ constructor(cache: StreamingQueryCache, eventWire: EventWire);
25
+ /**
26
+ * Register views for event handling
27
+ */
28
+ registerViews(views: ArcViewAny[]): void;
29
+ /**
30
+ * Publish an event
31
+ * 1. Apply to local cache (optimistic)
32
+ * 2. Send to server
33
+ */
34
+ publish(event: ArcEventInstance<ArcEventAny>): Promise<void>;
35
+ /**
36
+ * Subscribe to events of a specific type
37
+ */
38
+ subscribe(eventType: string, callback: (event: ArcEventInstance<ArcEventAny>) => Promise<void> | void): () => void;
39
+ /**
40
+ * Mark events as synced - no-op in streaming mode
41
+ * (we don't track sync status locally)
42
+ */
43
+ markSynced(_eventIds: string[]): Promise<void>;
44
+ /**
45
+ * Get unsynced events - always empty in streaming mode
46
+ * (we send events immediately, don't queue them)
47
+ */
48
+ getUnsyncedEvents(_eventType?: string): Promise<EventWithSyncStatus[]>;
49
+ private notifySubscribers;
50
+ }
51
+ //# sourceMappingURL=streaming-event-publisher.d.ts.map
@@ -0,0 +1,25 @@
1
+ /**
2
+ * StreamingLiveQuery - Live query implementation for streaming mode
3
+ *
4
+ * Uses SSE stream to get initial data and updates from server.
5
+ * Uses StreamingQueryCache for local state and reactivity.
6
+ * Deduplicates SSE streams - multiple queries on same view share one stream.
7
+ */
8
+ import type { QueryWire } from "../adapters/query-wire";
9
+ import type { ArcContextAny } from "../context/context";
10
+ import type { LiveQueryResult, QueryContext } from "../model/live-query/live-query";
11
+ import type { Model } from "../model/model";
12
+ import type { StreamingQueryCache } from "./streaming-query-cache";
13
+ export interface StreamingLiveQueryOptions {
14
+ queryWire: QueryWire;
15
+ cache: StreamingQueryCache;
16
+ authToken?: string | null;
17
+ }
18
+ /**
19
+ * Create a streaming live query
20
+ *
21
+ * Opens SSE stream to server, populates cache, and reacts to changes.
22
+ * Reuses existing streams for the same view (deduplication via cache).
23
+ */
24
+ export declare function streamingLiveQuery<C extends ArcContextAny, TResult>(model: Model<C>, queryFn: (q: QueryContext<C>) => Promise<TResult>, callback: (data: TResult) => void, options: StreamingLiveQueryOptions): LiveQueryResult<TResult>;
25
+ //# sourceMappingURL=streaming-live-query.d.ts.map
@@ -0,0 +1,74 @@
1
+ /**
2
+ * StreamingQueryCache - Lightweight in-memory cache for streaming mode
3
+ *
4
+ * Used when client connects without local database (no SQLite/IndexedDB).
5
+ * Holds view state in memory, receives data from SSE, applies local events.
6
+ *
7
+ * Features:
8
+ * - Stores view data in memory (Map-based)
9
+ * - Supports reactive queries with listeners
10
+ * - Applies view handlers for local event emission
11
+ * - Receives updates from SSE stream
12
+ * - Deduplicates SSE streams (one stream per view)
13
+ */
14
+ import type { ArcEventAny } from "../context-element/event/event";
15
+ import type { ArcEventInstance } from "../context-element/event/instance";
16
+ import type { ArcViewAny } from "../context-element/view/view";
17
+ import type { FindOptions } from "../data-storage/find-options";
18
+ export type CacheChangeListener = () => void;
19
+ export interface StreamingQueryCacheStore<Item extends {
20
+ _id: string;
21
+ }> {
22
+ find(options?: FindOptions<Item>): Item[];
23
+ findOne(where?: Record<string, any>): Item | undefined;
24
+ subscribe(listener: CacheChangeListener): () => void;
25
+ }
26
+ /**
27
+ * StreamingQueryCache - Main cache class
28
+ */
29
+ export declare class StreamingQueryCache {
30
+ private stores;
31
+ private views;
32
+ private activeStreams;
33
+ /**
34
+ * Register views that this cache will handle
35
+ */
36
+ registerViews(views: ArcViewAny[]): void;
37
+ /**
38
+ * Get a store for a specific view
39
+ */
40
+ getStore<Item extends {
41
+ _id: string;
42
+ }>(viewName: string): StreamingQueryCacheStore<Item>;
43
+ /**
44
+ * Check if a stream is already active for a view
45
+ */
46
+ hasActiveStream(viewName: string): boolean;
47
+ /**
48
+ * Register an active stream for a view (increment ref count if exists)
49
+ * Returns a function to unregister when done
50
+ */
51
+ registerStream(viewName: string, createStream: () => {
52
+ unsubscribe: () => void;
53
+ }): () => void;
54
+ /**
55
+ * Unregister from a stream (decrement ref count, close if zero)
56
+ */
57
+ private unregisterStream;
58
+ /**
59
+ * Set initial data for a view (from SSE stream)
60
+ */
61
+ setViewData<Item extends {
62
+ _id: string;
63
+ }>(viewName: string, items: Item[]): void;
64
+ /**
65
+ * Apply an event to update view state
66
+ * Runs view handlers to update the cache
67
+ */
68
+ applyEvent(event: ArcEventInstance<ArcEventAny>): Promise<void>;
69
+ /**
70
+ * Clear all cached data and close all streams
71
+ */
72
+ clear(): void;
73
+ }
74
+ //# sourceMappingURL=streaming-query-cache.d.ts.map
@@ -21,10 +21,7 @@
21
21
  *
22
22
  * // Define protection on view (not on token!)
23
23
  * const tasks = view("tasks", taskId, taskSchema)
24
- * .protectBy(userToken, (params) => ({
25
- * read: { userId: params.userId },
26
- * write: { userId: params.userId },
27
- * }));
24
+ * .protectBy(userToken, (params) => ({ userId: params.userId }));
28
25
  *
29
26
  * // Create instance and use
30
27
  * const instance = userToken.create({ userId: "user_123" });
@@ -33,7 +30,7 @@
33
30
  * const securedStorage = secureDataStorage(dataStorage, instance, context);
34
31
  * ```
35
32
  */
36
- export { secureDataStorage, SecuredDataStorage, SecuredStoreState, } from "./secured-data-storage";
33
+ export { SecuredDataStorage, SecuredStoreState, secureDataStorage, } from "./secured-data-storage";
37
34
  export { ArcToken, token, type ArcTokenAny } from "./token";
38
35
  export { TokenCache, type TokenCacheOptions } from "./token-cache";
39
36
  export type { ArcTokenData, TokenParams, TokenRule, TokenRuleContext, TokenRules, } from "./token-data";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@arcote.tech/arc",
3
3
  "type": "module",
4
- "version": "0.3.1",
4
+ "version": "0.3.3",
5
5
  "private": false,
6
6
  "author": "Przemysław Krasiński [arcote.tech]",
7
7
  "description": "Arc framework core rewrite with improved event emission and type safety",