@liorandb/core 1.0.17 → 1.0.19

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.
@@ -1,63 +1,136 @@
1
- /* ----------------------------- MANAGER OPTIONS ----------------------------- */
1
+ /* ============================= MANAGER OPTIONS ============================= */
2
2
 
3
3
  export interface LioranManagerOptions {
4
- rootPath?: string
5
- encryptionKey?: string | Buffer
6
- ipc?: boolean
4
+ rootPath?: string;
5
+ encryptionKey?: string | Buffer;
6
+ ipc?: boolean;
7
+
8
+ /**
9
+ * If true, database auto-applies pending migrations on startup.
10
+ */
11
+ autoMigrate?: boolean;
7
12
  }
8
13
 
9
- /* ----------------------------- UPDATE OPTIONS ----------------------------- */
14
+ /* ============================= UPDATE OPTIONS ============================= */
10
15
 
11
16
  export interface UpdateOptions {
12
- upsert?: boolean
17
+ upsert?: boolean;
18
+
19
+ /**
20
+ * If true, returns the modified document instead of the original.
21
+ */
22
+ returnNew?: boolean;
13
23
  }
14
24
 
15
- /* --------------------------------- QUERY --------------------------------- */
25
+ /* ================================ QUERY =================================== */
16
26
 
17
- export type Query<T = any> = Partial<T> & {
18
- [key: string]: any
19
- }
27
+ export type Query<T = any> =
28
+ | Partial<T>
29
+ | {
30
+ [K in keyof T]?: any;
31
+ } & {
32
+ [key: string]: any;
33
+ };
20
34
 
21
- /* --------------------------------- INDEX --------------------------------- */
35
+ /* ================================ INDEX =================================== */
22
36
 
23
- export type IndexType = "hash" | "btree"
37
+ export type IndexType = "hash" | "btree";
24
38
 
25
39
  export interface IndexDefinition<T = any> {
26
- field: keyof T | string
27
- unique?: boolean
28
- sparse?: boolean
29
- type?: IndexType
40
+ field: keyof T | string;
41
+ unique?: boolean;
42
+ sparse?: boolean;
43
+ type?: IndexType;
30
44
  }
31
45
 
32
46
  export interface IndexMetadata {
33
- field: string
34
- unique: boolean
35
- sparse: boolean
36
- type: IndexType
37
- createdAt: number
47
+ field: string;
48
+ unique: boolean;
49
+ sparse: boolean;
50
+ type: IndexType;
51
+ createdAt: number;
38
52
  }
39
53
 
40
- /* ----------------------------- QUERY PLANNER ------------------------------ */
54
+ /* =========================== QUERY PLANNER ================================ */
41
55
 
42
56
  export interface QueryExplainPlan {
43
- indexUsed?: string
44
- indexType?: IndexType
45
- scannedDocuments: number
46
- returnedDocuments: number
47
- executionTimeMs: number
57
+ indexUsed?: string;
58
+ indexType?: IndexType;
59
+ scannedDocuments: number;
60
+ returnedDocuments: number;
61
+ executionTimeMs: number;
62
+ }
63
+
64
+ /* ========================== SCHEMA VERSIONING ============================= */
65
+
66
+ /**
67
+ * Per-collection document schema version
68
+ */
69
+ export type SchemaVersion = number;
70
+
71
+ /**
72
+ * Collection-level migration definition
73
+ */
74
+ export interface CollectionMigration<T = any> {
75
+ from: SchemaVersion;
76
+ to: SchemaVersion;
77
+ migrate: (doc: any) => T;
78
+ }
79
+
80
+ /**
81
+ * Database-level migration definition
82
+ */
83
+ export interface DatabaseMigration {
84
+ from: string;
85
+ to: string;
86
+ migrate: () => Promise<void>;
48
87
  }
49
88
 
50
- /* ------------------------------ COLLECTION -------------------------------- */
89
+ /* ============================== COLLECTION ================================ */
90
+
91
+ export interface CollectionOptions<T = any> {
92
+ /**
93
+ * Zod schema used for validation
94
+ */
95
+ schema?: any;
96
+
97
+ /**
98
+ * Current document schema version
99
+ */
100
+ schemaVersion?: SchemaVersion;
101
+
102
+ /**
103
+ * Optional migrations for automatic document upgrading
104
+ */
105
+ migrations?: CollectionMigration<T>[];
106
+ }
51
107
 
52
108
  export interface CollectionIndexAPI<T = any> {
53
- createIndex(def: IndexDefinition<T>): Promise<void>
54
- dropIndex(field: keyof T | string): Promise<void>
55
- listIndexes(): Promise<IndexMetadata[]>
56
- rebuildIndexes(): Promise<void>
109
+ createIndex(def: IndexDefinition<T>): Promise<void>;
110
+ dropIndex(field: keyof T | string): Promise<void>;
111
+ listIndexes(): Promise<IndexMetadata[]>;
112
+ rebuildIndexes(): Promise<void>;
57
113
  }
58
114
 
59
- /* ------------------------------- DATABASE --------------------------------- */
115
+ /* =============================== DATABASE ================================= */
60
116
 
61
117
  export interface DatabaseIndexAPI {
62
- rebuildAllIndexes(): Promise<void>
118
+ rebuildAllIndexes(): Promise<void>;
119
+ }
120
+
121
+ /**
122
+ * Database migration coordination API
123
+ */
124
+ export interface DatabaseMigrationAPI {
125
+ migrate(
126
+ from: string,
127
+ to: string,
128
+ fn: () => Promise<void>
129
+ ): void;
130
+
131
+ applyMigrations(targetVersion: string): Promise<void>;
132
+
133
+ getSchemaVersion(): string;
134
+
135
+ setSchemaVersion(version: string): void;
63
136
  }