@soulcraft/brainy 5.2.1 → 5.3.1

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,347 @@
1
+ /**
2
+ * VersioningAPI - Public API for Entity Versioning (v5.3.0)
3
+ *
4
+ * User-friendly wrapper around VersionManager with:
5
+ * - Clean, simple API
6
+ * - Smart defaults
7
+ * - Error handling
8
+ * - Type safety
9
+ *
10
+ * Usage:
11
+ * const version = await brain.versions.save('entity-123', { tag: 'v1.0' })
12
+ * const versions = await brain.versions.list('entity-123')
13
+ * await brain.versions.restore('entity-123', 5)
14
+ * const diff = await brain.versions.compare('entity-123', 2, 5)
15
+ *
16
+ * NO MOCKS - Production implementation
17
+ */
18
+ import type { EntityVersion, SaveVersionOptions, RestoreOptions, PruneOptions, VersionQuery } from './VersionManager.js';
19
+ import type { VersionDiff } from './VersionDiff.js';
20
+ /**
21
+ * VersioningAPI - User-friendly versioning interface
22
+ */
23
+ export declare class VersioningAPI {
24
+ private manager;
25
+ private brain;
26
+ constructor(brain: any);
27
+ /**
28
+ * Save current state of entity as a new version
29
+ *
30
+ * Creates a version snapshot of the current entity state.
31
+ * Automatically handles deduplication - if content hasn't changed,
32
+ * returns the last version instead of creating a duplicate.
33
+ *
34
+ * @param entityId Entity ID to version
35
+ * @param options Save options
36
+ * @returns Created (or existing) version metadata
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * // Simple save
41
+ * const version = await brain.versions.save('user-123')
42
+ *
43
+ * // Save with tag and description
44
+ * const version = await brain.versions.save('user-123', {
45
+ * tag: 'v1.0',
46
+ * description: 'Initial release',
47
+ * author: 'alice'
48
+ * })
49
+ *
50
+ * // Save and create commit
51
+ * const version = await brain.versions.save('user-123', {
52
+ * tag: 'milestone-1',
53
+ * createCommit: true,
54
+ * commitMessage: 'Milestone 1 complete'
55
+ * })
56
+ * ```
57
+ */
58
+ save(entityId: string, options?: SaveVersionOptions): Promise<EntityVersion>;
59
+ /**
60
+ * List all versions of an entity
61
+ *
62
+ * Returns versions sorted by version number (newest first).
63
+ * Supports filtering by tag, date range, and pagination.
64
+ *
65
+ * @param entityId Entity ID
66
+ * @param options Query options
67
+ * @returns List of versions (newest first)
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * // Get all versions
72
+ * const versions = await brain.versions.list('user-123')
73
+ *
74
+ * // Get last 10 versions
75
+ * const recent = await brain.versions.list('user-123', { limit: 10 })
76
+ *
77
+ * // Get tagged versions
78
+ * const tagged = await brain.versions.list('user-123', { tag: 'v*' })
79
+ *
80
+ * // Get versions from last 30 days
81
+ * const recent = await brain.versions.list('user-123', {
82
+ * startDate: Date.now() - 30 * 24 * 60 * 60 * 1000
83
+ * })
84
+ * ```
85
+ */
86
+ list(entityId: string, options?: Partial<VersionQuery>): Promise<EntityVersion[]>;
87
+ /**
88
+ * Get specific version of an entity
89
+ *
90
+ * @param entityId Entity ID
91
+ * @param version Version number (1-indexed)
92
+ * @returns Version metadata or null if not found
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * const version = await brain.versions.getVersion('user-123', 5)
97
+ * if (version) {
98
+ * console.log(`Version ${version.version} created at ${new Date(version.timestamp)}`)
99
+ * }
100
+ * ```
101
+ */
102
+ getVersion(entityId: string, version: number): Promise<EntityVersion | null>;
103
+ /**
104
+ * Get version by tag
105
+ *
106
+ * @param entityId Entity ID
107
+ * @param tag Version tag
108
+ * @returns Version metadata or null if not found
109
+ *
110
+ * @example
111
+ * ```typescript
112
+ * const version = await brain.versions.getVersionByTag('user-123', 'v1.0')
113
+ * ```
114
+ */
115
+ getVersionByTag(entityId: string, tag: string): Promise<EntityVersion | null>;
116
+ /**
117
+ * Get latest version of an entity
118
+ *
119
+ * @param entityId Entity ID
120
+ * @returns Latest version or null if no versions exist
121
+ *
122
+ * @example
123
+ * ```typescript
124
+ * const latest = await brain.versions.getLatest('user-123')
125
+ * ```
126
+ */
127
+ getLatest(entityId: string): Promise<EntityVersion | null>;
128
+ /**
129
+ * Get version content without restoring
130
+ *
131
+ * Allows you to preview version data without modifying the current entity.
132
+ *
133
+ * @param entityId Entity ID
134
+ * @param version Version number or tag
135
+ * @returns Version content
136
+ *
137
+ * @example
138
+ * ```typescript
139
+ * // Preview version 5 without restoring
140
+ * const oldData = await brain.versions.getContent('user-123', 5)
141
+ * console.log('Version 5 had name:', oldData.name)
142
+ *
143
+ * // Compare with current
144
+ * const current = await brain.getNounMetadata('user-123')
145
+ * console.log('Current name:', current.name)
146
+ * ```
147
+ */
148
+ getContent(entityId: string, version: number | string): Promise<any>;
149
+ /**
150
+ * Restore entity to a specific version
151
+ *
152
+ * Overwrites current entity state with the specified version.
153
+ * Optionally creates a snapshot before restoring for undo capability.
154
+ *
155
+ * @param entityId Entity ID
156
+ * @param version Version number or tag to restore to
157
+ * @param options Restore options
158
+ * @returns Restored version metadata
159
+ *
160
+ * @example
161
+ * ```typescript
162
+ * // Simple restore
163
+ * await brain.versions.restore('user-123', 5)
164
+ *
165
+ * // Restore with safety snapshot
166
+ * await brain.versions.restore('user-123', 5, {
167
+ * createSnapshot: true,
168
+ * snapshotTag: 'before-restore'
169
+ * })
170
+ *
171
+ * // Restore by tag
172
+ * await brain.versions.restore('user-123', 'v1.0')
173
+ * ```
174
+ */
175
+ restore(entityId: string, version: number | string, options?: RestoreOptions): Promise<EntityVersion>;
176
+ /**
177
+ * Compare two versions of an entity
178
+ *
179
+ * Generates a deep diff showing added, removed, modified, and type-changed fields.
180
+ *
181
+ * @param entityId Entity ID
182
+ * @param fromVersion Version number or tag (older)
183
+ * @param toVersion Version number or tag (newer)
184
+ * @returns Diff between versions
185
+ *
186
+ * @example
187
+ * ```typescript
188
+ * // Compare version 2 to version 5
189
+ * const diff = await brain.versions.compare('user-123', 2, 5)
190
+ *
191
+ * console.log(`Added fields: ${diff.added.length}`)
192
+ * console.log(`Removed fields: ${diff.removed.length}`)
193
+ * console.log(`Modified fields: ${diff.modified.length}`)
194
+ *
195
+ * // Print human-readable diff
196
+ * import { formatDiff } from './VersionDiff.js'
197
+ * console.log(formatDiff(diff))
198
+ * ```
199
+ */
200
+ compare(entityId: string, fromVersion: number | string, toVersion: number | string): Promise<VersionDiff>;
201
+ /**
202
+ * Prune old versions based on retention policy
203
+ *
204
+ * Removes old versions while preserving recent and tagged versions.
205
+ * Use dryRun to preview what would be deleted without actually deleting.
206
+ *
207
+ * @param entityId Entity ID (or '*' for all entities - NOT IMPLEMENTED YET)
208
+ * @param options Prune options
209
+ * @returns Count of deleted and kept versions
210
+ *
211
+ * @example
212
+ * ```typescript
213
+ * // Keep last 10 versions, delete rest
214
+ * const result = await brain.versions.prune('user-123', {
215
+ * keepRecent: 10
216
+ * })
217
+ * console.log(`Deleted ${result.deleted} versions`)
218
+ *
219
+ * // Keep last 30 days, preserve tagged versions
220
+ * const result = await brain.versions.prune('user-123', {
221
+ * keepAfter: Date.now() - 30 * 24 * 60 * 60 * 1000,
222
+ * keepTagged: true
223
+ * })
224
+ *
225
+ * // Dry run - see what would be deleted
226
+ * const result = await brain.versions.prune('user-123', {
227
+ * keepRecent: 5,
228
+ * dryRun: true
229
+ * })
230
+ * console.log(`Would delete ${result.deleted} versions`)
231
+ * ```
232
+ */
233
+ prune(entityId: string, options: PruneOptions): Promise<{
234
+ deleted: number;
235
+ kept: number;
236
+ }>;
237
+ /**
238
+ * Get version count for an entity
239
+ *
240
+ * @param entityId Entity ID
241
+ * @returns Number of versions
242
+ *
243
+ * @example
244
+ * ```typescript
245
+ * const count = await brain.versions.count('user-123')
246
+ * console.log(`Entity has ${count} versions`)
247
+ * ```
248
+ */
249
+ count(entityId: string): Promise<number>;
250
+ /**
251
+ * Check if entity has any versions
252
+ *
253
+ * @param entityId Entity ID
254
+ * @returns True if entity has versions
255
+ *
256
+ * @example
257
+ * ```typescript
258
+ * if (await brain.versions.hasVersions('user-123')) {
259
+ * console.log('Entity is versioned')
260
+ * }
261
+ * ```
262
+ */
263
+ hasVersions(entityId: string): Promise<boolean>;
264
+ /**
265
+ * Clear all versions for an entity
266
+ *
267
+ * WARNING: This permanently deletes all version history!
268
+ *
269
+ * @param entityId Entity ID
270
+ * @returns Number of versions deleted
271
+ *
272
+ * @example
273
+ * ```typescript
274
+ * const deleted = await brain.versions.clear('user-123')
275
+ * console.log(`Deleted ${deleted} versions`)
276
+ * ```
277
+ */
278
+ clear(entityId: string): Promise<number>;
279
+ /**
280
+ * Quick save with auto-generated tag
281
+ *
282
+ * Generates tag in format: 'auto-{timestamp}'
283
+ *
284
+ * @param entityId Entity ID
285
+ * @param description Optional description
286
+ * @returns Created version
287
+ */
288
+ quickSave(entityId: string, description?: string): Promise<EntityVersion>;
289
+ /**
290
+ * Undo last change (restore to previous version)
291
+ *
292
+ * Safely restores to previous version with automatic snapshot.
293
+ *
294
+ * @param entityId Entity ID
295
+ * @returns Restored version metadata
296
+ */
297
+ undo(entityId: string): Promise<EntityVersion | null>;
298
+ /**
299
+ * Get version history summary
300
+ *
301
+ * @param entityId Entity ID
302
+ * @returns Summary statistics
303
+ */
304
+ history(entityId: string): Promise<{
305
+ total: number;
306
+ oldest?: EntityVersion;
307
+ newest?: EntityVersion;
308
+ tagged: number;
309
+ branches: string[];
310
+ }>;
311
+ /**
312
+ * Revert to previous version (alias for undo with better semantics)
313
+ *
314
+ * Restores entity to the previous version with automatic safety snapshot.
315
+ *
316
+ * @param entityId Entity ID
317
+ * @returns Restored version or null if not possible
318
+ *
319
+ * @example
320
+ * ```typescript
321
+ * // Made a mistake? Revert!
322
+ * await brain.update('user-123', { name: 'Wrong Name' })
323
+ * await brain.versions.revert('user-123') // Back to previous state
324
+ * ```
325
+ */
326
+ revert(entityId: string): Promise<EntityVersion | null>;
327
+ /**
328
+ * Tag an existing version
329
+ *
330
+ * Updates the tag of an existing version.
331
+ * Note: This creates a new version with the tag, not modifying the existing one.
332
+ *
333
+ * @param entityId Entity ID
334
+ * @param version Version number
335
+ * @param tag New tag
336
+ * @returns Updated version
337
+ */
338
+ tag(entityId: string, version: number, tag: string): Promise<EntityVersion>;
339
+ /**
340
+ * Get diff between entity's current state and a version
341
+ *
342
+ * @param entityId Entity ID
343
+ * @param version Version to compare against
344
+ * @returns Diff showing changes
345
+ */
346
+ diffWithCurrent(entityId: string, version: number | string): Promise<VersionDiff>;
347
+ }