@arcote.tech/arc 0.1.11 → 0.3.0
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/adapters/auth-adapter.d.ts +47 -0
- package/dist/adapters/command-wire.d.ts +28 -0
- package/dist/adapters/event-publisher.d.ts +106 -0
- package/dist/adapters/event-wire.d.ts +79 -0
- package/dist/adapters/index.d.ts +18 -0
- package/dist/adapters/wire.d.ts +20 -0
- package/dist/context/context.d.ts +49 -52
- package/dist/context/index.d.ts +1 -9
- package/dist/context-element/command/command-context.d.ts +71 -0
- package/dist/context-element/command/command-data.d.ts +33 -0
- package/dist/context-element/command/command-handler.d.ts +6 -0
- package/dist/context-element/command/command.d.ts +198 -0
- package/dist/context-element/command/index.d.ts +6 -0
- package/dist/context-element/context-element.d.ts +75 -0
- package/dist/context-element/event/event-data.d.ts +35 -0
- package/dist/context-element/event/event.d.ts +158 -0
- package/dist/context-element/event/index.d.ts +5 -0
- package/dist/context-element/event/instance.d.ts +26 -0
- package/dist/context-element/index.d.ts +10 -0
- package/dist/context-element/view/index.d.ts +5 -0
- package/dist/context-element/view/view-context.d.ts +51 -0
- package/dist/context-element/view/view-data.d.ts +40 -0
- package/dist/context-element/view/view.d.ts +194 -0
- package/dist/data-storage/data-storage-forked.d.ts +1 -1
- package/dist/data-storage/data-storage-master.d.ts +7 -10
- package/dist/data-storage/data-storage-observable.d.ts +61 -0
- package/dist/data-storage/data-storage.abstract.d.ts +1 -1
- package/dist/{db/interface.d.ts → data-storage/database-adapter.d.ts} +8 -3
- package/dist/{database → data-storage}/database-store.d.ts +45 -0
- package/dist/data-storage/{types.d.ts → find-options.d.ts} +1 -1
- package/dist/data-storage/index.d.ts +6 -2
- package/dist/{db/postgresAdapter.d.ts → data-storage/postgresql-adapter.d.ts} +7 -33
- package/dist/data-storage/query-result-resolver.d.ts +18 -0
- package/dist/data-storage/query-result-resolver.test.d.ts +2 -0
- package/dist/{db/sqliteAdapter.d.ts → data-storage/sqlite-adapter.d.ts} +5 -31
- package/dist/data-storage/store-state-fork.d.ts +1 -1
- package/dist/data-storage/store-state-master.d.ts +6 -2
- package/dist/data-storage/store-state.abstract.d.ts +1 -1
- package/dist/elements/abstract.d.ts +1 -1
- package/dist/elements/any.d.ts +1 -1
- package/dist/elements/array.d.ts +5 -5
- package/dist/elements/blob.d.ts +1 -1
- package/dist/elements/boolean.d.ts +1 -1
- package/dist/elements/branded.d.ts +5 -5
- package/dist/elements/date.d.ts +1 -1
- package/dist/elements/default.d.ts +5 -5
- package/dist/elements/file.d.ts +1 -1
- package/dist/elements/id.d.ts +3 -3
- package/dist/elements/index.d.ts +1 -0
- package/dist/elements/number.d.ts +1 -1
- package/dist/elements/object.d.ts +11 -10
- package/dist/elements/optional.d.ts +5 -5
- package/dist/elements/or.d.ts +5 -5
- package/dist/elements/record.d.ts +3 -3
- package/dist/elements/string-enum.d.ts +1 -1
- package/dist/elements/string.d.ts +1 -1
- package/dist/index.d.ts +8 -7
- package/dist/index.js +2355 -3371
- package/dist/model/index.d.ts +2 -0
- package/dist/model/live-query/index.d.ts +2 -0
- package/dist/model/live-query/live-query.d.ts +31 -0
- package/dist/model/live-query/query-cache.d.ts +60 -0
- package/dist/model/model-adapters.d.ts +13 -0
- package/dist/model/model.d.ts +17 -66
- package/dist/model/mutation-executor/index.d.ts +2 -0
- package/dist/model/mutation-executor/mutation-executor.d.ts +29 -0
- package/dist/token/index.d.ts +41 -0
- package/dist/token/secured-data-storage.d.ts +125 -0
- package/dist/token/token-cache.d.ts +100 -0
- package/dist/token/token-data.d.ts +38 -0
- package/dist/token/token-instance.d.ts +71 -0
- package/dist/token/token.d.ts +127 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/types/add-question-marks.d.ts +9 -0
- package/dist/utils/types/first-argument.d.ts +5 -0
- package/dist/utils/types/get-type.d.ts +13 -0
- package/dist/utils/types/index.d.ts +6 -0
- package/dist/utils/types/merge.d.ts +7 -0
- package/dist/utils/types/object-util.d.ts +6 -0
- package/dist/utils/types/simplify.d.ts +7 -0
- package/package.json +10 -6
- package/dist/command/command.d.ts +0 -45
- package/dist/command/index.d.ts +0 -2
- package/dist/context/commands.d.ts +0 -12
- package/dist/context/element.d.ts +0 -80
- package/dist/context/event.d.ts +0 -44
- package/dist/context/query-builder-context.d.ts +0 -15
- package/dist/context/query-builders.d.ts +0 -17
- package/dist/context/query-cache.d.ts +0 -9
- package/dist/context/query.d.ts +0 -12
- package/dist/context/reactive-query.d.ts +0 -23
- package/dist/context/serializable-query.d.ts +0 -11
- package/dist/database/database-mappers.d.ts +0 -39
- package/dist/database/index.d.ts +0 -3
- package/dist/db/index.d.ts +0 -4
- package/dist/listener/index.d.ts +0 -2
- package/dist/listener/listener.d.ts +0 -23
- package/dist/route/index.d.ts +0 -2
- package/dist/route/route.d.ts +0 -35
- package/dist/rtc/client.d.ts +0 -3
- package/dist/rtc/index.d.ts +0 -4
- package/dist/rtc/messages.d.ts +0 -20
- package/dist/rtc/rtc.d.ts +0 -11
- package/dist/state/index.d.ts +0 -2
- package/dist/state/query-builder.d.ts +0 -2
- package/dist/state/query.d.ts +0 -2
- package/dist/state/state.d.ts +0 -2
- package/dist/telemetry/context.d.ts +0 -65
- package/dist/telemetry/index.d.ts +0 -47
- package/dist/telemetry/interfaces.d.ts +0 -84
- package/dist/telemetry/logger.d.ts +0 -67
- package/dist/telemetry/no-op.d.ts +0 -54
- package/dist/telemetry/tracer.d.ts +0 -85
- package/dist/tests/context/context.test.d.ts +0 -2
- package/dist/tests/pipe.d.ts +0 -2
- package/dist/tests/query/advance-query.test.d.ts +0 -2
- package/dist/tests/query/collection-all.test.d.ts +0 -2
- package/dist/tests/utils/expect-not-false.d.ts +0 -2
- package/dist/tests/utils/sqlite-adapter.d.ts +0 -3
- package/dist/tests/utils/test-model.d.ts +0 -25
- package/dist/tests/validations/array.test.d.ts +0 -2
- package/dist/tests/validations/date.test.d.ts +0 -2
- package/dist/tests/validations/number.test.d.ts +0 -2
- package/dist/tests/validations/object.test.d.ts +0 -2
- package/dist/tests/validations/record.test.d.ts +0 -2
- package/dist/tests/validations/string-enum.test.d.ts +0 -2
- package/dist/tests/validations/string.test.d.ts +0 -2
- package/dist/utils.d.ts +0 -56
- package/dist/view/index.d.ts +0 -6
- package/dist/view/queries/abstract-view-query.d.ts +0 -19
- package/dist/view/queries/find-one.d.ts +0 -13
- package/dist/view/queries/find.d.ts +0 -21
- package/dist/view/queries/index.d.ts +0 -3
- package/dist/view/query-builders/find-one.d.ts +0 -14
- package/dist/view/query-builders/find.d.ts +0 -14
- package/dist/view/query-builders/index.d.ts +0 -2
- package/dist/view/record.d.ts +0 -4
- package/dist/view/static-view.d.ts +0 -43
- package/dist/view/view.d.ts +0 -68
- /package/dist/{database → data-storage}/schema-extraction.d.ts +0 -0
- /package/dist/{data-storage → utils}/deep-merge.d.ts +0 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AuthAdapter - Manages authentication token for the model
|
|
3
|
+
*
|
|
4
|
+
* Stores the current JWT token and provides decoded params.
|
|
5
|
+
* On client: decodes token without signature verification
|
|
6
|
+
* On server: token is verified before being set
|
|
7
|
+
*/
|
|
8
|
+
export interface DecodedToken {
|
|
9
|
+
tokenName: string;
|
|
10
|
+
params: Record<string, any>;
|
|
11
|
+
iat?: number;
|
|
12
|
+
exp?: number;
|
|
13
|
+
}
|
|
14
|
+
export declare class AuthAdapter {
|
|
15
|
+
private token;
|
|
16
|
+
private decoded;
|
|
17
|
+
/**
|
|
18
|
+
* Set the JWT token
|
|
19
|
+
* Decodes the payload (without signature verification on client)
|
|
20
|
+
*/
|
|
21
|
+
setToken(token: string | null): void;
|
|
22
|
+
/**
|
|
23
|
+
* Get the raw JWT token string
|
|
24
|
+
*/
|
|
25
|
+
getToken(): string | null;
|
|
26
|
+
/**
|
|
27
|
+
* Get decoded token data
|
|
28
|
+
*/
|
|
29
|
+
getDecoded(): DecodedToken | null;
|
|
30
|
+
/**
|
|
31
|
+
* Get token params (e.g., { userId, projectId })
|
|
32
|
+
*/
|
|
33
|
+
getParams(): Record<string, any> | null;
|
|
34
|
+
/**
|
|
35
|
+
* Get token name (e.g., "user")
|
|
36
|
+
*/
|
|
37
|
+
getTokenName(): string | null;
|
|
38
|
+
/**
|
|
39
|
+
* Check if token is set and valid
|
|
40
|
+
*/
|
|
41
|
+
isAuthenticated(): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Check if token is expired
|
|
44
|
+
*/
|
|
45
|
+
isExpired(): boolean;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=auth-adapter.d.ts.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CommandWire - Wire adapter specialized for command execution
|
|
3
|
+
*
|
|
4
|
+
* Extends Wire to provide command-specific functionality:
|
|
5
|
+
* - Execute commands remotely on the server
|
|
6
|
+
* - Handle command request/response serialization
|
|
7
|
+
*/
|
|
8
|
+
import { Wire } from "./wire";
|
|
9
|
+
export declare class CommandWire extends Wire {
|
|
10
|
+
constructor(baseUrl: string);
|
|
11
|
+
/**
|
|
12
|
+
* Execute a command on the remote server
|
|
13
|
+
*
|
|
14
|
+
* @param name - Command name
|
|
15
|
+
* @param params - Command parameters
|
|
16
|
+
* @returns Command result from server
|
|
17
|
+
*/
|
|
18
|
+
executeCommand(name: string, params: any): Promise<any>;
|
|
19
|
+
/**
|
|
20
|
+
* Register a command handler on the server side
|
|
21
|
+
* Called during init() for server environment
|
|
22
|
+
*
|
|
23
|
+
* @param name - Command name
|
|
24
|
+
* @param handler - Handler function to execute command
|
|
25
|
+
*/
|
|
26
|
+
registerCommandHandler?(name: string, handler: (params: any) => Promise<any>): void;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=command-wire.d.ts.map
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EventPublisher - Adapter for publishing and synchronizing events
|
|
3
|
+
*
|
|
4
|
+
* Responsibilities:
|
|
5
|
+
* 1. Apply events to local views (via dataStorage)
|
|
6
|
+
* 2. Store events locally with sync status
|
|
7
|
+
* 3. Provide API for synchronization (implementation done elsewhere)
|
|
8
|
+
*
|
|
9
|
+
* All events are stored in shared tables:
|
|
10
|
+
* - events - single table for ALL events (distinguished by `type` field)
|
|
11
|
+
* - event_tags - tags with FK to events
|
|
12
|
+
* - event_sync_status - sync tracking (separate from events)
|
|
13
|
+
*/
|
|
14
|
+
import type { ArcEventAny } from "../context-element/event";
|
|
15
|
+
import type { ArcEventInstance } from "../context-element/event/instance";
|
|
16
|
+
import type { ArcViewAny } from "../context-element/view/view";
|
|
17
|
+
import type { DataStorage } from "../data-storage";
|
|
18
|
+
/** Shared table names for all events */
|
|
19
|
+
export declare const EVENT_TABLES: {
|
|
20
|
+
readonly events: "events";
|
|
21
|
+
readonly tags: "event_tags";
|
|
22
|
+
readonly syncStatus: "event_sync_status";
|
|
23
|
+
};
|
|
24
|
+
/** Stored event record in the events table */
|
|
25
|
+
export interface StoredEvent {
|
|
26
|
+
_id: string;
|
|
27
|
+
type: string;
|
|
28
|
+
payload: string;
|
|
29
|
+
createdAt: string;
|
|
30
|
+
}
|
|
31
|
+
/** Event tag record in the event_tags table */
|
|
32
|
+
export interface StoredEventTag {
|
|
33
|
+
_id: string;
|
|
34
|
+
eventId: string;
|
|
35
|
+
tagKey: string;
|
|
36
|
+
tagValue: string;
|
|
37
|
+
}
|
|
38
|
+
/** Sync status record in the event_sync_status table */
|
|
39
|
+
export interface StoredEventSyncStatus {
|
|
40
|
+
_id: string;
|
|
41
|
+
eventId: string;
|
|
42
|
+
synced: boolean;
|
|
43
|
+
timestamp: number;
|
|
44
|
+
retryCount: number;
|
|
45
|
+
}
|
|
46
|
+
/** Combined event with sync status for API consumers */
|
|
47
|
+
export interface EventWithSyncStatus {
|
|
48
|
+
event: StoredEvent;
|
|
49
|
+
syncStatus: StoredEventSyncStatus;
|
|
50
|
+
tags: StoredEventTag[];
|
|
51
|
+
}
|
|
52
|
+
export interface EventPublisher {
|
|
53
|
+
/**
|
|
54
|
+
* Publish an event locally and mark for sync
|
|
55
|
+
*
|
|
56
|
+
* @param event - Event instance to publish
|
|
57
|
+
*/
|
|
58
|
+
publish(event: ArcEventInstance<ArcEventAny>): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Mark events as synced after successful server sync
|
|
61
|
+
*
|
|
62
|
+
* @param eventIds - Array of event IDs that were synced
|
|
63
|
+
*/
|
|
64
|
+
markSynced(eventIds: string[]): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Get all unsynced events, optionally filtered by event type
|
|
67
|
+
*
|
|
68
|
+
* @param eventType - Optional event type name to filter by
|
|
69
|
+
* @returns Array of unsynced events with their sync status
|
|
70
|
+
*/
|
|
71
|
+
getUnsyncedEvents(eventType?: string): Promise<EventWithSyncStatus[]>;
|
|
72
|
+
/**
|
|
73
|
+
* Register views that should be updated when events are published
|
|
74
|
+
*
|
|
75
|
+
* @param views - Array of views to register
|
|
76
|
+
*/
|
|
77
|
+
registerViews(views: ArcViewAny[]): void;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Local EventPublisher implementation
|
|
81
|
+
* Stores all events in shared tables, distinguished by `type` field
|
|
82
|
+
*/
|
|
83
|
+
export declare class LocalEventPublisher implements EventPublisher {
|
|
84
|
+
private readonly dataStorage;
|
|
85
|
+
private views;
|
|
86
|
+
private syncCallback?;
|
|
87
|
+
constructor(dataStorage: DataStorage);
|
|
88
|
+
/**
|
|
89
|
+
* Set a callback to be called after each event is published
|
|
90
|
+
* Used for syncing events to the host
|
|
91
|
+
*/
|
|
92
|
+
onPublish(callback: (event: ArcEventInstance<ArcEventAny>) => void): void;
|
|
93
|
+
/**
|
|
94
|
+
* Register views that should be updated when events are published
|
|
95
|
+
*/
|
|
96
|
+
registerViews(views: ArcViewAny[]): void;
|
|
97
|
+
publish(event: ArcEventInstance<ArcEventAny>): Promise<void>;
|
|
98
|
+
markSynced(eventIds: string[]): Promise<void>;
|
|
99
|
+
getUnsyncedEvents(eventType?: string): Promise<EventWithSyncStatus[]>;
|
|
100
|
+
/**
|
|
101
|
+
* Collect view changes without committing them
|
|
102
|
+
* Returns changes that can be batched with other changes
|
|
103
|
+
*/
|
|
104
|
+
private collectViewChanges;
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=event-publisher.d.ts.map
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EventWire - WebSocket adapter for bidirectional event sync
|
|
3
|
+
*
|
|
4
|
+
* Connects to the host via WebSocket and:
|
|
5
|
+
* - Sends locally created events to the host
|
|
6
|
+
* - Receives events from the host (from other clients)
|
|
7
|
+
* - Handles reconnection and sync state
|
|
8
|
+
*/
|
|
9
|
+
export interface SyncableEvent {
|
|
10
|
+
localId: string;
|
|
11
|
+
type: string;
|
|
12
|
+
payload: any;
|
|
13
|
+
createdAt: string;
|
|
14
|
+
}
|
|
15
|
+
export interface ReceivedEvent {
|
|
16
|
+
localId: string;
|
|
17
|
+
hostId: string;
|
|
18
|
+
type: string;
|
|
19
|
+
payload: any;
|
|
20
|
+
createdAt: string;
|
|
21
|
+
clientId: string;
|
|
22
|
+
}
|
|
23
|
+
type EventWireState = "disconnected" | "connecting" | "connected";
|
|
24
|
+
export declare class EventWire {
|
|
25
|
+
private readonly baseUrl;
|
|
26
|
+
private ws;
|
|
27
|
+
private state;
|
|
28
|
+
private token;
|
|
29
|
+
private lastHostEventId;
|
|
30
|
+
private pendingEvents;
|
|
31
|
+
private onEventCallback?;
|
|
32
|
+
private onSyncedCallback?;
|
|
33
|
+
private reconnectTimeout?;
|
|
34
|
+
private syncRequested;
|
|
35
|
+
constructor(baseUrl: string);
|
|
36
|
+
/**
|
|
37
|
+
* Set authentication token
|
|
38
|
+
*/
|
|
39
|
+
setAuthToken(token: string | null): void;
|
|
40
|
+
/**
|
|
41
|
+
* Set the last synced host event ID
|
|
42
|
+
* Used to restore sync state after page refresh
|
|
43
|
+
*/
|
|
44
|
+
setLastHostEventId(id: string | null): void;
|
|
45
|
+
/**
|
|
46
|
+
* Get the last synced host event ID
|
|
47
|
+
*/
|
|
48
|
+
getLastHostEventId(): string | null;
|
|
49
|
+
/**
|
|
50
|
+
* Connect to the host WebSocket
|
|
51
|
+
*/
|
|
52
|
+
connect(): void;
|
|
53
|
+
/**
|
|
54
|
+
* Disconnect from the host
|
|
55
|
+
*/
|
|
56
|
+
disconnect(): void;
|
|
57
|
+
/**
|
|
58
|
+
* Send events to the host
|
|
59
|
+
*/
|
|
60
|
+
syncEvents(events: SyncableEvent[]): void;
|
|
61
|
+
/**
|
|
62
|
+
* Set callback for receiving events from host
|
|
63
|
+
*/
|
|
64
|
+
onEvent(callback: (event: ReceivedEvent) => void): void;
|
|
65
|
+
/**
|
|
66
|
+
* Set callback for when events are confirmed synced
|
|
67
|
+
*/
|
|
68
|
+
onSynced(callback: (localIds: string[]) => void): void;
|
|
69
|
+
/**
|
|
70
|
+
* Get current connection state
|
|
71
|
+
*/
|
|
72
|
+
getState(): EventWireState;
|
|
73
|
+
private handleMessage;
|
|
74
|
+
private requestSync;
|
|
75
|
+
private flushPendingEvents;
|
|
76
|
+
private scheduleReconnect;
|
|
77
|
+
}
|
|
78
|
+
export {};
|
|
79
|
+
//# sourceMappingURL=event-wire.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapters - External dependencies for Arc Framework
|
|
3
|
+
*
|
|
4
|
+
* Adapters provide pluggable implementations for:
|
|
5
|
+
* - Wire: Client-server communication
|
|
6
|
+
* - CommandWire: Command execution over network
|
|
7
|
+
* - EventPublisher: Event persistence and synchronization
|
|
8
|
+
* - DataStorage: Data persistence (defined elsewhere)
|
|
9
|
+
*/
|
|
10
|
+
export { AuthAdapter } from "./auth-adapter";
|
|
11
|
+
export type { DecodedToken } from "./auth-adapter";
|
|
12
|
+
export { CommandWire } from "./command-wire";
|
|
13
|
+
export { EventWire } from "./event-wire";
|
|
14
|
+
export type { ReceivedEvent, SyncableEvent } from "./event-wire";
|
|
15
|
+
export { Wire } from "./wire";
|
|
16
|
+
export { EVENT_TABLES, LocalEventPublisher } from "./event-publisher";
|
|
17
|
+
export type { EventPublisher, EventWithSyncStatus, StoredEvent, StoredEventSyncStatus, StoredEventTag, } from "./event-publisher";
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire - Base abstraction for client-server communication
|
|
3
|
+
*
|
|
4
|
+
* Handles JWT token management and provides fetch abstraction
|
|
5
|
+
* for making authenticated requests to the server.
|
|
6
|
+
*/
|
|
7
|
+
export declare class Wire {
|
|
8
|
+
private readonly baseUrl;
|
|
9
|
+
private token;
|
|
10
|
+
constructor(baseUrl: string);
|
|
11
|
+
/**
|
|
12
|
+
* Set authentication token for requests
|
|
13
|
+
*/
|
|
14
|
+
setAuthToken(token: string | null): void;
|
|
15
|
+
/**
|
|
16
|
+
* Make authenticated fetch request to server
|
|
17
|
+
*/
|
|
18
|
+
fetch(endpoint: string, options?: RequestInit): Promise<Response>;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=wire.d.ts.map
|
|
@@ -1,55 +1,52 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
get: <ArcElement extends ArcContextElementAny>(element: ArcElement) => ArcElement["commandContext"] extends infer CommandContext ? CommandContext extends (...args: any) => any ? ReturnType<CommandContext> : never : never;
|
|
20
|
-
};
|
|
21
|
-
export type RemoveFalseAndResolvedPromiseFromArray<T extends any[]> = T extends [infer First, ...infer Rest] ? First extends false ? RemoveFalseAndResolvedPromiseFromArray<Rest> : First extends Promise<{
|
|
22
|
-
default: infer Inner;
|
|
23
|
-
}> ? RemoveFalseAndResolvedPromiseFromArray<[Inner, ...Rest]> : [First, ...RemoveFalseAndResolvedPromiseFromArray<Rest>] : [];
|
|
24
|
-
export type FindElementByName<E extends ArcContextElementAny[], Name extends string> = E extends [
|
|
25
|
-
infer First extends ArcContextElementAny,
|
|
26
|
-
...infer Rest extends ArcContextElementAny[]
|
|
27
|
-
] ? First["name"] extends Name ? First : FindElementByName<Rest, Name> : never;
|
|
28
|
-
export declare class ArcContext<const E extends ArcContextElementAny[]> {
|
|
29
|
-
readonly elements: E;
|
|
30
|
-
private elementsSet;
|
|
31
|
-
constructor(elements: E);
|
|
32
|
-
get<Name extends E[number]["name"]>(name: Name): FindElementByName<E, Name>;
|
|
33
|
-
getSyncListeners(eventType: string, authContext: AuthContext): EventListener<any>[];
|
|
34
|
-
getAsyncListeners(eventType: string, authContext: AuthContext): EventListener<any>[];
|
|
35
|
-
pipe<const NewElements extends (ArcContextElementAny | false | Promise<{
|
|
36
|
-
default: ArcContextElementAny;
|
|
37
|
-
}>)[]>(newElements: NewElements): ArcContext<[
|
|
38
|
-
...E,
|
|
39
|
-
...RemoveFalseAndResolvedPromiseFromArray<NewElements>
|
|
40
|
-
]>;
|
|
41
|
-
queryBuilder(queryContext: QueryBuilderContext, authContext: AuthContext): ArcContextElementMethodReturnType<E, "queryBuilder">;
|
|
42
|
-
commandContext(dataStorage: DataStorage, publishEvent: PublishEventFunction, authContext: AuthContext): ArcCommandContext<E>;
|
|
1
|
+
import type { ArcContextElement, ArcContextElementAny } from "../context-element/context-element";
|
|
2
|
+
/**
|
|
3
|
+
* Arc Context
|
|
4
|
+
*
|
|
5
|
+
* A collection of context elements (commands, events, views, listeners).
|
|
6
|
+
* Provides a simple container for organizing related elements.
|
|
7
|
+
*/
|
|
8
|
+
export declare class ArcContext<const Elements extends ArcContextElement<any>[]> {
|
|
9
|
+
readonly elements: Elements;
|
|
10
|
+
readonly elementMap: Map<string, Elements[number]>;
|
|
11
|
+
constructor(elements: Elements);
|
|
12
|
+
/**
|
|
13
|
+
* Get an element by name
|
|
14
|
+
*
|
|
15
|
+
* @param name - The name of the element to retrieve
|
|
16
|
+
* @returns The element if found, undefined otherwise
|
|
17
|
+
*/
|
|
18
|
+
get(name: string): Elements[number] | undefined;
|
|
43
19
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Create a new context from an array of elements
|
|
22
|
+
*
|
|
23
|
+
* @param elements - Array of context elements (commands, events, views, listeners)
|
|
24
|
+
* @returns New context instance
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* const myContext = context([
|
|
29
|
+
* myCommand,
|
|
30
|
+
* myEvent,
|
|
31
|
+
* myView,
|
|
32
|
+
* ]);
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare function context<const Elements extends ArcContextElement<any>[]>(elements: Elements): ArcContext<Elements>;
|
|
36
|
+
/**
|
|
37
|
+
* Merge multiple contexts into one
|
|
38
|
+
*
|
|
39
|
+
* @param contexts - Contexts to merge
|
|
40
|
+
* @returns New context with all elements from all contexts
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const mergedContext = contextMerge(authContext, taskContext, chatContext);
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
53
47
|
export declare function contextMerge<const Contexts extends ArcContextAny[]>(...contexts: Contexts): ArcContext<Contexts[number]["elements"]>;
|
|
54
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Type alias for any context (used in collections)
|
|
50
|
+
*/
|
|
51
|
+
export type ArcContextAny = ArcContext<ArcContextElementAny[]>;
|
|
55
52
|
//# sourceMappingURL=context.d.ts.map
|
package/dist/context/index.d.ts
CHANGED
|
@@ -1,10 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export * from "./context";
|
|
3
|
-
export * from "./element";
|
|
4
|
-
export * from "./event";
|
|
5
|
-
export * from "./query";
|
|
6
|
-
export * from "./query-builder-context";
|
|
7
|
-
export * from "./query-builders";
|
|
8
|
-
export * from "./query-cache";
|
|
9
|
-
export * from "./reactive-query";
|
|
1
|
+
export { ArcContext, context, contextMerge, type ArcContextAny, } from "./context";
|
|
10
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { ArcToken, ArcTokenAny } from "../../token/token";
|
|
2
|
+
import type { $type } from "../../utils/types/get-type";
|
|
3
|
+
import type { ArcContextElement } from "../context-element";
|
|
4
|
+
import type { CommandProtection } from "./command-data";
|
|
5
|
+
/**
|
|
6
|
+
* Build context object from query elements
|
|
7
|
+
* Each element gets its context by calling element.queryContext(adapters)
|
|
8
|
+
* Only includes elements that have queryContext method
|
|
9
|
+
*/
|
|
10
|
+
type QueryContext<Elements extends ArcContextElement<any>[]> = {
|
|
11
|
+
[K in Elements[number] as K["queryContext"] extends (...args: any) => any ? K["name"] : never]: K["queryContext"] extends (...args: any) => infer R ? R : never;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Build context object from mutation elements
|
|
15
|
+
* Each element gets its context by calling element.mutateContext(adapters)
|
|
16
|
+
* Only includes elements that have mutateContext method
|
|
17
|
+
*/
|
|
18
|
+
type MutationContext<Elements extends ArcContextElement<any>[]> = {
|
|
19
|
+
[K in Elements[number] as K["mutateContext"] extends (...args: any) => any ? K["name"] : never]: K["mutateContext"] extends (...args: any) => infer R ? R : never;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Extract token params type from a token
|
|
23
|
+
*/
|
|
24
|
+
type TokenParams<T extends ArcTokenAny> = T extends {
|
|
25
|
+
paramsSchema: infer P extends {
|
|
26
|
+
deserialize: (...args: any) => any;
|
|
27
|
+
};
|
|
28
|
+
} ? $type<P> : Record<string, any>;
|
|
29
|
+
/**
|
|
30
|
+
* Auth context type for protected commands
|
|
31
|
+
* Provides access to token params from the authenticated user
|
|
32
|
+
*/
|
|
33
|
+
export type AuthContext<T extends ArcTokenAny> = {
|
|
34
|
+
params: TokenParams<T>;
|
|
35
|
+
tokenName: T extends ArcToken<infer Name, any, any, any> ? Name : string;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Extract union of all token types from protections array
|
|
39
|
+
*/
|
|
40
|
+
type ProtectionTokens<Protections extends CommandProtection[]> = Protections[number]["token"];
|
|
41
|
+
/**
|
|
42
|
+
* Get function type for backward compatibility
|
|
43
|
+
* Allows: ctx.get(view).findOne() or ctx.get(event).emit()
|
|
44
|
+
* Returns any for flexibility - the runtime will provide the correct context
|
|
45
|
+
*/
|
|
46
|
+
type GetFunction<_QueryElements extends ArcContextElement<any>[], _MutationElements extends ArcContextElement<any>[]> = {
|
|
47
|
+
get: <T extends ArcContextElement<any>>(element: T) => any;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Command context provided to command handlers
|
|
51
|
+
* Combines query and mutation contexts from all elements
|
|
52
|
+
*
|
|
53
|
+
* Each element is accessible by its name:
|
|
54
|
+
* - Query elements: ctx.myView.findOne(...)
|
|
55
|
+
* - Mutation elements: ctx.myEvent.emit(...)
|
|
56
|
+
* - Auth context: ctx.$auth.params (only for protected commands)
|
|
57
|
+
* - Get function: ctx.get(element) for backward compatibility
|
|
58
|
+
*/
|
|
59
|
+
export type ArcCommandContext<QueryElements extends ArcContextElement<any>[], MutationElements extends ArcContextElement<any>[], Protections extends CommandProtection[] = []> = QueryContext<QueryElements> & MutationContext<MutationElements> & GetFunction<QueryElements, MutationElements> & (Protections extends [] ? object : {
|
|
60
|
+
$auth: AuthContext<ProtectionTokens<Protections>>;
|
|
61
|
+
});
|
|
62
|
+
/**
|
|
63
|
+
* Helper type to extract command context from command data
|
|
64
|
+
*/
|
|
65
|
+
export type ArcCommandContextFromData<Data> = Data extends {
|
|
66
|
+
queryElements: infer Q extends ArcContextElement<any>[];
|
|
67
|
+
mutationElements: infer M extends ArcContextElement<any>[];
|
|
68
|
+
protections?: infer P extends CommandProtection[];
|
|
69
|
+
} ? ArcCommandContext<Q, M, P extends undefined ? [] : P> : never;
|
|
70
|
+
export {};
|
|
71
|
+
//# sourceMappingURL=command-context.d.ts.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ArcObjectAny } from "../../elements/object";
|
|
2
|
+
import type { ArcTokenAny } from "../../token/token";
|
|
3
|
+
import type { TokenInstanceAny } from "../../token/token-instance";
|
|
4
|
+
import type { ArcContextElement } from "../context-element";
|
|
5
|
+
import type { ArcCommandHandler } from "./command-handler";
|
|
6
|
+
/**
|
|
7
|
+
* Protection check function for commands
|
|
8
|
+
* Receives token instance and returns whether access is allowed
|
|
9
|
+
*/
|
|
10
|
+
export type CommandProtectionCheck<T extends ArcTokenAny> = (tokenInstance: TokenInstanceAny) => boolean | Promise<boolean>;
|
|
11
|
+
/**
|
|
12
|
+
* Protection configuration for a command
|
|
13
|
+
*/
|
|
14
|
+
export type CommandProtection = {
|
|
15
|
+
token: ArcTokenAny;
|
|
16
|
+
check: CommandProtectionCheck<any>;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Command data configuration
|
|
20
|
+
* Contains all generic types and non-generic configuration in one object
|
|
21
|
+
*/
|
|
22
|
+
export type ArcCommandData = {
|
|
23
|
+
name: string;
|
|
24
|
+
params: ArcObjectAny | null;
|
|
25
|
+
results: ArcObjectAny[];
|
|
26
|
+
queryElements: ArcContextElement<any>[];
|
|
27
|
+
mutationElements: ArcContextElement<any>[];
|
|
28
|
+
description?: string;
|
|
29
|
+
isPublic?: boolean;
|
|
30
|
+
handler?: ArcCommandHandler<any, any, any> | false;
|
|
31
|
+
protections?: CommandProtection[];
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=command-data.d.ts.map
|