@arcote.tech/arc 0.3.1 → 0.3.2

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,23 @@
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
+ */
7
+ import type { QueryWire } from "../adapters/query-wire";
8
+ import type { ArcContextAny } from "../context/context";
9
+ import type { LiveQueryResult, QueryContext } from "../model/live-query/live-query";
10
+ import type { Model } from "../model/model";
11
+ import type { StreamingQueryCache } from "./streaming-query-cache";
12
+ export interface StreamingLiveQueryOptions {
13
+ queryWire: QueryWire;
14
+ cache: StreamingQueryCache;
15
+ authToken?: string | null;
16
+ }
17
+ /**
18
+ * Create a streaming live query
19
+ *
20
+ * Opens SSE stream to server, populates cache, and reacts to changes.
21
+ */
22
+ 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>;
23
+ //# sourceMappingURL=streaming-live-query.d.ts.map
@@ -0,0 +1,57 @@
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
+ */
13
+ import type { ArcEventAny } from "../context-element/event/event";
14
+ import type { ArcEventInstance } from "../context-element/event/instance";
15
+ import type { ArcViewAny } from "../context-element/view/view";
16
+ import type { FindOptions } from "../data-storage/find-options";
17
+ export type CacheChangeListener = () => void;
18
+ export interface StreamingQueryCacheStore<Item extends {
19
+ _id: string;
20
+ }> {
21
+ find(options?: FindOptions<Item>): Item[];
22
+ findOne(where?: Record<string, any>): Item | undefined;
23
+ subscribe(listener: CacheChangeListener): () => void;
24
+ }
25
+ /**
26
+ * StreamingQueryCache - Main cache class
27
+ */
28
+ export declare class StreamingQueryCache {
29
+ private stores;
30
+ private views;
31
+ /**
32
+ * Register views that this cache will handle
33
+ */
34
+ registerViews(views: ArcViewAny[]): void;
35
+ /**
36
+ * Get a store for a specific view
37
+ */
38
+ getStore<Item extends {
39
+ _id: string;
40
+ }>(viewName: string): StreamingQueryCacheStore<Item>;
41
+ /**
42
+ * Set initial data for a view (from SSE stream)
43
+ */
44
+ setViewData<Item extends {
45
+ _id: string;
46
+ }>(viewName: string, items: Item[]): void;
47
+ /**
48
+ * Apply an event to update view state
49
+ * Runs view handlers to update the cache
50
+ */
51
+ applyEvent(event: ArcEventInstance<ArcEventAny>): Promise<void>;
52
+ /**
53
+ * Clear all cached data
54
+ */
55
+ clear(): void;
56
+ }
57
+ //# 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.2",
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",