@rool-dev/client 0.3.1 → 0.4.0-dev.22f8ef0

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.
@@ -0,0 +1,256 @@
1
+ import { EventEmitter } from './event-emitter.js';
2
+ import type { GraphQLClient } from './graphql.js';
3
+ import type { MediaClient } from './media.js';
4
+ import type { RoolSpaceData, RoolObject, JSONPatchOp, SpaceEvents, RoolUserRole, RoolUser, PromptOptions, MediaItem } from './types.js';
5
+ export declare function generateEntityId(): string;
6
+ interface SpaceConfig {
7
+ id: string;
8
+ name: string;
9
+ role: RoolUserRole;
10
+ initialData: RoolSpaceData;
11
+ graphqlClient: GraphQLClient;
12
+ mediaClient: MediaClient;
13
+ onRegisterForEvents: (spaceId: string, space: RoolSpace) => void;
14
+ onUnregisterFromEvents: (spaceId: string) => void;
15
+ }
16
+ /**
17
+ * First-class Space object.
18
+ *
19
+ * Features:
20
+ * - High-level object/link operations
21
+ * - Built-in undo/redo with checkpoints
22
+ * - Metadata management
23
+ * - Event emission for state changes
24
+ * - Real-time subscription support
25
+ */
26
+ export declare class RoolSpace extends EventEmitter<SpaceEvents> {
27
+ private _id;
28
+ private _name;
29
+ private _role;
30
+ private _data;
31
+ private graphqlClient;
32
+ private mediaClient;
33
+ private onRegisterForEvents;
34
+ private onUnregisterFromEvents;
35
+ private undoStack;
36
+ private redoStack;
37
+ private _isSubscribed;
38
+ constructor(config: SpaceConfig);
39
+ get id(): string;
40
+ get name(): string;
41
+ get role(): RoolUserRole;
42
+ get isReadOnly(): boolean;
43
+ get isSubscribed(): boolean;
44
+ /**
45
+ * Rename this space.
46
+ */
47
+ rename(newName: string): Promise<void>;
48
+ /**
49
+ * Subscribe to real-time updates for this space.
50
+ * Registers with the client for event routing.
51
+ */
52
+ subscribe(): void;
53
+ /**
54
+ * Unsubscribe from real-time updates.
55
+ */
56
+ unsubscribe(): void;
57
+ /**
58
+ * Close this space and clean up resources.
59
+ */
60
+ close(): void;
61
+ /**
62
+ * Create a checkpoint for undo.
63
+ * Call this before a user action to capture the current state.
64
+ */
65
+ checkpoint(label?: string): void;
66
+ /**
67
+ * Check if undo is available.
68
+ */
69
+ canUndo(): boolean;
70
+ /**
71
+ * Check if redo is available.
72
+ */
73
+ canRedo(): boolean;
74
+ /**
75
+ * Undo to the previous checkpoint.
76
+ * @returns true if undo was performed
77
+ */
78
+ undo(): Promise<boolean>;
79
+ /**
80
+ * Redo a previously undone action.
81
+ * @returns true if redo was performed
82
+ */
83
+ redo(): Promise<boolean>;
84
+ /**
85
+ * Clear undo/redo history.
86
+ * Called when external changes invalidate local history.
87
+ */
88
+ clearHistory(): void;
89
+ /**
90
+ * Get an object's data by ID.
91
+ * Returns just the data portion (RoolObject), not the full entry with meta/links.
92
+ * @throws Error if object not found
93
+ */
94
+ getObject(objectId: string): RoolObject;
95
+ /**
96
+ * Get an object's data by ID, or undefined if not found.
97
+ */
98
+ getObjectOrUndefined(objectId: string): RoolObject | undefined;
99
+ /**
100
+ * Get an object's metadata (position, UI state, etc).
101
+ */
102
+ getObjectMeta(objectId: string): Record<string, unknown>;
103
+ /**
104
+ * Query objects by field values.
105
+ * Returns all objects where all specified fields match the given values.
106
+ *
107
+ * @example
108
+ * space.queryObjects({ type: 'article' })
109
+ * space.queryObjects({ type: 'task', status: 'done' })
110
+ */
111
+ queryObjects(where: Record<string, unknown>): RoolObject[];
112
+ /**
113
+ * Get all object IDs.
114
+ */
115
+ getObjectIds(): string[];
116
+ /**
117
+ * Create a new object with optional AI generation.
118
+ * @param options.data - Object data fields (any key-value pairs). Use {{placeholder}} for AI-generated content.
119
+ * @param options.meta - Client-private metadata (optional). Hidden from AI operations.
120
+ * @param options.prompt - AI prompt for content generation (optional).
121
+ * @returns The generated object ID
122
+ */
123
+ createObject(options: {
124
+ data: Record<string, unknown>;
125
+ meta?: Record<string, unknown>;
126
+ prompt?: string;
127
+ }): Promise<{
128
+ id: string;
129
+ message: string;
130
+ }>;
131
+ /**
132
+ * Update an existing object.
133
+ * @param objectId - The ID of the object to update
134
+ * @param options.data - Fields to add or update. Use {{placeholder}} for AI-generated content.
135
+ * @param options.meta - Client-private metadata to merge. Hidden from AI operations.
136
+ * @param options.prompt - AI prompt for content editing (optional).
137
+ */
138
+ updateObject(objectId: string, options: {
139
+ data?: Record<string, unknown>;
140
+ meta?: Record<string, unknown>;
141
+ prompt?: string;
142
+ }): Promise<string>;
143
+ /**
144
+ * Delete objects by IDs.
145
+ * Outbound links are automatically deleted with the object.
146
+ * Inbound links become orphans (tolerated).
147
+ */
148
+ deleteObjects(objectIds: string[]): Promise<void>;
149
+ /**
150
+ * Create a link between objects.
151
+ * Links are stored on the source object.
152
+ */
153
+ link(sourceId: string, targetId: string, linkType: string): Promise<void>;
154
+ /**
155
+ * Remove a link between two objects.
156
+ * @param linkType - Optional: if provided, only removes that type; otherwise removes all links between the objects
157
+ * @returns true if any links were removed
158
+ */
159
+ unlink(sourceId: string, targetId: string, linkType?: string): Promise<boolean>;
160
+ /**
161
+ * Get parent object IDs (objects that have links pointing TO this object).
162
+ * @param linkType - Optional filter by link type
163
+ */
164
+ getParents(objectId: string, linkType?: string): string[];
165
+ /**
166
+ * Get child object IDs (objects that this object has links pointing TO).
167
+ * Filters out orphan targets (targets that don't exist).
168
+ * @param linkType - Optional filter by link type
169
+ */
170
+ getChildren(objectId: string, linkType?: string): string[];
171
+ /**
172
+ * Get all child object IDs including orphans (targets that may not exist).
173
+ * @param linkType - Optional filter by link type
174
+ */
175
+ getChildrenIncludingOrphans(objectId: string, linkType?: string): string[];
176
+ /**
177
+ * Set a space-level metadata value.
178
+ * Metadata is stored in meta and hidden from AI operations.
179
+ */
180
+ setMetadata(key: string, value: unknown): void;
181
+ /**
182
+ * Get a space-level metadata value.
183
+ */
184
+ getMetadata(key: string): unknown;
185
+ /**
186
+ * Get all space-level metadata.
187
+ */
188
+ getAllMetadata(): Record<string, unknown>;
189
+ /**
190
+ * Send a prompt to the AI agent for space manipulation.
191
+ */
192
+ prompt(prompt: string, options?: PromptOptions): Promise<string | null>;
193
+ /**
194
+ * List users with access to this space.
195
+ */
196
+ listUsers(): Promise<RoolUser[]>;
197
+ /**
198
+ * Add a user to this space with specified role.
199
+ */
200
+ addUser(userId: string, role: RoolUserRole): Promise<void>;
201
+ /**
202
+ * Remove a user from this space.
203
+ */
204
+ removeUser(userId: string): Promise<void>;
205
+ /**
206
+ * List all media files for this space.
207
+ */
208
+ listMedia(): Promise<MediaItem[]>;
209
+ /**
210
+ * Upload a file to this space.
211
+ */
212
+ uploadMedia(file: File | Blob | {
213
+ data: string;
214
+ contentType: string;
215
+ }): Promise<MediaItem>;
216
+ /**
217
+ * Get the URL for a media file.
218
+ */
219
+ getMediaUrl(uuid: string): string;
220
+ /**
221
+ * Download a media file as a Blob.
222
+ */
223
+ downloadMedia(uuid: string): Promise<Blob>;
224
+ /**
225
+ * Delete a media file.
226
+ */
227
+ deleteMedia(uuid: string): Promise<void>;
228
+ /**
229
+ * Get the full space data.
230
+ * Use sparingly - prefer specific operations.
231
+ */
232
+ getData(): RoolSpaceData;
233
+ /**
234
+ * Handle a patch event from another client.
235
+ * @internal
236
+ */
237
+ handleRemotePatch(patch: JSONPatchOp[], source?: 'user' | 'agent'): void;
238
+ /**
239
+ * Parse JSON patch operations and emit semantic events.
240
+ * @internal
241
+ */
242
+ private emitSemanticEventsFromPatch;
243
+ /**
244
+ * Handle a full reload from server.
245
+ * @internal
246
+ */
247
+ handleRemoteChange(newData: RoolSpaceData): void;
248
+ /**
249
+ * Update the name from external source.
250
+ * @internal
251
+ */
252
+ handleRemoteRename(newName: string): void;
253
+ private resyncFromServer;
254
+ }
255
+ export {};
256
+ //# sourceMappingURL=space.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"space.d.ts","sourceRoot":"","sources":["../src/space.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,EAAE,aAAa,EAAE,MAA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